blob: 28c1f7e8744e71ab4dd4e151304e903353e5ab47 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
6#include <errno.h>
7#include <assert.h>
8
9#include "asn1parser.h"
10
11#define YYPARSE_PARAM param
Lev Walkin4354b442005-06-07 21:25:42 +000012#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000013#define YYERROR_VERBOSE
14
15int yylex(void);
16int yyerror(const char *msg);
Lev Walkin8daab912005-06-07 21:32:16 +000017#ifdef YYBYACC
18int yyparse(void **param); /* byacc does not produce a prototype */
19#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000020void asn1p_lexer_hack_push_opaque_state(void);
21void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000022void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000023#define yylineno asn1p_lineno
24extern int asn1p_lineno;
25
Lev Walkin1ed22092005-08-12 10:06:17 +000026/*
Lev Walkin4696c742005-08-22 12:23:54 +000027 * Process modifiers as <asn1c:pointer>
28 */
29extern int asn1p_as_pointer;
30static asn1p_expr_t *asn1p_last_type;
31static void apply_nonstd_mods(void);
32
33/*
Lev Walkin1ed22092005-08-12 10:06:17 +000034 * This temporary variable is used to solve the shortcomings of 1-lookahead
35 * parser.
36 */
37static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000038
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000039static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
40static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000041
Lev Walkin1ed22092005-08-12 10:06:17 +000042#define checkmem(ptr) do { \
43 if(!(ptr)) \
44 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000045 } while(0)
46
Lev Walkin2c14a692005-08-12 10:08:45 +000047#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000048 if(arg1->type != constr_type) { \
49 int __ret; \
50 root = asn1p_constraint_new(yylineno); \
51 checkmem(root); \
52 root->type = constr_type; \
53 __ret = asn1p_constraint_insert(root, \
54 arg1); \
55 checkmem(__ret == 0); \
56 } else { \
57 root = arg1; \
58 } \
59 if(arg2) { \
60 int __ret \
61 = asn1p_constraint_insert(root, arg2); \
62 checkmem(__ret == 0); \
63 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000064 } while(0)
65
66%}
67
68
69/*
70 * Token value definition.
71 * a_*: ASN-specific types.
72 * tv_*: Locally meaningful types.
73 */
74%union {
75 asn1p_t *a_grammar;
76 asn1p_module_flags_e a_module_flags;
77 asn1p_module_t *a_module;
78 asn1p_expr_type_e a_type; /* ASN.1 Type */
79 asn1p_expr_t *a_expr; /* Constructed collection */
80 asn1p_constraint_t *a_constr; /* Constraint */
81 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
82 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +000083 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +000084 asn1p_oid_t *a_oid; /* Object Identifier */
85 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
86 struct asn1p_type_tag_s a_tag; /* A tag */
87 asn1p_ref_t *a_ref; /* Reference to custom type */
88 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
89 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
90 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
91 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
92 struct asn1p_param_s a_parg; /* A parameter argument */
93 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +000094 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +000095 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +000096 asn1c_integer_t a_int;
Lev Walkinf15320b2004-06-03 03:38:44 +000097 char *tv_str;
98 struct {
99 char *buf;
100 int len;
101 } tv_opaque;
102 struct {
103 char *name;
104 struct asn1p_type_tag_s tag;
105 } tv_nametag;
106};
107
108/*
109 * Token types returned by scanner.
110 */
111%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
112%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
113%token <tv_str> TOK_bstring
114%token <tv_opaque> TOK_cstring
115%token <tv_str> TOK_hstring
116%token <tv_str> TOK_identifier
117%token <a_int> TOK_number
Lev Walkind9574ae2005-03-24 16:22:35 +0000118%token <a_int> TOK_tuple
119%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000120%token <a_int> TOK_number_negative
121%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000122%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000123%token <tv_str> TOK_typefieldreference /* "&Pork" */
124%token <tv_str> TOK_valuefieldreference /* "&id" */
125
126/*
127 * Token types representing ASN.1 standard keywords.
128 */
129%token TOK_ABSENT
130%token TOK_ABSTRACT_SYNTAX
131%token TOK_ALL
132%token TOK_ANY
133%token TOK_APPLICATION
134%token TOK_AUTOMATIC
135%token TOK_BEGIN
136%token TOK_BIT
137%token TOK_BMPString
138%token TOK_BOOLEAN
139%token TOK_BY
140%token TOK_CHARACTER
141%token TOK_CHOICE
142%token TOK_CLASS
143%token TOK_COMPONENT
144%token TOK_COMPONENTS
145%token TOK_CONSTRAINED
146%token TOK_CONTAINING
147%token TOK_DEFAULT
148%token TOK_DEFINITIONS
149%token TOK_DEFINED
150%token TOK_EMBEDDED
151%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000152%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000153%token TOK_END
154%token TOK_ENUMERATED
155%token TOK_EXPLICIT
156%token TOK_EXPORTS
157%token TOK_EXTENSIBILITY
158%token TOK_EXTERNAL
159%token TOK_FALSE
160%token TOK_FROM
161%token TOK_GeneralizedTime
162%token TOK_GeneralString
163%token TOK_GraphicString
164%token TOK_IA5String
165%token TOK_IDENTIFIER
166%token TOK_IMPLICIT
167%token TOK_IMPLIED
168%token TOK_IMPORTS
169%token TOK_INCLUDES
170%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000171%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000172%token TOK_INTEGER
173%token TOK_ISO646String
174%token TOK_MAX
175%token TOK_MIN
176%token TOK_MINUS_INFINITY
177%token TOK_NULL
178%token TOK_NumericString
179%token TOK_OBJECT
180%token TOK_ObjectDescriptor
181%token TOK_OCTET
182%token TOK_OF
183%token TOK_OPTIONAL
184%token TOK_PATTERN
185%token TOK_PDV
186%token TOK_PLUS_INFINITY
187%token TOK_PRESENT
188%token TOK_PrintableString
189%token TOK_PRIVATE
190%token TOK_REAL
191%token TOK_RELATIVE_OID
192%token TOK_SEQUENCE
193%token TOK_SET
194%token TOK_SIZE
195%token TOK_STRING
196%token TOK_SYNTAX
197%token TOK_T61String
198%token TOK_TAGS
199%token TOK_TeletexString
200%token TOK_TRUE
201%token TOK_TYPE_IDENTIFIER
202%token TOK_UNIQUE
203%token TOK_UNIVERSAL
204%token TOK_UniversalString
205%token TOK_UTCTime
206%token TOK_UTF8String
207%token TOK_VideotexString
208%token TOK_VisibleString
209%token TOK_WITH
210
Lev Walkinf15320b2004-06-03 03:38:44 +0000211%left TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000212%left '^' TOK_INTERSECTION
213%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000214
215/* Misc tags */
216%token TOK_TwoDots /* .. */
217%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000218
219
220/*
221 * Types defined herein.
222 */
223%type <a_grammar> ModuleList
224%type <a_module> ModuleSpecification
225%type <a_module> ModuleSpecificationBody
226%type <a_module> ModuleSpecificationElement
227%type <a_module> optModuleSpecificationBody /* Optional */
228%type <a_module_flags> optModuleSpecificationFlags
229%type <a_module_flags> ModuleSpecificationFlags /* Set of FL */
230%type <a_module_flags> ModuleSpecificationFlag /* Single FL */
231%type <a_module> ImportsDefinition
232%type <a_module> ImportsBundleSet
233%type <a_xports> ImportsBundle
234%type <a_xports> ImportsList
235%type <a_xports> ExportsDefinition
236%type <a_xports> ExportsBody
237%type <a_expr> ImportsElement
238%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000239%type <a_expr> ExtensionAndException
Lev Walkin070a52d2004-08-22 03:19:54 +0000240%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000241%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000242%type <a_ref> ComplexTypeReference
243%type <a_ref> ComplexTypeReferenceAmpList
244%type <a_refcomp> ComplexTypeReferenceElement
245%type <a_refcomp> ClassFieldIdentifier
246%type <a_refcomp> ClassFieldName
247%type <a_expr> ClassFieldList
248%type <a_expr> ClassField
249%type <a_expr> ClassDeclaration
Lev Walkin070a52d2004-08-22 03:19:54 +0000250%type <a_expr> Type
Lev Walkinf15320b2004-06-03 03:38:44 +0000251%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
252%type <a_expr> DefinedTypeRef
253%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
254%type <a_expr> ValueDefinition /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000255%type <a_value> Value
Lev Walkinf15320b2004-06-03 03:38:44 +0000256%type <a_value> DefinedValue
257%type <a_value> SignedNumber
Lev Walkin144db9b2004-10-12 23:26:53 +0000258%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000259%type <a_expr> ComponentTypeLists
260%type <a_expr> ComponentType
261%type <a_expr> AlternativeTypeLists
262%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000263//%type <a_expr> optUniverationDefinition
264%type <a_expr> UniverationDefinition
265%type <a_expr> UniverationList
266%type <a_expr> UniverationElement
267%type <tv_str> TypeRefName
268%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000269%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000270%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000271%type <a_parg> ParameterArgumentName
272%type <a_plist> ParameterArgumentList
273%type <a_expr> ActualParameter
274%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000275%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000276%type <a_oid> ObjectIdentifier /* OID */
277%type <a_oid> optObjectIdentifier /* Optional OID */
278%type <a_oid> ObjectIdentifierBody
279%type <a_oid_arc> ObjectIdentifierElement
280%type <a_expr> BasicType
281%type <a_type> BasicTypeId
282%type <a_type> BasicTypeId_UniverationCompatible
283%type <a_type> BasicString
284%type <tv_opaque> Opaque
285//%type <tv_opaque> StringValue
Lev Walkinc603f102005-01-23 09:51:44 +0000286%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
287%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000288%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
289%type <a_constr> optConstraints
Lev Walkind2ea1de2004-08-20 13:25:29 +0000290%type <a_constr> Constraints
Lev Walkinf59d0752004-08-18 04:59:12 +0000291%type <a_constr> SetOfConstraints
292%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
293%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000294%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000295%type <a_constr> SimpleTableConstraint
296%type <a_constr> TableConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000297%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000298%type <a_constr> WithComponentsList
299%type <a_constr> WithComponentsElement
300%type <a_constr> ComponentRelationConstraint
301%type <a_constr> AtNotationList
302%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000303%type <a_value> SingleValue
304%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000305%type <a_ctype> ConstraintSpec
306%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000307%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000308%type <a_wsynt> optWithSyntax
309%type <a_wsynt> WithSyntax
310%type <a_wsynt> WithSyntaxFormat
311%type <a_wchunk> WithSyntaxFormatToken
312%type <a_marker> optMarker Marker
313%type <a_int> optUnique
314%type <a_pres> optPresenceConstraint PresenceConstraint
315%type <tv_str> ComponentIdList
316
317
318%%
319
320
321ParsedGrammar:
322 ModuleList {
323 *(void **)param = $1;
324 }
325 ;
326
327ModuleList:
328 ModuleSpecification {
329 $$ = asn1p_new();
330 checkmem($$);
331 TQ_ADD(&($$->modules), $1, mod_next);
332 }
333 | ModuleList ModuleSpecification {
334 $$ = $1;
335 TQ_ADD(&($$->modules), $2, mod_next);
336 }
337 ;
338
339/*
340 * ASN module definition.
341 * === EXAMPLE ===
342 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
343 * BEGIN
344 * ...
345 * END
346 * === EOF ===
347 */
348
349ModuleSpecification:
350 TypeRefName optObjectIdentifier TOK_DEFINITIONS
351 optModuleSpecificationFlags
352 TOK_PPEQ TOK_BEGIN
353 optModuleSpecificationBody
354 TOK_END {
355
356 if($7) {
357 $$ = $7;
358 } else {
359 /* There's a chance that a module is just plain empty */
360 $$ = asn1p_module_new();
361 }
362 checkmem($$);
363
Lev Walkin1ed22092005-08-12 10:06:17 +0000364 $$->ModuleName = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000365 $$->module_oid = $2;
366 $$->module_flags = $4;
367 }
368 ;
369
370/*
371 * Object Identifier Definition
372 * { iso member-body(2) 3 }
373 */
374optObjectIdentifier:
375 { $$ = 0; }
376 | ObjectIdentifier { $$ = $1; }
377 ;
378
379ObjectIdentifier:
380 '{' ObjectIdentifierBody '}' {
381 $$ = $2;
382 }
383 | '{' '}' {
384 $$ = 0;
385 }
386 ;
387
388ObjectIdentifierBody:
389 ObjectIdentifierElement {
390 $$ = asn1p_oid_new();
391 asn1p_oid_add_arc($$, &$1);
392 if($1.name)
393 free($1.name);
394 }
395 | ObjectIdentifierBody ObjectIdentifierElement {
396 $$ = $1;
397 asn1p_oid_add_arc($$, &$2);
398 if($2.name)
399 free($2.name);
400 }
401 ;
402
403ObjectIdentifierElement:
404 Identifier { /* iso */
405 $$.name = $1;
406 $$.number = -1;
407 }
408 | Identifier '(' TOK_number ')' { /* iso(1) */
409 $$.name = $1;
410 $$.number = $3;
411 }
412 | TOK_number { /* 1 */
413 $$.name = 0;
414 $$.number = $1;
415 }
416 ;
417
418/*
419 * Optional module flags.
420 */
421optModuleSpecificationFlags:
422 { $$ = MSF_NOFLAGS; }
423 | ModuleSpecificationFlags {
424 $$ = $1;
425 }
426 ;
427
428/*
429 * Module flags.
430 */
431ModuleSpecificationFlags:
432 ModuleSpecificationFlag {
433 $$ = $1;
434 }
435 | ModuleSpecificationFlags ModuleSpecificationFlag {
436 $$ = $1 | $2;
437 }
438 ;
439
440/*
441 * Single module flag.
442 */
443ModuleSpecificationFlag:
444 TOK_EXPLICIT TOK_TAGS {
445 $$ = MSF_EXPLICIT_TAGS;
446 }
447 | TOK_IMPLICIT TOK_TAGS {
448 $$ = MSF_IMPLICIT_TAGS;
449 }
450 | TOK_AUTOMATIC TOK_TAGS {
451 $$ = MSF_AUTOMATIC_TAGS;
452 }
453 | TOK_EXTENSIBILITY TOK_IMPLIED {
454 $$ = MSF_EXTENSIBILITY_IMPLIED;
455 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000456 /* EncodingReferenceDefault */
457 | TOK_capitalreference TOK_INSTRUCTIONS {
458 /* X.680Amd1 specifies TAG and XER */
459 if(strcmp($1, "TAG") == 0) {
460 $$ = MSF_TAG_INSTRUCTIONS;
461 } else if(strcmp($1, "XER") == 0) {
462 $$ = MSF_XER_INSTRUCTIONS;
463 } else {
464 fprintf(stderr,
465 "WARNING: %s INSTRUCTIONS at line %d: "
466 "Unrecognized encoding reference\n",
467 $1, yylineno);
468 $$ = MSF_unk_INSTRUCTIONS;
469 }
470 free($1);
471 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000472 ;
473
474/*
475 * Optional module body.
476 */
477optModuleSpecificationBody:
478 { $$ = 0; }
479 | ModuleSpecificationBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000480 $$ = $1;
481 }
482 ;
483
484/*
485 * ASN.1 Module body.
486 */
487ModuleSpecificationBody:
488 ModuleSpecificationElement {
489 $$ = $1;
490 }
491 | ModuleSpecificationBody ModuleSpecificationElement {
492 $$ = $1;
493
Lev Walkinf59d0752004-08-18 04:59:12 +0000494 /* Behave well when one of them is skipped. */
495 if(!($1)) {
496 if($2) $$ = $2;
497 break;
498 }
499
Lev Walkinf15320b2004-06-03 03:38:44 +0000500#ifdef MY_IMPORT
501#error MY_IMPORT DEFINED ELSEWHERE!
502#endif
503#define MY_IMPORT(foo,field) do { \
Lev Walkinbc55d232004-08-13 12:31:09 +0000504 while(TQ_FIRST(&($2->foo))) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000505 TQ_ADD(&($$->foo), \
506 TQ_REMOVE(&($2->foo), field), \
507 field); \
Lev Walkinbc55d232004-08-13 12:31:09 +0000508 } \
509 assert(TQ_FIRST(&($2->foo)) == 0); \
510 } while(0)
Lev Walkinf15320b2004-06-03 03:38:44 +0000511
512 MY_IMPORT(imports, xp_next);
513 MY_IMPORT(exports, xp_next);
514 MY_IMPORT(members, next);
515#undef MY_IMPORT
516
517 }
518 ;
519
520/*
521 * One of the elements of ASN.1 module specification.
522 */
523ModuleSpecificationElement:
524 ImportsDefinition {
525 $$ = $1;
526 }
527 | ExportsDefinition {
528 $$ = asn1p_module_new();
529 checkmem($$);
530 if($1) {
531 TQ_ADD(&($$->exports), $1, xp_next);
532 } else {
533 /* "EXPORTS ALL;" ? */
534 }
535 }
536 | DataTypeReference {
537 $$ = asn1p_module_new();
538 checkmem($$);
539 assert($1->expr_type != A1TC_INVALID);
540 assert($1->meta_type != AMT_INVALID);
541 TQ_ADD(&($$->members), $1, next);
542 }
543 | ValueDefinition {
544 $$ = asn1p_module_new();
545 checkmem($$);
546 assert($1->expr_type != A1TC_INVALID);
547 assert($1->meta_type != AMT_INVALID);
548 TQ_ADD(&($$->members), $1, next);
549 }
550 /*
551 * Value set definition
552 * === EXAMPLE ===
553 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
554 * === EOF ===
555 */
556 | ValueSetDefinition {
557 $$ = asn1p_module_new();
558 checkmem($$);
559 assert($1->expr_type != A1TC_INVALID);
560 assert($1->meta_type != AMT_INVALID);
561 TQ_ADD(&($$->members), $1, next);
562 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000563 | TOK_ENCODING_CONTROL TOK_capitalreference
564 { asn1p_lexer_hack_push_encoding_control(); }
565 {
566 fprintf(stderr,
567 "WARNING: ENCODING-CONTROL %s "
568 "specification at line %d ignored\n",
569 $2, yylineno);
570 free($2);
571 $$ = 0;
572 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000573
574 /*
575 * Erroneous attemps
576 */
577 | BasicString {
578 return yyerror(
579 "Attempt to redefine a standard basic type, "
580 "use -ftypesXY to switch back "
581 "to older version of ASN.1 standard");
582 }
583 ;
584
585/*
586 * === EXAMPLE ===
587 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
588 * === EOF ===
589 */
590ImportsDefinition:
591 TOK_IMPORTS ImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000592 if(!saved_aid && 0)
593 return yyerror("Unterminated IMPORTS FROM, "
594 "expected semicolon ';'");
595 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000596 $$ = $2;
597 }
598 /*
599 * Some error cases.
600 */
601 | TOK_IMPORTS TOK_FROM /* ... */ {
602 return yyerror("Empty IMPORTS list");
603 }
604 ;
605
606ImportsBundleSet:
607 ImportsBundle {
608 $$ = asn1p_module_new();
609 checkmem($$);
610 TQ_ADD(&($$->imports), $1, xp_next);
611 }
612 | ImportsBundleSet ImportsBundle {
613 $$ = $1;
614 TQ_ADD(&($$->imports), $2, xp_next);
615 }
616 ;
617
Lev Walkin1ed22092005-08-12 10:06:17 +0000618AssignedIdentifier:
619 { memset(&$$, 0, sizeof($$)); }
620 | ObjectIdentifier { $$.oid = $1; };
621 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
622
Lev Walkinf15320b2004-06-03 03:38:44 +0000623ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000624 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000625 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000626 $$->fromModuleName = $3;
627 $$->identifier = $4;
628 /* This stupid thing is used for look-back hack. */
629 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000630 checkmem($$);
631 }
632 ;
633
634ImportsList:
635 ImportsElement {
636 $$ = asn1p_xports_new();
637 checkmem($$);
638 TQ_ADD(&($$->members), $1, next);
639 }
640 | ImportsList ',' ImportsElement {
641 $$ = $1;
642 TQ_ADD(&($$->members), $3, next);
643 }
644 ;
645
646ImportsElement:
647 TypeRefName {
648 $$ = asn1p_expr_new(yylineno);
649 checkmem($$);
650 $$->Identifier = $1;
651 $$->expr_type = A1TC_REFERENCE;
652 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000653 | TypeRefName '{' '}' { /* Completely equivalent to above */
654 $$ = asn1p_expr_new(yylineno);
655 checkmem($$);
656 $$->Identifier = $1;
657 $$->expr_type = A1TC_REFERENCE;
658 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000659 | Identifier {
660 $$ = asn1p_expr_new(yylineno);
661 checkmem($$);
662 $$->Identifier = $1;
663 $$->expr_type = A1TC_REFERENCE;
664 }
665 ;
666
667ExportsDefinition:
668 TOK_EXPORTS ExportsBody ';' {
669 $$ = $2;
670 }
671 | TOK_EXPORTS TOK_ALL ';' {
672 $$ = 0;
673 }
674 | TOK_EXPORTS ';' {
675 /* Empty EXPORTS clause effectively prohibits export. */
676 $$ = asn1p_xports_new();
677 checkmem($$);
678 }
679 ;
680
681ExportsBody:
682 ExportsElement {
683 $$ = asn1p_xports_new();
684 assert($$);
685 TQ_ADD(&($$->members), $1, next);
686 }
687 | ExportsBody ',' ExportsElement {
688 $$ = $1;
689 TQ_ADD(&($$->members), $3, next);
690 }
691 ;
692
693ExportsElement:
694 TypeRefName {
695 $$ = asn1p_expr_new(yylineno);
696 checkmem($$);
697 $$->Identifier = $1;
698 $$->expr_type = A1TC_EXPORTVAR;
699 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000700 | TypeRefName '{' '}' {
701 $$ = asn1p_expr_new(yylineno);
702 checkmem($$);
703 $$->Identifier = $1;
704 $$->expr_type = A1TC_EXPORTVAR;
705 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000706 | Identifier {
707 $$ = asn1p_expr_new(yylineno);
708 checkmem($$);
709 $$->Identifier = $1;
710 $$->expr_type = A1TC_EXPORTVAR;
711 }
712 ;
713
714
715ValueSetDefinition:
Lev Walkin8ea99482005-03-31 21:48:13 +0000716 TypeRefName DefinedTypeRef TOK_PPEQ
717 '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +0000718 $$ = $2;
719 assert($$->Identifier == 0);
720 $$->Identifier = $1;
721 $$->meta_type = AMT_VALUESET;
Lev Walkin8ea99482005-03-31 21:48:13 +0000722 // take care of ValueSet body
Lev Walkinf15320b2004-06-03 03:38:44 +0000723 }
724 ;
725
726DefinedTypeRef:
727 ComplexTypeReference {
728 $$ = asn1p_expr_new(yylineno);
729 checkmem($$);
730 $$->reference = $1;
731 $$->expr_type = A1TC_REFERENCE;
732 $$->meta_type = AMT_TYPEREF;
733 }
734 | BasicTypeId {
735 $$ = asn1p_expr_new(yylineno);
736 checkmem($$);
737 $$->expr_type = $1;
738 $$->meta_type = AMT_TYPE;
739 }
740 ;
741
Lev Walkinf15320b2004-06-03 03:38:44 +0000742/*
743 * Data Type Reference.
744 * === EXAMPLE ===
745 * Type3 ::= CHOICE { a Type1, b Type 2 }
746 * === EOF ===
747 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000748DataTypeReference:
749 /*
750 * Optionally tagged type definition.
751 */
752 TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER {
753 $$ = asn1p_expr_new(yylineno);
754 checkmem($$);
755 $$->Identifier = $1;
756 $$->tag = $3;
757 $$->expr_type = A1TC_TYPEID;
758 $$->meta_type = AMT_TYPE;
759 }
Lev Walkinaf120f72004-09-14 02:36:39 +0000760 | TypeRefName TOK_PPEQ Type {
761 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000762 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000763 assert($$->expr_type);
764 assert($$->meta_type);
765 }
766 | TypeRefName TOK_PPEQ ClassDeclaration {
767 $$ = $3;
768 $$->Identifier = $1;
769 assert($$->expr_type == A1TC_CLASSDEF);
770 assert($$->meta_type == AMT_OBJECT);
771 }
772 /*
773 * Parametrized <Type> declaration:
774 * === EXAMPLE ===
775 * SIGNED { ToBeSigned } ::= SEQUENCE {
776 * toBeSigned ToBeSigned,
777 * algorithm AlgorithmIdentifier,
778 * signature BIT STRING
779 * }
780 * === EOF ===
781 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000782 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000783 $$ = $6;
784 assert($$->Identifier == 0);
785 $$->Identifier = $1;
786 $$->params = $3;
787 $$->meta_type = AMT_PARAMTYPE;
788 }
789 ;
790
791ParameterArgumentList:
792 ParameterArgumentName {
793 int ret;
794 $$ = asn1p_paramlist_new(yylineno);
795 checkmem($$);
796 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
797 checkmem(ret == 0);
798 if($1.governor) asn1p_ref_free($1.governor);
799 if($1.argument) free($1.argument);
800 }
801 | ParameterArgumentList ',' ParameterArgumentName {
802 int ret;
803 $$ = $1;
804 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
805 checkmem(ret == 0);
806 if($3.governor) asn1p_ref_free($3.governor);
807 if($3.argument) free($3.argument);
808 }
809 ;
810
811ParameterArgumentName:
812 TypeRefName {
813 $$.governor = NULL;
814 $$.argument = $1;
815 }
816 | TypeRefName ':' Identifier {
817 int ret;
818 $$.governor = asn1p_ref_new(yylineno);
819 ret = asn1p_ref_add_component($$.governor, $1, 0);
820 checkmem(ret == 0);
821 $$.argument = $3;
822 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000823 | TypeRefName ':' TypeRefName {
824 int ret;
825 $$.governor = asn1p_ref_new(yylineno);
826 ret = asn1p_ref_add_component($$.governor, $1, 0);
827 checkmem(ret == 0);
828 $$.argument = $3;
829 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000830 | BasicTypeId ':' Identifier {
831 int ret;
832 $$.governor = asn1p_ref_new(yylineno);
833 ret = asn1p_ref_add_component($$.governor,
834 ASN_EXPR_TYPE2STR($1), 1);
835 checkmem(ret == 0);
836 $$.argument = $3;
837 }
838 ;
839
840ActualParameterList:
841 ActualParameter {
842 $$ = asn1p_expr_new(yylineno);
843 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000844 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000845 }
846 | ActualParameterList ',' ActualParameter {
847 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000848 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000849 }
850 ;
851
852ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000853 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000854 $$ = $1;
855 }
856 | Identifier {
857 $$ = asn1p_expr_new(yylineno);
858 checkmem($$);
859 $$->Identifier = $1;
860 $$->expr_type = A1TC_REFERENCE;
861 $$->meta_type = AMT_VALUE;
862 }
863 ;
864
865/*
Lev Walkinc8092cb2005-02-18 16:34:21 +0000866 | '{' ActualParameter '}' {
867 $$ = asn1p_expr_new(yylineno);
868 checkmem($$);
869 asn1p_expr_add($$, $2);
870 $$->expr_type = A1TC_PARAMETRIZED;
871 $$->meta_type = AMT_TYPE;
872 }
873 ;
874*/
875
876/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000877 * A collection of constructed data type members.
878 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000879optComponentTypeLists:
880 { $$ = asn1p_expr_new(yylineno); }
881 | ComponentTypeLists { $$ = $1; };
882
Lev Walkin070a52d2004-08-22 03:19:54 +0000883ComponentTypeLists:
884 ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000885 $$ = asn1p_expr_new(yylineno);
886 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000887 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000888 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000889 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000890 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000891 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000892 }
893 ;
894
Lev Walkin070a52d2004-08-22 03:19:54 +0000895ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000896 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000897 $$ = $2;
898 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000899 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000900 $$->marker = $3;
901 }
902 | TOK_COMPONENTS TOK_OF Type {
903 $$ = asn1p_expr_new(yylineno);
904 checkmem($$);
905 $$->meta_type = $3->meta_type;
906 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +0000907 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000908 }
909 | ExtensionAndException {
910 $$ = $1;
911 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +0000912 | Type optMarker {
913 $$ = $1;
914 $$->marker = $2;
915 _fixup_anonymous_identifier($$);
916 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000917 ;
918
919AlternativeTypeLists:
920 AlternativeType {
921 $$ = asn1p_expr_new(yylineno);
922 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000923 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +0000924 }
925 | AlternativeTypeLists ',' AlternativeType {
926 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000927 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +0000928 }
929 ;
930
931AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000932 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +0000933 $$ = $2;
934 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000935 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +0000936 }
937 | ExtensionAndException {
938 $$ = $1;
939 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +0000940 | Type {
941 $$ = $1;
942 _fixup_anonymous_identifier($$);
943 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000944 ;
945
Lev Walkinf15320b2004-06-03 03:38:44 +0000946ClassDeclaration:
947 TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
948 $$ = $3;
949 checkmem($$);
950 $$->with_syntax = $5;
951 assert($$->expr_type == A1TC_CLASSDEF);
952 assert($$->meta_type == AMT_OBJECT);
953 }
954 ;
955
956optUnique:
957 { $$ = 0; }
958 | TOK_UNIQUE { $$ = 1; }
959 ;
960
961ClassFieldList:
962 ClassField {
963 $$ = asn1p_expr_new(yylineno);
964 checkmem($$);
965 $$->expr_type = A1TC_CLASSDEF;
966 $$->meta_type = AMT_OBJECT;
Lev Walkin1004aa92004-09-08 00:28:11 +0000967 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000968 }
969 | ClassFieldList ',' ClassField {
970 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000971 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000972 }
973 ;
974
975ClassField:
976 ClassFieldIdentifier optMarker {
977 $$ = asn1p_expr_new(yylineno);
978 checkmem($$);
979 $$->Identifier = $1.name;
980 $$->expr_type = A1TC_CLASSFIELD;
981 $$->meta_type = AMT_OBJECTFIELD;
982 $$->marker = $2;
983 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000984 | ClassFieldIdentifier Type optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000985 $$ = $2;
986 $$->Identifier = $1.name;
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000987 $$->marker = $4;
988 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000989 }
Lev Walkinb7c45ca2004-11-24 17:43:29 +0000990 | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker {
Lev Walkinf15320b2004-06-03 03:38:44 +0000991 int ret;
992 $$ = asn1p_expr_new(yylineno);
993 checkmem($$);
994 $$->Identifier = $1.name;
995 $$->reference = asn1p_ref_new(yylineno);
996 checkmem($$->reference);
997 ret = asn1p_ref_add_component($$->reference,
998 $2.name, $2.lex_type);
999 checkmem(ret == 0);
1000 $$->expr_type = A1TC_CLASSFIELD;
1001 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001002 $$->marker = $4;
1003 $$->unique = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001004 }
1005 ;
1006
1007optWithSyntax:
1008 { $$ = 0; }
1009 | WithSyntax {
1010 $$ = $1;
1011 }
1012 ;
1013
1014WithSyntax:
1015 TOK_WITH TOK_SYNTAX '{'
1016 { asn1p_lexer_hack_enable_with_syntax(); }
1017 WithSyntaxFormat
1018 '}' {
1019 $$ = $5;
1020 }
1021 ;
1022
1023WithSyntaxFormat:
1024 WithSyntaxFormatToken {
1025 $$ = asn1p_wsyntx_new();
1026 TQ_ADD(&($$->chunks), $1, next);
1027 }
1028 | WithSyntaxFormat WithSyntaxFormatToken {
1029 $$ = $1;
1030 TQ_ADD(&($$->chunks), $2, next);
1031 }
1032 ;
1033
1034WithSyntaxFormatToken:
1035 TOK_opaque {
1036 $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0);
1037 }
1038 | ClassFieldIdentifier {
1039 asn1p_ref_t *ref;
1040 int ret;
1041 ref = asn1p_ref_new(yylineno);
1042 checkmem(ref);
1043 ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type);
1044 checkmem(ret == 0);
1045 $$ = asn1p_wsyntx_chunk_fromref(ref, 0);
1046 }
1047 ;
1048
Lev Walkinf15320b2004-06-03 03:38:44 +00001049ExtensionAndException:
1050 TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00001051 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001052 checkmem($$);
1053 $$->Identifier = strdup("...");
1054 checkmem($$->Identifier);
1055 $$->expr_type = A1TC_EXTENSIBLE;
1056 $$->meta_type = AMT_TYPE;
1057 }
1058 | TOK_ThreeDots '!' DefinedValue {
Lev Walkinceb20e72004-09-05 10:40:41 +00001059 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001060 checkmem($$);
1061 $$->Identifier = strdup("...");
1062 checkmem($$->Identifier);
1063 $$->value = $3;
1064 $$->expr_type = A1TC_EXTENSIBLE;
1065 $$->meta_type = AMT_TYPE;
1066 }
1067 | TOK_ThreeDots '!' SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001068 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001069 checkmem($$);
1070 $$->Identifier = strdup("...");
1071 $$->value = $3;
1072 checkmem($$->Identifier);
1073 $$->expr_type = A1TC_EXTENSIBLE;
1074 $$->meta_type = AMT_TYPE;
1075 }
1076 ;
1077
Lev Walkin070a52d2004-08-22 03:19:54 +00001078Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001079 optTag TypeDeclaration optConstraints {
1080 $$ = $2;
1081 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001082 /*
1083 * Outer constraint for SEQUENCE OF and SET OF applies
1084 * to the inner type.
1085 */
1086 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1087 || $$->expr_type == ASN_CONSTR_SET_OF) {
1088 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001089 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001090 } else {
1091 if($$->constraints) {
1092 assert(!$2);
1093 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001094 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001095 }
1096 }
Lev Walkin4696c742005-08-22 12:23:54 +00001097 asn1p_last_type = $$;
Lev Walkin070a52d2004-08-22 03:19:54 +00001098 }
1099 ;
1100
1101TypeDeclaration:
Lev Walkin4696c742005-08-22 12:23:54 +00001102 {apply_nonstd_mods();} TypeDeclarationSet {
1103 $$ = $2;
1104 }
1105
1106TypeDeclarationSet:
Lev Walkinf15320b2004-06-03 03:38:44 +00001107 BasicType {
1108 $$ = $1;
1109 }
Lev Walkin4696c742005-08-22 12:23:54 +00001110 | TOK_CHOICE '{' AlternativeTypeLists {apply_nonstd_mods();} '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001111 $$ = $3;
1112 assert($$->expr_type == A1TC_INVALID);
1113 $$->expr_type = ASN_CONSTR_CHOICE;
1114 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001115 }
Lev Walkin4696c742005-08-22 12:23:54 +00001116 | TOK_SEQUENCE '{' optComponentTypeLists {apply_nonstd_mods();} '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001117 $$ = $3;
1118 assert($$->expr_type == A1TC_INVALID);
1119 $$->expr_type = ASN_CONSTR_SEQUENCE;
1120 $$->meta_type = AMT_TYPE;
1121 }
Lev Walkin4696c742005-08-22 12:23:54 +00001122 | TOK_SET '{' optComponentTypeLists {apply_nonstd_mods();} '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001123 $$ = $3;
1124 assert($$->expr_type == A1TC_INVALID);
1125 $$->expr_type = ASN_CONSTR_SET;
1126 $$->meta_type = AMT_TYPE;
1127 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001128 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001129 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001130 checkmem($$);
1131 $$->constraints = $2;
1132 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1133 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001134 $6->Identifier = $4;
1135 $6->tag = $5;
1136 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001137 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001138 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkinceb20e72004-09-05 10:40:41 +00001139 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001140 checkmem($$);
1141 $$->constraints = $2;
1142 $$->expr_type = ASN_CONSTR_SET_OF;
1143 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001144 $6->Identifier = $4;
1145 $6->tag = $5;
1146 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001147 }
1148 | TOK_ANY {
Lev Walkinceb20e72004-09-05 10:40:41 +00001149 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001150 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001151 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001152 $$->meta_type = AMT_TYPE;
1153 }
1154 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1155 int ret;
Lev Walkinceb20e72004-09-05 10:40:41 +00001156 $$ = asn1p_expr_new(yylineno);
Lev Walkin070a52d2004-08-22 03:19:54 +00001157 checkmem($$);
1158 $$->reference = asn1p_ref_new(yylineno);
1159 ret = asn1p_ref_add_component($$->reference,
1160 $4, RLT_lowercase);
1161 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001162 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001163 $$->meta_type = AMT_TYPE;
1164 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001165 /*
1166 * A parametrized assignment.
1167 */
1168 | TypeRefName '{' ActualParameterList '}' {
1169 int ret;
1170 $$ = $3;
1171 assert($$->expr_type == 0);
1172 assert($$->meta_type == 0);
1173 assert($$->reference == 0);
1174 $$->reference = asn1p_ref_new(yylineno);
1175 checkmem($$->reference);
1176 ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN);
1177 checkmem(ret == 0);
1178 free($1);
1179 $$->expr_type = A1TC_PARAMETRIZED;
1180 $$->meta_type = AMT_TYPE;
1181 }
1182 /*
1183 * A DefinedType reference.
1184 * "CLASS1.&id.&id2"
1185 * or
1186 * "Module.Type"
1187 * or
1188 * "Module.identifier"
1189 * or
1190 * "Type"
1191 */
1192 | ComplexTypeReference {
1193 $$ = asn1p_expr_new(yylineno);
1194 checkmem($$);
1195 $$->reference = $1;
1196 $$->expr_type = A1TC_REFERENCE;
1197 $$->meta_type = AMT_TYPEREF;
1198 }
1199 | TOK_INSTANCE TOK_OF ComplexTypeReference {
1200 $$ = asn1p_expr_new(yylineno);
1201 checkmem($$);
1202 $$->reference = $3;
1203 $$->expr_type = A1TC_INSTANCE;
1204 $$->meta_type = AMT_TYPE;
1205 }
1206 ;
1207
1208/*
1209 * A type name consisting of several components.
1210 * === EXAMPLE ===
1211 * === EOF ===
1212 */
1213ComplexTypeReference:
1214 TOK_typereference {
1215 int ret;
1216 $$ = asn1p_ref_new(yylineno);
1217 checkmem($$);
1218 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1219 checkmem(ret == 0);
1220 free($1);
1221 }
1222 | TOK_typereference '.' TypeRefName {
1223 int ret;
1224 $$ = asn1p_ref_new(yylineno);
1225 checkmem($$);
1226 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1227 checkmem(ret == 0);
1228 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1229 checkmem(ret == 0);
1230 free($1);
1231 }
Lev Walkin9c974182004-09-15 11:59:51 +00001232 | ObjectClassReference '.' TypeRefName {
1233 int ret;
1234 $$ = asn1p_ref_new(yylineno);
1235 checkmem($$);
1236 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1237 checkmem(ret == 0);
1238 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1239 checkmem(ret == 0);
1240 free($1);
1241 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001242 | TOK_typereference '.' Identifier {
1243 int ret;
1244 $$ = asn1p_ref_new(yylineno);
1245 checkmem($$);
1246 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1247 checkmem(ret == 0);
1248 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1249 checkmem(ret == 0);
1250 free($1);
1251 }
1252 | ObjectClassReference {
1253 int ret;
1254 $$ = asn1p_ref_new(yylineno);
1255 checkmem($$);
1256 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1257 free($1);
1258 checkmem(ret == 0);
1259 }
1260 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1261 int ret;
1262 $$ = $3;
1263 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1264 free($1);
1265 checkmem(ret == 0);
1266 /*
1267 * Move the last element infront.
1268 */
1269 {
1270 struct asn1p_ref_component_s tmp_comp;
1271 tmp_comp = $$->components[$$->comp_count-1];
1272 memmove(&$$->components[1],
1273 &$$->components[0],
1274 sizeof($$->components[0])
1275 * ($$->comp_count - 1));
1276 $$->components[0] = tmp_comp;
1277 }
1278 }
1279 ;
1280
1281ComplexTypeReferenceAmpList:
1282 ComplexTypeReferenceElement {
1283 int ret;
1284 $$ = asn1p_ref_new(yylineno);
1285 checkmem($$);
1286 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1287 free($1.name);
1288 checkmem(ret == 0);
1289 }
1290 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1291 int ret;
1292 $$ = $1;
1293 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1294 free($3.name);
1295 checkmem(ret == 0);
1296 }
1297 ;
1298
1299ComplexTypeReferenceElement: ClassFieldName;
1300ClassFieldIdentifier: ClassFieldName;
1301
1302ClassFieldName:
1303 /* "&Type1" */
1304 TOK_typefieldreference {
1305 $$.lex_type = RLT_AmpUppercase;
1306 $$.name = $1;
1307 }
1308 /* "&id" */
1309 | TOK_valuefieldreference {
1310 $$.lex_type = RLT_Amplowercase;
1311 $$.name = $1;
1312 }
1313 ;
1314
1315
1316/*
1317 * === EXAMPLE ===
1318 * value INTEGER ::= 1
1319 * === EOF ===
1320 */
1321ValueDefinition:
Lev Walkin9c974182004-09-15 11:59:51 +00001322 Identifier DefinedTypeRef TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001323 $$ = $2;
1324 assert($$->Identifier == NULL);
1325 $$->Identifier = $1;
1326 $$->meta_type = AMT_VALUE;
1327 $$->value = $4;
1328 }
1329 ;
1330
Lev Walkin9c974182004-09-15 11:59:51 +00001331Value:
1332 Identifier ':' Value {
1333 $$ = asn1p_value_fromint(0);
1334 checkmem($$);
1335 $$->type = ATV_CHOICE_IDENTIFIER;
1336 $$->value.choice_identifier.identifier = $1;
1337 $$->value.choice_identifier.value = $3;
1338 }
Lev Walkincbad2512005-03-24 16:27:02 +00001339 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001340 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1341 checkmem($$);
1342 $$->type = ATV_UNPARSED;
1343 }
Lev Walkin9c974182004-09-15 11:59:51 +00001344 | TOK_NULL {
1345 $$ = asn1p_value_fromint(0);
1346 checkmem($$);
1347 $$->type = ATV_NULL;
1348 }
1349 | TOK_FALSE {
1350 $$ = asn1p_value_fromint(0);
1351 checkmem($$);
1352 $$->type = ATV_FALSE;
1353 }
1354 | TOK_TRUE {
1355 $$ = asn1p_value_fromint(0);
1356 checkmem($$);
1357 $$->type = ATV_TRUE;
1358 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001359 | TOK_bstring {
1360 $$ = _convert_bitstring2binary($1, 'B');
1361 checkmem($$);
1362 }
1363 | TOK_hstring {
1364 $$ = _convert_bitstring2binary($1, 'H');
1365 checkmem($$);
1366 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001367 | RestrictedCharacterStringValue {
1368 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001369 }
1370 | SignedNumber {
1371 $$ = $1;
1372 }
1373 | DefinedValue {
1374 $$ = $1;
1375 }
1376 ;
1377
1378DefinedValue:
1379 Identifier {
1380 asn1p_ref_t *ref;
1381 int ret;
1382 ref = asn1p_ref_new(yylineno);
1383 checkmem(ref);
1384 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1385 checkmem(ret == 0);
1386 $$ = asn1p_value_fromref(ref, 0);
1387 checkmem($$);
1388 free($1);
1389 }
1390 | TypeRefName '.' Identifier {
1391 asn1p_ref_t *ref;
1392 int ret;
1393 ref = asn1p_ref_new(yylineno);
1394 checkmem(ref);
1395 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1396 checkmem(ret == 0);
1397 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1398 checkmem(ret == 0);
1399 $$ = asn1p_value_fromref(ref, 0);
1400 checkmem($$);
1401 free($1);
1402 free($3);
1403 }
1404 ;
1405
Lev Walkin1e448d32005-03-24 14:26:38 +00001406
1407RestrictedCharacterStringValue:
1408 TOK_cstring {
1409 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1410 checkmem($$);
1411 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001412 | TOK_tuple {
1413 $$ = asn1p_value_fromint($1);
1414 checkmem($$);
1415 $$->type = ATV_TUPLE;
1416 }
1417 | TOK_quadruple {
1418 $$ = asn1p_value_fromint($1);
1419 checkmem($$);
1420 $$->type = ATV_QUADRUPLE;
1421 }
1422 /*
Lev Walkin1e448d32005-03-24 14:26:38 +00001423 | '{' TOK_number ',' TOK_number '}' {
1424 asn1c_integer_t v = ($2 << 4) + $4;
1425 if($2 > 7) return yyerror("X.680:2003, #37.14 "
1426 "mandates 0..7 range for Tuple's TableColumn");
1427 if($4 > 15) return yyerror("X.680:2003, #37.14 "
1428 "mandates 0..15 range for Tuple's TableRow");
1429 $$ = asn1p_value_fromint(v);
1430 checkmem($$);
1431 $$->type = ATV_TUPLE;
1432 }
1433 | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' {
1434 asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8;
1435 if($2 > 127) return yyerror("X.680:2003, #37.12 "
1436 "mandates 0..127 range for Quadruple's Group");
1437 if($4 > 255) return yyerror("X.680:2003, #37.12 "
1438 "mandates 0..255 range for Quadruple's Plane");
1439 if($6 > 255) return yyerror("X.680:2003, #37.12 "
1440 "mandates 0..255 range for Quadruple's Row");
1441 if($8 > 255) return yyerror("X.680:2003, #37.12 "
1442 "mandates 0..255 range for Quadruple's Cell");
1443 $$ = asn1p_value_fromint(v);
1444 checkmem($$);
1445 $$->type = ATV_QUADRUPLE;
1446 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001447 */
Lev Walkin1e448d32005-03-24 14:26:38 +00001448 ;
1449
Lev Walkinf15320b2004-06-03 03:38:44 +00001450Opaque:
1451 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001452 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001453 $$.buf = malloc($$.len + 1);
1454 checkmem($$.buf);
1455 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001456 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001457 $$.buf[$$.len] = '\0';
1458 free($1.buf);
1459 }
1460 | Opaque TOK_opaque {
1461 int newsize = $1.len + $2.len;
1462 char *p = malloc(newsize + 1);
1463 checkmem(p);
1464 memcpy(p , $1.buf, $1.len);
1465 memcpy(p + $1.len, $2.buf, $2.len);
1466 p[newsize] = '\0';
1467 free($1.buf);
1468 free($2.buf);
1469 $$.buf = p;
1470 $$.len = newsize;
1471 }
1472 ;
1473
1474BasicTypeId:
1475 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1476 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1477 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1478 | BasicTypeId_UniverationCompatible { $$ = $1; }
1479 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1480 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1481 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1482 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1483 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1484 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1485 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1486 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001487 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001488 ;
1489
1490/*
1491 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1492 */
1493BasicTypeId_UniverationCompatible:
1494 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1495 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1496 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1497 ;
1498
1499BasicType:
1500 BasicTypeId {
Lev Walkinceb20e72004-09-05 10:40:41 +00001501 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001502 checkmem($$);
1503 $$->expr_type = $1;
1504 $$->meta_type = AMT_TYPE;
1505 }
1506 | BasicTypeId_UniverationCompatible UniverationDefinition {
1507 if($2) {
1508 $$ = $2;
1509 } else {
Lev Walkinceb20e72004-09-05 10:40:41 +00001510 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001511 checkmem($$);
1512 }
1513 $$->expr_type = $1;
1514 $$->meta_type = AMT_TYPE;
1515 }
1516 ;
1517
1518BasicString:
1519 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1520 | TOK_GeneralString {
1521 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001522 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001523 }
1524 | TOK_GraphicString {
1525 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001526 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001527 }
1528 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1529 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1530 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1531 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1532 | TOK_T61String {
1533 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001534 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001535 }
1536 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1537 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1538 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1539 | TOK_VideotexString {
1540 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001541 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001542 }
1543 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1544 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1545 ;
1546
Lev Walkind2ea1de2004-08-20 13:25:29 +00001547
Lev Walkinf15320b2004-06-03 03:38:44 +00001548/*
1549 * Data type constraints.
1550 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001551Union: '|' | TOK_UNION;
1552Intersection: '^' | TOK_INTERSECTION;
1553Except: TOK_EXCEPT;
1554
Lev Walkinf59d0752004-08-18 04:59:12 +00001555optConstraints:
1556 { $$ = 0; }
Lev Walkind2ea1de2004-08-20 13:25:29 +00001557 | Constraints {
1558 $$ = $1;
1559 }
1560 ;
1561
1562Constraints:
1563 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001564 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001565 }
1566 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001567 /*
1568 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001569 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001570 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001571 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001572 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001573 ;
1574
Lev Walkinf59d0752004-08-18 04:59:12 +00001575SetOfConstraints:
1576 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001577 $$ = $2;
1578 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001579 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001580 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001581 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001582 ;
1583
Lev Walkinf59d0752004-08-18 04:59:12 +00001584ElementSetSpecs:
1585 ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001586 $$ = $1;
1587 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001588 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001589 asn1p_constraint_t *ct;
1590 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001591 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001592 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001593 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001594 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001595 asn1p_constraint_t *ct;
1596 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001597 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001598 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001599 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001600 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001601 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001602 ;
1603
Lev Walkinf59d0752004-08-18 04:59:12 +00001604ElementSetSpec:
1605 ConstraintSubtypeElement {
1606 $$ = $1;
1607 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001608 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001609 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001610 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001611 | ElementSetSpec Union ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001612 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001613 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001614 | ElementSetSpec Intersection ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001615 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001616 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001617 | ConstraintSubtypeElement Except ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001618 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001619 }
1620 ;
1621
1622ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001623 ConstraintSpec '(' ElementSetSpecs ')' {
1624 int ret;
1625 $$ = asn1p_constraint_new(yylineno);
1626 checkmem($$);
1627 $$->type = $1;
1628 ret = asn1p_constraint_insert($$, $3);
1629 checkmem(ret == 0);
1630 }
1631 | '(' ElementSetSpecs ')' {
1632 int ret;
1633 $$ = asn1p_constraint_new(yylineno);
1634 checkmem($$);
1635 $$->type = ACT_CA_SET;
1636 ret = asn1p_constraint_insert($$, $2);
1637 checkmem(ret == 0);
1638 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001639 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001640 $$ = asn1p_constraint_new(yylineno);
1641 checkmem($$);
1642 $$->type = ACT_EL_VALUE;
1643 $$->value = $1;
1644 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001645 | ContainedSubtype {
1646 $$ = asn1p_constraint_new(yylineno);
1647 checkmem($$);
1648 $$->type = ACT_EL_TYPE;
1649 $$->containedSubtype = $1;
1650 }
1651 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001652 $$ = asn1p_constraint_new(yylineno);
1653 checkmem($$);
1654 $$->type = $2;
1655 $$->range_start = $1;
1656 $$->range_stop = $3;
1657 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001658 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001659 $$ = asn1p_constraint_new(yylineno);
1660 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001661 $$->type = $2;
1662 $$->range_start = asn1p_value_fromint(-123);
1663 $$->range_stop = $3;
1664 $$->range_start->type = ATV_MIN;
1665 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001666 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001667 $$ = asn1p_constraint_new(yylineno);
1668 checkmem($$);
1669 $$->type = $2;
1670 $$->range_start = $1;
1671 $$->range_stop = asn1p_value_fromint(321);
1672 $$->range_stop->type = ATV_MAX;
1673 }
1674 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1675 $$ = asn1p_constraint_new(yylineno);
1676 checkmem($$);
1677 $$->type = $2;
1678 $$->range_start = asn1p_value_fromint(-123);
1679 $$->range_stop = asn1p_value_fromint(321);
1680 $$->range_start->type = ATV_MIN;
1681 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001682 }
1683 | TableConstraint {
1684 $$ = $1;
1685 }
Lev Walkine596bf02005-03-28 15:01:27 +00001686 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001687 $$ = $1;
1688 }
Lev Walkin1893ddf2005-03-20 14:28:32 +00001689 | TOK_CONSTRAINED TOK_BY '{'
1690 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
1691 $$ = asn1p_constraint_new(yylineno);
1692 checkmem($$);
1693 $$->type = ACT_CT_CTDBY;
1694 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
1695 checkmem($$->value);
1696 $$->value->type = ATV_UNPARSED;
1697 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001698 ;
1699
1700ConstraintRangeSpec:
1701 TOK_TwoDots { $$ = ACT_EL_RANGE; }
1702 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
1703 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
1704 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
1705 ;
1706
1707ConstraintSpec:
1708 TOK_SIZE {
1709 $$ = ACT_CT_SIZE;
1710 }
1711 | TOK_FROM {
1712 $$ = ACT_CT_FROM;
1713 }
1714 ;
1715
Lev Walkinff7dd142005-03-20 12:58:00 +00001716SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001717 TOK_FALSE {
1718 $$ = asn1p_value_fromint(0);
1719 checkmem($$);
1720 $$->type = ATV_FALSE;
1721 }
1722 | TOK_TRUE {
1723 $$ = asn1p_value_fromint(1);
1724 checkmem($$);
1725 $$->type = ATV_TRUE;
1726 }
1727 | SignedNumber {
Lev Walkinf15320b2004-06-03 03:38:44 +00001728 $$ = $1;
1729 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001730 | RestrictedCharacterStringValue {
1731 $$ = $1;
Lev Walkinc8092cb2005-02-18 16:34:21 +00001732 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001733 | Identifier {
1734 asn1p_ref_t *ref;
1735 int ret;
1736 ref = asn1p_ref_new(yylineno);
1737 checkmem(ref);
1738 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1739 checkmem(ret == 0);
1740 $$ = asn1p_value_fromref(ref, 0);
1741 checkmem($$);
1742 free($1);
1743 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001744 ;
1745
1746ContainedSubtype:
1747 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001748 asn1p_ref_t *ref;
1749 int ret;
1750 ref = asn1p_ref_new(yylineno);
1751 checkmem(ref);
1752 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1753 checkmem(ret == 0);
1754 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001755 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001756 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001757 }
1758 ;
1759
Lev Walkine596bf02005-03-28 15:01:27 +00001760InnerTypeConstraint:
1761 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001762 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001763 }
1764 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001765 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001766 }
1767 ;
1768
1769WithComponentsList:
1770 WithComponentsElement {
1771 $$ = $1;
1772 }
1773 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001774 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001775 }
1776 ;
1777
1778WithComponentsElement:
1779 TOK_ThreeDots {
1780 $$ = asn1p_constraint_new(yylineno);
1781 checkmem($$);
1782 $$->type = ACT_EL_EXT;
Lev Walkine596bf02005-03-28 15:01:27 +00001783 $$->value = asn1p_value_frombuf("...", 3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001784 }
1785 | Identifier optConstraints optPresenceConstraint {
1786 $$ = asn1p_constraint_new(yylineno);
1787 checkmem($$);
1788 $$->type = ACT_EL_VALUE;
1789 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1790 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001791 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001792 }
1793 ;
1794
1795/*
1796 * presence constraint for WithComponents
1797 */
1798optPresenceConstraint:
1799 { $$ = ACPRES_DEFAULT; }
1800 | PresenceConstraint { $$ = $1; }
1801 ;
1802
1803PresenceConstraint:
1804 TOK_PRESENT {
1805 $$ = ACPRES_PRESENT;
1806 }
1807 | TOK_ABSENT {
1808 $$ = ACPRES_ABSENT;
1809 }
1810 | TOK_OPTIONAL {
1811 $$ = ACPRES_OPTIONAL;
1812 }
1813 ;
1814
1815TableConstraint:
1816 SimpleTableConstraint {
1817 $$ = $1;
1818 }
1819 | ComponentRelationConstraint {
1820 $$ = $1;
1821 }
1822 ;
1823
1824/*
1825 * "{ExtensionSet}"
1826 */
1827SimpleTableConstraint:
1828 '{' TypeRefName '}' {
1829 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
1830 asn1p_constraint_t *ct;
1831 int ret;
1832 ret = asn1p_ref_add_component(ref, $2, 0);
1833 checkmem(ret == 0);
1834 ct = asn1p_constraint_new(yylineno);
1835 checkmem($$);
1836 ct->type = ACT_EL_VALUE;
1837 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001838 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001839 }
1840 ;
1841
1842ComponentRelationConstraint:
1843 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001844 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001845 }
1846 ;
1847
1848AtNotationList:
1849 AtNotationElement {
1850 $$ = asn1p_constraint_new(yylineno);
1851 checkmem($$);
1852 $$->type = ACT_EL_VALUE;
1853 $$->value = asn1p_value_fromref($1, 0);
1854 }
1855 | AtNotationList ',' AtNotationElement {
1856 asn1p_constraint_t *ct;
1857 ct = asn1p_constraint_new(yylineno);
1858 checkmem(ct);
1859 ct->type = ACT_EL_VALUE;
1860 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00001861 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001862 }
1863 ;
1864
1865/*
1866 * @blah
1867 */
1868AtNotationElement:
1869 '@' ComponentIdList {
1870 char *p = malloc(strlen($2) + 2);
1871 int ret;
1872 *p = '@';
1873 strcpy(p + 1, $2);
1874 $$ = asn1p_ref_new(yylineno);
1875 ret = asn1p_ref_add_component($$, p, 0);
1876 checkmem(ret == 0);
1877 free(p);
1878 free($2);
1879 }
1880 | '@' '.' ComponentIdList {
1881 char *p = malloc(strlen($3) + 3);
1882 int ret;
1883 p[0] = '@';
1884 p[1] = '.';
1885 strcpy(p + 2, $3);
1886 $$ = asn1p_ref_new(yylineno);
1887 ret = asn1p_ref_add_component($$, p, 0);
1888 checkmem(ret == 0);
1889 free(p);
1890 free($3);
1891 }
1892 ;
1893
1894/* identifier "." ... */
1895ComponentIdList:
1896 Identifier {
1897 $$ = $1;
1898 }
1899 | ComponentIdList '.' Identifier {
1900 int l1 = strlen($1);
1901 int l3 = strlen($3);
1902 $$ = malloc(l1 + 1 + l3 + 1);
1903 memcpy($$, $1, l1);
1904 $$[l1] = '.';
1905 memcpy($$ + l1 + 1, $3, l3);
1906 $$[l1 + 1 + l3] = '\0';
1907 }
1908 ;
1909
1910
1911
1912/*
1913 * MARKERS
1914 */
1915
1916optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00001917 {
1918 $$.flags = EM_NOMARK;
1919 $$.default_value = 0;
1920 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001921 | Marker { $$ = $1; }
1922 ;
1923
1924Marker:
1925 TOK_OPTIONAL {
Lev Walkin9c974182004-09-15 11:59:51 +00001926 $$.flags = EM_OPTIONAL;
1927 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00001928 }
Lev Walkin9c974182004-09-15 11:59:51 +00001929 | TOK_DEFAULT Value {
1930 $$.flags = EM_DEFAULT;
1931 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001932 }
1933 ;
1934
1935/*
1936 * Universal enumeration definition to use in INTEGER and ENUMERATED.
1937 * === EXAMPLE ===
1938 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
1939 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
1940 * === EOF ===
1941 */
1942/*
1943optUniverationDefinition:
1944 { $$ = 0; }
1945 | UniverationDefinition {
1946 $$ = $1;
1947 }
1948 ;
1949*/
1950
1951UniverationDefinition:
1952 '{' '}' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001953 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001954 checkmem($$);
1955 }
1956 | '{' UniverationList '}' {
1957 $$ = $2;
1958 }
1959 ;
1960
1961UniverationList:
1962 UniverationElement {
Lev Walkinceb20e72004-09-05 10:40:41 +00001963 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001964 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001965 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001966 }
1967 | UniverationList ',' UniverationElement {
1968 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001969 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001970 }
1971 ;
1972
1973UniverationElement:
1974 Identifier {
Lev Walkinceb20e72004-09-05 10:40:41 +00001975 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001976 checkmem($$);
1977 $$->expr_type = A1TC_UNIVERVAL;
1978 $$->meta_type = AMT_VALUE;
1979 $$->Identifier = $1;
1980 }
1981 | Identifier '(' SignedNumber ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001982 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001983 checkmem($$);
1984 $$->expr_type = A1TC_UNIVERVAL;
1985 $$->meta_type = AMT_VALUE;
1986 $$->Identifier = $1;
1987 $$->value = $3;
1988 }
1989 | Identifier '(' DefinedValue ')' {
Lev Walkinceb20e72004-09-05 10:40:41 +00001990 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001991 checkmem($$);
1992 $$->expr_type = A1TC_UNIVERVAL;
1993 $$->meta_type = AMT_VALUE;
1994 $$->Identifier = $1;
1995 $$->value = $3;
1996 }
1997 | SignedNumber {
Lev Walkinceb20e72004-09-05 10:40:41 +00001998 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001999 checkmem($$);
2000 $$->expr_type = A1TC_UNIVERVAL;
2001 $$->meta_type = AMT_VALUE;
2002 $$->value = $1;
2003 }
2004 | TOK_ThreeDots {
Lev Walkinceb20e72004-09-05 10:40:41 +00002005 $$ = asn1p_expr_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00002006 checkmem($$);
2007 $$->Identifier = strdup("...");
2008 checkmem($$->Identifier);
2009 $$->expr_type = A1TC_EXTENSIBLE;
2010 $$->meta_type = AMT_VALUE;
2011 }
2012 ;
2013
2014SignedNumber:
2015 TOK_number {
2016 $$ = asn1p_value_fromint($1);
2017 checkmem($$);
2018 }
2019 | TOK_number_negative {
2020 $$ = asn1p_value_fromint($1);
2021 checkmem($$);
2022 }
2023 ;
2024
2025/*
2026 * SEQUENCE definition.
2027 * === EXAMPLE ===
2028 * Struct1 ::= SEQUENCE {
2029 * memb1 Struct2,
2030 * memb2 SEQUENCE OF {
2031 * memb2-1 Struct 3
2032 * }
2033 * }
2034 * === EOF ===
2035 */
2036
2037
2038
2039/*
2040 * SET definition.
2041 * === EXAMPLE ===
2042 * Person ::= SET {
2043 * name [0] PrintableString (SIZE(1..20)),
2044 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2045 * }
2046 * === EOF ===
2047 */
2048
2049optTag:
2050 { memset(&$$, 0, sizeof($$)); }
2051 | Tag { $$ = $1; }
2052 ;
2053
2054Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002055 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002056 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002057 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002058 }
Lev Walkinc603f102005-01-23 09:51:44 +00002059 ;
2060
2061TagTypeValue:
2062 '[' TagClass TOK_number ']' {
2063 $$ = $2;
2064 $$.tag_value = $3;
2065 };
2066
2067TagClass:
2068 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2069 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2070 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2071 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2072 ;
2073
2074TagPlicit:
2075 { $$.tag_mode = TM_DEFAULT; }
2076 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2077 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002078 ;
2079
2080TypeRefName:
2081 TOK_typereference {
2082 checkmem($1);
2083 $$ = $1;
2084 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002085 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002086 checkmem($1);
2087 $$ = $1;
2088 }
2089 ;
2090
Lev Walkinf59d0752004-08-18 04:59:12 +00002091
Lev Walkinf15320b2004-06-03 03:38:44 +00002092ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002093 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002094 checkmem($1);
2095 $$ = $1;
2096 }
2097 ;
2098
Lev Walkin83cac2f2004-09-22 16:03:36 +00002099optIdentifier:
2100 { $$ = 0; }
2101 | Identifier {
2102 $$ = $1;
2103 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002104 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002105
Lev Walkinf15320b2004-06-03 03:38:44 +00002106Identifier:
2107 TOK_identifier {
2108 checkmem($1);
2109 $$ = $1;
2110 }
2111 ;
2112
Lev Walkinf15320b2004-06-03 03:38:44 +00002113%%
2114
2115
2116/*
2117 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2118 */
2119static asn1p_value_t *
2120_convert_bitstring2binary(char *str, int base) {
2121 asn1p_value_t *val;
2122 int slen;
2123 int memlen;
2124 int baselen;
2125 int bits;
2126 uint8_t *binary_vector;
2127 uint8_t *bv_ptr;
2128 uint8_t cur_val;
2129
2130 assert(str);
2131 assert(str[0] == '\'');
2132
2133 switch(base) {
2134 case 'B':
2135 baselen = 1;
2136 break;
2137 case 'H':
2138 baselen = 4;
2139 break;
2140 default:
2141 assert(base == 'B' || base == 'H');
2142 errno = EINVAL;
2143 return NULL;
2144 }
2145
2146 slen = strlen(str);
2147 assert(str[slen - 1] == base);
2148 assert(str[slen - 2] == '\'');
2149
2150 memlen = slen / (8 / baselen); /* Conservative estimate */
2151
2152 bv_ptr = binary_vector = malloc(memlen + 1);
2153 if(bv_ptr == NULL)
2154 /* ENOMEM */
2155 return NULL;
2156
2157 cur_val = 0;
2158 bits = 0;
2159 while(*(++str) != '\'') {
2160 switch(baselen) {
2161 case 1:
2162 switch(*str) {
2163 case '1':
2164 cur_val |= 1 << (7 - (bits % 8));
2165 case '0':
2166 break;
2167 default:
2168 assert(!"_y UNREACH1");
2169 case ' ': case '\r': case '\n':
2170 continue;
2171 }
2172 break;
2173 case 4:
2174 switch(*str) {
2175 case '0': case '1': case '2': case '3': case '4':
2176 case '5': case '6': case '7': case '8': case '9':
2177 cur_val |= (*str - '0') << (4 - (bits % 8));
2178 break;
2179 case 'A': case 'B': case 'C':
2180 case 'D': case 'E': case 'F':
2181 cur_val |= ((*str - 'A') + 10)
2182 << (4 - (bits % 8));
2183 break;
2184 default:
2185 assert(!"_y UNREACH2");
2186 case ' ': case '\r': case '\n':
2187 continue;
2188 }
2189 break;
2190 }
2191
2192 bits += baselen;
2193 if((bits % 8) == 0) {
2194 *bv_ptr++ = cur_val;
2195 cur_val = 0;
2196 }
2197 }
2198
2199 *bv_ptr = cur_val;
2200 assert((bv_ptr - binary_vector) <= memlen);
2201
2202 val = asn1p_value_frombits(binary_vector, bits, 0);
2203 if(val == NULL) {
2204 free(binary_vector);
2205 }
2206
2207 return val;
2208}
2209
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002210/*
2211 * For unnamed types (used in old X.208 compliant modules)
2212 * generate some sort of interim names, to not to force human being to fix
2213 * the specification's compliance to modern ASN.1 standards.
2214 */
2215static void
2216_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2217 char *p;
2218 assert(expr->Identifier == 0);
2219
2220 /*
2221 * Try to figure out the type name
2222 * without going too much into details
2223 */
2224 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2225 if(expr->reference && expr->reference->comp_count > 0)
2226 expr->Identifier = expr->reference->components[0].name;
2227
2228 fprintf(stderr,
2229 "WARNING: Line %d: expected lower-case member identifier, "
2230 "found an unnamed %s.\n"
2231 "WARNING: Obsolete X.208 syntax detected, "
2232 "please give the member a name.\n",
2233 yylineno, expr->Identifier ? expr->Identifier : "type");
2234
2235 if(!expr->Identifier)
2236 expr->Identifier = "unnamed";
2237 expr->Identifier = strdup(expr->Identifier);
2238 assert(expr->Identifier);
2239 /* Make a lowercase identifier from the type name */
2240 for(p = expr->Identifier; *p; p++) {
2241 switch(*p) {
2242 case 'A' ... 'Z': *p += 32; break;
2243 case ' ': *p = '_'; break;
2244 case '-': *p = '_'; break;
2245 }
2246 }
2247 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2248 "Name clash may occur later.\n",
2249 expr->Identifier);
2250}
2251
Lev Walkin4696c742005-08-22 12:23:54 +00002252static void
2253apply_nonstd_mods() {
2254 if(!asn1p_as_pointer) return;
2255 asn1p_as_pointer = 0;
2256
2257 if(asn1p_last_type) {
2258 asn1p_last_type->marker.flags |= EM_INDIRECT;
2259 fprintf(stderr, "INFO: Modifier <asn1c:pointer> "
2260 "applied to \"%s\" at line %d\n",
2261 asn1p_last_type->Identifier
2262 ? asn1p_last_type->Identifier : "<anonymous>",
2263 asn1p_last_type->_lineno);
2264 asn1p_last_type = 0;
2265 }
2266}
2267
Lev Walkinf15320b2004-06-03 03:38:44 +00002268extern char *asn1p_text;
2269
2270int
2271yyerror(const char *msg) {
2272 fprintf(stderr,
2273 "ASN.1 grammar parse error "
2274 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002275 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002276 return -1;
2277}
2278
2279