only resign PAC if there is a verified PAC on the way in
[heimdal.git] / lib / asn1 / asn1parse.y
blob611c5b521ad906a6260edbeb59264f38b3af9319
1 /*
2 * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 /* $Id$ */
40 #include <config.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include "symbol.h"
46 #include "lex.h"
47 #include "gen_locl.h"
48 #include "der.h"
50 RCSID("$Id$");
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;
277 gen_template_import(s);
279 add_import($3);
283 Exports : kw_EXPORTS referencenames ';'
285 struct string_list *sl;
286 for(sl = $2; sl != NULL; sl = sl->next)
287 add_export(sl->string);
289 | kw_EXPORTS kw_ALL
290 | /* empty */
293 AssignmentList : Assignment
294 | Assignment AssignmentList
297 Assignment : TypeAssignment
298 | ValueAssignment
301 referencenames : IDENTIFIER ',' referencenames
303 $$ = emalloc(sizeof(*$$));
304 $$->string = $1;
305 $$->next = $3;
307 | IDENTIFIER
309 $$ = emalloc(sizeof(*$$));
310 $$->string = $1;
311 $$->next = NULL;
315 TypeAssignment : IDENTIFIER EEQUAL Type
317 Symbol *s = addsym ($1);
318 s->stype = Stype;
319 s->type = $3;
320 fix_labels(s);
321 generate_type (s);
325 Type : BuiltinType
326 | ReferencedType
327 | ConstrainedType
330 BuiltinType : BitStringType
331 | BooleanType
332 | CharacterStringType
333 | ChoiceType
334 | EnumeratedType
335 | IntegerType
336 | NullType
337 | ObjectIdentifierType
338 | OctetStringType
339 | SequenceType
340 | SequenceOfType
341 | SetType
342 | SetOfType
343 | TaggedType
346 BooleanType : kw_BOOLEAN
348 $$ = new_tag(ASN1_C_UNIV, UT_Boolean,
349 TE_EXPLICIT, new_type(TBoolean));
353 range : '(' Value RANGE Value ')'
355 if($2->type != integervalue)
356 error_message("Non-integer used in first part of range");
357 if($2->type != integervalue)
358 error_message("Non-integer in second part of range");
359 $$ = ecalloc(1, sizeof(*$$));
360 $$->min = $2->u.integervalue;
361 $$->max = $4->u.integervalue;
363 | '(' Value RANGE kw_MAX ')'
365 if($2->type != integervalue)
366 error_message("Non-integer in first part of range");
367 $$ = ecalloc(1, sizeof(*$$));
368 $$->min = $2->u.integervalue;
369 $$->max = $2->u.integervalue - 1;
371 | '(' kw_MIN RANGE Value ')'
373 if($4->type != integervalue)
374 error_message("Non-integer in second part of range");
375 $$ = ecalloc(1, sizeof(*$$));
376 $$->min = $4->u.integervalue + 2;
377 $$->max = $4->u.integervalue;
379 | '(' Value ')'
381 if($2->type != integervalue)
382 error_message("Non-integer used in limit");
383 $$ = ecalloc(1, sizeof(*$$));
384 $$->min = $2->u.integervalue;
385 $$->max = $2->u.integervalue;
390 IntegerType : kw_INTEGER
392 $$ = new_tag(ASN1_C_UNIV, UT_Integer,
393 TE_EXPLICIT, new_type(TInteger));
395 | kw_INTEGER range
397 $$ = new_type(TInteger);
398 $$->range = $2;
399 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
401 | kw_INTEGER '{' NamedNumberList '}'
403 $$ = new_type(TInteger);
404 $$->members = $3;
405 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
409 NamedNumberList : NamedNumber
411 $$ = emalloc(sizeof(*$$));
412 ASN1_TAILQ_INIT($$);
413 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
415 | NamedNumberList ',' NamedNumber
417 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
418 $$ = $1;
420 | NamedNumberList ',' ELLIPSIS
421 { $$ = $1; } /* XXX used for Enumerations */
424 NamedNumber : IDENTIFIER '(' SignedNumber ')'
426 $$ = emalloc(sizeof(*$$));
427 $$->name = $1;
428 $$->gen_name = estrdup($1);
429 output_name ($$->gen_name);
430 $$->val = $3;
431 $$->optional = 0;
432 $$->ellipsis = 0;
433 $$->type = NULL;
437 EnumeratedType : kw_ENUMERATED '{' Enumerations '}'
439 $$ = new_type(TInteger);
440 $$->members = $3;
441 $$ = new_tag(ASN1_C_UNIV, UT_Enumerated, TE_EXPLICIT, $$);
445 Enumerations : NamedNumberList /* XXX */
448 BitStringType : kw_BIT kw_STRING
450 $$ = new_type(TBitString);
451 $$->members = emalloc(sizeof(*$$->members));
452 ASN1_TAILQ_INIT($$->members);
453 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
455 | kw_BIT kw_STRING '{' NamedBitList '}'
457 $$ = new_type(TBitString);
458 $$->members = $4;
459 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
463 ObjectIdentifierType: kw_OBJECT kw_IDENTIFIER
465 $$ = new_tag(ASN1_C_UNIV, UT_OID,
466 TE_EXPLICIT, new_type(TOID));
469 OctetStringType : kw_OCTET kw_STRING size
471 Type *t = new_type(TOctetString);
472 t->range = $3;
473 $$ = new_tag(ASN1_C_UNIV, UT_OctetString,
474 TE_EXPLICIT, t);
478 NullType : kw_NULL
480 $$ = new_tag(ASN1_C_UNIV, UT_Null,
481 TE_EXPLICIT, new_type(TNull));
485 size :
486 { $$ = NULL; }
487 | kw_SIZE range
488 { $$ = $2; }
492 SequenceType : kw_SEQUENCE '{' /* ComponentTypeLists */ ComponentTypeList '}'
494 $$ = new_type(TSequence);
495 $$->members = $3;
496 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
498 | kw_SEQUENCE '{' '}'
500 $$ = new_type(TSequence);
501 $$->members = NULL;
502 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
506 SequenceOfType : kw_SEQUENCE size kw_OF Type
508 $$ = new_type(TSequenceOf);
509 $$->range = $2;
510 $$->subtype = $4;
511 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
515 SetType : kw_SET '{' /* ComponentTypeLists */ ComponentTypeList '}'
517 $$ = new_type(TSet);
518 $$->members = $3;
519 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
521 | kw_SET '{' '}'
523 $$ = new_type(TSet);
524 $$->members = NULL;
525 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
529 SetOfType : kw_SET kw_OF Type
531 $$ = new_type(TSetOf);
532 $$->subtype = $3;
533 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
537 ChoiceType : kw_CHOICE '{' /* AlternativeTypeLists */ ComponentTypeList '}'
539 $$ = new_type(TChoice);
540 $$->members = $3;
544 ReferencedType : DefinedType
545 | UsefulType
548 DefinedType : IDENTIFIER
550 Symbol *s = addsym($1);
551 $$ = new_type(TType);
552 if(s->stype != Stype && s->stype != SUndefined)
553 error_message ("%s is not a type\n", $1);
554 else
555 $$->symbol = s;
559 UsefulType : kw_GeneralizedTime
561 $$ = new_tag(ASN1_C_UNIV, UT_GeneralizedTime,
562 TE_EXPLICIT, new_type(TGeneralizedTime));
564 | kw_UTCTime
566 $$ = new_tag(ASN1_C_UNIV, UT_UTCTime,
567 TE_EXPLICIT, new_type(TUTCTime));
571 ConstrainedType : Type Constraint
573 /* if (Constraint.type == contentConstrant) {
574 assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
575 if (Constraint.u.constraint.type) {
576 assert((Constraint.u.constraint.type.length % 8) == 0);
579 if (Constraint.u.constraint.encoding) {
580 type == der-oid|ber-oid
587 Constraint : '(' ConstraintSpec ')'
589 $$ = $2;
593 ConstraintSpec : GeneralConstraint
596 GeneralConstraint: ContentsConstraint
597 | UserDefinedConstraint
600 ContentsConstraint: kw_CONTAINING Type
602 $$ = new_constraint_spec(CT_CONTENTS);
603 $$->u.content.type = $2;
604 $$->u.content.encoding = NULL;
606 | kw_ENCODED kw_BY Value
608 if ($3->type != objectidentifiervalue)
609 error_message("Non-OID used in ENCODED BY constraint");
610 $$ = new_constraint_spec(CT_CONTENTS);
611 $$->u.content.type = NULL;
612 $$->u.content.encoding = $3;
614 | kw_CONTAINING Type kw_ENCODED kw_BY Value
616 if ($5->type != objectidentifiervalue)
617 error_message("Non-OID used in ENCODED BY constraint");
618 $$ = new_constraint_spec(CT_CONTENTS);
619 $$->u.content.type = $2;
620 $$->u.content.encoding = $5;
624 UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}'
626 $$ = new_constraint_spec(CT_USER);
630 TaggedType : Tag tagenv Type
632 $$ = new_type(TTag);
633 $$->tag = $1;
634 $$->tag.tagenv = $2;
635 if($3->type == TTag && $2 == TE_IMPLICIT) {
636 $$->subtype = $3->subtype;
637 free($3);
638 } else
639 $$->subtype = $3;
643 Tag : '[' Class NUMBER ']'
645 $$.tagclass = $2;
646 $$.tagvalue = $3;
647 $$.tagenv = TE_EXPLICIT;
651 Class : /* */
653 $$ = ASN1_C_CONTEXT;
655 | kw_UNIVERSAL
657 $$ = ASN1_C_UNIV;
659 | kw_APPLICATION
661 $$ = ASN1_C_APPL;
663 | kw_PRIVATE
665 $$ = ASN1_C_PRIVATE;
669 tagenv : /* */
671 $$ = TE_EXPLICIT;
673 | kw_EXPLICIT
675 $$ = TE_EXPLICIT;
677 | kw_IMPLICIT
679 $$ = TE_IMPLICIT;
684 ValueAssignment : IDENTIFIER Type EEQUAL Value
686 Symbol *s;
687 s = addsym ($1);
689 s->stype = SValue;
690 s->value = $4;
691 generate_constant (s);
695 CharacterStringType: RestrictedCharactedStringType
698 RestrictedCharactedStringType: kw_GeneralString
700 $$ = new_tag(ASN1_C_UNIV, UT_GeneralString,
701 TE_EXPLICIT, new_type(TGeneralString));
703 | kw_TeletexString
705 $$ = new_tag(ASN1_C_UNIV, UT_TeletexString,
706 TE_EXPLICIT, new_type(TTeletexString));
708 | kw_UTF8String
710 $$ = new_tag(ASN1_C_UNIV, UT_UTF8String,
711 TE_EXPLICIT, new_type(TUTF8String));
713 | kw_PrintableString
715 $$ = new_tag(ASN1_C_UNIV, UT_PrintableString,
716 TE_EXPLICIT, new_type(TPrintableString));
718 | kw_VisibleString
720 $$ = new_tag(ASN1_C_UNIV, UT_VisibleString,
721 TE_EXPLICIT, new_type(TVisibleString));
723 | kw_IA5String
725 $$ = new_tag(ASN1_C_UNIV, UT_IA5String,
726 TE_EXPLICIT, new_type(TIA5String));
728 | kw_BMPString
730 $$ = new_tag(ASN1_C_UNIV, UT_BMPString,
731 TE_EXPLICIT, new_type(TBMPString));
733 | kw_UniversalString
735 $$ = new_tag(ASN1_C_UNIV, UT_UniversalString,
736 TE_EXPLICIT, new_type(TUniversalString));
741 ComponentTypeList: ComponentType
743 $$ = emalloc(sizeof(*$$));
744 ASN1_TAILQ_INIT($$);
745 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
747 | ComponentTypeList ',' ComponentType
749 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
750 $$ = $1;
752 | ComponentTypeList ',' ELLIPSIS
754 struct member *m = ecalloc(1, sizeof(*m));
755 m->name = estrdup("...");
756 m->gen_name = estrdup("asn1_ellipsis");
757 m->ellipsis = 1;
758 ASN1_TAILQ_INSERT_TAIL($1, m, members);
759 $$ = $1;
763 NamedType : IDENTIFIER Type
765 $$ = emalloc(sizeof(*$$));
766 $$->name = $1;
767 $$->gen_name = estrdup($1);
768 output_name ($$->gen_name);
769 $$->type = $2;
770 $$->ellipsis = 0;
774 ComponentType : NamedType
776 $$ = $1;
777 $$->optional = 0;
778 $$->defval = NULL;
780 | NamedType kw_OPTIONAL
782 $$ = $1;
783 $$->optional = 1;
784 $$->defval = NULL;
786 | NamedType kw_DEFAULT Value
788 $$ = $1;
789 $$->optional = 0;
790 $$->defval = $3;
794 NamedBitList : NamedBit
796 $$ = emalloc(sizeof(*$$));
797 ASN1_TAILQ_INIT($$);
798 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
800 | NamedBitList ',' NamedBit
802 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
803 $$ = $1;
807 NamedBit : IDENTIFIER '(' NUMBER ')'
809 $$ = emalloc(sizeof(*$$));
810 $$->name = $1;
811 $$->gen_name = estrdup($1);
812 output_name ($$->gen_name);
813 $$->val = $3;
814 $$->optional = 0;
815 $$->ellipsis = 0;
816 $$->type = NULL;
820 objid_opt : objid
821 | /* empty */ { $$ = NULL; }
824 objid : '{' objid_list '}'
826 $$ = $2;
830 objid_list : /* empty */
832 $$ = NULL;
834 | objid_element objid_list
836 if ($2) {
837 $$ = $2;
838 add_oid_to_tail($2, $1);
839 } else {
840 $$ = $1;
845 objid_element : IDENTIFIER '(' NUMBER ')'
847 $$ = new_objid($1, $3);
849 | IDENTIFIER
851 Symbol *s = addsym($1);
852 if(s->stype != SValue ||
853 s->value->type != objectidentifiervalue) {
854 error_message("%s is not an object identifier\n",
855 s->name);
856 exit(1);
858 $$ = s->value->u.objectidentifiervalue;
860 | NUMBER
862 $$ = new_objid(NULL, $1);
866 Value : BuiltinValue
867 | ReferencedValue
870 BuiltinValue : BooleanValue
871 | CharacterStringValue
872 | IntegerValue
873 | ObjectIdentifierValue
874 | NullValue
877 ReferencedValue : DefinedValue
880 DefinedValue : Valuereference
883 Valuereference : IDENTIFIER
885 Symbol *s = addsym($1);
886 if(s->stype != SValue)
887 error_message ("%s is not a value\n",
888 s->name);
889 else
890 $$ = s->value;
894 CharacterStringValue: STRING
896 $$ = emalloc(sizeof(*$$));
897 $$->type = stringvalue;
898 $$->u.stringvalue = $1;
902 BooleanValue : kw_TRUE
904 $$ = emalloc(sizeof(*$$));
905 $$->type = booleanvalue;
906 $$->u.booleanvalue = 0;
908 | kw_FALSE
910 $$ = emalloc(sizeof(*$$));
911 $$->type = booleanvalue;
912 $$->u.booleanvalue = 0;
916 IntegerValue : SignedNumber
918 $$ = emalloc(sizeof(*$$));
919 $$->type = integervalue;
920 $$->u.integervalue = $1;
924 SignedNumber : NUMBER
927 NullValue : kw_NULL
932 ObjectIdentifierValue: objid
934 $$ = emalloc(sizeof(*$$));
935 $$->type = objectidentifiervalue;
936 $$->u.objectidentifiervalue = $1;
942 void
943 yyerror (const char *s)
945 error_message ("%s\n", s);
948 static Type *
949 new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype)
951 Type *t;
952 if(oldtype->type == TTag && oldtype->tag.tagenv == TE_IMPLICIT) {
953 t = oldtype;
954 oldtype = oldtype->subtype; /* XXX */
955 } else
956 t = new_type (TTag);
958 t->tag.tagclass = tagclass;
959 t->tag.tagvalue = tagvalue;
960 t->tag.tagenv = tagenv;
961 t->subtype = oldtype;
962 return t;
965 static struct objid *
966 new_objid(const char *label, int value)
968 struct objid *s;
969 s = emalloc(sizeof(*s));
970 s->label = label;
971 s->value = value;
972 s->next = NULL;
973 return s;
976 static void
977 add_oid_to_tail(struct objid *head, struct objid *tail)
979 struct objid *o;
980 o = head;
981 while (o->next)
982 o = o->next;
983 o->next = tail;
986 static Type *
987 new_type (Typetype tt)
989 Type *t = ecalloc(1, sizeof(*t));
990 t->type = tt;
991 return t;
994 static struct constraint_spec *
995 new_constraint_spec(enum ctype ct)
997 struct constraint_spec *c = ecalloc(1, sizeof(*c));
998 c->ctype = ct;
999 return c;
1002 static void fix_labels2(Type *t, const char *prefix);
1003 static void fix_labels1(struct memhead *members, const char *prefix)
1005 Member *m;
1007 if(members == NULL)
1008 return;
1009 ASN1_TAILQ_FOREACH(m, members, members) {
1010 if (asprintf(&m->label, "%s_%s", prefix, m->gen_name) < 0)
1011 errx(1, "malloc");
1012 if (m->label == NULL)
1013 errx(1, "malloc");
1014 if(m->type != NULL)
1015 fix_labels2(m->type, m->label);
1019 static void fix_labels2(Type *t, const char *prefix)
1021 for(; t; t = t->subtype)
1022 fix_labels1(t->members, prefix);
1025 static void
1026 fix_labels(Symbol *s)
1028 char *p = NULL;
1029 if (asprintf(&p, "choice_%s", s->gen_name) < 0 || p == NULL)
1030 errx(1, "malloc");
1031 fix_labels2(s->type, p);
1032 free(p);