Home | History | Annotate | Line # | Download | only in asn1
asn1parse.y revision 1.1
      1  1.1  elric /*	$NetBSD: asn1parse.y,v 1.1 2011/04/13 18:14:39 elric Exp $	*/
      2  1.1  elric 
      3  1.1  elric /*
      4  1.1  elric  * Copyright (c) 1997 - 2007 Kungliga Tekniska Hgskolan
      5  1.1  elric  * (Royal Institute of Technology, Stockholm, Sweden).
      6  1.1  elric  * All rights reserved.
      7  1.1  elric  *
      8  1.1  elric  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
      9  1.1  elric  *
     10  1.1  elric  * Redistribution and use in source and binary forms, with or without
     11  1.1  elric  * modification, are permitted provided that the following conditions
     12  1.1  elric  * are met:
     13  1.1  elric  *
     14  1.1  elric  * 1. Redistributions of source code must retain the above copyright
     15  1.1  elric  *    notice, this list of conditions and the following disclaimer.
     16  1.1  elric  *
     17  1.1  elric  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1  elric  *    notice, this list of conditions and the following disclaimer in the
     19  1.1  elric  *    documentation and/or other materials provided with the distribution.
     20  1.1  elric  *
     21  1.1  elric  * 3. Neither the name of the Institute nor the names of its contributors
     22  1.1  elric  *    may be used to endorse or promote products derived from this software
     23  1.1  elric  *    without specific prior written permission.
     24  1.1  elric  *
     25  1.1  elric  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
     26  1.1  elric  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1  elric  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1  elric  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
     29  1.1  elric  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1  elric  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1  elric  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1  elric  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1  elric  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1  elric  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1  elric  * SUCH DAMAGE.
     36  1.1  elric  */
     37  1.1  elric 
     38  1.1  elric /* $Id: asn1parse.y,v 1.1 2011/04/13 18:14:39 elric Exp $ */
     39  1.1  elric 
     40  1.1  elric %{
     41  1.1  elric 
     42  1.1  elric #include <config.h>
     43  1.1  elric 
     44  1.1  elric #include <stdio.h>
     45  1.1  elric #include <stdlib.h>
     46  1.1  elric #include <string.h>
     47  1.1  elric #include "symbol.h"
     48  1.1  elric #include "lex.h"
     49  1.1  elric #include "gen_locl.h"
     50  1.1  elric #include "der.h"
     51  1.1  elric 
     52  1.1  elric __RCSID("$NetBSD: asn1parse.y,v 1.1 2011/04/13 18:14:39 elric Exp $");
     53  1.1  elric 
     54  1.1  elric static Type *new_type (Typetype t);
     55  1.1  elric static struct constraint_spec *new_constraint_spec(enum ctype);
     56  1.1  elric static Type *new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype);
     57  1.1  elric void yyerror (const char *);
     58  1.1  elric static struct objid *new_objid(const char *label, int value);
     59  1.1  elric static void add_oid_to_tail(struct objid *, struct objid *);
     60  1.1  elric static void fix_labels(Symbol *s);
     61  1.1  elric 
     62  1.1  elric struct string_list {
     63  1.1  elric     char *string;
     64  1.1  elric     struct string_list *next;
     65  1.1  elric };
     66  1.1  elric 
     67  1.1  elric /* Declarations for Bison */
     68  1.1  elric #define YYMALLOC malloc
     69  1.1  elric #define YYFREE   free
     70  1.1  elric 
     71  1.1  elric %}
     72  1.1  elric 
     73  1.1  elric %union {
     74  1.1  elric     int constant;
     75  1.1  elric     struct value *value;
     76  1.1  elric     struct range *range;
     77  1.1  elric     char *name;
     78  1.1  elric     Type *type;
     79  1.1  elric     Member *member;
     80  1.1  elric     struct objid *objid;
     81  1.1  elric     char *defval;
     82  1.1  elric     struct string_list *sl;
     83  1.1  elric     struct tagtype tag;
     84  1.1  elric     struct memhead *members;
     85  1.1  elric     struct constraint_spec *constraint_spec;
     86  1.1  elric }
     87  1.1  elric 
     88  1.1  elric %token kw_ABSENT
     89  1.1  elric %token kw_ABSTRACT_SYNTAX
     90  1.1  elric %token kw_ALL
     91  1.1  elric %token kw_APPLICATION
     92  1.1  elric %token kw_AUTOMATIC
     93  1.1  elric %token kw_BEGIN
     94  1.1  elric %token kw_BIT
     95  1.1  elric %token kw_BMPString
     96  1.1  elric %token kw_BOOLEAN
     97  1.1  elric %token kw_BY
     98  1.1  elric %token kw_CHARACTER
     99  1.1  elric %token kw_CHOICE
    100  1.1  elric %token kw_CLASS
    101  1.1  elric %token kw_COMPONENT
    102  1.1  elric %token kw_COMPONENTS
    103  1.1  elric %token kw_CONSTRAINED
    104  1.1  elric %token kw_CONTAINING
    105  1.1  elric %token kw_DEFAULT
    106  1.1  elric %token kw_DEFINITIONS
    107  1.1  elric %token kw_EMBEDDED
    108  1.1  elric %token kw_ENCODED
    109  1.1  elric %token kw_END
    110  1.1  elric %token kw_ENUMERATED
    111  1.1  elric %token kw_EXCEPT
    112  1.1  elric %token kw_EXPLICIT
    113  1.1  elric %token kw_EXPORTS
    114  1.1  elric %token kw_EXTENSIBILITY
    115  1.1  elric %token kw_EXTERNAL
    116  1.1  elric %token kw_FALSE
    117  1.1  elric %token kw_FROM
    118  1.1  elric %token kw_GeneralString
    119  1.1  elric %token kw_GeneralizedTime
    120  1.1  elric %token kw_GraphicString
    121  1.1  elric %token kw_IA5String
    122  1.1  elric %token kw_IDENTIFIER
    123  1.1  elric %token kw_IMPLICIT
    124  1.1  elric %token kw_IMPLIED
    125  1.1  elric %token kw_IMPORTS
    126  1.1  elric %token kw_INCLUDES
    127  1.1  elric %token kw_INSTANCE
    128  1.1  elric %token kw_INTEGER
    129  1.1  elric %token kw_INTERSECTION
    130  1.1  elric %token kw_ISO646String
    131  1.1  elric %token kw_MAX
    132  1.1  elric %token kw_MIN
    133  1.1  elric %token kw_MINUS_INFINITY
    134  1.1  elric %token kw_NULL
    135  1.1  elric %token kw_NumericString
    136  1.1  elric %token kw_OBJECT
    137  1.1  elric %token kw_OCTET
    138  1.1  elric %token kw_OF
    139  1.1  elric %token kw_OPTIONAL
    140  1.1  elric %token kw_ObjectDescriptor
    141  1.1  elric %token kw_PATTERN
    142  1.1  elric %token kw_PDV
    143  1.1  elric %token kw_PLUS_INFINITY
    144  1.1  elric %token kw_PRESENT
    145  1.1  elric %token kw_PRIVATE
    146  1.1  elric %token kw_PrintableString
    147  1.1  elric %token kw_REAL
    148  1.1  elric %token kw_RELATIVE_OID
    149  1.1  elric %token kw_SEQUENCE
    150  1.1  elric %token kw_SET
    151  1.1  elric %token kw_SIZE
    152  1.1  elric %token kw_STRING
    153  1.1  elric %token kw_SYNTAX
    154  1.1  elric %token kw_T61String
    155  1.1  elric %token kw_TAGS
    156  1.1  elric %token kw_TRUE
    157  1.1  elric %token kw_TYPE_IDENTIFIER
    158  1.1  elric %token kw_TeletexString
    159  1.1  elric %token kw_UNION
    160  1.1  elric %token kw_UNIQUE
    161  1.1  elric %token kw_UNIVERSAL
    162  1.1  elric %token kw_UTCTime
    163  1.1  elric %token kw_UTF8String
    164  1.1  elric %token kw_UniversalString
    165  1.1  elric %token kw_VideotexString
    166  1.1  elric %token kw_VisibleString
    167  1.1  elric %token kw_WITH
    168  1.1  elric 
    169  1.1  elric %token RANGE
    170  1.1  elric %token EEQUAL
    171  1.1  elric %token ELLIPSIS
    172  1.1  elric 
    173  1.1  elric %token <name> IDENTIFIER  referencename
    174  1.1  elric %token <name> STRING
    175  1.1  elric 
    176  1.1  elric %token <constant> NUMBER
    177  1.1  elric %type <constant> SignedNumber
    178  1.1  elric %type <constant> Class tagenv
    179  1.1  elric 
    180  1.1  elric %type <value> Value
    181  1.1  elric %type <value> BuiltinValue
    182  1.1  elric %type <value> IntegerValue
    183  1.1  elric %type <value> BooleanValue
    184  1.1  elric %type <value> ObjectIdentifierValue
    185  1.1  elric %type <value> CharacterStringValue
    186  1.1  elric %type <value> NullValue
    187  1.1  elric %type <value> DefinedValue
    188  1.1  elric %type <value> ReferencedValue
    189  1.1  elric %type <value> Valuereference
    190  1.1  elric 
    191  1.1  elric %type <type> Type
    192  1.1  elric %type <type> BuiltinType
    193  1.1  elric %type <type> BitStringType
    194  1.1  elric %type <type> BooleanType
    195  1.1  elric %type <type> ChoiceType
    196  1.1  elric %type <type> ConstrainedType
    197  1.1  elric %type <type> EnumeratedType
    198  1.1  elric %type <type> IntegerType
    199  1.1  elric %type <type> NullType
    200  1.1  elric %type <type> OctetStringType
    201  1.1  elric %type <type> SequenceType
    202  1.1  elric %type <type> SequenceOfType
    203  1.1  elric %type <type> SetType
    204  1.1  elric %type <type> SetOfType
    205  1.1  elric %type <type> TaggedType
    206  1.1  elric %type <type> ReferencedType
    207  1.1  elric %type <type> DefinedType
    208  1.1  elric %type <type> UsefulType
    209  1.1  elric %type <type> ObjectIdentifierType
    210  1.1  elric %type <type> CharacterStringType
    211  1.1  elric %type <type> RestrictedCharactedStringType
    212  1.1  elric 
    213  1.1  elric %type <tag> Tag
    214  1.1  elric 
    215  1.1  elric %type <member> ComponentType
    216  1.1  elric %type <member> NamedBit
    217  1.1  elric %type <member> NamedNumber
    218  1.1  elric %type <member> NamedType
    219  1.1  elric %type <members> ComponentTypeList
    220  1.1  elric %type <members> Enumerations
    221  1.1  elric %type <members> NamedBitList
    222  1.1  elric %type <members> NamedNumberList
    223  1.1  elric 
    224  1.1  elric %type <objid> objid objid_list objid_element objid_opt
    225  1.1  elric %type <range> range size
    226  1.1  elric 
    227  1.1  elric %type <sl> referencenames
    228  1.1  elric 
    229  1.1  elric %type <constraint_spec> Constraint
    230  1.1  elric %type <constraint_spec> ConstraintSpec
    231  1.1  elric %type <constraint_spec> GeneralConstraint
    232  1.1  elric %type <constraint_spec> ContentsConstraint
    233  1.1  elric %type <constraint_spec> UserDefinedConstraint
    234  1.1  elric 
    235  1.1  elric 
    236  1.1  elric 
    237  1.1  elric %start ModuleDefinition
    238  1.1  elric 
    239  1.1  elric %%
    240  1.1  elric 
    241  1.1  elric ModuleDefinition: IDENTIFIER objid_opt kw_DEFINITIONS TagDefault ExtensionDefault
    242  1.1  elric 			EEQUAL kw_BEGIN ModuleBody kw_END
    243  1.1  elric 		{
    244  1.1  elric 			checkundefined();
    245  1.1  elric 		}
    246  1.1  elric 		;
    247  1.1  elric 
    248  1.1  elric TagDefault	: kw_EXPLICIT kw_TAGS
    249  1.1  elric 		| kw_IMPLICIT kw_TAGS
    250  1.1  elric 		      { lex_error_message("implicit tagging is not supported"); }
    251  1.1  elric 		| kw_AUTOMATIC kw_TAGS
    252  1.1  elric 		      { lex_error_message("automatic tagging is not supported"); }
    253  1.1  elric 		| /* empty */
    254  1.1  elric 		;
    255  1.1  elric 
    256  1.1  elric ExtensionDefault: kw_EXTENSIBILITY kw_IMPLIED
    257  1.1  elric 		      { lex_error_message("no extensibility options supported"); }
    258  1.1  elric 		| /* empty */
    259  1.1  elric 		;
    260  1.1  elric 
    261  1.1  elric ModuleBody	: Exports Imports AssignmentList
    262  1.1  elric 		| /* empty */
    263  1.1  elric 		;
    264  1.1  elric 
    265  1.1  elric Imports		: kw_IMPORTS SymbolsImported ';'
    266  1.1  elric 		| /* empty */
    267  1.1  elric 		;
    268  1.1  elric 
    269  1.1  elric SymbolsImported	: SymbolsFromModuleList
    270  1.1  elric 		| /* empty */
    271  1.1  elric 		;
    272  1.1  elric 
    273  1.1  elric SymbolsFromModuleList: SymbolsFromModule
    274  1.1  elric 		| SymbolsFromModuleList SymbolsFromModule
    275  1.1  elric 		;
    276  1.1  elric 
    277  1.1  elric SymbolsFromModule: referencenames kw_FROM IDENTIFIER objid_opt
    278  1.1  elric 		{
    279  1.1  elric 		    struct string_list *sl;
    280  1.1  elric 		    for(sl = $1; sl != NULL; sl = sl->next) {
    281  1.1  elric 			Symbol *s = addsym(sl->string);
    282  1.1  elric 			s->stype = Stype;
    283  1.1  elric 			gen_template_import(s);
    284  1.1  elric 		    }
    285  1.1  elric 		    add_import($3);
    286  1.1  elric 		}
    287  1.1  elric 		;
    288  1.1  elric 
    289  1.1  elric Exports		: kw_EXPORTS referencenames ';'
    290  1.1  elric 		{
    291  1.1  elric 		    struct string_list *sl;
    292  1.1  elric 		    for(sl = $2; sl != NULL; sl = sl->next)
    293  1.1  elric 			add_export(sl->string);
    294  1.1  elric 		}
    295  1.1  elric 		| kw_EXPORTS kw_ALL
    296  1.1  elric 		| /* empty */
    297  1.1  elric 		;
    298  1.1  elric 
    299  1.1  elric AssignmentList	: Assignment
    300  1.1  elric 		| Assignment AssignmentList
    301  1.1  elric 		;
    302  1.1  elric 
    303  1.1  elric Assignment	: TypeAssignment
    304  1.1  elric 		| ValueAssignment
    305  1.1  elric 		;
    306  1.1  elric 
    307  1.1  elric referencenames	: IDENTIFIER ',' referencenames
    308  1.1  elric 		{
    309  1.1  elric 		    $$ = emalloc(sizeof(*$$));
    310  1.1  elric 		    $$->string = $1;
    311  1.1  elric 		    $$->next = $3;
    312  1.1  elric 		}
    313  1.1  elric 		| IDENTIFIER
    314  1.1  elric 		{
    315  1.1  elric 		    $$ = emalloc(sizeof(*$$));
    316  1.1  elric 		    $$->string = $1;
    317  1.1  elric 		    $$->next = NULL;
    318  1.1  elric 		}
    319  1.1  elric 		;
    320  1.1  elric 
    321  1.1  elric TypeAssignment	: IDENTIFIER EEQUAL Type
    322  1.1  elric 		{
    323  1.1  elric 		    Symbol *s = addsym ($1);
    324  1.1  elric 		    s->stype = Stype;
    325  1.1  elric 		    s->type = $3;
    326  1.1  elric 		    fix_labels(s);
    327  1.1  elric 		    generate_type (s);
    328  1.1  elric 		}
    329  1.1  elric 		;
    330  1.1  elric 
    331  1.1  elric Type		: BuiltinType
    332  1.1  elric 		| ReferencedType
    333  1.1  elric 		| ConstrainedType
    334  1.1  elric 		;
    335  1.1  elric 
    336  1.1  elric BuiltinType	: BitStringType
    337  1.1  elric 		| BooleanType
    338  1.1  elric 		| CharacterStringType
    339  1.1  elric 		| ChoiceType
    340  1.1  elric 		| EnumeratedType
    341  1.1  elric 		| IntegerType
    342  1.1  elric 		| NullType
    343  1.1  elric 		| ObjectIdentifierType
    344  1.1  elric 		| OctetStringType
    345  1.1  elric 		| SequenceType
    346  1.1  elric 		| SequenceOfType
    347  1.1  elric 		| SetType
    348  1.1  elric 		| SetOfType
    349  1.1  elric 		| TaggedType
    350  1.1  elric 		;
    351  1.1  elric 
    352  1.1  elric BooleanType	: kw_BOOLEAN
    353  1.1  elric 		{
    354  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_Boolean,
    355  1.1  elric 				     TE_EXPLICIT, new_type(TBoolean));
    356  1.1  elric 		}
    357  1.1  elric 		;
    358  1.1  elric 
    359  1.1  elric range		: '(' Value RANGE Value ')'
    360  1.1  elric 		{
    361  1.1  elric 		    if($2->type != integervalue)
    362  1.1  elric 			lex_error_message("Non-integer used in first part of range");
    363  1.1  elric 		    if($2->type != integervalue)
    364  1.1  elric 			lex_error_message("Non-integer in second part of range");
    365  1.1  elric 		    $$ = ecalloc(1, sizeof(*$$));
    366  1.1  elric 		    $$->min = $2->u.integervalue;
    367  1.1  elric 		    $$->max = $4->u.integervalue;
    368  1.1  elric 		}
    369  1.1  elric 		| '(' Value RANGE kw_MAX ')'
    370  1.1  elric 		{
    371  1.1  elric 		    if($2->type != integervalue)
    372  1.1  elric 			lex_error_message("Non-integer in first part of range");
    373  1.1  elric 		    $$ = ecalloc(1, sizeof(*$$));
    374  1.1  elric 		    $$->min = $2->u.integervalue;
    375  1.1  elric 		    $$->max = $2->u.integervalue - 1;
    376  1.1  elric 		}
    377  1.1  elric 		| '(' kw_MIN RANGE Value ')'
    378  1.1  elric 		{
    379  1.1  elric 		    if($4->type != integervalue)
    380  1.1  elric 			lex_error_message("Non-integer in second part of range");
    381  1.1  elric 		    $$ = ecalloc(1, sizeof(*$$));
    382  1.1  elric 		    $$->min = $4->u.integervalue + 2;
    383  1.1  elric 		    $$->max = $4->u.integervalue;
    384  1.1  elric 		}
    385  1.1  elric 		| '(' Value ')'
    386  1.1  elric 		{
    387  1.1  elric 		    if($2->type != integervalue)
    388  1.1  elric 			lex_error_message("Non-integer used in limit");
    389  1.1  elric 		    $$ = ecalloc(1, sizeof(*$$));
    390  1.1  elric 		    $$->min = $2->u.integervalue;
    391  1.1  elric 		    $$->max = $2->u.integervalue;
    392  1.1  elric 		}
    393  1.1  elric 		;
    394  1.1  elric 
    395  1.1  elric 
    396  1.1  elric IntegerType	: kw_INTEGER
    397  1.1  elric 		{
    398  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_Integer,
    399  1.1  elric 				     TE_EXPLICIT, new_type(TInteger));
    400  1.1  elric 		}
    401  1.1  elric 		| kw_INTEGER range
    402  1.1  elric 		{
    403  1.1  elric 			$$ = new_type(TInteger);
    404  1.1  elric 			$$->range = $2;
    405  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
    406  1.1  elric 		}
    407  1.1  elric 		| kw_INTEGER '{' NamedNumberList '}'
    408  1.1  elric 		{
    409  1.1  elric 		  $$ = new_type(TInteger);
    410  1.1  elric 		  $$->members = $3;
    411  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Integer, TE_EXPLICIT, $$);
    412  1.1  elric 		}
    413  1.1  elric 		;
    414  1.1  elric 
    415  1.1  elric NamedNumberList	: NamedNumber
    416  1.1  elric 		{
    417  1.1  elric 			$$ = emalloc(sizeof(*$$));
    418  1.1  elric 			ASN1_TAILQ_INIT($$);
    419  1.1  elric 			ASN1_TAILQ_INSERT_HEAD($$, $1, members);
    420  1.1  elric 		}
    421  1.1  elric 		| NamedNumberList ',' NamedNumber
    422  1.1  elric 		{
    423  1.1  elric 			ASN1_TAILQ_INSERT_TAIL($1, $3, members);
    424  1.1  elric 			$$ = $1;
    425  1.1  elric 		}
    426  1.1  elric 		| NamedNumberList ',' ELLIPSIS
    427  1.1  elric 			{ $$ = $1; } /* XXX used for Enumerations */
    428  1.1  elric 		;
    429  1.1  elric 
    430  1.1  elric NamedNumber	: IDENTIFIER '(' SignedNumber ')'
    431  1.1  elric 		{
    432  1.1  elric 			$$ = emalloc(sizeof(*$$));
    433  1.1  elric 			$$->name = $1;
    434  1.1  elric 			$$->gen_name = estrdup($1);
    435  1.1  elric 			output_name ($$->gen_name);
    436  1.1  elric 			$$->val = $3;
    437  1.1  elric 			$$->optional = 0;
    438  1.1  elric 			$$->ellipsis = 0;
    439  1.1  elric 			$$->type = NULL;
    440  1.1  elric 		}
    441  1.1  elric 		;
    442  1.1  elric 
    443  1.1  elric EnumeratedType	: kw_ENUMERATED '{' Enumerations '}'
    444  1.1  elric 		{
    445  1.1  elric 		  $$ = new_type(TInteger);
    446  1.1  elric 		  $$->members = $3;
    447  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Enumerated, TE_EXPLICIT, $$);
    448  1.1  elric 		}
    449  1.1  elric 		;
    450  1.1  elric 
    451  1.1  elric Enumerations	: NamedNumberList /* XXX */
    452  1.1  elric 		;
    453  1.1  elric 
    454  1.1  elric BitStringType	: kw_BIT kw_STRING
    455  1.1  elric 		{
    456  1.1  elric 		  $$ = new_type(TBitString);
    457  1.1  elric 		  $$->members = emalloc(sizeof(*$$->members));
    458  1.1  elric 		  ASN1_TAILQ_INIT($$->members);
    459  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
    460  1.1  elric 		}
    461  1.1  elric 		| kw_BIT kw_STRING '{' NamedBitList '}'
    462  1.1  elric 		{
    463  1.1  elric 		  $$ = new_type(TBitString);
    464  1.1  elric 		  $$->members = $4;
    465  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_BitString, TE_EXPLICIT, $$);
    466  1.1  elric 		}
    467  1.1  elric 		;
    468  1.1  elric 
    469  1.1  elric ObjectIdentifierType: kw_OBJECT kw_IDENTIFIER
    470  1.1  elric 		{
    471  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_OID,
    472  1.1  elric 				     TE_EXPLICIT, new_type(TOID));
    473  1.1  elric 		}
    474  1.1  elric 		;
    475  1.1  elric OctetStringType	: kw_OCTET kw_STRING size
    476  1.1  elric 		{
    477  1.1  elric 		    Type *t = new_type(TOctetString);
    478  1.1  elric 		    t->range = $3;
    479  1.1  elric 		    $$ = new_tag(ASN1_C_UNIV, UT_OctetString,
    480  1.1  elric 				 TE_EXPLICIT, t);
    481  1.1  elric 		}
    482  1.1  elric 		;
    483  1.1  elric 
    484  1.1  elric NullType	: kw_NULL
    485  1.1  elric 		{
    486  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_Null,
    487  1.1  elric 				     TE_EXPLICIT, new_type(TNull));
    488  1.1  elric 		}
    489  1.1  elric 		;
    490  1.1  elric 
    491  1.1  elric size		:
    492  1.1  elric 		{ $$ = NULL; }
    493  1.1  elric 		| kw_SIZE range
    494  1.1  elric 		{ $$ = $2; }
    495  1.1  elric 		;
    496  1.1  elric 
    497  1.1  elric 
    498  1.1  elric SequenceType	: kw_SEQUENCE '{' /* ComponentTypeLists */ ComponentTypeList '}'
    499  1.1  elric 		{
    500  1.1  elric 		  $$ = new_type(TSequence);
    501  1.1  elric 		  $$->members = $3;
    502  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
    503  1.1  elric 		}
    504  1.1  elric 		| kw_SEQUENCE '{' '}'
    505  1.1  elric 		{
    506  1.1  elric 		  $$ = new_type(TSequence);
    507  1.1  elric 		  $$->members = NULL;
    508  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
    509  1.1  elric 		}
    510  1.1  elric 		;
    511  1.1  elric 
    512  1.1  elric SequenceOfType	: kw_SEQUENCE size kw_OF Type
    513  1.1  elric 		{
    514  1.1  elric 		  $$ = new_type(TSequenceOf);
    515  1.1  elric 		  $$->range = $2;
    516  1.1  elric 		  $$->subtype = $4;
    517  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Sequence, TE_EXPLICIT, $$);
    518  1.1  elric 		}
    519  1.1  elric 		;
    520  1.1  elric 
    521  1.1  elric SetType		: kw_SET '{' /* ComponentTypeLists */ ComponentTypeList '}'
    522  1.1  elric 		{
    523  1.1  elric 		  $$ = new_type(TSet);
    524  1.1  elric 		  $$->members = $3;
    525  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
    526  1.1  elric 		}
    527  1.1  elric 		| kw_SET '{' '}'
    528  1.1  elric 		{
    529  1.1  elric 		  $$ = new_type(TSet);
    530  1.1  elric 		  $$->members = NULL;
    531  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
    532  1.1  elric 		}
    533  1.1  elric 		;
    534  1.1  elric 
    535  1.1  elric SetOfType	: kw_SET kw_OF Type
    536  1.1  elric 		{
    537  1.1  elric 		  $$ = new_type(TSetOf);
    538  1.1  elric 		  $$->subtype = $3;
    539  1.1  elric 		  $$ = new_tag(ASN1_C_UNIV, UT_Set, TE_EXPLICIT, $$);
    540  1.1  elric 		}
    541  1.1  elric 		;
    542  1.1  elric 
    543  1.1  elric ChoiceType	: kw_CHOICE '{' /* AlternativeTypeLists */ ComponentTypeList '}'
    544  1.1  elric 		{
    545  1.1  elric 		  $$ = new_type(TChoice);
    546  1.1  elric 		  $$->members = $3;
    547  1.1  elric 		}
    548  1.1  elric 		;
    549  1.1  elric 
    550  1.1  elric ReferencedType	: DefinedType
    551  1.1  elric 		| UsefulType
    552  1.1  elric 		;
    553  1.1  elric 
    554  1.1  elric DefinedType	: IDENTIFIER
    555  1.1  elric 		{
    556  1.1  elric 		  Symbol *s = addsym($1);
    557  1.1  elric 		  $$ = new_type(TType);
    558  1.1  elric 		  if(s->stype != Stype && s->stype != SUndefined)
    559  1.1  elric 		    lex_error_message ("%s is not a type\n", $1);
    560  1.1  elric 		  else
    561  1.1  elric 		    $$->symbol = s;
    562  1.1  elric 		}
    563  1.1  elric 		;
    564  1.1  elric 
    565  1.1  elric UsefulType	: kw_GeneralizedTime
    566  1.1  elric 		{
    567  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_GeneralizedTime,
    568  1.1  elric 				     TE_EXPLICIT, new_type(TGeneralizedTime));
    569  1.1  elric 		}
    570  1.1  elric 		| kw_UTCTime
    571  1.1  elric 		{
    572  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_UTCTime,
    573  1.1  elric 				     TE_EXPLICIT, new_type(TUTCTime));
    574  1.1  elric 		}
    575  1.1  elric 		;
    576  1.1  elric 
    577  1.1  elric ConstrainedType	: Type Constraint
    578  1.1  elric 		{
    579  1.1  elric 		    /* if (Constraint.type == contentConstrant) {
    580  1.1  elric 		       assert(Constraint.u.constraint.type == octetstring|bitstring-w/o-NamedBitList); // remember to check type reference too
    581  1.1  elric 		       if (Constraint.u.constraint.type) {
    582  1.1  elric 		         assert((Constraint.u.constraint.type.length % 8) == 0);
    583  1.1  elric 		       }
    584  1.1  elric 		      }
    585  1.1  elric 		      if (Constraint.u.constraint.encoding) {
    586  1.1  elric 		        type == der-oid|ber-oid
    587  1.1  elric 		      }
    588  1.1  elric 		    */
    589  1.1  elric 		}
    590  1.1  elric 		;
    591  1.1  elric 
    592  1.1  elric 
    593  1.1  elric Constraint	: '(' ConstraintSpec ')'
    594  1.1  elric 		{
    595  1.1  elric 		    $$ = $2;
    596  1.1  elric 		}
    597  1.1  elric 		;
    598  1.1  elric 
    599  1.1  elric ConstraintSpec	: GeneralConstraint
    600  1.1  elric 		;
    601  1.1  elric 
    602  1.1  elric GeneralConstraint: ContentsConstraint
    603  1.1  elric 		| UserDefinedConstraint
    604  1.1  elric 		;
    605  1.1  elric 
    606  1.1  elric ContentsConstraint: kw_CONTAINING Type
    607  1.1  elric 		{
    608  1.1  elric 		    $$ = new_constraint_spec(CT_CONTENTS);
    609  1.1  elric 		    $$->u.content.type = $2;
    610  1.1  elric 		    $$->u.content.encoding = NULL;
    611  1.1  elric 		}
    612  1.1  elric 		| kw_ENCODED kw_BY Value
    613  1.1  elric 		{
    614  1.1  elric 		    if ($3->type != objectidentifiervalue)
    615  1.1  elric 			lex_error_message("Non-OID used in ENCODED BY constraint");
    616  1.1  elric 		    $$ = new_constraint_spec(CT_CONTENTS);
    617  1.1  elric 		    $$->u.content.type = NULL;
    618  1.1  elric 		    $$->u.content.encoding = $3;
    619  1.1  elric 		}
    620  1.1  elric 		| kw_CONTAINING Type kw_ENCODED kw_BY Value
    621  1.1  elric 		{
    622  1.1  elric 		    if ($5->type != objectidentifiervalue)
    623  1.1  elric 			lex_error_message("Non-OID used in ENCODED BY constraint");
    624  1.1  elric 		    $$ = new_constraint_spec(CT_CONTENTS);
    625  1.1  elric 		    $$->u.content.type = $2;
    626  1.1  elric 		    $$->u.content.encoding = $5;
    627  1.1  elric 		}
    628  1.1  elric 		;
    629  1.1  elric 
    630  1.1  elric UserDefinedConstraint: kw_CONSTRAINED kw_BY '{' '}'
    631  1.1  elric 		{
    632  1.1  elric 		    $$ = new_constraint_spec(CT_USER);
    633  1.1  elric 		}
    634  1.1  elric 		;
    635  1.1  elric 
    636  1.1  elric TaggedType	: Tag tagenv Type
    637  1.1  elric 		{
    638  1.1  elric 			$$ = new_type(TTag);
    639  1.1  elric 			$$->tag = $1;
    640  1.1  elric 			$$->tag.tagenv = $2;
    641  1.1  elric 			if($3->type == TTag && $2 == TE_IMPLICIT) {
    642  1.1  elric 				$$->subtype = $3->subtype;
    643  1.1  elric 				free($3);
    644  1.1  elric 			} else
    645  1.1  elric 				$$->subtype = $3;
    646  1.1  elric 		}
    647  1.1  elric 		;
    648  1.1  elric 
    649  1.1  elric Tag		: '[' Class NUMBER ']'
    650  1.1  elric 		{
    651  1.1  elric 			$$.tagclass = $2;
    652  1.1  elric 			$$.tagvalue = $3;
    653  1.1  elric 			$$.tagenv = TE_EXPLICIT;
    654  1.1  elric 		}
    655  1.1  elric 		;
    656  1.1  elric 
    657  1.1  elric Class		: /* */
    658  1.1  elric 		{
    659  1.1  elric 			$$ = ASN1_C_CONTEXT;
    660  1.1  elric 		}
    661  1.1  elric 		| kw_UNIVERSAL
    662  1.1  elric 		{
    663  1.1  elric 			$$ = ASN1_C_UNIV;
    664  1.1  elric 		}
    665  1.1  elric 		| kw_APPLICATION
    666  1.1  elric 		{
    667  1.1  elric 			$$ = ASN1_C_APPL;
    668  1.1  elric 		}
    669  1.1  elric 		| kw_PRIVATE
    670  1.1  elric 		{
    671  1.1  elric 			$$ = ASN1_C_PRIVATE;
    672  1.1  elric 		}
    673  1.1  elric 		;
    674  1.1  elric 
    675  1.1  elric tagenv		: /* */
    676  1.1  elric 		{
    677  1.1  elric 			$$ = TE_EXPLICIT;
    678  1.1  elric 		}
    679  1.1  elric 		| kw_EXPLICIT
    680  1.1  elric 		{
    681  1.1  elric 			$$ = TE_EXPLICIT;
    682  1.1  elric 		}
    683  1.1  elric 		| kw_IMPLICIT
    684  1.1  elric 		{
    685  1.1  elric 			$$ = TE_IMPLICIT;
    686  1.1  elric 		}
    687  1.1  elric 		;
    688  1.1  elric 
    689  1.1  elric 
    690  1.1  elric ValueAssignment	: IDENTIFIER Type EEQUAL Value
    691  1.1  elric 		{
    692  1.1  elric 			Symbol *s;
    693  1.1  elric 			s = addsym ($1);
    694  1.1  elric 
    695  1.1  elric 			s->stype = SValue;
    696  1.1  elric 			s->value = $4;
    697  1.1  elric 			generate_constant (s);
    698  1.1  elric 		}
    699  1.1  elric 		;
    700  1.1  elric 
    701  1.1  elric CharacterStringType: RestrictedCharactedStringType
    702  1.1  elric 		;
    703  1.1  elric 
    704  1.1  elric RestrictedCharactedStringType: kw_GeneralString
    705  1.1  elric 		{
    706  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_GeneralString,
    707  1.1  elric 				     TE_EXPLICIT, new_type(TGeneralString));
    708  1.1  elric 		}
    709  1.1  elric 		| kw_TeletexString
    710  1.1  elric 		{
    711  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_TeletexString,
    712  1.1  elric 				     TE_EXPLICIT, new_type(TTeletexString));
    713  1.1  elric 		}
    714  1.1  elric 		| kw_UTF8String
    715  1.1  elric 		{
    716  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_UTF8String,
    717  1.1  elric 				     TE_EXPLICIT, new_type(TUTF8String));
    718  1.1  elric 		}
    719  1.1  elric 		| kw_PrintableString
    720  1.1  elric 		{
    721  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_PrintableString,
    722  1.1  elric 				     TE_EXPLICIT, new_type(TPrintableString));
    723  1.1  elric 		}
    724  1.1  elric 		| kw_VisibleString
    725  1.1  elric 		{
    726  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_VisibleString,
    727  1.1  elric 				     TE_EXPLICIT, new_type(TVisibleString));
    728  1.1  elric 		}
    729  1.1  elric 		| kw_IA5String
    730  1.1  elric 		{
    731  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_IA5String,
    732  1.1  elric 				     TE_EXPLICIT, new_type(TIA5String));
    733  1.1  elric 		}
    734  1.1  elric 		| kw_BMPString
    735  1.1  elric 		{
    736  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_BMPString,
    737  1.1  elric 				     TE_EXPLICIT, new_type(TBMPString));
    738  1.1  elric 		}
    739  1.1  elric 		| kw_UniversalString
    740  1.1  elric 		{
    741  1.1  elric 			$$ = new_tag(ASN1_C_UNIV, UT_UniversalString,
    742  1.1  elric 				     TE_EXPLICIT, new_type(TUniversalString));
    743  1.1  elric 		}
    744  1.1  elric 
    745  1.1  elric 		;
    746  1.1  elric 
    747  1.1  elric ComponentTypeList: ComponentType
    748  1.1  elric 		{
    749  1.1  elric 			$$ = emalloc(sizeof(*$$));
    750  1.1  elric 			ASN1_TAILQ_INIT($$);
    751  1.1  elric 			ASN1_TAILQ_INSERT_HEAD($$, $1, members);
    752  1.1  elric 		}
    753  1.1  elric 		| ComponentTypeList ',' ComponentType
    754  1.1  elric 		{
    755  1.1  elric 			ASN1_TAILQ_INSERT_TAIL($1, $3, members);
    756  1.1  elric 			$$ = $1;
    757  1.1  elric 		}
    758  1.1  elric 		| ComponentTypeList ',' ELLIPSIS
    759  1.1  elric 		{
    760  1.1  elric 		        struct member *m = ecalloc(1, sizeof(*m));
    761  1.1  elric 			m->name = estrdup("...");
    762  1.1  elric 			m->gen_name = estrdup("asn1_ellipsis");
    763  1.1  elric 			m->ellipsis = 1;
    764  1.1  elric 			ASN1_TAILQ_INSERT_TAIL($1, m, members);
    765  1.1  elric 			$$ = $1;
    766  1.1  elric 		}
    767  1.1  elric 		;
    768  1.1  elric 
    769  1.1  elric NamedType	: IDENTIFIER Type
    770  1.1  elric 		{
    771  1.1  elric 		  $$ = emalloc(sizeof(*$$));
    772  1.1  elric 		  $$->name = $1;
    773  1.1  elric 		  $$->gen_name = estrdup($1);
    774  1.1  elric 		  output_name ($$->gen_name);
    775  1.1  elric 		  $$->type = $2;
    776  1.1  elric 		  $$->ellipsis = 0;
    777  1.1  elric 		}
    778  1.1  elric 		;
    779  1.1  elric 
    780  1.1  elric ComponentType	: NamedType
    781  1.1  elric 		{
    782  1.1  elric 			$$ = $1;
    783  1.1  elric 			$$->optional = 0;
    784  1.1  elric 			$$->defval = NULL;
    785  1.1  elric 		}
    786  1.1  elric 		| NamedType kw_OPTIONAL
    787  1.1  elric 		{
    788  1.1  elric 			$$ = $1;
    789  1.1  elric 			$$->optional = 1;
    790  1.1  elric 			$$->defval = NULL;
    791  1.1  elric 		}
    792  1.1  elric 		| NamedType kw_DEFAULT Value
    793  1.1  elric 		{
    794  1.1  elric 			$$ = $1;
    795  1.1  elric 			$$->optional = 0;
    796  1.1  elric 			$$->defval = $3;
    797  1.1  elric 		}
    798  1.1  elric 		;
    799  1.1  elric 
    800  1.1  elric NamedBitList	: NamedBit
    801  1.1  elric 		{
    802  1.1  elric 			$$ = emalloc(sizeof(*$$));
    803  1.1  elric 			ASN1_TAILQ_INIT($$);
    804  1.1  elric 			ASN1_TAILQ_INSERT_HEAD($$, $1, members);
    805  1.1  elric 		}
    806  1.1  elric 		| NamedBitList ',' NamedBit
    807  1.1  elric 		{
    808  1.1  elric 			ASN1_TAILQ_INSERT_TAIL($1, $3, members);
    809  1.1  elric 			$$ = $1;
    810  1.1  elric 		}
    811  1.1  elric 		;
    812  1.1  elric 
    813  1.1  elric NamedBit	: IDENTIFIER '(' NUMBER ')'
    814  1.1  elric 		{
    815  1.1  elric 		  $$ = emalloc(sizeof(*$$));
    816  1.1  elric 		  $$->name = $1;
    817  1.1  elric 		  $$->gen_name = estrdup($1);
    818  1.1  elric 		  output_name ($$->gen_name);
    819  1.1  elric 		  $$->val = $3;
    820  1.1  elric 		  $$->optional = 0;
    821  1.1  elric 		  $$->ellipsis = 0;
    822  1.1  elric 		  $$->type = NULL;
    823  1.1  elric 		}
    824  1.1  elric 		;
    825  1.1  elric 
    826  1.1  elric objid_opt	: objid
    827  1.1  elric 		| /* empty */ { $$ = NULL; }
    828  1.1  elric 		;
    829  1.1  elric 
    830  1.1  elric objid		: '{' objid_list '}'
    831  1.1  elric 		{
    832  1.1  elric 			$$ = $2;
    833  1.1  elric 		}
    834  1.1  elric 		;
    835  1.1  elric 
    836  1.1  elric objid_list	:  /* empty */
    837  1.1  elric 		{
    838  1.1  elric 			$$ = NULL;
    839  1.1  elric 		}
    840  1.1  elric 		| objid_element objid_list
    841  1.1  elric 		{
    842  1.1  elric 		        if ($2) {
    843  1.1  elric 				$$ = $2;
    844  1.1  elric 				add_oid_to_tail($2, $1);
    845  1.1  elric 			} else {
    846  1.1  elric 				$$ = $1;
    847  1.1  elric 			}
    848  1.1  elric 		}
    849  1.1  elric 		;
    850  1.1  elric 
    851  1.1  elric objid_element	: IDENTIFIER '(' NUMBER ')'
    852  1.1  elric 		{
    853  1.1  elric 			$$ = new_objid($1, $3);
    854  1.1  elric 		}
    855  1.1  elric 		| IDENTIFIER
    856  1.1  elric 		{
    857  1.1  elric 		    Symbol *s = addsym($1);
    858  1.1  elric 		    if(s->stype != SValue ||
    859  1.1  elric 		       s->value->type != objectidentifiervalue) {
    860  1.1  elric 			lex_error_message("%s is not an object identifier\n",
    861  1.1  elric 				      s->name);
    862  1.1  elric 			exit(1);
    863  1.1  elric 		    }
    864  1.1  elric 		    $$ = s->value->u.objectidentifiervalue;
    865  1.1  elric 		}
    866  1.1  elric 		| NUMBER
    867  1.1  elric 		{
    868  1.1  elric 		    $$ = new_objid(NULL, $1);
    869  1.1  elric 		}
    870  1.1  elric 		;
    871  1.1  elric 
    872  1.1  elric Value		: BuiltinValue
    873  1.1  elric 		| ReferencedValue
    874  1.1  elric 		;
    875  1.1  elric 
    876  1.1  elric BuiltinValue	: BooleanValue
    877  1.1  elric 		| CharacterStringValue
    878  1.1  elric 		| IntegerValue
    879  1.1  elric 		| ObjectIdentifierValue
    880  1.1  elric 		| NullValue
    881  1.1  elric 		;
    882  1.1  elric 
    883  1.1  elric ReferencedValue	: DefinedValue
    884  1.1  elric 		;
    885  1.1  elric 
    886  1.1  elric DefinedValue	: Valuereference
    887  1.1  elric 		;
    888  1.1  elric 
    889  1.1  elric Valuereference	: IDENTIFIER
    890  1.1  elric 		{
    891  1.1  elric 			Symbol *s = addsym($1);
    892  1.1  elric 			if(s->stype != SValue)
    893  1.1  elric 				lex_error_message ("%s is not a value\n",
    894  1.1  elric 						s->name);
    895  1.1  elric 			else
    896  1.1  elric 				$$ = s->value;
    897  1.1  elric 		}
    898  1.1  elric 		;
    899  1.1  elric 
    900  1.1  elric CharacterStringValue: STRING
    901  1.1  elric 		{
    902  1.1  elric 			$$ = emalloc(sizeof(*$$));
    903  1.1  elric 			$$->type = stringvalue;
    904  1.1  elric 			$$->u.stringvalue = $1;
    905  1.1  elric 		}
    906  1.1  elric 		;
    907  1.1  elric 
    908  1.1  elric BooleanValue	: kw_TRUE
    909  1.1  elric 		{
    910  1.1  elric 			$$ = emalloc(sizeof(*$$));
    911  1.1  elric 			$$->type = booleanvalue;
    912  1.1  elric 			$$->u.booleanvalue = 0;
    913  1.1  elric 		}
    914  1.1  elric 		| kw_FALSE
    915  1.1  elric 		{
    916  1.1  elric 			$$ = emalloc(sizeof(*$$));
    917  1.1  elric 			$$->type = booleanvalue;
    918  1.1  elric 			$$->u.booleanvalue = 0;
    919  1.1  elric 		}
    920  1.1  elric 		;
    921  1.1  elric 
    922  1.1  elric IntegerValue	: SignedNumber
    923  1.1  elric 		{
    924  1.1  elric 			$$ = emalloc(sizeof(*$$));
    925  1.1  elric 			$$->type = integervalue;
    926  1.1  elric 			$$->u.integervalue = $1;
    927  1.1  elric 		}
    928  1.1  elric 		;
    929  1.1  elric 
    930  1.1  elric SignedNumber	: NUMBER
    931  1.1  elric 		;
    932  1.1  elric 
    933  1.1  elric NullValue	: kw_NULL
    934  1.1  elric 		{
    935  1.1  elric 		}
    936  1.1  elric 		;
    937  1.1  elric 
    938  1.1  elric ObjectIdentifierValue: objid
    939  1.1  elric 		{
    940  1.1  elric 			$$ = emalloc(sizeof(*$$));
    941  1.1  elric 			$$->type = objectidentifiervalue;
    942  1.1  elric 			$$->u.objectidentifiervalue = $1;
    943  1.1  elric 		}
    944  1.1  elric 		;
    945  1.1  elric 
    946  1.1  elric %%
    947  1.1  elric 
    948  1.1  elric void
    949  1.1  elric yyerror (const char *s)
    950  1.1  elric {
    951  1.1  elric      lex_error_message ("%s\n", s);
    952  1.1  elric }
    953  1.1  elric 
    954  1.1  elric static Type *
    955  1.1  elric new_tag(int tagclass, int tagvalue, int tagenv, Type *oldtype)
    956  1.1  elric {
    957  1.1  elric     Type *t;
    958  1.1  elric     if(oldtype->type == TTag && oldtype->tag.tagenv == TE_IMPLICIT) {
    959  1.1  elric 	t = oldtype;
    960  1.1  elric 	oldtype = oldtype->subtype; /* XXX */
    961  1.1  elric     } else
    962  1.1  elric 	t = new_type (TTag);
    963  1.1  elric 
    964  1.1  elric     t->tag.tagclass = tagclass;
    965  1.1  elric     t->tag.tagvalue = tagvalue;
    966  1.1  elric     t->tag.tagenv = tagenv;
    967  1.1  elric     t->subtype = oldtype;
    968  1.1  elric     return t;
    969  1.1  elric }
    970  1.1  elric 
    971  1.1  elric static struct objid *
    972  1.1  elric new_objid(const char *label, int value)
    973  1.1  elric {
    974  1.1  elric     struct objid *s;
    975  1.1  elric     s = emalloc(sizeof(*s));
    976  1.1  elric     s->label = label;
    977  1.1  elric     s->value = value;
    978  1.1  elric     s->next = NULL;
    979  1.1  elric     return s;
    980  1.1  elric }
    981  1.1  elric 
    982  1.1  elric static void
    983  1.1  elric add_oid_to_tail(struct objid *head, struct objid *tail)
    984  1.1  elric {
    985  1.1  elric     struct objid *o;
    986  1.1  elric     o = head;
    987  1.1  elric     while (o->next)
    988  1.1  elric 	o = o->next;
    989  1.1  elric     o->next = tail;
    990  1.1  elric }
    991  1.1  elric 
    992  1.1  elric static Type *
    993  1.1  elric new_type (Typetype tt)
    994  1.1  elric {
    995  1.1  elric     Type *t = ecalloc(1, sizeof(*t));
    996  1.1  elric     t->type = tt;
    997  1.1  elric     return t;
    998  1.1  elric }
    999  1.1  elric 
   1000  1.1  elric static struct constraint_spec *
   1001  1.1  elric new_constraint_spec(enum ctype ct)
   1002  1.1  elric {
   1003  1.1  elric     struct constraint_spec *c = ecalloc(1, sizeof(*c));
   1004  1.1  elric     c->ctype = ct;
   1005  1.1  elric     return c;
   1006  1.1  elric }
   1007  1.1  elric 
   1008  1.1  elric static void fix_labels2(Type *t, const char *prefix);
   1009  1.1  elric static void fix_labels1(struct memhead *members, const char *prefix)
   1010  1.1  elric {
   1011  1.1  elric     Member *m;
   1012  1.1  elric 
   1013  1.1  elric     if(members == NULL)
   1014  1.1  elric 	return;
   1015  1.1  elric     ASN1_TAILQ_FOREACH(m, members, members) {
   1016  1.1  elric 	if (asprintf(&m->label, "%s_%s", prefix, m->gen_name) < 0)
   1017  1.1  elric 	    errx(1, "malloc");
   1018  1.1  elric 	if (m->label == NULL)
   1019  1.1  elric 	    errx(1, "malloc");
   1020  1.1  elric 	if(m->type != NULL)
   1021  1.1  elric 	    fix_labels2(m->type, m->label);
   1022  1.1  elric     }
   1023  1.1  elric }
   1024  1.1  elric 
   1025  1.1  elric static void fix_labels2(Type *t, const char *prefix)
   1026  1.1  elric {
   1027  1.1  elric     for(; t; t = t->subtype)
   1028  1.1  elric 	fix_labels1(t->members, prefix);
   1029  1.1  elric }
   1030  1.1  elric 
   1031  1.1  elric static void
   1032  1.1  elric fix_labels(Symbol *s)
   1033  1.1  elric {
   1034  1.1  elric     char *p = NULL;
   1035  1.1  elric     if (asprintf(&p, "choice_%s", s->gen_name) < 0 || p == NULL)
   1036  1.1  elric 	errx(1, "malloc");
   1037  1.1  elric     fix_labels2(s->type, p);
   1038  1.1  elric     free(p);
   1039  1.1  elric }
   1040