Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / asn1 / asn1parse.y
blob051440655313ad29bc04615b4447d922f6af9a04
1 /* $NetBSD: asn1parse.y,v 1.1.1.3 2014/04/24 12:45:28 pettai Exp $ */
3 /*
4 * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the Institute nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
38 /* Id */
42 #include <config.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include "symbol.h"
48 #include "lex.h"
49 #include "gen_locl.h"
50 #include "der.h"
52 __RCSID("NetBSD");
54 static Type *new_type (Typetype t);
55 static struct constraint_spec *new_constraint_spec(enum ctype);
56 static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype);
57 void yyerror (const char *);
58 static struct objid *new_objid(const char *label, int value);
59 static void add_oid_to_tail(struct objid *, struct objid *);
60 static void fix_labels(Symbol *s);
62 struct string_list {
63 char *string;
64 struct string_list *next;
67 /* Declarations for Bison */
68 #define YYMALLOC malloc
69 #define YYFREE free
73 %union {
74 int constant;
75 struct value *value;
76 struct range *range;
77 char *name;
78 Type *type;
79 Member *member;
80 struct objid *objid;
81 char *defval;
82 struct string_list *sl;
83 struct tagtype tag;
84 struct memhead *members;
85 struct constraint_spec *constraint_spec;
88 %token kw_ABSENT
89 %token kw_ABSTRACT_SYNTAX
90 %token kw_ALL
91 %token kw_APPLICATION
92 %token kw_AUTOMATIC
93 %token kw_BEGIN
94 %token kw_BIT
95 %token kw_BMPString
96 %token kw_BOOLEAN
97 %token kw_BY
98 %token kw_CHARACTER
99 %token kw_CHOICE
100 %token kw_CLASS
101 %token kw_COMPONENT
102 %token kw_COMPONENTS
103 %token kw_CONSTRAINED
104 %token kw_CONTAINING
105 %token kw_DEFAULT
106 %token kw_DEFINITIONS
107 %token kw_EMBEDDED
108 %token kw_ENCODED
109 %token kw_END
110 %token kw_ENUMERATED
111 %token kw_EXCEPT
112 %token kw_EXPLICIT
113 %token kw_EXPORTS
114 %token kw_EXTENSIBILITY
115 %token kw_EXTERNAL
116 %token kw_FALSE
117 %token kw_FROM
118 %token kw_GeneralString
119 %token kw_GeneralizedTime
120 %token kw_GraphicString
121 %token kw_IA5String
122 %token kw_IDENTIFIER
123 %token kw_IMPLICIT
124 %token kw_IMPLIED
125 %token kw_IMPORTS
126 %token kw_INCLUDES
127 %token kw_INSTANCE
128 %token kw_INTEGER
129 %token kw_INTERSECTION
130 %token kw_ISO646String
131 %token kw_MAX
132 %token kw_MIN
133 %token kw_MINUS_INFINITY
134 %token kw_NULL
135 %token kw_NumericString
136 %token kw_OBJECT
137 %token kw_OCTET
138 %token kw_OF
139 %token kw_OPTIONAL
140 %token kw_ObjectDescriptor
141 %token kw_PATTERN
142 %token kw_PDV
143 %token kw_PLUS_INFINITY
144 %token kw_PRESENT
145 %token kw_PRIVATE
146 %token kw_PrintableString
147 %token kw_REAL
148 %token kw_RELATIVE_OID
149 %token kw_SEQUENCE
150 %token kw_SET
151 %token kw_SIZE
152 %token kw_STRING
153 %token kw_SYNTAX
154 %token kw_T61String
155 %token kw_TAGS
156 %token kw_TRUE
157 %token kw_TYPE_IDENTIFIER
158 %token kw_TeletexString
159 %token kw_UNION
160 %token kw_UNIQUE
161 %token kw_UNIVERSAL
162 %token kw_UTCTime
163 %token kw_UTF8String
164 %token kw_UniversalString
165 %token kw_VideotexString
166 %token kw_VisibleString
167 %token kw_WITH
169 %token RANGE
170 %token EEQUAL
171 %token ELLIPSIS
173 %token <name> IDENTIFIER referencename
174 %token <name> STRING
176 %token <constant> NUMBER
177 %type <constant> SignedNumber
178 %type <constant> Class tagenv
180 %type <value> Value
181 %type <value> BuiltinValue
182 %type <value> IntegerValue
183 %type <value> BooleanValue
184 %type <value> ObjectIdentifierValue
185 %type <value> CharacterStringValue
186 %type <value> NullValue
187 %type <value> DefinedValue
188 %type <value> ReferencedValue
189 %type <value> Valuereference
191 %type <type> Type
192 %type <type> BuiltinType
193 %type <type> BitStringType
194 %type <type> BooleanType
195 %type <type> ChoiceType
196 %type <type> ConstrainedType
197 %type <type> EnumeratedType
198 %type <type> IntegerType
199 %type <type> NullType
200 %type <type> OctetStringType
201 %type <type> SequenceType
202 %type <type> SequenceOfType
203 %type <type> SetType
204 %type <type> SetOfType
205 %type <type> TaggedType
206 %type <type> ReferencedType
207 %type <type> DefinedType
208 %type <type> UsefulType
209 %type <type> ObjectIdentifierType
210 %type <type> CharacterStringType
211 %type <type> RestrictedCharactedStringType
213 %type <tag> Tag
215 %type <member> ComponentType
216 %type <member> NamedBit
217 %type <member> NamedNumber
218 %type <member> NamedType
219 %type <members> ComponentTypeList
220 %type <members> Enumerations
221 %type <members> NamedBitList
222 %type <members> NamedNumberList
224 %type <objid> objid objid_list objid_element objid_opt
225 %type <range> range size
227 %type <sl> referencenames
229 %type <constraint_spec> Constraint
230 %type <constraint_spec> ConstraintSpec
231 %type <constraint_spec> GeneralConstraint
232 %type <constraint_spec> ContentsConstraint
233 %type <constraint_spec> UserDefinedConstraint
237 %start ModuleDefinition
241 ModuleDefinition: IDENTIFIER objid_opt kw_DEFINITIONS TagDefault ExtensionDefault
242 EEQUAL kw_BEGIN ModuleBody kw_END
244 checkundefined();
248 TagDefault : kw_EXPLICIT kw_TAGS
249 | kw_IMPLICIT kw_TAGS
250 { lex_error_message("implicit tagging is not supported"); }
251 | kw_AUTOMATIC kw_TAGS
252 { lex_error_message("automatic tagging is not supported"); }
253 | /* empty */
256 ExtensionDefault: kw_EXTENSIBILITY kw_IMPLIED
257 { lex_error_message("no extensibility options supported"); }
258 | /* empty */
261 ModuleBody : Exports Imports AssignmentList
262 | /* empty */
265 Imports : kw_IMPORTS SymbolsImported ';'
266 | /* empty */
269 SymbolsImported : SymbolsFromModuleList
270 | /* empty */
273 SymbolsFromModuleList: SymbolsFromModule
274 | SymbolsFromModuleList SymbolsFromModule
277 SymbolsFromModule: referencenames kw_FROM IDENTIFIER objid_opt
279 struct string_list *sl;
280 for(sl = $1; sl != NULL; sl = sl->next) {
281 Symbol *s = addsym(sl->string);
282 s->stype = Stype;
283 gen_template_import(s);
285 add_import($3);
289 Exports : kw_EXPORTS referencenames ';'
291 struct string_list *sl;
292 for(sl = $2; sl != NULL; sl = sl->next)
293 add_export(sl->string);
295 | kw_EXPORTS kw_ALL
296 | /* empty */
299 AssignmentList : Assignment
300 | Assignment AssignmentList
303 Assignment : TypeAssignment
304 | ValueAssignment
307 referencenames : IDENTIFIER ',' referencenames
309 $$ = emalloc(sizeof(*$$));
310 $$->string = $1;
311 $$->next = $3;
313 | IDENTIFIER
315 $$ = emalloc(sizeof(*$$));
316 $$->string = $1;
317 $$->next = NULL;
321 TypeAssignment : IDENTIFIER EEQUAL Type
323 Symbol *s = addsym ($1);
324 s->stype = Stype;
325 s->type = $3;
326 fix_labels(s);
327 generate_type (s);
331 Type : BuiltinType
332 | ReferencedType
333 | ConstrainedType
336 BuiltinType : BitStringType
337 | BooleanType
338 | CharacterStringType
339 | ChoiceType
340 | EnumeratedType
341 | IntegerType
342 | NullType
343 | ObjectIdentifierType
344 | OctetStringType
345 | SequenceType
346 | SequenceOfType
347 | SetType
348 | SetOfType
349 | TaggedType
352 BooleanType : kw_BOOLEAN
354 $$ = new_tag(ASN1_C_UNIV, UT_Boolean,
355 TE_EXPLICIT, new_type(TBoolean));
359 range : '(' Value RANGE Value ')'
361 if($2->type != integervalue)
362 lex_error_message("Non-integer used in first part of range");
363 if($2->type != integervalue)
364 lex_error_message("Non-integer in second part of range");
365 $$ = ecalloc(1, sizeof(*$$));
366 $$->min = $2->u.integervalue;
367 $$->max = $4->u.integervalue;
369 | '(' Value RANGE kw_MAX ')'
371 if($2->type != integervalue)
372 lex_error_message("Non-integer in first part of range");
373 $$ = ecalloc(1, sizeof(*$$));
374 $$->min = $2->u.integervalue;
375 $$->max = $2->u.integervalue - 1;
377 | '(' kw_MIN RANGE Value ')'
379 if($4->type != integervalue)
380 lex_error_message("Non-integer in second part of range");
381 $$ = ecalloc(1, sizeof(*$$));
382 $$->min = $4->u.integervalue + 2;
383 $$->max = $4->u.integervalue;
385 | '(' Value ')'
387 if($2->type != integervalue)
388 lex_error_message("Non-integer used in limit");
389 $$ = ecalloc(1, sizeof(*$$));
390 $$->min = $2->u.integervalue;
391 $$->max = $2->u.integervalue;
396 IntegerType : kw_INTEGER
398 $$ = new_tag(ASN1_C_UNIV, UT_Integer,
399 TE_EXPLICIT, new_type(TInteger));
401 | kw_INTEGER range
403 $$ = new_type(TInteger);
404 $$->range = $2;
405 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
407 | kw_INTEGER '{' NamedNumberList '}'
409 $$ = new_type(TInteger);
410 $$->members = $3;
411 $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
415 NamedNumberList : NamedNumber
417 $$ = emalloc(sizeof(*$$));
418 ASN1_TAILQ_INIT($$);
419 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
421 | NamedNumberList ',' NamedNumber
423 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
424 $$ = $1;
426 | NamedNumberList ',' ELLIPSIS
427 { $$ = $1; } /* XXX used for Enumerations */
430 NamedNumber : IDENTIFIER '(' SignedNumber ')'
432 $$ = emalloc(sizeof(*$$));
433 $$->name = $1;
434 $$->gen_name = estrdup($1);
435 output_name ($$->gen_name);
436 $$->val = $3;
437 $$->optional = 0;
438 $$->ellipsis = 0;
439 $$->type = NULL;
443 EnumeratedType : kw_ENUMERATED '{' Enumerations '}'
445 $$ = new_type(TInteger);
446 $$->members = $3;
447 $$ = new_tag(ASN1_C_UNIV, UT_Enumerated, TE_EXPLICIT, $$);
451 Enumerations : NamedNumberList /* XXX */
454 BitStringType : kw_BIT kw_STRING
456 $$ = new_type(TBitString);
457 $$->members = emalloc(sizeof(*$$->members));
458 ASN1_TAILQ_INIT($$->members);
459 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
461 | kw_BIT kw_STRING '{' NamedBitList '}'
463 $$ = new_type(TBitString);
464 $$->members = $4;
465 $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
469 ObjectIdentifierType: kw_OBJECT kw_IDENTIFIER
471 $$ = new_tag(ASN1_C_UNIV, UT_OID,
472 TE_EXPLICIT, new_type(TOID));
475 OctetStringType : kw_OCTET kw_STRING size
477 Type *t = new_type(TOctetString);
478 t->range = $3;
479 $$ = new_tag(ASN1_C_UNIV, UT_OctetString,
480 TE_EXPLICIT, t);
484 NullType : kw_NULL
486 $$ = new_tag(ASN1_C_UNIV, UT_Null,
487 TE_EXPLICIT, new_type(TNull));
491 size :
492 { $$ = NULL; }
493 | kw_SIZE range
494 { $$ = $2; }
498 SequenceType : kw_SEQUENCE '{' /* ComponentTypeLists */ ComponentTypeList '}'
500 $$ = new_type(TSequence);
501 $$->members = $3;
502 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
504 | kw_SEQUENCE '{' '}'
506 $$ = new_type(TSequence);
507 $$->members = NULL;
508 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
512 SequenceOfType : kw_SEQUENCE size kw_OF Type
514 $$ = new_type(TSequenceOf);
515 $$->range = $2;
516 $$->subtype = $4;
517 $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
521 SetType : kw_SET '{' /* ComponentTypeLists */ ComponentTypeList '}'
523 $$ = new_type(TSet);
524 $$->members = $3;
525 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
527 | kw_SET '{' '}'
529 $$ = new_type(TSet);
530 $$->members = NULL;
531 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
535 SetOfType : kw_SET kw_OF Type
537 $$ = new_type(TSetOf);
538 $$->subtype = $3;
539 $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
543 ChoiceType : kw_CHOICE '{' /* AlternativeTypeLists */ ComponentTypeList '}'
545 $$ = new_type(TChoice);
546 $$->members = $3;
550 ReferencedType : DefinedType
551 | UsefulType
554 DefinedType : IDENTIFIER
556 Symbol *s = addsym($1);
557 $$ = new_type(TType);
558 if(s->stype != Stype && s->stype != SUndefined)
559 lex_error_message ("%s is not a type\n", $1);
560 else
561 $$->symbol = s;
565 UsefulType : kw_GeneralizedTime
567 $$ = new_tag(ASN1_C_UNIV, UT_GeneralizedTime,
568 TE_EXPLICIT, new_type(TGeneralizedTime));
570 | kw_UTCTime
572 $$ = new_tag(ASN1_C_UNIV, UT_UTCTime,
573 TE_EXPLICIT, new_type(TUTCTime));
577 ConstrainedType : Type Constraint
579 /* if (Constraint.type == contentConstrant) {
580 assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
581 if (Constraint.u.constraint.type) {
582 assert((Constraint.u.constraint.type.length % 8) == 0);
585 if (Constraint.u.constraint.encoding) {
586 type == der-oid|ber-oid
593 Constraint : '(' ConstraintSpec ')'
595 $$ = $2;
599 ConstraintSpec : GeneralConstraint
602 GeneralConstraint: ContentsConstraint
603 | UserDefinedConstraint
606 ContentsConstraint: kw_CONTAINING Type
608 $$ = new_constraint_spec(CT_CONTENTS);
609 $$->u.content.type = $2;
610 $$->u.content.encoding = NULL;
612 | kw_ENCODED kw_BY Value
614 if ($3->type != objectidentifiervalue)
615 lex_error_message("Non-OID used in ENCODED BY constraint");
616 $$ = new_constraint_spec(CT_CONTENTS);
617 $$->u.content.type = NULL;
618 $$->u.content.encoding = $3;
620 | kw_CONTAINING Type kw_ENCODED kw_BY Value
622 if ($5->type != objectidentifiervalue)
623 lex_error_message("Non-OID used in ENCODED BY constraint");
624 $$ = new_constraint_spec(CT_CONTENTS);
625 $$->u.content.type = $2;
626 $$->u.content.encoding = $5;
630 UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}'
632 $$ = new_constraint_spec(CT_USER);
636 TaggedType : Tag tagenv Type
638 $$ = new_type(TTag);
639 $$->tag = $1;
640 $$->tag.tagenv = $2;
641 if($3->type == TTag && $2 == TE_IMPLICIT) {
642 $$->subtype = $3->subtype;
643 free($3);
644 } else
645 $$->subtype = $3;
649 Tag : '[' Class NUMBER ']'
651 $$.tagclass = $2;
652 $$.tagvalue = $3;
653 $$.tagenv = TE_EXPLICIT;
657 Class : /* */
659 $$ = ASN1_C_CONTEXT;
661 | kw_UNIVERSAL
663 $$ = ASN1_C_UNIV;
665 | kw_APPLICATION
667 $$ = ASN1_C_APPL;
669 | kw_PRIVATE
671 $$ = ASN1_C_PRIVATE;
675 tagenv : /* */
677 $$ = TE_EXPLICIT;
679 | kw_EXPLICIT
681 $$ = TE_EXPLICIT;
683 | kw_IMPLICIT
685 $$ = TE_IMPLICIT;
690 ValueAssignment : IDENTIFIER Type EEQUAL Value
692 Symbol *s;
693 s = addsym ($1);
695 s->stype = SValue;
696 s->value = $4;
697 generate_constant (s);
701 CharacterStringType: RestrictedCharactedStringType
704 RestrictedCharactedStringType: kw_GeneralString
706 $$ = new_tag(ASN1_C_UNIV, UT_GeneralString,
707 TE_EXPLICIT, new_type(TGeneralString));
709 | kw_TeletexString
711 $$ = new_tag(ASN1_C_UNIV, UT_TeletexString,
712 TE_EXPLICIT, new_type(TTeletexString));
714 | kw_UTF8String
716 $$ = new_tag(ASN1_C_UNIV, UT_UTF8String,
717 TE_EXPLICIT, new_type(TUTF8String));
719 | kw_PrintableString
721 $$ = new_tag(ASN1_C_UNIV, UT_PrintableString,
722 TE_EXPLICIT, new_type(TPrintableString));
724 | kw_VisibleString
726 $$ = new_tag(ASN1_C_UNIV, UT_VisibleString,
727 TE_EXPLICIT, new_type(TVisibleString));
729 | kw_IA5String
731 $$ = new_tag(ASN1_C_UNIV, UT_IA5String,
732 TE_EXPLICIT, new_type(TIA5String));
734 | kw_BMPString
736 $$ = new_tag(ASN1_C_UNIV, UT_BMPString,
737 TE_EXPLICIT, new_type(TBMPString));
739 | kw_UniversalString
741 $$ = new_tag(ASN1_C_UNIV, UT_UniversalString,
742 TE_EXPLICIT, new_type(TUniversalString));
747 ComponentTypeList: ComponentType
749 $$ = emalloc(sizeof(*$$));
750 ASN1_TAILQ_INIT($$);
751 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
753 | ComponentTypeList ',' ComponentType
755 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
756 $$ = $1;
758 | ComponentTypeList ',' ELLIPSIS
760 struct member *m = ecalloc(1, sizeof(*m));
761 m->name = estrdup("...");
762 m->gen_name = estrdup("asn1_ellipsis");
763 m->ellipsis = 1;
764 ASN1_TAILQ_INSERT_TAIL($1, m, members);
765 $$ = $1;
769 NamedType : IDENTIFIER Type
771 $$ = emalloc(sizeof(*$$));
772 $$->name = $1;
773 $$->gen_name = estrdup($1);
774 output_name ($$->gen_name);
775 $$->type = $2;
776 $$->ellipsis = 0;
780 ComponentType : NamedType
782 $$ = $1;
783 $$->optional = 0;
784 $$->defval = NULL;
786 | NamedType kw_OPTIONAL
788 $$ = $1;
789 $$->optional = 1;
790 $$->defval = NULL;
792 | NamedType kw_DEFAULT Value
794 $$ = $1;
795 $$->optional = 0;
796 $$->defval = $3;
800 NamedBitList : NamedBit
802 $$ = emalloc(sizeof(*$$));
803 ASN1_TAILQ_INIT($$);
804 ASN1_TAILQ_INSERT_HEAD($$, $1, members);
806 | NamedBitList ',' NamedBit
808 ASN1_TAILQ_INSERT_TAIL($1, $3, members);
809 $$ = $1;
813 NamedBit : IDENTIFIER '(' NUMBER ')'
815 $$ = emalloc(sizeof(*$$));
816 $$->name = $1;
817 $$->gen_name = estrdup($1);
818 output_name ($$->gen_name);
819 $$->val = $3;
820 $$->optional = 0;
821 $$->ellipsis = 0;
822 $$->type = NULL;
826 objid_opt : objid
827 | /* empty */ { $$ = NULL; }
830 objid : '{' objid_list '}'
832 $$ = $2;
836 objid_list : /* empty */
838 $$ = NULL;
840 | objid_element objid_list
842 if ($2) {
843 $$ = $2;
844 add_oid_to_tail($2, $1);
845 } else {
846 $$ = $1;
851 objid_element : IDENTIFIER '(' NUMBER ')'
853 $$ = new_objid($1, $3);
855 | IDENTIFIER
857 Symbol *s = addsym($1);
858 if(s->stype != SValue ||
859 s->value->type != objectidentifiervalue) {
860 lex_error_message("%s is not an object identifier\n",
861 s->name);
862 exit(1);
864 $$ = s->value->u.objectidentifiervalue;
866 | NUMBER
868 $$ = new_objid(NULL, $1);
872 Value : BuiltinValue
873 | ReferencedValue
876 BuiltinValue : BooleanValue
877 | CharacterStringValue
878 | IntegerValue
879 | ObjectIdentifierValue
880 | NullValue
883 ReferencedValue : DefinedValue
886 DefinedValue : Valuereference
889 Valuereference : IDENTIFIER
891 Symbol *s = addsym($1);
892 if(s->stype != SValue)
893 lex_error_message ("%s is not a value\n",
894 s->name);
895 else
896 $$ = s->value;
900 CharacterStringValue: STRING
902 $$ = emalloc(sizeof(*$$));
903 $$->type = stringvalue;
904 $$->u.stringvalue = $1;
908 BooleanValue : kw_TRUE
910 $$ = emalloc(sizeof(*$$));
911 $$->type = booleanvalue;
912 $$->u.booleanvalue = 0;
914 | kw_FALSE
916 $$ = emalloc(sizeof(*$$));
917 $$->type = booleanvalue;
918 $$->u.booleanvalue = 0;
922 IntegerValue : SignedNumber
924 $$ = emalloc(sizeof(*$$));
925 $$->type = integervalue;
926 $$->u.integervalue = $1;
930 SignedNumber : NUMBER
933 NullValue : kw_NULL
938 ObjectIdentifierValue: objid
940 $$ = emalloc(sizeof(*$$));
941 $$->type = objectidentifiervalue;
942 $$->u.objectidentifiervalue = $1;
948 void
949 yyerror (const char *s)
951 lex_error_message ("%s\n", s);
954 static Type *
955 new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype)
957 Type *t;
958 if(oldtype->type == TTag && oldtype->tag.tagenv == TE_IMPLICIT) {
959 t = oldtype;
960 oldtype = oldtype->subtype; /* XXX */
961 } else
962 t = new_type (TTag);
964 t->tag.tagclass = tagclass;
965 t->tag.tagvalue = tagvalue;
966 t->tag.tagenv = tagenv;
967 t->subtype = oldtype;
968 return t;
971 static struct objid *
972 new_objid(const char *label, int value)
974 struct objid *s;
975 s = emalloc(sizeof(*s));
976 s->label = label;
977 s->value = value;
978 s->next = NULL;
979 return s;
982 static void
983 add_oid_to_tail(struct objid *head, struct objid *tail)
985 struct objid *o;
986 o = head;
987 while (o->next)
988 o = o->next;
989 o->next = tail;
992 static Type *
993 new_type (Typetype tt)
995 Type *t = ecalloc(1, sizeof(*t));
996 t->type = tt;
997 return t;
1000 static struct constraint_spec *
1001 new_constraint_spec(enum ctype ct)
1003 struct constraint_spec *c = ecalloc(1, sizeof(*c));
1004 c->ctype = ct;
1005 return c;
1008 static void fix_labels2(Type *t, const char *prefix);
1009 static void fix_labels1(struct memhead *members, const char *prefix)
1011 Member *m;
1013 if(members == NULL)
1014 return;
1015 ASN1_TAILQ_FOREACH(m, members, members) {
1016 if (asprintf(&m->label, "%s_%s", prefix, m->gen_name) < 0)
1017 errx(1, "malloc");
1018 if (m->label == NULL)
1019 errx(1, "malloc");
1020 if(m->type != NULL)
1021 fix_labels2(m->type, m->label);
1025 static void fix_labels2(Type *t, const char *prefix)
1027 for(; t; t = t->subtype)
1028 fix_labels1(t->members, prefix);
1031 static void
1032 fix_labels(Symbol *s)
1034 char *p = NULL;
1035 if (asprintf(&p, "choice_%s", s->gen_name) < 0 || p == NULL)
1036 errx(1, "malloc");
1037 fix_labels2(s->type, p);
1038 free(p);