No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / asn1 / parse.y
blobf901124f13fe8da686750bd9f81031636f5cb4a2
1 /*
2 * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* $Heimdal: parse.y 21597 2007-07-16 18:48:58Z lha $
35 $NetBSD$ */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include "symbol.h"
45 #include "lex.h"
46 #include "gen_locl.h"
47 #include "der.h"
49 __RCSID("$Heimdal: parse.y 21597 2007-07-16 18:48:58Z lha $"
50 "$NetBSD$");
52 static Type *new_type (Typetype t);
53 static struct constraint_spec *new_constraint_spec(enum ctype);
54 static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype);
55 void yyerror (const char *);
56 static struct objid *new_objid(const char *label, int value);
57 static void add_oid_to_tail(struct objid *, struct objid *);
58 static void fix_labels(Symbol *s);
60 struct string_list {
61 char *string;
62 struct string_list *next;
67 %union {
68 int constant;
69 struct value *value;
70 struct range *range;
71 char *name;
72 Type *type;
73 Member *member;
74 struct objid *objid;
75 char *defval;
76 struct string_list *sl;
77 struct tagtype tag;
78 struct memhead *members;
79 struct constraint_spec *constraint_spec;
82 %token kw_ABSENT
83 %token kw_ABSTRACT_SYNTAX
84 %token kw_ALL
85 %token kw_APPLICATION
86 %token kw_AUTOMATIC
87 %token kw_BEGIN
88 %token kw_BIT
89 %token kw_BMPString
90 %token kw_BOOLEAN
91 %token kw_BY
92 %token kw_CHARACTER
93 %token kw_CHOICE
94 %token kw_CLASS
95 %token kw_COMPONENT
96 %token kw_COMPONENTS
97 %token kw_CONSTRAINED
98 %token kw_CONTAINING
99 %token kw_DEFAULT
100 %token kw_DEFINITIONS
101 %token kw_EMBEDDED
102 %token kw_ENCODED
103 %token kw_END
104 %token kw_ENUMERATED
105 %token kw_EXCEPT
106 %token kw_EXPLICIT
107 %token kw_EXPORTS
108 %token kw_EXTENSIBILITY
109 %token kw_EXTERNAL
110 %token kw_FALSE
111 %token kw_FROM
112 %token kw_GeneralString
113 %token kw_GeneralizedTime
114 %token kw_GraphicString
115 %token kw_IA5String
116 %token kw_IDENTIFIER
117 %token kw_IMPLICIT
118 %token kw_IMPLIED
119 %token kw_IMPORTS
120 %token kw_INCLUDES
121 %token kw_INSTANCE
122 %token kw_INTEGER
123 %token kw_INTERSECTION
124 %token kw_ISO646String
125 %token kw_MAX
126 %token kw_MIN
127 %token kw_MINUS_INFINITY
128 %token kw_NULL
129 %token kw_NumericString
130 %token kw_OBJECT
131 %token kw_OCTET
132 %token kw_OF
133 %token kw_OPTIONAL
134 %token kw_ObjectDescriptor
135 %token kw_PATTERN
136 %token kw_PDV
137 %token kw_PLUS_INFINITY
138 %token kw_PRESENT
139 %token kw_PRIVATE
140 %token kw_PrintableString
141 %token kw_REAL
142 %token kw_RELATIVE_OID
143 %token kw_SEQUENCE
144 %token kw_SET
145 %token kw_SIZE
146 %token kw_STRING
147 %token kw_SYNTAX
148 %token kw_T61String
149 %token kw_TAGS
150 %token kw_TRUE
151 %token kw_TYPE_IDENTIFIER
152 %token kw_TeletexString
153 %token kw_UNION
154 %token kw_UNIQUE
155 %token kw_UNIVERSAL
156 %token kw_UTCTime
157 %token kw_UTF8String
158 %token kw_UniversalString
159 %token kw_VideotexString
160 %token kw_VisibleString
161 %token kw_WITH
163 %token RANGE
164 %token EEQUAL
165 %token ELLIPSIS
167 %token <name> IDENTIFIER referencename
168 %token <name> STRING
170 %token <constant> NUMBER
171 %type <constant> SignedNumber
172 %type <constant> Class tagenv
174 %type <value> Value
175 %type <value> BuiltinValue
176 %type <value> IntegerValue
177 %type <value> BooleanValue
178 %type <value> ObjectIdentifierValue
179 %type <value> CharacterStringValue
180 %type <value> NullValue
181 %type <value> DefinedValue
182 %type <value> ReferencedValue
183 %type <value> Valuereference
185 %type <type> Type
186 %type <type> BuiltinType
187 %type <type> BitStringType
188 %type <type> BooleanType
189 %type <type> ChoiceType
190 %type <type> ConstrainedType
191 %type <type> EnumeratedType
192 %type <type> IntegerType
193 %type <type> NullType
194 %type <type> OctetStringType
195 %type <type> SequenceType
196 %type <type> SequenceOfType
197 %type <type> SetType
198 %type <type> SetOfType
199 %type <type> TaggedType
200 %type <type> ReferencedType
201 %type <type> DefinedType
202 %type <type> UsefulType
203 %type <type> ObjectIdentifierType
204 %type <type> CharacterStringType
205 %type <type> RestrictedCharactedStringType
207 %type <tag> Tag
209 %type <member> ComponentType
210 %type <member> NamedBit
211 %type <member> NamedNumber
212 %type <member> NamedType
213 %type <members> ComponentTypeList
214 %type <members> Enumerations
215 %type <members> NamedBitList
216 %type <members> NamedNumberList
218 %type <objid> objid objid_list objid_element objid_opt
219 %type <range> range size
221 %type <sl> referencenames
223 %type <constraint_spec> Constraint
224 %type <constraint_spec> ConstraintSpec
225 %type <constraint_spec> GeneralConstraint
226 %type <constraint_spec> ContentsConstraint
227 %type <constraint_spec> UserDefinedConstraint
231 %start ModuleDefinition
235 ModuleDefinition: IDENTIFIER objid_opt kw_DEFINITIONS TagDefault ExtensionDefault
236 EEQUAL kw_BEGIN ModuleBody kw_END
238 checkundefined();
242 TagDefault : kw_EXPLICIT kw_TAGS
243 | kw_IMPLICIT kw_TAGS
244 { error_message("implicit tagging is not supported"); }
245 | kw_AUTOMATIC kw_TAGS
246 { error_message("automatic tagging is not supported"); }
247 | /* empty */
250 ExtensionDefault: kw_EXTENSIBILITY kw_IMPLIED
251 { error_message("no extensibility options supported"); }
252 | /* empty */
255 ModuleBody : /* Exports */ Imports AssignmentList
256 | /* empty */
259 Imports : kw_IMPORTS SymbolsImported ';'
260 | /* empty */
263 SymbolsImported : SymbolsFromModuleList
264 | /* empty */
267 SymbolsFromModuleList: SymbolsFromModule
268 | SymbolsFromModuleList SymbolsFromModule
271 SymbolsFromModule: referencenames kw_FROM IDENTIFIER objid_opt
273 struct string_list *sl;
274 for(sl = $1; sl != NULL; sl = sl->next) {
275 Symbol *s = addsym(sl->string);
276 s->stype = Stype;
278 add_import($3);
282 AssignmentList : Assignment
283 | Assignment AssignmentList
286 Assignment : TypeAssignment
287 | ValueAssignment
290 referencenames : IDENTIFIER ',' referencenames
292 $$ = emalloc(sizeof(*$$));
293 $$->string = $1;
294 $$->next = $3;
296 | IDENTIFIER
298 $$ = emalloc(sizeof(*$$));
299 $$->string = $1;
300 $$->next = NULL;
304 TypeAssignment : IDENTIFIER EEQUAL Type
306 Symbol *s = addsym ($1);
307 s->stype = Stype;
308 s->type = $3;
309 fix_labels(s);
310 generate_type (s);
314 Type : BuiltinType
315 | ReferencedType
316 | ConstrainedType
319 BuiltinType : BitStringType
320 | BooleanType
321 | CharacterStringType
322 | ChoiceType
323 | EnumeratedType
324 | IntegerType
325 | NullType
326 | ObjectIdentifierType
327 | OctetStringType
328 | SequenceType
329 | SequenceOfType
330 | SetType
331 | SetOfType
332 | TaggedType
335 BooleanType : kw_BOOLEAN
337 $$ = new_tag(ASN1_C_UNIV, UT_Boolean,
338 TE_EXPLICIT, new_type(TBoolean));
342 range : '(' Value RANGE Value ')'
344 if($2->type != integervalue)
345 error_message("Non-integer used in first part of range");
346 if($2->type != integervalue)
347 error_message("Non-integer in second part of range");
348 $$ = ecalloc(1, sizeof(*$$));
349 $$->min = $2->u.integervalue;
350 $$->max = $4->u.integervalue;
352 | '(' Value RANGE kw_MAX ')'
354 if($2->type != integervalue)
355 error_message("Non-integer in first part of range");
356 $$ = ecalloc(1, sizeof(*$$));
357 $$->min = $2->u.integervalue;
358 $$->max = $2->u.integervalue - 1;
360 | '(' kw_MIN RANGE Value ')'
362 if($4->type != integervalue)
363 error_message("Non-integer in second part of range");
364 $$ = ecalloc(1, sizeof(*$$));
365 $$->min = $4->u.integervalue + 2;
366 $$->max = $4->u.integervalue;
368 | '(' Value ')'
370 if($2->type != integervalue)
371 error_message("Non-integer used in limit");
372 $$ = ecalloc(1, sizeof(*$$));
373 $$->min = $2->u.integervalue;
374 $$->max = $2->u.integervalue;
379 IntegerType : kw_INTEGER
381 $$ = new_tag(ASN1_C_UNIV, UT_Integer,
382 TE_EXPLICIT, new_type(TInteger));
384 | kw_INTEGER range
386 $$ = new_type(TInteger);
387 $$->range = $2;
388 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
390 | kw_INTEGER '{' NamedNumberList '}'
392 $$ = new_type(TInteger);
393 $$->members = $3;
394 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
398 NamedNumberList : NamedNumber
400 $$ = emalloc(sizeof(*$$));
401 ASN1_TAILQ_INIT($$);
402 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
404 | NamedNumberList ',' NamedNumber
406 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
407 $$ = $1;
409 | NamedNumberList ',' ELLIPSIS
410 { $$ = $1; } /* XXX used for Enumerations */
413 NamedNumber : IDENTIFIER '(' SignedNumber ')'
415 $$ = emalloc(sizeof(*$$));
416 $$->name = $1;
417 $$->gen_name = estrdup($1);
418 output_name ($$->gen_name);
419 $$->val = $3;
420 $$->optional = 0;
421 $$->ellipsis = 0;
422 $$->type = NULL;
426 EnumeratedType : kw_ENUMERATED '{' Enumerations '}'
428 $$ = new_type(TInteger);
429 $$->members = $3;
430 $$ = new_tag(ASN1_C_UNIV, UT_Enumerated, TE_EXPLICIT, $$);
434 Enumerations : NamedNumberList /* XXX */
437 BitStringType : kw_BIT kw_STRING
439 $$ = new_type(TBitString);
440 $$->members = emalloc(sizeof(*$$->members));
441 ASN1_TAILQ_INIT($$->members);
442 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
444 | kw_BIT kw_STRING '{' NamedBitList '}'
446 $$ = new_type(TBitString);
447 $$->members = $4;
448 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
452 ObjectIdentifierType: kw_OBJECT kw_IDENTIFIER
454 $$ = new_tag(ASN1_C_UNIV, UT_OID,
455 TE_EXPLICIT, new_type(TOID));
458 OctetStringType : kw_OCTET kw_STRING size
460 Type *t = new_type(TOctetString);
461 t->range = $3;
462 $$ = new_tag(ASN1_C_UNIV, UT_OctetString,
463 TE_EXPLICIT, t);
467 NullType : kw_NULL
469 $$ = new_tag(ASN1_C_UNIV, UT_Null,
470 TE_EXPLICIT, new_type(TNull));
474 size :
475 { $$ = NULL; }
476 | kw_SIZE range
477 { $$ = $2; }
481 SequenceType : kw_SEQUENCE '{' /* ComponentTypeLists */ ComponentTypeList '}'
483 $$ = new_type(TSequence);
484 $$->members = $3;
485 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
487 | kw_SEQUENCE '{' '}'
489 $$ = new_type(TSequence);
490 $$->members = NULL;
491 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
495 SequenceOfType : kw_SEQUENCE size kw_OF Type
497 $$ = new_type(TSequenceOf);
498 $$->range = $2;
499 $$->subtype = $4;
500 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
504 SetType : kw_SET '{' /* ComponentTypeLists */ ComponentTypeList '}'
506 $$ = new_type(TSet);
507 $$->members = $3;
508 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
510 | kw_SET '{' '}'
512 $$ = new_type(TSet);
513 $$->members = NULL;
514 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
518 SetOfType : kw_SET kw_OF Type
520 $$ = new_type(TSetOf);
521 $$->subtype = $3;
522 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
526 ChoiceType : kw_CHOICE '{' /* AlternativeTypeLists */ ComponentTypeList '}'
528 $$ = new_type(TChoice);
529 $$->members = $3;
533 ReferencedType : DefinedType
534 | UsefulType
537 DefinedType : IDENTIFIER
539 Symbol *s = addsym($1);
540 $$ = new_type(TType);
541 if(s->stype != Stype && s->stype != SUndefined)
542 error_message ("%s is not a type\n", $1);
543 else
544 $$->symbol = s;
548 UsefulType : kw_GeneralizedTime
550 $$ = new_tag(ASN1_C_UNIV, UT_GeneralizedTime,
551 TE_EXPLICIT, new_type(TGeneralizedTime));
553 | kw_UTCTime
555 $$ = new_tag(ASN1_C_UNIV, UT_UTCTime,
556 TE_EXPLICIT, new_type(TUTCTime));
560 ConstrainedType : Type Constraint
562 /* if (Constraint.type == contentConstrant) {
563 assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
564 if (Constraint.u.constraint.type) {
565 assert((Constraint.u.constraint.type.length % 8) == 0);
568 if (Constraint.u.constraint.encoding) {
569 type == der-oid|ber-oid
576 Constraint : '(' ConstraintSpec ')'
578 $$ = $2;
582 ConstraintSpec : GeneralConstraint
585 GeneralConstraint: ContentsConstraint
586 | UserDefinedConstraint
589 ContentsConstraint: kw_CONTAINING Type
591 $$ = new_constraint_spec(CT_CONTENTS);
592 $$->u.content.type = $2;
593 $$->u.content.encoding = NULL;
595 | kw_ENCODED kw_BY Value
597 if ($3->type != objectidentifiervalue)
598 error_message("Non-OID used in ENCODED BY constraint");
599 $$ = new_constraint_spec(CT_CONTENTS);
600 $$->u.content.type = NULL;
601 $$->u.content.encoding = $3;
603 | kw_CONTAINING Type kw_ENCODED kw_BY Value
605 if ($5->type != objectidentifiervalue)
606 error_message("Non-OID used in ENCODED BY constraint");
607 $$ = new_constraint_spec(CT_CONTENTS);
608 $$->u.content.type = $2;
609 $$->u.content.encoding = $5;
613 UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}'
615 $$ = new_constraint_spec(CT_USER);
619 TaggedType : Tag tagenv Type
621 $$ = new_type(TTag);
622 $$->tag = $1;
623 $$->tag.tagenv = $2;
624 if($3->type == TTag && $2 == TE_IMPLICIT) {
625 $$->subtype = $3->subtype;
626 free($3);
627 } else
628 $$->subtype = $3;
632 Tag : '[' Class NUMBER ']'
634 $$.tagclass = $2;
635 $$.tagvalue = $3;
636 $$.tagenv = TE_EXPLICIT;
640 Class : /* */
642 $$ = ASN1_C_CONTEXT;
644 | kw_UNIVERSAL
646 $$ = ASN1_C_UNIV;
648 | kw_APPLICATION
650 $$ = ASN1_C_APPL;
652 | kw_PRIVATE
654 $$ = ASN1_C_PRIVATE;
658 tagenv : /* */
660 $$ = TE_EXPLICIT;
662 | kw_EXPLICIT
664 $$ = TE_EXPLICIT;
666 | kw_IMPLICIT
668 $$ = TE_IMPLICIT;
673 ValueAssignment : IDENTIFIER Type EEQUAL Value
675 Symbol *s;
676 s = addsym ($1);
678 s->stype = SValue;
679 s->value = $4;
680 generate_constant (s);
684 CharacterStringType: RestrictedCharactedStringType
687 RestrictedCharactedStringType: kw_GeneralString
689 $$ = new_tag(ASN1_C_UNIV, UT_GeneralString,
690 TE_EXPLICIT, new_type(TGeneralString));
692 | kw_UTF8String
694 $$ = new_tag(ASN1_C_UNIV, UT_UTF8String,
695 TE_EXPLICIT, new_type(TUTF8String));
697 | kw_PrintableString
699 $$ = new_tag(ASN1_C_UNIV, UT_PrintableString,
700 TE_EXPLICIT, new_type(TPrintableString));
702 | kw_VisibleString
704 $$ = new_tag(ASN1_C_UNIV, UT_VisibleString,
705 TE_EXPLICIT, new_type(TVisibleString));
707 | kw_IA5String
709 $$ = new_tag(ASN1_C_UNIV, UT_IA5String,
710 TE_EXPLICIT, new_type(TIA5String));
712 | kw_BMPString
714 $$ = new_tag(ASN1_C_UNIV, UT_BMPString,
715 TE_EXPLICIT, new_type(TBMPString));
717 | kw_UniversalString
719 $$ = new_tag(ASN1_C_UNIV, UT_UniversalString,
720 TE_EXPLICIT, new_type(TUniversalString));
725 ComponentTypeList: ComponentType
727 $$ = emalloc(sizeof(*$$));
728 ASN1_TAILQ_INIT($$);
729 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
731 | ComponentTypeList ',' ComponentType
733 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
734 $$ = $1;
736 | ComponentTypeList ',' ELLIPSIS
738 struct member *m = ecalloc(1, sizeof(*m));
739 m->name = estrdup("...");
740 m->gen_name = estrdup("asn1_ellipsis");
741 m->ellipsis = 1;
742 ASN1_TAILQ_INSERT_TAIL($1, m, members);
743 $$ = $1;
747 NamedType : IDENTIFIER Type
749 $$ = emalloc(sizeof(*$$));
750 $$->name = $1;
751 $$->gen_name = estrdup($1);
752 output_name ($$->gen_name);
753 $$->type = $2;
754 $$->ellipsis = 0;
758 ComponentType : NamedType
760 $$ = $1;
761 $$->optional = 0;
762 $$->defval = NULL;
764 | NamedType kw_OPTIONAL
766 $$ = $1;
767 $$->optional = 1;
768 $$->defval = NULL;
770 | NamedType kw_DEFAULT Value
772 $$ = $1;
773 $$->optional = 0;
774 $$->defval = $3;
778 NamedBitList : NamedBit
780 $$ = emalloc(sizeof(*$$));
781 ASN1_TAILQ_INIT($$);
782 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
784 | NamedBitList ',' NamedBit
786 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
787 $$ = $1;
791 NamedBit : IDENTIFIER '(' NUMBER ')'
793 $$ = emalloc(sizeof(*$$));
794 $$->name = $1;
795 $$->gen_name = estrdup($1);
796 output_name ($$->gen_name);
797 $$->val = $3;
798 $$->optional = 0;
799 $$->ellipsis = 0;
800 $$->type = NULL;
804 objid_opt : objid
805 | /* empty */ { $$ = NULL; }
808 objid : '{' objid_list '}'
810 $$ = $2;
814 objid_list : /* empty */
816 $$ = NULL;
818 | objid_element objid_list
820 if ($2) {
821 $$ = $2;
822 add_oid_to_tail($2, $1);
823 } else {
824 $$ = $1;
829 objid_element : IDENTIFIER '(' NUMBER ')'
831 $$ = new_objid($1, $3);
833 | IDENTIFIER
835 Symbol *s = addsym($1);
836 if(s->stype != SValue ||
837 s->value->type != objectidentifiervalue) {
838 error_message("%s is not an object identifier\n",
839 s->name);
840 exit(1);
842 $$ = s->value->u.objectidentifiervalue;
844 | NUMBER
846 $$ = new_objid(NULL, $1);
850 Value : BuiltinValue
851 | ReferencedValue
854 BuiltinValue : BooleanValue
855 | CharacterStringValue
856 | IntegerValue
857 | ObjectIdentifierValue
858 | NullValue
861 ReferencedValue : DefinedValue
864 DefinedValue : Valuereference
867 Valuereference : IDENTIFIER
869 Symbol *s = addsym($1);
870 if(s->stype != SValue)
871 error_message ("%s is not a value\n",
872 s->name);
873 else
874 $$ = s->value;
878 CharacterStringValue: STRING
880 $$ = emalloc(sizeof(*$$));
881 $$->type = stringvalue;
882 $$->u.stringvalue = $1;
886 BooleanValue : kw_TRUE
888 $$ = emalloc(sizeof(*$$));
889 $$->type = booleanvalue;
890 $$->u.booleanvalue = 0;
892 | kw_FALSE
894 $$ = emalloc(sizeof(*$$));
895 $$->type = booleanvalue;
896 $$->u.booleanvalue = 0;
900 IntegerValue : SignedNumber
902 $$ = emalloc(sizeof(*$$));
903 $$->type = integervalue;
904 $$->u.integervalue = $1;
908 SignedNumber : NUMBER
911 NullValue : kw_NULL
916 ObjectIdentifierValue: objid
918 $$ = emalloc(sizeof(*$$));
919 $$->type = objectidentifiervalue;
920 $$->u.objectidentifiervalue = $1;
926 void
927 yyerror (const char *s)
929 error_message ("%s\n", s);
932 static Type *
933 new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype)
935 Type *t;
936 if(oldtype->type == TTag && oldtype->tag.tagenv == TE_IMPLICIT) {
937 t = oldtype;
938 oldtype = oldtype->subtype; /* XXX */
939 } else
940 t = new_type (TTag);
942 t->tag.tagclass = tagclass;
943 t->tag.tagvalue = tagvalue;
944 t->tag.tagenv = tagenv;
945 t->subtype = oldtype;
946 return t;
949 static struct objid *
950 new_objid(const char *label, int value)
952 struct objid *s;
953 s = emalloc(sizeof(*s));
954 s->label = label;
955 s->value = value;
956 s->next = NULL;
957 return s;
960 static void
961 add_oid_to_tail(struct objid *head, struct objid *tail)
963 struct objid *o;
964 o = head;
965 while (o->next)
966 o = o->next;
967 o->next = tail;
970 static Type *
971 new_type (Typetype tt)
973 Type *t = ecalloc(1, sizeof(*t));
974 t->type = tt;
975 return t;
978 static struct constraint_spec *
979 new_constraint_spec(enum ctype ct)
981 struct constraint_spec *c = ecalloc(1, sizeof(*c));
982 c->ctype = ct;
983 return c;
986 static void fix_labels2(Type *t, const char *prefix);
987 static void fix_labels1(struct memhead *members, const char *prefix)
989 Member *m;
991 if(members == NULL)
992 return;
993 ASN1_TAILQ_FOREACH(m, members, members) {
994 asprintf(&m->label, "%s_%s", prefix, m->gen_name);
995 if (m->label == NULL)
996 errx(1, "malloc");
997 if(m->type != NULL)
998 fix_labels2(m->type, m->label);
1002 static void fix_labels2(Type *t, const char *prefix)
1004 for(; t; t = t->subtype)
1005 fix_labels1(t->members, prefix);
1008 static void
1009 fix_labels(Symbol *s)
1011 char *p;
1012 asprintf(&p, "choice_%s", s->gen_name);
1013 if (p == NULL)
1014 errx(1, "malloc");
1015 fix_labels2(s->type, p);
1016 free(p);