libsmbclient: Remove unused cli_session_setup_ntlmssp()
[Samba/gebeck_regimport.git] / source4 / heimdal / lib / asn1 / asn1parse.y
blobe3bea6ce0ac9241823606f47598c1db573799148
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;
65 /* Declarations for Bison */
66 #define YYMALLOC malloc
67 #define YYFREE free
71 %union {
72 int constant;
73 struct value *value;
74 struct range *range;
75 char *name;
76 Type *type;
77 Member *member;
78 struct objid *objid;
79 char *defval;
80 struct string_list *sl;
81 struct tagtype tag;
82 struct memhead *members;
83 struct constraint_spec *constraint_spec;
86 %token kw_ABSENT
87 %token kw_ABSTRACT_SYNTAX
88 %token kw_ALL
89 %token kw_APPLICATION
90 %token kw_AUTOMATIC
91 %token kw_BEGIN
92 %token kw_BIT
93 %token kw_BMPString
94 %token kw_BOOLEAN
95 %token kw_BY
96 %token kw_CHARACTER
97 %token kw_CHOICE
98 %token kw_CLASS
99 %token kw_COMPONENT
100 %token kw_COMPONENTS
101 %token kw_CONSTRAINED
102 %token kw_CONTAINING
103 %token kw_DEFAULT
104 %token kw_DEFINITIONS
105 %token kw_EMBEDDED
106 %token kw_ENCODED
107 %token kw_END
108 %token kw_ENUMERATED
109 %token kw_EXCEPT
110 %token kw_EXPLICIT
111 %token kw_EXPORTS
112 %token kw_EXTENSIBILITY
113 %token kw_EXTERNAL
114 %token kw_FALSE
115 %token kw_FROM
116 %token kw_GeneralString
117 %token kw_GeneralizedTime
118 %token kw_GraphicString
119 %token kw_IA5String
120 %token kw_IDENTIFIER
121 %token kw_IMPLICIT
122 %token kw_IMPLIED
123 %token kw_IMPORTS
124 %token kw_INCLUDES
125 %token kw_INSTANCE
126 %token kw_INTEGER
127 %token kw_INTERSECTION
128 %token kw_ISO646String
129 %token kw_MAX
130 %token kw_MIN
131 %token kw_MINUS_INFINITY
132 %token kw_NULL
133 %token kw_NumericString
134 %token kw_OBJECT
135 %token kw_OCTET
136 %token kw_OF
137 %token kw_OPTIONAL
138 %token kw_ObjectDescriptor
139 %token kw_PATTERN
140 %token kw_PDV
141 %token kw_PLUS_INFINITY
142 %token kw_PRESENT
143 %token kw_PRIVATE
144 %token kw_PrintableString
145 %token kw_REAL
146 %token kw_RELATIVE_OID
147 %token kw_SEQUENCE
148 %token kw_SET
149 %token kw_SIZE
150 %token kw_STRING
151 %token kw_SYNTAX
152 %token kw_T61String
153 %token kw_TAGS
154 %token kw_TRUE
155 %token kw_TYPE_IDENTIFIER
156 %token kw_TeletexString
157 %token kw_UNION
158 %token kw_UNIQUE
159 %token kw_UNIVERSAL
160 %token kw_UTCTime
161 %token kw_UTF8String
162 %token kw_UniversalString
163 %token kw_VideotexString
164 %token kw_VisibleString
165 %token kw_WITH
167 %token RANGE
168 %token EEQUAL
169 %token ELLIPSIS
171 %token <name> IDENTIFIER referencename
172 %token <name> STRING
174 %token <constant> NUMBER
175 %type <constant> SignedNumber
176 %type <constant> Class tagenv
178 %type <value> Value
179 %type <value> BuiltinValue
180 %type <value> IntegerValue
181 %type <value> BooleanValue
182 %type <value> ObjectIdentifierValue
183 %type <value> CharacterStringValue
184 %type <value> NullValue
185 %type <value> DefinedValue
186 %type <value> ReferencedValue
187 %type <value> Valuereference
189 %type <type> Type
190 %type <type> BuiltinType
191 %type <type> BitStringType
192 %type <type> BooleanType
193 %type <type> ChoiceType
194 %type <type> ConstrainedType
195 %type <type> EnumeratedType
196 %type <type> IntegerType
197 %type <type> NullType
198 %type <type> OctetStringType
199 %type <type> SequenceType
200 %type <type> SequenceOfType
201 %type <type> SetType
202 %type <type> SetOfType
203 %type <type> TaggedType
204 %type <type> ReferencedType
205 %type <type> DefinedType
206 %type <type> UsefulType
207 %type <type> ObjectIdentifierType
208 %type <type> CharacterStringType
209 %type <type> RestrictedCharactedStringType
211 %type <tag> Tag
213 %type <member> ComponentType
214 %type <member> NamedBit
215 %type <member> NamedNumber
216 %type <member> NamedType
217 %type <members> ComponentTypeList
218 %type <members> Enumerations
219 %type <members> NamedBitList
220 %type <members> NamedNumberList
222 %type <objid> objid objid_list objid_element objid_opt
223 %type <range> range size
225 %type <sl> referencenames
227 %type <constraint_spec> Constraint
228 %type <constraint_spec> ConstraintSpec
229 %type <constraint_spec> GeneralConstraint
230 %type <constraint_spec> ContentsConstraint
231 %type <constraint_spec> UserDefinedConstraint
235 %start ModuleDefinition
239 ModuleDefinition: IDENTIFIER objid_opt kw_DEFINITIONS TagDefault ExtensionDefault
240 EEQUAL kw_BEGIN ModuleBody kw_END
242 checkundefined();
246 TagDefault : kw_EXPLICIT kw_TAGS
247 | kw_IMPLICIT kw_TAGS
248 { lex_error_message("implicit tagging is not supported"); }
249 | kw_AUTOMATIC kw_TAGS
250 { lex_error_message("automatic tagging is not supported"); }
251 | /* empty */
254 ExtensionDefault: kw_EXTENSIBILITY kw_IMPLIED
255 { lex_error_message("no extensibility options supported"); }
256 | /* empty */
259 ModuleBody : Exports Imports AssignmentList
260 | /* empty */
263 Imports : kw_IMPORTS SymbolsImported ';'
264 | /* empty */
267 SymbolsImported : SymbolsFromModuleList
268 | /* empty */
271 SymbolsFromModuleList: SymbolsFromModule
272 | SymbolsFromModuleList SymbolsFromModule
275 SymbolsFromModule: referencenames kw_FROM IDENTIFIER objid_opt
277 struct string_list *sl;
278 for(sl = $1; sl != NULL; sl = sl->next) {
279 Symbol *s = addsym(sl->string);
280 s->stype = Stype;
281 gen_template_import(s);
283 add_import($3);
287 Exports : kw_EXPORTS referencenames ';'
289 struct string_list *sl;
290 for(sl = $2; sl != NULL; sl = sl->next)
291 add_export(sl->string);
293 | kw_EXPORTS kw_ALL
294 | /* empty */
297 AssignmentList : Assignment
298 | Assignment AssignmentList
301 Assignment : TypeAssignment
302 | ValueAssignment
305 referencenames : IDENTIFIER ',' referencenames
307 $$ = emalloc(sizeof(*$$));
308 $$->string = $1;
309 $$->next = $3;
311 | IDENTIFIER
313 $$ = emalloc(sizeof(*$$));
314 $$->string = $1;
315 $$->next = NULL;
319 TypeAssignment : IDENTIFIER EEQUAL Type
321 Symbol *s = addsym ($1);
322 s->stype = Stype;
323 s->type = $3;
324 fix_labels(s);
325 generate_type (s);
329 Type : BuiltinType
330 | ReferencedType
331 | ConstrainedType
334 BuiltinType : BitStringType
335 | BooleanType
336 | CharacterStringType
337 | ChoiceType
338 | EnumeratedType
339 | IntegerType
340 | NullType
341 | ObjectIdentifierType
342 | OctetStringType
343 | SequenceType
344 | SequenceOfType
345 | SetType
346 | SetOfType
347 | TaggedType
350 BooleanType : kw_BOOLEAN
352 $$ = new_tag(ASN1_C_UNIV, UT_Boolean,
353 TE_EXPLICIT, new_type(TBoolean));
357 range : '(' Value RANGE Value ')'
359 if($2->type != integervalue)
360 lex_error_message("Non-integer used in first part of range");
361 if($2->type != integervalue)
362 lex_error_message("Non-integer in second part of range");
363 $$ = ecalloc(1, sizeof(*$$));
364 $$->min = $2->u.integervalue;
365 $$->max = $4->u.integervalue;
367 | '(' Value RANGE kw_MAX ')'
369 if($2->type != integervalue)
370 lex_error_message("Non-integer in first part of range");
371 $$ = ecalloc(1, sizeof(*$$));
372 $$->min = $2->u.integervalue;
373 $$->max = $2->u.integervalue - 1;
375 | '(' kw_MIN RANGE Value ')'
377 if($4->type != integervalue)
378 lex_error_message("Non-integer in second part of range");
379 $$ = ecalloc(1, sizeof(*$$));
380 $$->min = $4->u.integervalue + 2;
381 $$->max = $4->u.integervalue;
383 | '(' Value ')'
385 if($2->type != integervalue)
386 lex_error_message("Non-integer used in limit");
387 $$ = ecalloc(1, sizeof(*$$));
388 $$->min = $2->u.integervalue;
389 $$->max = $2->u.integervalue;
394 IntegerType : kw_INTEGER
396 $$ = new_tag(ASN1_C_UNIV, UT_Integer,
397 TE_EXPLICIT, new_type(TInteger));
399 | kw_INTEGER range
401 $$ = new_type(TInteger);
402 $$->range = $2;
403 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
405 | kw_INTEGER '{' NamedNumberList '}'
407 $$ = new_type(TInteger);
408 $$->members = $3;
409 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
413 NamedNumberList : NamedNumber
415 $$ = emalloc(sizeof(*$$));
416 ASN1_TAILQ_INIT($$);
417 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
419 | NamedNumberList ',' NamedNumber
421 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
422 $$ = $1;
424 | NamedNumberList ',' ELLIPSIS
425 { $$ = $1; } /* XXX used for Enumerations */
428 NamedNumber : IDENTIFIER '(' SignedNumber ')'
430 $$ = emalloc(sizeof(*$$));
431 $$->name = $1;
432 $$->gen_name = estrdup($1);
433 output_name ($$->gen_name);
434 $$->val = $3;
435 $$->optional = 0;
436 $$->ellipsis = 0;
437 $$->type = NULL;
441 EnumeratedType : kw_ENUMERATED '{' Enumerations '}'
443 $$ = new_type(TInteger);
444 $$->members = $3;
445 $$ = new_tag(ASN1_C_UNIV, UT_Enumerated, TE_EXPLICIT, $$);
449 Enumerations : NamedNumberList /* XXX */
452 BitStringType : kw_BIT kw_STRING
454 $$ = new_type(TBitString);
455 $$->members = emalloc(sizeof(*$$->members));
456 ASN1_TAILQ_INIT($$->members);
457 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
459 | kw_BIT kw_STRING '{' NamedBitList '}'
461 $$ = new_type(TBitString);
462 $$->members = $4;
463 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
467 ObjectIdentifierType: kw_OBJECT kw_IDENTIFIER
469 $$ = new_tag(ASN1_C_UNIV, UT_OID,
470 TE_EXPLICIT, new_type(TOID));
473 OctetStringType : kw_OCTET kw_STRING size
475 Type *t = new_type(TOctetString);
476 t->range = $3;
477 $$ = new_tag(ASN1_C_UNIV, UT_OctetString,
478 TE_EXPLICIT, t);
482 NullType : kw_NULL
484 $$ = new_tag(ASN1_C_UNIV, UT_Null,
485 TE_EXPLICIT, new_type(TNull));
489 size :
490 { $$ = NULL; }
491 | kw_SIZE range
492 { $$ = $2; }
496 SequenceType : kw_SEQUENCE '{' /* ComponentTypeLists */ ComponentTypeList '}'
498 $$ = new_type(TSequence);
499 $$->members = $3;
500 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
502 | kw_SEQUENCE '{' '}'
504 $$ = new_type(TSequence);
505 $$->members = NULL;
506 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
510 SequenceOfType : kw_SEQUENCE size kw_OF Type
512 $$ = new_type(TSequenceOf);
513 $$->range = $2;
514 $$->subtype = $4;
515 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
519 SetType : kw_SET '{' /* ComponentTypeLists */ ComponentTypeList '}'
521 $$ = new_type(TSet);
522 $$->members = $3;
523 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
525 | kw_SET '{' '}'
527 $$ = new_type(TSet);
528 $$->members = NULL;
529 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
533 SetOfType : kw_SET kw_OF Type
535 $$ = new_type(TSetOf);
536 $$->subtype = $3;
537 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
541 ChoiceType : kw_CHOICE '{' /* AlternativeTypeLists */ ComponentTypeList '}'
543 $$ = new_type(TChoice);
544 $$->members = $3;
548 ReferencedType : DefinedType
549 | UsefulType
552 DefinedType : IDENTIFIER
554 Symbol *s = addsym($1);
555 $$ = new_type(TType);
556 if(s->stype != Stype && s->stype != SUndefined)
557 lex_error_message ("%s is not a type\n", $1);
558 else
559 $$->symbol = s;
563 UsefulType : kw_GeneralizedTime
565 $$ = new_tag(ASN1_C_UNIV, UT_GeneralizedTime,
566 TE_EXPLICIT, new_type(TGeneralizedTime));
568 | kw_UTCTime
570 $$ = new_tag(ASN1_C_UNIV, UT_UTCTime,
571 TE_EXPLICIT, new_type(TUTCTime));
575 ConstrainedType : Type Constraint
577 /* if (Constraint.type == contentConstrant) {
578 assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
579 if (Constraint.u.constraint.type) {
580 assert((Constraint.u.constraint.type.length % 8) == 0);
583 if (Constraint.u.constraint.encoding) {
584 type == der-oid|ber-oid
591 Constraint : '(' ConstraintSpec ')'
593 $$ = $2;
597 ConstraintSpec : GeneralConstraint
600 GeneralConstraint: ContentsConstraint
601 | UserDefinedConstraint
604 ContentsConstraint: kw_CONTAINING Type
606 $$ = new_constraint_spec(CT_CONTENTS);
607 $$->u.content.type = $2;
608 $$->u.content.encoding = NULL;
610 | kw_ENCODED kw_BY Value
612 if ($3->type != objectidentifiervalue)
613 lex_error_message("Non-OID used in ENCODED BY constraint");
614 $$ = new_constraint_spec(CT_CONTENTS);
615 $$->u.content.type = NULL;
616 $$->u.content.encoding = $3;
618 | kw_CONTAINING Type kw_ENCODED kw_BY Value
620 if ($5->type != objectidentifiervalue)
621 lex_error_message("Non-OID used in ENCODED BY constraint");
622 $$ = new_constraint_spec(CT_CONTENTS);
623 $$->u.content.type = $2;
624 $$->u.content.encoding = $5;
628 UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}'
630 $$ = new_constraint_spec(CT_USER);
634 TaggedType : Tag tagenv Type
636 $$ = new_type(TTag);
637 $$->tag = $1;
638 $$->tag.tagenv = $2;
639 if($3->type == TTag && $2 == TE_IMPLICIT) {
640 $$->subtype = $3->subtype;
641 free($3);
642 } else
643 $$->subtype = $3;
647 Tag : '[' Class NUMBER ']'
649 $$.tagclass = $2;
650 $$.tagvalue = $3;
651 $$.tagenv = TE_EXPLICIT;
655 Class : /* */
657 $$ = ASN1_C_CONTEXT;
659 | kw_UNIVERSAL
661 $$ = ASN1_C_UNIV;
663 | kw_APPLICATION
665 $$ = ASN1_C_APPL;
667 | kw_PRIVATE
669 $$ = ASN1_C_PRIVATE;
673 tagenv : /* */
675 $$ = TE_EXPLICIT;
677 | kw_EXPLICIT
679 $$ = TE_EXPLICIT;
681 | kw_IMPLICIT
683 $$ = TE_IMPLICIT;
688 ValueAssignment : IDENTIFIER Type EEQUAL Value
690 Symbol *s;
691 s = addsym ($1);
693 s->stype = SValue;
694 s->value = $4;
695 generate_constant (s);
699 CharacterStringType: RestrictedCharactedStringType
702 RestrictedCharactedStringType: kw_GeneralString
704 $$ = new_tag(ASN1_C_UNIV, UT_GeneralString,
705 TE_EXPLICIT, new_type(TGeneralString));
707 | kw_TeletexString
709 $$ = new_tag(ASN1_C_UNIV, UT_TeletexString,
710 TE_EXPLICIT, new_type(TTeletexString));
712 | kw_UTF8String
714 $$ = new_tag(ASN1_C_UNIV, UT_UTF8String,
715 TE_EXPLICIT, new_type(TUTF8String));
717 | kw_PrintableString
719 $$ = new_tag(ASN1_C_UNIV, UT_PrintableString,
720 TE_EXPLICIT, new_type(TPrintableString));
722 | kw_VisibleString
724 $$ = new_tag(ASN1_C_UNIV, UT_VisibleString,
725 TE_EXPLICIT, new_type(TVisibleString));
727 | kw_IA5String
729 $$ = new_tag(ASN1_C_UNIV, UT_IA5String,
730 TE_EXPLICIT, new_type(TIA5String));
732 | kw_BMPString
734 $$ = new_tag(ASN1_C_UNIV, UT_BMPString,
735 TE_EXPLICIT, new_type(TBMPString));
737 | kw_UniversalString
739 $$ = new_tag(ASN1_C_UNIV, UT_UniversalString,
740 TE_EXPLICIT, new_type(TUniversalString));
745 ComponentTypeList: ComponentType
747 $$ = emalloc(sizeof(*$$));
748 ASN1_TAILQ_INIT($$);
749 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
751 | ComponentTypeList ',' ComponentType
753 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
754 $$ = $1;
756 | ComponentTypeList ',' ELLIPSIS
758 struct member *m = ecalloc(1, sizeof(*m));
759 m->name = estrdup("...");
760 m->gen_name = estrdup("asn1_ellipsis");
761 m->ellipsis = 1;
762 ASN1_TAILQ_INSERT_TAIL($1, m, members);
763 $$ = $1;
767 NamedType : IDENTIFIER Type
769 $$ = emalloc(sizeof(*$$));
770 $$->name = $1;
771 $$->gen_name = estrdup($1);
772 output_name ($$->gen_name);
773 $$->type = $2;
774 $$->ellipsis = 0;
778 ComponentType : NamedType
780 $$ = $1;
781 $$->optional = 0;
782 $$->defval = NULL;
784 | NamedType kw_OPTIONAL
786 $$ = $1;
787 $$->optional = 1;
788 $$->defval = NULL;
790 | NamedType kw_DEFAULT Value
792 $$ = $1;
793 $$->optional = 0;
794 $$->defval = $3;
798 NamedBitList : NamedBit
800 $$ = emalloc(sizeof(*$$));
801 ASN1_TAILQ_INIT($$);
802 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
804 | NamedBitList ',' NamedBit
806 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
807 $$ = $1;
811 NamedBit : IDENTIFIER '(' NUMBER ')'
813 $$ = emalloc(sizeof(*$$));
814 $$->name = $1;
815 $$->gen_name = estrdup($1);
816 output_name ($$->gen_name);
817 $$->val = $3;
818 $$->optional = 0;
819 $$->ellipsis = 0;
820 $$->type = NULL;
824 objid_opt : objid
825 | /* empty */ { $$ = NULL; }
828 objid : '{' objid_list '}'
830 $$ = $2;
834 objid_list : /* empty */
836 $$ = NULL;
838 | objid_element objid_list
840 if ($2) {
841 $$ = $2;
842 add_oid_to_tail($2, $1);
843 } else {
844 $$ = $1;
849 objid_element : IDENTIFIER '(' NUMBER ')'
851 $$ = new_objid($1, $3);
853 | IDENTIFIER
855 Symbol *s = addsym($1);
856 if(s->stype != SValue ||
857 s->value->type != objectidentifiervalue) {
858 lex_error_message("%s is not an object identifier\n",
859 s->name);
860 exit(1);
862 $$ = s->value->u.objectidentifiervalue;
864 | NUMBER
866 $$ = new_objid(NULL, $1);
870 Value : BuiltinValue
871 | ReferencedValue
874 BuiltinValue : BooleanValue
875 | CharacterStringValue
876 | IntegerValue
877 | ObjectIdentifierValue
878 | NullValue
881 ReferencedValue : DefinedValue
884 DefinedValue : Valuereference
887 Valuereference : IDENTIFIER
889 Symbol *s = addsym($1);
890 if(s->stype != SValue)
891 lex_error_message ("%s is not a value\n",
892 s->name);
893 else
894 $$ = s->value;
898 CharacterStringValue: STRING
900 $$ = emalloc(sizeof(*$$));
901 $$->type = stringvalue;
902 $$->u.stringvalue = $1;
906 BooleanValue : kw_TRUE
908 $$ = emalloc(sizeof(*$$));
909 $$->type = booleanvalue;
910 $$->u.booleanvalue = 0;
912 | kw_FALSE
914 $$ = emalloc(sizeof(*$$));
915 $$->type = booleanvalue;
916 $$->u.booleanvalue = 0;
920 IntegerValue : SignedNumber
922 $$ = emalloc(sizeof(*$$));
923 $$->type = integervalue;
924 $$->u.integervalue = $1;
928 SignedNumber : NUMBER
931 NullValue : kw_NULL
936 ObjectIdentifierValue: objid
938 $$ = emalloc(sizeof(*$$));
939 $$->type = objectidentifiervalue;
940 $$->u.objectidentifiervalue = $1;
946 void
947 yyerror (const char *s)
949 lex_error_message ("%s\n", s);
952 static Type *
953 new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype)
955 Type *t;
956 if(oldtype->type == TTag && oldtype->tag.tagenv == TE_IMPLICIT) {
957 t = oldtype;
958 oldtype = oldtype->subtype; /* XXX */
959 } else
960 t = new_type (TTag);
962 t->tag.tagclass = tagclass;
963 t->tag.tagvalue = tagvalue;
964 t->tag.tagenv = tagenv;
965 t->subtype = oldtype;
966 return t;
969 static struct objid *
970 new_objid(const char *label, int value)
972 struct objid *s;
973 s = emalloc(sizeof(*s));
974 s->label = label;
975 s->value = value;
976 s->next = NULL;
977 return s;
980 static void
981 add_oid_to_tail(struct objid *head, struct objid *tail)
983 struct objid *o;
984 o = head;
985 while (o->next)
986 o = o->next;
987 o->next = tail;
990 static Type *
991 new_type (Typetype tt)
993 Type *t = ecalloc(1, sizeof(*t));
994 t->type = tt;
995 return t;
998 static struct constraint_spec *
999 new_constraint_spec(enum ctype ct)
1001 struct constraint_spec *c = ecalloc(1, sizeof(*c));
1002 c->ctype = ct;
1003 return c;
1006 static void fix_labels2(Type *t, const char *prefix);
1007 static void fix_labels1(struct memhead *members, const char *prefix)
1009 Member *m;
1011 if(members == NULL)
1012 return;
1013 ASN1_TAILQ_FOREACH(m, members, members) {
1014 if (asprintf(&m->label, "%s_%s", prefix, m->gen_name) < 0)
1015 errx(1, "malloc");
1016 if (m->label == NULL)
1017 errx(1, "malloc");
1018 if(m->type != NULL)
1019 fix_labels2(m->type, m->label);
1023 static void fix_labels2(Type *t, const char *prefix)
1025 for(; t; t = t->subtype)
1026 fix_labels1(t->members, prefix);
1029 static void
1030 fix_labels(Symbol *s)
1032 char *p = NULL;
1033 if (asprintf(&p, "choice_%s", s->gen_name) < 0 || p == NULL)
1034 errx(1, "malloc");
1035 fix_labels2(s->type, p);
1036 free(p);