blob: b8406b63adbf9d97849b6537f45950cf4fb07248 [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 Walkinef625402005-09-05 05:17:57 +000027 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000028 */
29extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000030
31/*
Lev Walkin1ed22092005-08-12 10:06:17 +000032 * This temporary variable is used to solve the shortcomings of 1-lookahead
33 * parser.
34 */
35static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000036
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000037static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
38static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000039
Lev Walkina9532f42006-09-17 04:52:50 +000040static asn1p_module_t *currentModule;
41#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
42
Lev Walkin1ed22092005-08-12 10:06:17 +000043#define checkmem(ptr) do { \
44 if(!(ptr)) \
45 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000046 } while(0)
47
Lev Walkin2c14a692005-08-12 10:08:45 +000048#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000049 if(arg1->type != constr_type) { \
50 int __ret; \
51 root = asn1p_constraint_new(yylineno); \
52 checkmem(root); \
53 root->type = constr_type; \
54 __ret = asn1p_constraint_insert(root, \
55 arg1); \
56 checkmem(__ret == 0); \
57 } else { \
58 root = arg1; \
59 } \
60 if(arg2) { \
61 int __ret \
62 = asn1p_constraint_insert(root, arg2); \
63 checkmem(__ret == 0); \
64 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000065 } while(0)
66
Lev Walkin866bd7f2006-09-14 10:35:20 +000067#ifdef AL_IMPORT
68#error AL_IMPORT DEFINED ELSEWHERE!
69#endif
70#define AL_IMPORT(to,where,from,field) do { \
71 if(!(from)) break; \
72 while(TQ_FIRST(&((from)->where))) { \
73 TQ_ADD(&((to)->where), \
74 TQ_REMOVE(&((from)->where), field), \
75 field); \
76 } \
77 assert(TQ_FIRST(&((from)->where)) == 0); \
78 } while(0)
79
Lev Walkinf15320b2004-06-03 03:38:44 +000080%}
81
82
83/*
84 * Token value definition.
85 * a_*: ASN-specific types.
86 * tv_*: Locally meaningful types.
87 */
88%union {
89 asn1p_t *a_grammar;
90 asn1p_module_flags_e a_module_flags;
91 asn1p_module_t *a_module;
92 asn1p_expr_type_e a_type; /* ASN.1 Type */
93 asn1p_expr_t *a_expr; /* Constructed collection */
94 asn1p_constraint_t *a_constr; /* Constraint */
95 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
96 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +000097 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +000098 asn1p_oid_t *a_oid; /* Object Identifier */
99 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
100 struct asn1p_type_tag_s a_tag; /* A tag */
101 asn1p_ref_t *a_ref; /* Reference to custom type */
102 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
103 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
104 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
105 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
106 struct asn1p_param_s a_parg; /* A parameter argument */
107 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +0000108 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +0000109 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +0000110 asn1c_integer_t a_int;
Lev Walkinadf863f2006-09-05 16:18:34 +0000111 double a_dbl;
Lev Walkinf15320b2004-06-03 03:38:44 +0000112 char *tv_str;
113 struct {
114 char *buf;
115 int len;
116 } tv_opaque;
117 struct {
118 char *name;
119 struct asn1p_type_tag_s tag;
120 } tv_nametag;
121};
122
123/*
124 * Token types returned by scanner.
125 */
126%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
Lev Walkin0e90aa02013-03-19 16:17:13 -0700127%token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
Lev Walkin57074f12006-03-16 05:11:14 +0000128%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000129%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
130%token <tv_str> TOK_bstring
131%token <tv_opaque> TOK_cstring
132%token <tv_str> TOK_hstring
133%token <tv_str> TOK_identifier
134%token <a_int> TOK_number
Lev Walkinadf863f2006-09-05 16:18:34 +0000135%token <a_int> TOK_number_negative
136%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000137%token <a_int> TOK_tuple
138%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000139%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000140%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000141%token <tv_str> TOK_typefieldreference /* "&Pork" */
142%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000143%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000144
145/*
146 * Token types representing ASN.1 standard keywords.
147 */
148%token TOK_ABSENT
149%token TOK_ABSTRACT_SYNTAX
150%token TOK_ALL
151%token TOK_ANY
152%token TOK_APPLICATION
153%token TOK_AUTOMATIC
154%token TOK_BEGIN
155%token TOK_BIT
156%token TOK_BMPString
157%token TOK_BOOLEAN
158%token TOK_BY
159%token TOK_CHARACTER
160%token TOK_CHOICE
161%token TOK_CLASS
162%token TOK_COMPONENT
163%token TOK_COMPONENTS
164%token TOK_CONSTRAINED
165%token TOK_CONTAINING
166%token TOK_DEFAULT
167%token TOK_DEFINITIONS
168%token TOK_DEFINED
169%token TOK_EMBEDDED
170%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000171%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000172%token TOK_END
173%token TOK_ENUMERATED
174%token TOK_EXPLICIT
175%token TOK_EXPORTS
176%token TOK_EXTENSIBILITY
177%token TOK_EXTERNAL
178%token TOK_FALSE
179%token TOK_FROM
180%token TOK_GeneralizedTime
181%token TOK_GeneralString
182%token TOK_GraphicString
183%token TOK_IA5String
184%token TOK_IDENTIFIER
185%token TOK_IMPLICIT
186%token TOK_IMPLIED
187%token TOK_IMPORTS
188%token TOK_INCLUDES
189%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000190%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000191%token TOK_INTEGER
192%token TOK_ISO646String
193%token TOK_MAX
194%token TOK_MIN
195%token TOK_MINUS_INFINITY
196%token TOK_NULL
197%token TOK_NumericString
198%token TOK_OBJECT
199%token TOK_ObjectDescriptor
200%token TOK_OCTET
201%token TOK_OF
202%token TOK_OPTIONAL
203%token TOK_PATTERN
204%token TOK_PDV
205%token TOK_PLUS_INFINITY
206%token TOK_PRESENT
207%token TOK_PrintableString
208%token TOK_PRIVATE
209%token TOK_REAL
210%token TOK_RELATIVE_OID
211%token TOK_SEQUENCE
212%token TOK_SET
213%token TOK_SIZE
214%token TOK_STRING
215%token TOK_SYNTAX
216%token TOK_T61String
217%token TOK_TAGS
218%token TOK_TeletexString
219%token TOK_TRUE
220%token TOK_TYPE_IDENTIFIER
221%token TOK_UNIQUE
222%token TOK_UNIVERSAL
223%token TOK_UniversalString
224%token TOK_UTCTime
225%token TOK_UTF8String
226%token TOK_VideotexString
227%token TOK_VisibleString
228%token TOK_WITH
229
Lev Walkinf1727152006-09-21 01:50:37 +0000230%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000231%left '^' TOK_INTERSECTION
232%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000233
234/* Misc tags */
235%token TOK_TwoDots /* .. */
236%token TOK_ThreeDots /* ... */
Lev Walkinf15320b2004-06-03 03:38:44 +0000237
238
239/*
240 * Types defined herein.
241 */
242%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000243%type <a_module> ModuleDefinition
244%type <a_module> ModuleBody
245%type <a_module> AssignmentList
246%type <a_module> Assignment
247%type <a_module> optModuleBody /* Optional */
248%type <a_module_flags> optModuleDefinitionFlags
249%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
250%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
251%type <a_module> optImports
252%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000253%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000254%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000255%type <a_module> ImportsBundleSet
256%type <a_xports> ImportsBundle
257%type <a_xports> ImportsList
258%type <a_xports> ExportsDefinition
259%type <a_xports> ExportsBody
260%type <a_expr> ImportsElement
261%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000262%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000263%type <a_expr> Type
Lev Walkin070a52d2004-08-22 03:19:54 +0000264%type <a_expr> TypeDeclaration
Lev Walkin4696c742005-08-22 12:23:54 +0000265%type <a_expr> TypeDeclarationSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000266%type <a_ref> ComplexTypeReference
267%type <a_ref> ComplexTypeReferenceAmpList
268%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000269%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000270%type <a_expr> FieldSpec
271%type <a_ref> FieldName
272%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000273%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000274%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000275%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000276%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000277%type <a_constr> ValueSet /* {a|b|c}*/
278%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000279%type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000280%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000281%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000282%type <a_value> DefinedValue
283%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000284%type <a_value> RealValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +0000285%type <a_value> BitStringValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000286%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000287%type <a_expr> ComponentTypeLists
288%type <a_expr> ComponentType
289%type <a_expr> AlternativeTypeLists
290%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000291%type <a_expr> UniverationDefinition
292%type <a_expr> UniverationList
293%type <a_expr> UniverationElement
294%type <tv_str> TypeRefName
295%type <tv_str> ObjectClassReference
Lev Walkinf15320b2004-06-03 03:38:44 +0000296%type <tv_str> Identifier
Lev Walkin83cac2f2004-09-22 16:03:36 +0000297%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000298%type <a_parg> ParameterArgumentName
299%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000300%type <a_expr> ActualParameter
301%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000302%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000303%type <a_oid> ObjectIdentifier /* OID */
304%type <a_oid> optObjectIdentifier /* Optional OID */
305%type <a_oid> ObjectIdentifierBody
306%type <a_oid_arc> ObjectIdentifierElement
307%type <a_expr> BasicType
308%type <a_type> BasicTypeId
309%type <a_type> BasicTypeId_UniverationCompatible
310%type <a_type> BasicString
311%type <tv_opaque> Opaque
Lev Walkinc603f102005-01-23 09:51:44 +0000312%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
313%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000314%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
315%type <a_constr> optConstraints
Lev Walkina9532f42006-09-17 04:52:50 +0000316%type <a_constr> Constraint
317%type <a_constr> SubtypeConstraint
318%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000319%type <a_constr> SetOfConstraints
320%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
321%type <a_constr> ElementSetSpec /* 1..2,...,3 */
Lev Walkinf1727152006-09-21 01:50:37 +0000322%type <a_constr> Unions
323%type <a_constr> Intersections
324%type <a_constr> IntersectionElements
Lev Walkinf15320b2004-06-03 03:38:44 +0000325%type <a_constr> ConstraintSubtypeElement /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000326%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000327%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000328%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000329%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000330%type <a_constr> PatternConstraint
Lev Walkine596bf02005-03-28 15:01:27 +0000331%type <a_constr> InnerTypeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000332%type <a_constr> WithComponentsList
333%type <a_constr> WithComponentsElement
334%type <a_constr> ComponentRelationConstraint
335%type <a_constr> AtNotationList
336%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000337%type <a_value> SingleValue
338%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000339%type <a_ctype> ConstraintSpec
340%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000341%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000342%type <a_wsynt> optWithSyntax
343%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000344%type <a_wsynt> WithSyntaxList
345%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000346%type <a_marker> optMarker Marker
347%type <a_int> optUnique
348%type <a_pres> optPresenceConstraint PresenceConstraint
349%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000350%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000351
352
353%%
354
355
356ParsedGrammar:
357 ModuleList {
358 *(void **)param = $1;
359 }
360 ;
361
362ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000363 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000364 $$ = asn1p_new();
365 checkmem($$);
366 TQ_ADD(&($$->modules), $1, mod_next);
367 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000368 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000369 $$ = $1;
370 TQ_ADD(&($$->modules), $2, mod_next);
371 }
372 ;
373
374/*
375 * ASN module definition.
376 * === EXAMPLE ===
377 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
378 * BEGIN
379 * ...
380 * END
381 * === EOF ===
382 */
383
Lev Walkin866bd7f2006-09-14 10:35:20 +0000384ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000385 TypeRefName { currentModule = asn1p_module_new(); }
386 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000387 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000388 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000389 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000390 TOK_END {
391
Lev Walkina9532f42006-09-17 04:52:50 +0000392 $$ = currentModule;
393
394 if($8) {
395 asn1p_module_t tmp = *($$);
396 *($$) = *($8);
397 *($8) = tmp;
398 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000399 } else {
400 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000401 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000402
Lev Walkin1ed22092005-08-12 10:06:17 +0000403 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000404 $$->module_oid = $3;
405 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000406 }
407 ;
408
409/*
410 * Object Identifier Definition
411 * { iso member-body(2) 3 }
412 */
413optObjectIdentifier:
414 { $$ = 0; }
415 | ObjectIdentifier { $$ = $1; }
416 ;
417
418ObjectIdentifier:
419 '{' ObjectIdentifierBody '}' {
420 $$ = $2;
421 }
422 | '{' '}' {
423 $$ = 0;
424 }
425 ;
426
427ObjectIdentifierBody:
428 ObjectIdentifierElement {
429 $$ = asn1p_oid_new();
430 asn1p_oid_add_arc($$, &$1);
431 if($1.name)
432 free($1.name);
433 }
434 | ObjectIdentifierBody ObjectIdentifierElement {
435 $$ = $1;
436 asn1p_oid_add_arc($$, &$2);
437 if($2.name)
438 free($2.name);
439 }
440 ;
441
442ObjectIdentifierElement:
443 Identifier { /* iso */
444 $$.name = $1;
445 $$.number = -1;
446 }
447 | Identifier '(' TOK_number ')' { /* iso(1) */
448 $$.name = $1;
449 $$.number = $3;
450 }
451 | TOK_number { /* 1 */
452 $$.name = 0;
453 $$.number = $1;
454 }
455 ;
456
457/*
458 * Optional module flags.
459 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000460optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000461 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000462 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000463 $$ = $1;
464 }
465 ;
466
467/*
468 * Module flags.
469 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000470ModuleDefinitionFlags:
471 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000472 $$ = $1;
473 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000474 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000475 $$ = $1 | $2;
476 }
477 ;
478
479/*
480 * Single module flag.
481 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000482ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000483 TOK_EXPLICIT TOK_TAGS {
484 $$ = MSF_EXPLICIT_TAGS;
485 }
486 | TOK_IMPLICIT TOK_TAGS {
487 $$ = MSF_IMPLICIT_TAGS;
488 }
489 | TOK_AUTOMATIC TOK_TAGS {
490 $$ = MSF_AUTOMATIC_TAGS;
491 }
492 | TOK_EXTENSIBILITY TOK_IMPLIED {
493 $$ = MSF_EXTENSIBILITY_IMPLIED;
494 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000495 /* EncodingReferenceDefault */
496 | TOK_capitalreference TOK_INSTRUCTIONS {
497 /* X.680Amd1 specifies TAG and XER */
498 if(strcmp($1, "TAG") == 0) {
499 $$ = MSF_TAG_INSTRUCTIONS;
500 } else if(strcmp($1, "XER") == 0) {
501 $$ = MSF_XER_INSTRUCTIONS;
502 } else {
503 fprintf(stderr,
504 "WARNING: %s INSTRUCTIONS at line %d: "
505 "Unrecognized encoding reference\n",
506 $1, yylineno);
507 $$ = MSF_unk_INSTRUCTIONS;
508 }
509 free($1);
510 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000511 ;
512
513/*
514 * Optional module body.
515 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000516optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000517 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000518 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000519 $$ = $1;
520 }
521 ;
522
523/*
524 * ASN.1 Module body.
525 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000526ModuleBody:
527 optExports optImports AssignmentList {
528 $$ = asn1p_module_new();
529 AL_IMPORT($$, exports, $1, xp_next);
530 AL_IMPORT($$, imports, $2, xp_next);
531 AL_IMPORT($$, members, $3, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800532
533 asn1p_module_free($1);
534 asn1p_module_free($2);
535 asn1p_module_free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000536 }
537 ;
538
Lev Walkin866bd7f2006-09-14 10:35:20 +0000539AssignmentList:
540 Assignment {
541 $$ = $1;
542 }
543 | AssignmentList Assignment {
544 if($1) {
545 $$ = $1;
546 } else {
547 $$ = $2;
548 break;
549 }
550 AL_IMPORT($$, members, $2, next);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800551 asn1p_module_free($2);
Lev Walkin866bd7f2006-09-14 10:35:20 +0000552 }
553 ;
554
555
Lev Walkinf15320b2004-06-03 03:38:44 +0000556/*
557 * One of the elements of ASN.1 module specification.
558 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000559Assignment:
560 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000561 $$ = asn1p_module_new();
562 checkmem($$);
563 assert($1->expr_type != A1TC_INVALID);
564 assert($1->meta_type != AMT_INVALID);
565 TQ_ADD(&($$->members), $1, next);
566 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000567 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000568 $$ = asn1p_module_new();
569 checkmem($$);
570 assert($1->expr_type != A1TC_INVALID);
571 assert($1->meta_type != AMT_INVALID);
572 TQ_ADD(&($$->members), $1, next);
573 }
574 /*
575 * Value set definition
576 * === EXAMPLE ===
577 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
578 * === EOF ===
579 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000580 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000581 $$ = asn1p_module_new();
582 checkmem($$);
583 assert($1->expr_type != A1TC_INVALID);
584 assert($1->meta_type != AMT_INVALID);
585 TQ_ADD(&($$->members), $1, next);
586 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000587 | TOK_ENCODING_CONTROL TOK_capitalreference
588 { asn1p_lexer_hack_push_encoding_control(); }
589 {
590 fprintf(stderr,
591 "WARNING: ENCODING-CONTROL %s "
592 "specification at line %d ignored\n",
593 $2, yylineno);
594 free($2);
595 $$ = 0;
596 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000597
598 /*
599 * Erroneous attemps
600 */
601 | BasicString {
602 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000603 "Attempt to redefine a standard basic string type, "
604 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000605 }
606 ;
607
608/*
609 * === EXAMPLE ===
610 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
611 * === EOF ===
612 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000613optImports:
614 { $$ = 0; }
615 | ImportsDefinition;
616
Lev Walkinf15320b2004-06-03 03:38:44 +0000617ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000618 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000619 if(!saved_aid && 0)
620 return yyerror("Unterminated IMPORTS FROM, "
621 "expected semicolon ';'");
622 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000623 $$ = $2;
624 }
625 /*
626 * Some error cases.
627 */
628 | TOK_IMPORTS TOK_FROM /* ... */ {
629 return yyerror("Empty IMPORTS list");
630 }
631 ;
632
Lev Walkin4a4543f2006-10-13 12:37:39 +0000633optImportsBundleSet:
634 { $$ = asn1p_module_new(); }
635 | ImportsBundleSet;
636
Lev Walkinf15320b2004-06-03 03:38:44 +0000637ImportsBundleSet:
638 ImportsBundle {
639 $$ = asn1p_module_new();
640 checkmem($$);
641 TQ_ADD(&($$->imports), $1, xp_next);
642 }
643 | ImportsBundleSet ImportsBundle {
644 $$ = $1;
645 TQ_ADD(&($$->imports), $2, xp_next);
646 }
647 ;
648
Lev Walkin1ed22092005-08-12 10:06:17 +0000649AssignedIdentifier:
650 { memset(&$$, 0, sizeof($$)); }
651 | ObjectIdentifier { $$.oid = $1; };
652 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
653
Lev Walkinf15320b2004-06-03 03:38:44 +0000654ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000655 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000656 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000657 $$->fromModuleName = $3;
658 $$->identifier = $4;
659 /* This stupid thing is used for look-back hack. */
660 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000661 checkmem($$);
662 }
663 ;
664
665ImportsList:
666 ImportsElement {
667 $$ = asn1p_xports_new();
668 checkmem($$);
669 TQ_ADD(&($$->members), $1, next);
670 }
671 | ImportsList ',' ImportsElement {
672 $$ = $1;
673 TQ_ADD(&($$->members), $3, next);
674 }
675 ;
676
677ImportsElement:
678 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000679 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000680 checkmem($$);
681 $$->Identifier = $1;
682 $$->expr_type = A1TC_REFERENCE;
683 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000684 | TypeRefName '{' '}' { /* Completely equivalent to above */
Lev Walkina9532f42006-09-17 04:52:50 +0000685 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000686 checkmem($$);
687 $$->Identifier = $1;
688 $$->expr_type = A1TC_REFERENCE;
689 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000690 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000691 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000692 checkmem($$);
693 $$->Identifier = $1;
694 $$->expr_type = A1TC_REFERENCE;
695 }
696 ;
697
Lev Walkin866bd7f2006-09-14 10:35:20 +0000698
699optExports:
700 { $$ = 0; }
701 | ExportsDefinition {
702 $$ = asn1p_module_new();
703 checkmem($$);
704 if($1) {
705 TQ_ADD(&($$->exports), $1, xp_next);
706 } else {
707 /* "EXPORTS ALL;" */
708 }
709 }
710 ;
711
Lev Walkinf15320b2004-06-03 03:38:44 +0000712ExportsDefinition:
713 TOK_EXPORTS ExportsBody ';' {
714 $$ = $2;
715 }
716 | TOK_EXPORTS TOK_ALL ';' {
717 $$ = 0;
718 }
719 | TOK_EXPORTS ';' {
720 /* Empty EXPORTS clause effectively prohibits export. */
721 $$ = asn1p_xports_new();
722 checkmem($$);
723 }
724 ;
725
726ExportsBody:
727 ExportsElement {
728 $$ = asn1p_xports_new();
729 assert($$);
730 TQ_ADD(&($$->members), $1, next);
731 }
732 | ExportsBody ',' ExportsElement {
733 $$ = $1;
734 TQ_ADD(&($$->members), $3, next);
735 }
736 ;
737
738ExportsElement:
739 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000740 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000741 checkmem($$);
742 $$->Identifier = $1;
743 $$->expr_type = A1TC_EXPORTVAR;
744 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000745 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000746 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000747 checkmem($$);
748 $$->Identifier = $1;
749 $$->expr_type = A1TC_EXPORTVAR;
750 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000751 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000752 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000753 checkmem($$);
754 $$->Identifier = $1;
755 $$->expr_type = A1TC_EXPORTVAR;
756 }
757 ;
758
759
Lev Walkin418298d2006-07-13 08:24:20 +0000760ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000761
762ValueSetTypeAssignment:
763 TypeRefName DefinedType TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000764 $$ = $2;
765 assert($$->Identifier == 0);
766 $$->Identifier = $1;
767 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000768 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000769 }
770 ;
771
Lev Walkin0c0bca62006-03-21 04:48:15 +0000772DefinedType:
773 BasicType {
774 $$ = $1;
775 }
776 /*
777 * A DefinedType reference.
778 * "CLASS1.&id.&id2"
779 * or
780 * "Module.Type"
781 * or
782 * "Module.identifier"
783 * or
784 * "Type"
785 */
786 | ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000787 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000788 checkmem($$);
789 $$->reference = $1;
790 $$->expr_type = A1TC_REFERENCE;
791 $$->meta_type = AMT_TYPEREF;
792 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000793 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000794 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000795 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000796 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000797 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000798 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000799 $$->reference = $1;
800 $$->rhs_pspecs = $3;
801 $$->expr_type = A1TC_REFERENCE;
802 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000803 }
804 ;
805
Lev Walkinf15320b2004-06-03 03:38:44 +0000806/*
807 * Data Type Reference.
808 * === EXAMPLE ===
809 * Type3 ::= CHOICE { a Type1, b Type 2 }
810 * === EOF ===
811 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000812DataTypeReference:
813 /*
814 * Optionally tagged type definition.
815 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000816 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000817 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000818 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000819 assert($$->expr_type);
820 assert($$->meta_type);
821 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000822 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000823 $$ = $3;
824 $$->Identifier = $1;
825 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000826 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000827 }
828 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000829 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000830 * === EXAMPLE ===
831 * SIGNED { ToBeSigned } ::= SEQUENCE {
832 * toBeSigned ToBeSigned,
833 * algorithm AlgorithmIdentifier,
834 * signature BIT STRING
835 * }
836 * === EOF ===
837 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000838 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000839 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000840 $$->Identifier = $1;
841 $$->lhs_params = $3;
842 }
843 /* Parameterized CLASS declaration */
844 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
845 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000846 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000847 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000848 }
849 ;
850
851ParameterArgumentList:
852 ParameterArgumentName {
853 int ret;
854 $$ = asn1p_paramlist_new(yylineno);
855 checkmem($$);
856 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
857 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700858 asn1p_ref_free($1.governor);
859 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000860 }
861 | ParameterArgumentList ',' ParameterArgumentName {
862 int ret;
863 $$ = $1;
864 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
865 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700866 asn1p_ref_free($3.governor);
867 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000868 }
869 ;
870
871ParameterArgumentName:
872 TypeRefName {
873 $$.governor = NULL;
874 $$.argument = $1;
875 }
876 | TypeRefName ':' Identifier {
877 int ret;
878 $$.governor = asn1p_ref_new(yylineno);
879 ret = asn1p_ref_add_component($$.governor, $1, 0);
880 checkmem(ret == 0);
881 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800882 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000883 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000884 | TypeRefName ':' TypeRefName {
885 int ret;
886 $$.governor = asn1p_ref_new(yylineno);
887 ret = asn1p_ref_add_component($$.governor, $1, 0);
888 checkmem(ret == 0);
889 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800890 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000891 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000892 | BasicTypeId ':' Identifier {
893 int ret;
894 $$.governor = asn1p_ref_new(yylineno);
895 ret = asn1p_ref_add_component($$.governor,
896 ASN_EXPR_TYPE2STR($1), 1);
897 checkmem(ret == 0);
898 $$.argument = $3;
899 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000900 | BasicTypeId ':' TypeRefName {
901 int ret;
902 $$.governor = asn1p_ref_new(yylineno);
903 ret = asn1p_ref_add_component($$.governor,
904 ASN_EXPR_TYPE2STR($1), 1);
905 checkmem(ret == 0);
906 $$.argument = $3;
907 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000908 ;
909
Lev Walkin5045dfa2006-03-21 09:41:28 +0000910ActualParameterList:
911 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000912 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000913 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000914 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000915 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000916 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000917 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000918 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000919 }
920 ;
921
Lev Walkin5045dfa2006-03-21 09:41:28 +0000922ActualParameter:
Lev Walkin070a52d2004-08-22 03:19:54 +0000923 Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000924 $$ = $1;
925 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000926 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000927 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000928 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800929 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000930 $$->expr_type = A1TC_REFERENCE;
931 $$->meta_type = AMT_VALUE;
932 $$->value = $1;
933 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000934 | Identifier {
Lev Walkina00d6b32006-03-21 03:40:38 +0000935 asn1p_ref_t *ref;
Lev Walkina9532f42006-09-17 04:52:50 +0000936 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000937 checkmem($$);
938 $$->Identifier = $1;
939 $$->expr_type = A1TC_REFERENCE;
940 $$->meta_type = AMT_VALUE;
Lev Walkina00d6b32006-03-21 03:40:38 +0000941 ref = asn1p_ref_new(yylineno);
942 asn1p_ref_add_component(ref, $1, RLT_lowercase);
943 $$->value = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000944 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000945 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000946 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +0000947 $$->expr_type = A1TC_VALUESET;
948 $$->meta_type = AMT_VALUESET;
949 $$->constraints = $1;
950 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000951 ;
952
953/*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000954 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000955 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +0000956 checkmem($$);
957 asn1p_expr_add($$, $2);
958 $$->expr_type = A1TC_PARAMETRIZED;
959 $$->meta_type = AMT_TYPE;
960 }
961 ;
962*/
963
964/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000965 * A collection of constructed data type members.
966 */
Lev Walkin144db9b2004-10-12 23:26:53 +0000967optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +0000968 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +0000969 | ComponentTypeLists { $$ = $1; };
970
Lev Walkin070a52d2004-08-22 03:19:54 +0000971ComponentTypeLists:
972 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +0000973 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000974 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000975 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000976 }
Lev Walkin070a52d2004-08-22 03:19:54 +0000977 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +0000978 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000979 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000980 }
Lev Walkin0e90aa02013-03-19 16:17:13 -0700981 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800982 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -0700983 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800984 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -0700985 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000986 ;
987
Lev Walkin070a52d2004-08-22 03:19:54 +0000988ComponentType:
Lev Walkinaf120f72004-09-14 02:36:39 +0000989 Identifier Type optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +0000990 $$ = $2;
991 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +0000992 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +0000993 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +0000994 $$->marker = $3;
995 }
Lev Walkinef625402005-09-05 05:17:57 +0000996 | Type optMarker {
997 $$ = $1;
998 $2.flags |= $$->marker.flags;
999 $$->marker = $2;
1000 _fixup_anonymous_identifier($$);
1001 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001002 | TOK_COMPONENTS TOK_OF Type {
Lev Walkina9532f42006-09-17 04:52:50 +00001003 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001004 checkmem($$);
1005 $$->meta_type = $3->meta_type;
1006 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001007 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001008 }
1009 | ExtensionAndException {
1010 $$ = $1;
1011 }
1012 ;
1013
1014AlternativeTypeLists:
1015 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001016 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001017 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001018 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001019 }
1020 | AlternativeTypeLists ',' AlternativeType {
1021 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001022 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001023 }
1024 ;
1025
1026AlternativeType:
Lev Walkinaf120f72004-09-14 02:36:39 +00001027 Identifier Type {
Lev Walkin070a52d2004-08-22 03:19:54 +00001028 $$ = $2;
1029 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001030 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001031 }
1032 | ExtensionAndException {
1033 $$ = $1;
1034 }
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001035 | Type {
1036 $$ = $1;
1037 _fixup_anonymous_identifier($$);
1038 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001039 ;
1040
Lev Walkin9c2285a2006-03-09 08:49:26 +00001041ObjectClass:
1042 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001043 $$ = $3;
1044 checkmem($$);
1045 $$->with_syntax = $5;
1046 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001047 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001048 }
1049 ;
1050
1051optUnique:
1052 { $$ = 0; }
1053 | TOK_UNIQUE { $$ = 1; }
1054 ;
1055
Lev Walkin9c2285a2006-03-09 08:49:26 +00001056FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001057 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001058 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001059 checkmem($$);
1060 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001061 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001062 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001063 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001064 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001065 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001066 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001067 }
1068 ;
1069
Lev Walkin9c2285a2006-03-09 08:49:26 +00001070 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001071ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001072
1073 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1074 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001075 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001076 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001077 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001078 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001079 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001080 $$->marker = $2;
1081 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001082
1083 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
1084 | TOK_valuefieldreference Type optUnique optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001085 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001086 $$->Identifier = $1;
1087 $$->meta_type = AMT_OBJECTFIELD;
1088 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001089 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001090 $$->marker = $4;
1091 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001092 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001093
1094 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1095 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001096 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001097 $$->Identifier = $1;
1098 $$->meta_type = AMT_OBJECTFIELD;
1099 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1100 $$->reference = $2;
1101 $$->marker = $3;
1102 }
1103
Lev Walkin9c2285a2006-03-09 08:49:26 +00001104 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1105 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001106 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001107 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001108 $$->Identifier = $1;
1109 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001110 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001111 $$->expr_type = A1TC_CLASSFIELD_OFS;
1112 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001113 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001114
Lev Walkin54868752006-03-09 09:08:49 +00001115 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1116 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001117 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001118 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001119 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001120 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1121 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001122 $$->marker = $3;
1123 }
1124
1125 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1126 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001127 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001128 checkmem($$);
1129 $$->Identifier = $1;
1130 $$->meta_type = AMT_OBJECTFIELD;
1131 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1132 asn1p_expr_add($$, $2);
1133 $$->marker = $3;
1134 }
1135
Lev Walkin54868752006-03-09 09:08:49 +00001136 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1137 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001138 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001139 checkmem($$);
1140 $$->Identifier = $1;
1141 $$->reference = $2;
1142 $$->meta_type = AMT_OBJECTFIELD;
1143 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1144 $$->marker = $3;
1145 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001146 ;
1147
1148optWithSyntax:
1149 { $$ = 0; }
1150 | WithSyntax {
1151 $$ = $1;
1152 }
1153 ;
1154
1155WithSyntax:
1156 TOK_WITH TOK_SYNTAX '{'
1157 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001158 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001159 '}' {
1160 $$ = $5;
1161 }
1162 ;
1163
Lev Walkin9d542d22006-03-14 16:31:37 +00001164WithSyntaxList:
1165 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001166 $$ = asn1p_wsyntx_new();
1167 TQ_ADD(&($$->chunks), $1, next);
1168 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001169 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001170 $$ = $1;
1171 TQ_ADD(&($$->chunks), $2, next);
1172 }
1173 ;
1174
Lev Walkin9d542d22006-03-14 16:31:37 +00001175WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001176 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001177 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001178 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001179 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001180 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001181 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001182 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001183 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001184 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001185 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001186 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001187 | '[' WithSyntaxList ']' {
1188 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1189 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001190 ;
1191
Lev Walkinf15320b2004-06-03 03:38:44 +00001192ExtensionAndException:
1193 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001194 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001195 checkmem($$);
1196 $$->Identifier = strdup("...");
1197 checkmem($$->Identifier);
1198 $$->expr_type = A1TC_EXTENSIBLE;
1199 $$->meta_type = AMT_TYPE;
1200 }
1201 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001202 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001203 checkmem($$);
1204 $$->Identifier = strdup("...");
1205 checkmem($$->Identifier);
1206 $$->value = $3;
1207 $$->expr_type = A1TC_EXTENSIBLE;
1208 $$->meta_type = AMT_TYPE;
1209 }
1210 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001211 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001212 checkmem($$);
1213 $$->Identifier = strdup("...");
1214 $$->value = $3;
1215 checkmem($$->Identifier);
1216 $$->expr_type = A1TC_EXTENSIBLE;
1217 $$->meta_type = AMT_TYPE;
1218 }
1219 ;
1220
Lev Walkin070a52d2004-08-22 03:19:54 +00001221Type:
Lev Walkinaf120f72004-09-14 02:36:39 +00001222 optTag TypeDeclaration optConstraints {
1223 $$ = $2;
1224 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001225 /*
1226 * Outer constraint for SEQUENCE OF and SET OF applies
1227 * to the inner type.
1228 */
1229 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1230 || $$->expr_type == ASN_CONSTR_SET_OF) {
1231 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001232 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001233 } else {
1234 if($$->constraints) {
1235 assert(!$2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001236 /* Check this : optConstraints is not used ?! */
1237 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001238 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001239 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001240 }
1241 }
Lev Walkinef625402005-09-05 05:17:57 +00001242 }
1243 ;
1244
1245NSTD_IndirectMarker:
1246 {
1247 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1248 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001249 }
1250 ;
1251
1252TypeDeclaration:
Lev Walkinef625402005-09-05 05:17:57 +00001253 NSTD_IndirectMarker TypeDeclarationSet {
Lev Walkin4696c742005-08-22 12:23:54 +00001254 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001255 $$->marker.flags |= $1;
1256
1257 if(($$->marker.flags & EM_INDIRECT)
1258 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1259 fprintf(stderr,
1260 "INFO: Directive <ASN1C:RepresentAsPointer> "
1261 "applied to %s at line %d\n",
1262 ASN_EXPR_TYPE2STR($$->expr_type)
1263 ? ASN_EXPR_TYPE2STR($$->expr_type)
1264 : "member",
1265 $$->_lineno
1266 );
1267 }
Lev Walkin4696c742005-08-22 12:23:54 +00001268 }
Lev Walkinef625402005-09-05 05:17:57 +00001269 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001270
1271TypeDeclarationSet:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001272 DefinedType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001273 $$ = $1;
1274 }
Lev Walkinef625402005-09-05 05:17:57 +00001275 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001276 $$ = $3;
1277 assert($$->expr_type == A1TC_INVALID);
1278 $$->expr_type = ASN_CONSTR_CHOICE;
1279 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001280 }
Lev Walkinef625402005-09-05 05:17:57 +00001281 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001282 $$ = $3;
1283 assert($$->expr_type == A1TC_INVALID);
1284 $$->expr_type = ASN_CONSTR_SEQUENCE;
1285 $$->meta_type = AMT_TYPE;
1286 }
Lev Walkinef625402005-09-05 05:17:57 +00001287 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001288 $$ = $3;
1289 assert($$->expr_type == A1TC_INVALID);
1290 $$->expr_type = ASN_CONSTR_SET;
1291 $$->meta_type = AMT_TYPE;
1292 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001293 | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001294 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001295 checkmem($$);
1296 $$->constraints = $2;
1297 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1298 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001299 $6->Identifier = $4;
1300 $6->tag = $5;
1301 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001302 }
Lev Walkin83cac2f2004-09-22 16:03:36 +00001303 | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001304 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001305 checkmem($$);
1306 $$->constraints = $2;
1307 $$->expr_type = ASN_CONSTR_SET_OF;
1308 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001309 $6->Identifier = $4;
1310 $6->tag = $5;
1311 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001312 }
1313 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001314 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001315 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001316 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001317 $$->meta_type = AMT_TYPE;
1318 }
1319 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1320 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001321 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001322 checkmem($$);
1323 $$->reference = asn1p_ref_new(yylineno);
1324 ret = asn1p_ref_add_component($$->reference,
1325 $4, RLT_lowercase);
1326 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001327 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001328 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001329 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001330 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001331 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001332 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001333 checkmem($$);
1334 $$->reference = $3;
1335 $$->expr_type = A1TC_INSTANCE;
1336 $$->meta_type = AMT_TYPE;
1337 }
1338 ;
1339
1340/*
1341 * A type name consisting of several components.
1342 * === EXAMPLE ===
1343 * === EOF ===
1344 */
1345ComplexTypeReference:
1346 TOK_typereference {
1347 int ret;
1348 $$ = asn1p_ref_new(yylineno);
1349 checkmem($$);
1350 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1351 checkmem(ret == 0);
1352 free($1);
1353 }
1354 | TOK_typereference '.' TypeRefName {
1355 int ret;
1356 $$ = asn1p_ref_new(yylineno);
1357 checkmem($$);
1358 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1359 checkmem(ret == 0);
1360 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1361 checkmem(ret == 0);
1362 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001363 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001364 }
Lev Walkin9c974182004-09-15 11:59:51 +00001365 | ObjectClassReference '.' TypeRefName {
1366 int ret;
1367 $$ = asn1p_ref_new(yylineno);
1368 checkmem($$);
1369 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1370 checkmem(ret == 0);
1371 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1372 checkmem(ret == 0);
1373 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001374 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001375 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001376 | TOK_typereference '.' Identifier {
1377 int ret;
1378 $$ = asn1p_ref_new(yylineno);
1379 checkmem($$);
1380 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1381 checkmem(ret == 0);
1382 ret = asn1p_ref_add_component($$, $3, RLT_lowercase);
1383 checkmem(ret == 0);
1384 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001385 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001386 }
1387 | ObjectClassReference {
1388 int ret;
1389 $$ = asn1p_ref_new(yylineno);
1390 checkmem($$);
1391 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1392 free($1);
1393 checkmem(ret == 0);
1394 }
1395 | ObjectClassReference '.' ComplexTypeReferenceAmpList {
1396 int ret;
1397 $$ = $3;
1398 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1399 free($1);
1400 checkmem(ret == 0);
1401 /*
1402 * Move the last element infront.
1403 */
1404 {
1405 struct asn1p_ref_component_s tmp_comp;
1406 tmp_comp = $$->components[$$->comp_count-1];
1407 memmove(&$$->components[1],
1408 &$$->components[0],
1409 sizeof($$->components[0])
1410 * ($$->comp_count - 1));
1411 $$->components[0] = tmp_comp;
1412 }
1413 }
1414 ;
1415
1416ComplexTypeReferenceAmpList:
1417 ComplexTypeReferenceElement {
1418 int ret;
1419 $$ = asn1p_ref_new(yylineno);
1420 checkmem($$);
1421 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1422 free($1.name);
1423 checkmem(ret == 0);
1424 }
1425 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1426 int ret;
1427 $$ = $1;
1428 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1429 free($3.name);
1430 checkmem(ret == 0);
1431 }
1432 ;
1433
Lev Walkind370e9f2006-03-16 10:03:35 +00001434ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001435
Lev Walkind370e9f2006-03-16 10:03:35 +00001436PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001437 /* "&Type1" */
1438 TOK_typefieldreference {
1439 $$.lex_type = RLT_AmpUppercase;
1440 $$.name = $1;
1441 }
1442 /* "&id" */
1443 | TOK_valuefieldreference {
1444 $$.lex_type = RLT_Amplowercase;
1445 $$.name = $1;
1446 }
1447 ;
1448
1449
Lev Walkin9c2285a2006-03-09 08:49:26 +00001450FieldName:
1451 /* "&Type1" */
1452 TOK_typefieldreference {
1453 $$ = asn1p_ref_new(yylineno);
1454 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001455 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001456 }
1457 | FieldName '.' TOK_typefieldreference {
1458 $$ = $$;
1459 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001460 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001461 }
1462 | FieldName '.' TOK_valuefieldreference {
1463 $$ = $$;
1464 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001465 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001466 }
1467 ;
1468
1469DefinedObjectClass:
1470 TOK_capitalreference {
1471 $$ = asn1p_ref_new(yylineno);
1472 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001473 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001474 }
Lev Walkin54868752006-03-09 09:08:49 +00001475/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001476 | TypeRefName '.' TOK_capitalreference {
1477 $$ = asn1p_ref_new(yylineno);
1478 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1479 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001480 free($1);
1481 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001482 }
Lev Walkin54868752006-03-09 09:08:49 +00001483*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001484 ;
1485
1486
Lev Walkinf15320b2004-06-03 03:38:44 +00001487/*
1488 * === EXAMPLE ===
1489 * value INTEGER ::= 1
1490 * === EOF ===
1491 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001492ValueAssignment:
1493 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001494 $$ = $2;
1495 assert($$->Identifier == NULL);
1496 $$->Identifier = $1;
1497 $$->meta_type = AMT_VALUE;
1498 $$->value = $4;
1499 }
1500 ;
1501
Lev Walkin9c974182004-09-15 11:59:51 +00001502Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001503 SimpleValue
1504 | DefinedValue
1505 | Identifier ':' Value {
Lev Walkin9c974182004-09-15 11:59:51 +00001506 $$ = asn1p_value_fromint(0);
1507 checkmem($$);
1508 $$->type = ATV_CHOICE_IDENTIFIER;
1509 $$->value.choice_identifier.identifier = $1;
1510 $$->value.choice_identifier.value = $3;
1511 }
Lev Walkincbad2512005-03-24 16:27:02 +00001512 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Lev Walkinf15320b2004-06-03 03:38:44 +00001513 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1514 checkmem($$);
1515 $$->type = ATV_UNPARSED;
1516 }
Lev Walkin9c974182004-09-15 11:59:51 +00001517 | TOK_NULL {
1518 $$ = asn1p_value_fromint(0);
1519 checkmem($$);
1520 $$->type = ATV_NULL;
1521 }
Lev Walkin0c0bca62006-03-21 04:48:15 +00001522 ;
1523
1524SimpleValue:
1525 TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001526 $$ = asn1p_value_fromint(0);
1527 checkmem($$);
1528 $$->type = ATV_FALSE;
1529 }
1530 | TOK_TRUE {
1531 $$ = asn1p_value_fromint(0);
1532 checkmem($$);
1533 $$->type = ATV_TRUE;
1534 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001535 | TOK_bstring {
1536 $$ = _convert_bitstring2binary($1, 'B');
1537 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001538 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001539 }
1540 | TOK_hstring {
1541 $$ = _convert_bitstring2binary($1, 'H');
1542 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001543 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001544 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001545 | RestrictedCharacterStringValue {
1546 $$ = $$;
Lev Walkinf15320b2004-06-03 03:38:44 +00001547 }
1548 | SignedNumber {
1549 $$ = $1;
1550 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001551 ;
1552
1553DefinedValue:
1554 Identifier {
1555 asn1p_ref_t *ref;
1556 int ret;
1557 ref = asn1p_ref_new(yylineno);
1558 checkmem(ref);
1559 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1560 checkmem(ret == 0);
1561 $$ = asn1p_value_fromref(ref, 0);
1562 checkmem($$);
1563 free($1);
1564 }
1565 | TypeRefName '.' Identifier {
1566 asn1p_ref_t *ref;
1567 int ret;
1568 ref = asn1p_ref_new(yylineno);
1569 checkmem(ref);
1570 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1571 checkmem(ret == 0);
1572 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1573 checkmem(ret == 0);
1574 $$ = asn1p_value_fromref(ref, 0);
1575 checkmem($$);
1576 free($1);
1577 free($3);
1578 }
1579 ;
1580
Lev Walkin1e448d32005-03-24 14:26:38 +00001581
1582RestrictedCharacterStringValue:
1583 TOK_cstring {
1584 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1585 checkmem($$);
1586 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001587 | TOK_tuple {
1588 $$ = asn1p_value_fromint($1);
1589 checkmem($$);
1590 $$->type = ATV_TUPLE;
1591 }
1592 | TOK_quadruple {
1593 $$ = asn1p_value_fromint($1);
1594 checkmem($$);
1595 $$->type = ATV_QUADRUPLE;
1596 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001597 ;
1598
Lev Walkinf15320b2004-06-03 03:38:44 +00001599Opaque:
1600 TOK_opaque {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001601 $$.len = $1.len + 1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001602 $$.buf = malloc($$.len + 1);
1603 checkmem($$.buf);
1604 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001605 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001606 $$.buf[$$.len] = '\0';
1607 free($1.buf);
1608 }
1609 | Opaque TOK_opaque {
1610 int newsize = $1.len + $2.len;
1611 char *p = malloc(newsize + 1);
1612 checkmem(p);
1613 memcpy(p , $1.buf, $1.len);
1614 memcpy(p + $1.len, $2.buf, $2.len);
1615 p[newsize] = '\0';
1616 free($1.buf);
1617 free($2.buf);
1618 $$.buf = p;
1619 $$.len = newsize;
1620 }
1621 ;
1622
1623BasicTypeId:
1624 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1625 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1626 | TOK_REAL { $$ = ASN_BASIC_REAL; }
1627 | BasicTypeId_UniverationCompatible { $$ = $1; }
1628 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1629 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1630 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1631 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1632 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1633 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1634 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1635 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinc7d939d2005-03-20 11:12:40 +00001636 | BasicString { $$ = $1; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001637 ;
1638
1639/*
1640 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1641 */
1642BasicTypeId_UniverationCompatible:
1643 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
1644 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
1645 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1646 ;
1647
1648BasicType:
1649 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001650 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001651 checkmem($$);
1652 $$->expr_type = $1;
1653 $$->meta_type = AMT_TYPE;
1654 }
1655 | BasicTypeId_UniverationCompatible UniverationDefinition {
1656 if($2) {
1657 $$ = $2;
1658 } else {
Lev Walkina9532f42006-09-17 04:52:50 +00001659 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001660 checkmem($$);
1661 }
1662 $$->expr_type = $1;
1663 $$->meta_type = AMT_TYPE;
1664 }
1665 ;
1666
1667BasicString:
1668 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1669 | TOK_GeneralString {
1670 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001671 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001672 }
1673 | TOK_GraphicString {
1674 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001675 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001676 }
1677 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1678 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1679 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1680 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1681 | TOK_T61String {
1682 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001683 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001684 }
1685 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1686 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1687 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1688 | TOK_VideotexString {
1689 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001690 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001691 }
1692 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1693 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1694 ;
1695
Lev Walkind2ea1de2004-08-20 13:25:29 +00001696
Lev Walkinf15320b2004-06-03 03:38:44 +00001697/*
1698 * Data type constraints.
1699 */
Lev Walkinf1727152006-09-21 01:50:37 +00001700UnionMark: '|' | TOK_UNION;
1701IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001702
Lev Walkinf59d0752004-08-18 04:59:12 +00001703optConstraints:
1704 { $$ = 0; }
Lev Walkina9532f42006-09-17 04:52:50 +00001705 | Constraint {
Lev Walkind2ea1de2004-08-20 13:25:29 +00001706 $$ = $1;
1707 }
1708 ;
1709
Lev Walkina9532f42006-09-17 04:52:50 +00001710Constraint:
1711 SubtypeConstraint
Lev Walkina9532f42006-09-17 04:52:50 +00001712 ;
1713
1714SubtypeConstraint:
Lev Walkind2ea1de2004-08-20 13:25:29 +00001715 SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001716 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
Lev Walkinf59d0752004-08-18 04:59:12 +00001717 }
1718 | TOK_SIZE '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001719 /*
1720 * This is a special case, for compatibility purposes.
Lev Walkinf59d0752004-08-18 04:59:12 +00001721 * It goes without parentheses.
Lev Walkinf15320b2004-06-03 03:38:44 +00001722 */
Lev Walkin2c14a692005-08-12 10:08:45 +00001723 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001724 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001725 ;
1726
Lev Walkinf59d0752004-08-18 04:59:12 +00001727SetOfConstraints:
1728 '(' ElementSetSpecs ')' {
Lev Walkinf15320b2004-06-03 03:38:44 +00001729 $$ = $2;
1730 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001731 | SetOfConstraints '(' ElementSetSpecs ')' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001732 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
Lev Walkinf59d0752004-08-18 04:59:12 +00001733 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001734 ;
1735
Lev Walkinf59d0752004-08-18 04:59:12 +00001736ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001737 TOK_ThreeDots {
1738 $$ = asn1p_constraint_new(yylineno);
1739 $$->type = ACT_EL_EXT;
1740 }
1741 | ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001742 $$ = $1;
1743 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001744 | ElementSetSpec ',' TOK_ThreeDots {
Lev Walkinf15320b2004-06-03 03:38:44 +00001745 asn1p_constraint_t *ct;
1746 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001747 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001748 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00001749 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001750 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
Lev Walkinf15320b2004-06-03 03:38:44 +00001751 asn1p_constraint_t *ct;
1752 ct = asn1p_constraint_new(yylineno);
Lev Walkinf15320b2004-06-03 03:38:44 +00001753 ct->type = ACT_EL_EXT;
Lev Walkin2c14a692005-08-12 10:08:45 +00001754 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinb4fcdd22004-08-13 12:35:09 +00001755 ct = $$;
Lev Walkin2c14a692005-08-12 10:08:45 +00001756 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
Lev Walkinf15320b2004-06-03 03:38:44 +00001757 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001758 | GeneralConstraint {
1759 $$ = $1;
1760 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001761 ;
1762
Lev Walkinf59d0752004-08-18 04:59:12 +00001763ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001764 Unions
Lev Walkin1e448d32005-03-24 14:26:38 +00001765 | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001766 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001767 }
Lev Walkinf1727152006-09-21 01:50:37 +00001768 ;
1769
1770Unions:
1771 Intersections
1772 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001773 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001774 }
Lev Walkinf1727152006-09-21 01:50:37 +00001775 ;
1776
1777Intersections:
1778 IntersectionElements
1779 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001780 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001781 }
Lev Walkinf1727152006-09-21 01:50:37 +00001782 ;
1783
1784
1785IntersectionElements:
1786 ConstraintSubtypeElement
1787 | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001788 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001789 }
1790 ;
1791
1792ConstraintSubtypeElement:
Lev Walkinf59d0752004-08-18 04:59:12 +00001793 ConstraintSpec '(' ElementSetSpecs ')' {
1794 int ret;
1795 $$ = asn1p_constraint_new(yylineno);
1796 checkmem($$);
1797 $$->type = $1;
1798 ret = asn1p_constraint_insert($$, $3);
1799 checkmem(ret == 0);
1800 }
1801 | '(' ElementSetSpecs ')' {
1802 int ret;
1803 $$ = asn1p_constraint_new(yylineno);
1804 checkmem($$);
1805 $$->type = ACT_CA_SET;
1806 ret = asn1p_constraint_insert($$, $2);
1807 checkmem(ret == 0);
1808 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001809 | SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001810 $$ = asn1p_constraint_new(yylineno);
1811 checkmem($$);
1812 $$->type = ACT_EL_VALUE;
1813 $$->value = $1;
1814 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001815 | ContainedSubtype {
1816 $$ = asn1p_constraint_new(yylineno);
1817 checkmem($$);
1818 $$->type = ACT_EL_TYPE;
1819 $$->containedSubtype = $1;
1820 }
1821 | SingleValue ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001822 $$ = asn1p_constraint_new(yylineno);
1823 checkmem($$);
1824 $$->type = $2;
1825 $$->range_start = $1;
1826 $$->range_stop = $3;
1827 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001828 | TOK_MIN ConstraintRangeSpec SingleValue {
Lev Walkinf15320b2004-06-03 03:38:44 +00001829 $$ = asn1p_constraint_new(yylineno);
1830 checkmem($$);
Lev Walkinf59d0752004-08-18 04:59:12 +00001831 $$->type = $2;
1832 $$->range_start = asn1p_value_fromint(-123);
1833 $$->range_stop = $3;
1834 $$->range_start->type = ATV_MIN;
1835 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001836 | SingleValue ConstraintRangeSpec TOK_MAX {
Lev Walkinf59d0752004-08-18 04:59:12 +00001837 $$ = asn1p_constraint_new(yylineno);
1838 checkmem($$);
1839 $$->type = $2;
1840 $$->range_start = $1;
1841 $$->range_stop = asn1p_value_fromint(321);
1842 $$->range_stop->type = ATV_MAX;
1843 }
1844 | TOK_MIN ConstraintRangeSpec TOK_MAX {
1845 $$ = asn1p_constraint_new(yylineno);
1846 checkmem($$);
1847 $$->type = $2;
1848 $$->range_start = asn1p_value_fromint(-123);
1849 $$->range_stop = asn1p_value_fromint(321);
1850 $$->range_start->type = ATV_MIN;
1851 $$->range_stop->type = ATV_MAX;
Lev Walkinf15320b2004-06-03 03:38:44 +00001852 }
Lev Walkine596bf02005-03-28 15:01:27 +00001853 | InnerTypeConstraint {
Lev Walkinf15320b2004-06-03 03:38:44 +00001854 $$ = $1;
1855 }
Lev Walkin5c541f12006-10-18 18:40:14 +00001856 | PatternConstraint {
1857 $$ = $1;
1858 }
1859 ;
1860
1861PatternConstraint:
1862 TOK_PATTERN TOK_cstring {
1863 $$ = asn1p_constraint_new(yylineno);
1864 $$->type = ACT_CT_PATTERN;
1865 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1866 }
1867 | TOK_PATTERN Identifier {
1868 asn1p_ref_t *ref;
1869 $$ = asn1p_constraint_new(yylineno);
1870 $$->type = ACT_CT_PATTERN;
1871 ref = asn1p_ref_new(yylineno);
1872 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1873 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001874 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001875 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001876 ;
1877
1878ConstraintSpec:
1879 TOK_SIZE {
1880 $$ = ACT_CT_SIZE;
1881 }
1882 | TOK_FROM {
1883 $$ = ACT_CT_FROM;
1884 }
1885 ;
1886
Lev Walkinff7dd142005-03-20 12:58:00 +00001887SingleValue:
Lev Walkinc8092cb2005-02-18 16:34:21 +00001888 TOK_FALSE {
1889 $$ = asn1p_value_fromint(0);
1890 checkmem($$);
1891 $$->type = ATV_FALSE;
1892 }
1893 | TOK_TRUE {
1894 $$ = asn1p_value_fromint(1);
1895 checkmem($$);
1896 $$->type = ATV_TRUE;
1897 }
Lev Walkinadf863f2006-09-05 16:18:34 +00001898 | RealValue
1899 | RestrictedCharacterStringValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001900 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001901 | Identifier {
1902 asn1p_ref_t *ref;
1903 int ret;
1904 ref = asn1p_ref_new(yylineno);
1905 checkmem(ref);
1906 ret = asn1p_ref_add_component(ref, $1, RLT_lowercase);
1907 checkmem(ret == 0);
1908 $$ = asn1p_value_fromref(ref, 0);
1909 checkmem($$);
1910 free($1);
1911 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001912 ;
1913
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001914BitStringValue:
1915 TOK_bstring {
1916 $$ = _convert_bitstring2binary($1, 'B');
1917 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001918 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001919 }
1920 | TOK_hstring {
1921 $$ = _convert_bitstring2binary($1, 'H');
1922 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001923 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001924 }
1925 ;
1926
Lev Walkinff7dd142005-03-20 12:58:00 +00001927ContainedSubtype:
1928 TypeRefName {
Lev Walkinc8092cb2005-02-18 16:34:21 +00001929 asn1p_ref_t *ref;
1930 int ret;
1931 ref = asn1p_ref_new(yylineno);
1932 checkmem(ref);
1933 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1934 checkmem(ret == 0);
1935 $$ = asn1p_value_fromref(ref, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001936 checkmem($$);
Lev Walkinc8092cb2005-02-18 16:34:21 +00001937 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001938 }
1939 ;
1940
Lev Walkine596bf02005-03-28 15:01:27 +00001941InnerTypeConstraint:
1942 TOK_WITH TOK_COMPONENT SetOfConstraints {
Lev Walkin2c14a692005-08-12 10:08:45 +00001943 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00001944 }
1945 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00001946 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +00001947 }
1948 ;
1949
1950WithComponentsList:
1951 WithComponentsElement {
1952 $$ = $1;
1953 }
1954 | WithComponentsList ',' WithComponentsElement {
Lev Walkin2c14a692005-08-12 10:08:45 +00001955 CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001956 }
1957 ;
1958
1959WithComponentsElement:
1960 TOK_ThreeDots {
1961 $$ = asn1p_constraint_new(yylineno);
1962 checkmem($$);
1963 $$->type = ACT_EL_EXT;
Lev Walkin418298d2006-07-13 08:24:20 +00001964 $$->value = asn1p_value_frombuf("...", 3, 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001965 }
1966 | Identifier optConstraints optPresenceConstraint {
1967 $$ = asn1p_constraint_new(yylineno);
1968 checkmem($$);
1969 $$->type = ACT_EL_VALUE;
1970 $$->value = asn1p_value_frombuf($1, strlen($1), 0);
1971 $$->presence = $3;
Lev Walkine596bf02005-03-28 15:01:27 +00001972 if($2) asn1p_constraint_insert($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001973 }
1974 ;
1975
1976/*
1977 * presence constraint for WithComponents
1978 */
1979optPresenceConstraint:
1980 { $$ = ACPRES_DEFAULT; }
1981 | PresenceConstraint { $$ = $1; }
1982 ;
1983
1984PresenceConstraint:
1985 TOK_PRESENT {
1986 $$ = ACPRES_PRESENT;
1987 }
1988 | TOK_ABSENT {
1989 $$ = ACPRES_ABSENT;
1990 }
1991 | TOK_OPTIONAL {
1992 $$ = ACPRES_OPTIONAL;
1993 }
1994 ;
1995
Lev Walkina9532f42006-09-17 04:52:50 +00001996
1997/* X.682 */
1998GeneralConstraint:
1999 UserDefinedConstraint
2000 | TableConstraint
2001 | ContentsConstraint
2002 ;
2003
2004UserDefinedConstraint:
2005 TOK_CONSTRAINED TOK_BY '{'
2006 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
2007 $$ = asn1p_constraint_new(yylineno);
2008 checkmem($$);
2009 $$->type = ACT_CT_CTDBY;
2010 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2011 checkmem($$->value);
2012 $$->value->type = ATV_UNPARSED;
2013 }
2014 ;
2015
2016ContentsConstraint:
2017 TOK_CONTAINING Type {
2018 $$ = asn1p_constraint_new(yylineno);
2019 $$->type = ACT_CT_CTNG;
2020 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002021 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002022 }
2023 ;
2024
2025ConstraintRangeSpec:
2026 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2027 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2028 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2029 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2030 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002031TableConstraint:
2032 SimpleTableConstraint {
2033 $$ = $1;
2034 }
2035 | ComponentRelationConstraint {
2036 $$ = $1;
2037 }
2038 ;
2039
2040/*
2041 * "{ExtensionSet}"
2042 */
2043SimpleTableConstraint:
2044 '{' TypeRefName '}' {
2045 asn1p_ref_t *ref = asn1p_ref_new(yylineno);
2046 asn1p_constraint_t *ct;
2047 int ret;
2048 ret = asn1p_ref_add_component(ref, $2, 0);
2049 checkmem(ret == 0);
2050 ct = asn1p_constraint_new(yylineno);
2051 checkmem($$);
2052 ct->type = ACT_EL_VALUE;
2053 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002054 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002055 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002056 }
2057 ;
2058
2059ComponentRelationConstraint:
2060 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002061 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002062 }
2063 ;
2064
2065AtNotationList:
2066 AtNotationElement {
2067 $$ = asn1p_constraint_new(yylineno);
2068 checkmem($$);
2069 $$->type = ACT_EL_VALUE;
2070 $$->value = asn1p_value_fromref($1, 0);
2071 }
2072 | AtNotationList ',' AtNotationElement {
2073 asn1p_constraint_t *ct;
2074 ct = asn1p_constraint_new(yylineno);
2075 checkmem(ct);
2076 ct->type = ACT_EL_VALUE;
2077 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002078 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002079 }
2080 ;
2081
2082/*
2083 * @blah
2084 */
2085AtNotationElement:
2086 '@' ComponentIdList {
2087 char *p = malloc(strlen($2) + 2);
2088 int ret;
2089 *p = '@';
2090 strcpy(p + 1, $2);
2091 $$ = asn1p_ref_new(yylineno);
2092 ret = asn1p_ref_add_component($$, p, 0);
2093 checkmem(ret == 0);
2094 free(p);
2095 free($2);
2096 }
2097 | '@' '.' ComponentIdList {
2098 char *p = malloc(strlen($3) + 3);
2099 int ret;
2100 p[0] = '@';
2101 p[1] = '.';
2102 strcpy(p + 2, $3);
2103 $$ = asn1p_ref_new(yylineno);
2104 ret = asn1p_ref_add_component($$, p, 0);
2105 checkmem(ret == 0);
2106 free(p);
2107 free($3);
2108 }
2109 ;
2110
2111/* identifier "." ... */
2112ComponentIdList:
2113 Identifier {
2114 $$ = $1;
2115 }
2116 | ComponentIdList '.' Identifier {
2117 int l1 = strlen($1);
2118 int l3 = strlen($3);
2119 $$ = malloc(l1 + 1 + l3 + 1);
2120 memcpy($$, $1, l1);
2121 $$[l1] = '.';
2122 memcpy($$ + l1 + 1, $3, l3);
2123 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002124 free($1);
2125 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002126 }
2127 ;
2128
2129
2130
2131/*
2132 * MARKERS
2133 */
2134
2135optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002136 {
2137 $$.flags = EM_NOMARK;
2138 $$.default_value = 0;
2139 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002140 | Marker { $$ = $1; }
2141 ;
2142
2143Marker:
2144 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002145 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002146 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002147 }
Lev Walkin9c974182004-09-15 11:59:51 +00002148 | TOK_DEFAULT Value {
2149 $$.flags = EM_DEFAULT;
2150 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002151 }
2152 ;
2153
2154/*
2155 * Universal enumeration definition to use in INTEGER and ENUMERATED.
2156 * === EXAMPLE ===
2157 * Gender ::= ENUMERATED { unknown(0), male(1), female(2) }
2158 * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) }
2159 * === EOF ===
2160 */
2161/*
2162optUniverationDefinition:
2163 { $$ = 0; }
2164 | UniverationDefinition {
2165 $$ = $1;
2166 }
2167 ;
2168*/
2169
2170UniverationDefinition:
2171 '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00002172 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002173 checkmem($$);
2174 }
2175 | '{' UniverationList '}' {
2176 $$ = $2;
2177 }
2178 ;
2179
2180UniverationList:
2181 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002182 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002183 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002184 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002185 }
2186 | UniverationList ',' UniverationElement {
2187 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002188 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002189 }
2190 ;
2191
2192UniverationElement:
2193 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002194 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002195 checkmem($$);
2196 $$->expr_type = A1TC_UNIVERVAL;
2197 $$->meta_type = AMT_VALUE;
2198 $$->Identifier = $1;
2199 }
2200 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002201 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002202 checkmem($$);
2203 $$->expr_type = A1TC_UNIVERVAL;
2204 $$->meta_type = AMT_VALUE;
2205 $$->Identifier = $1;
2206 $$->value = $3;
2207 }
2208 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002209 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002210 checkmem($$);
2211 $$->expr_type = A1TC_UNIVERVAL;
2212 $$->meta_type = AMT_VALUE;
2213 $$->Identifier = $1;
2214 $$->value = $3;
2215 }
2216 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002217 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002218 checkmem($$);
2219 $$->expr_type = A1TC_UNIVERVAL;
2220 $$->meta_type = AMT_VALUE;
2221 $$->value = $1;
2222 }
2223 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002224 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002225 checkmem($$);
2226 $$->Identifier = strdup("...");
2227 checkmem($$->Identifier);
2228 $$->expr_type = A1TC_EXTENSIBLE;
2229 $$->meta_type = AMT_VALUE;
2230 }
2231 ;
2232
2233SignedNumber:
2234 TOK_number {
2235 $$ = asn1p_value_fromint($1);
2236 checkmem($$);
2237 }
2238 | TOK_number_negative {
2239 $$ = asn1p_value_fromint($1);
2240 checkmem($$);
2241 }
2242 ;
2243
Lev Walkinadf863f2006-09-05 16:18:34 +00002244RealValue:
2245 SignedNumber
2246 | TOK_realnumber {
2247 $$ = asn1p_value_fromdouble($1);
2248 checkmem($$);
2249 }
2250 ;
2251
Lev Walkinf15320b2004-06-03 03:38:44 +00002252/*
2253 * SEQUENCE definition.
2254 * === EXAMPLE ===
2255 * Struct1 ::= SEQUENCE {
2256 * memb1 Struct2,
2257 * memb2 SEQUENCE OF {
2258 * memb2-1 Struct 3
2259 * }
2260 * }
2261 * === EOF ===
2262 */
2263
2264
2265
2266/*
2267 * SET definition.
2268 * === EXAMPLE ===
2269 * Person ::= SET {
2270 * name [0] PrintableString (SIZE(1..20)),
2271 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2272 * }
2273 * === EOF ===
2274 */
2275
2276optTag:
2277 { memset(&$$, 0, sizeof($$)); }
2278 | Tag { $$ = $1; }
2279 ;
2280
2281Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002282 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002283 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002284 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002285 }
Lev Walkinc603f102005-01-23 09:51:44 +00002286 ;
2287
2288TagTypeValue:
2289 '[' TagClass TOK_number ']' {
2290 $$ = $2;
2291 $$.tag_value = $3;
2292 };
2293
2294TagClass:
2295 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2296 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2297 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2298 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2299 ;
2300
2301TagPlicit:
2302 { $$.tag_mode = TM_DEFAULT; }
2303 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2304 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002305 ;
2306
2307TypeRefName:
2308 TOK_typereference {
2309 checkmem($1);
2310 $$ = $1;
2311 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002312 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002313 checkmem($1);
2314 $$ = $1;
2315 }
2316 ;
2317
Lev Walkinf59d0752004-08-18 04:59:12 +00002318
Lev Walkinf15320b2004-06-03 03:38:44 +00002319ObjectClassReference:
Lev Walkinf59d0752004-08-18 04:59:12 +00002320 TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002321 checkmem($1);
2322 $$ = $1;
2323 }
2324 ;
2325
Lev Walkin83cac2f2004-09-22 16:03:36 +00002326optIdentifier:
2327 { $$ = 0; }
2328 | Identifier {
2329 $$ = $1;
2330 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002331 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002332
Lev Walkinf15320b2004-06-03 03:38:44 +00002333Identifier:
2334 TOK_identifier {
2335 checkmem($1);
2336 $$ = $1;
2337 }
2338 ;
2339
Lev Walkinf15320b2004-06-03 03:38:44 +00002340%%
2341
2342
2343/*
2344 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2345 */
2346static asn1p_value_t *
2347_convert_bitstring2binary(char *str, int base) {
2348 asn1p_value_t *val;
2349 int slen;
2350 int memlen;
2351 int baselen;
2352 int bits;
2353 uint8_t *binary_vector;
2354 uint8_t *bv_ptr;
2355 uint8_t cur_val;
2356
2357 assert(str);
2358 assert(str[0] == '\'');
2359
2360 switch(base) {
2361 case 'B':
2362 baselen = 1;
2363 break;
2364 case 'H':
2365 baselen = 4;
2366 break;
2367 default:
2368 assert(base == 'B' || base == 'H');
2369 errno = EINVAL;
2370 return NULL;
2371 }
2372
2373 slen = strlen(str);
2374 assert(str[slen - 1] == base);
2375 assert(str[slen - 2] == '\'');
2376
2377 memlen = slen / (8 / baselen); /* Conservative estimate */
2378
2379 bv_ptr = binary_vector = malloc(memlen + 1);
2380 if(bv_ptr == NULL)
2381 /* ENOMEM */
2382 return NULL;
2383
2384 cur_val = 0;
2385 bits = 0;
2386 while(*(++str) != '\'') {
2387 switch(baselen) {
2388 case 1:
2389 switch(*str) {
2390 case '1':
2391 cur_val |= 1 << (7 - (bits % 8));
2392 case '0':
2393 break;
2394 default:
2395 assert(!"_y UNREACH1");
2396 case ' ': case '\r': case '\n':
2397 continue;
2398 }
2399 break;
2400 case 4:
2401 switch(*str) {
2402 case '0': case '1': case '2': case '3': case '4':
2403 case '5': case '6': case '7': case '8': case '9':
2404 cur_val |= (*str - '0') << (4 - (bits % 8));
2405 break;
2406 case 'A': case 'B': case 'C':
2407 case 'D': case 'E': case 'F':
2408 cur_val |= ((*str - 'A') + 10)
2409 << (4 - (bits % 8));
2410 break;
2411 default:
2412 assert(!"_y UNREACH2");
2413 case ' ': case '\r': case '\n':
2414 continue;
2415 }
2416 break;
2417 }
2418
2419 bits += baselen;
2420 if((bits % 8) == 0) {
2421 *bv_ptr++ = cur_val;
2422 cur_val = 0;
2423 }
2424 }
2425
2426 *bv_ptr = cur_val;
2427 assert((bv_ptr - binary_vector) <= memlen);
2428
2429 val = asn1p_value_frombits(binary_vector, bits, 0);
2430 if(val == NULL) {
2431 free(binary_vector);
2432 }
2433
2434 return val;
2435}
2436
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002437/*
2438 * For unnamed types (used in old X.208 compliant modules)
2439 * generate some sort of interim names, to not to force human being to fix
2440 * the specification's compliance to modern ASN.1 standards.
2441 */
2442static void
2443_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2444 char *p;
2445 assert(expr->Identifier == 0);
2446
2447 /*
2448 * Try to figure out the type name
2449 * without going too much into details
2450 */
2451 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2452 if(expr->reference && expr->reference->comp_count > 0)
2453 expr->Identifier = expr->reference->components[0].name;
2454
2455 fprintf(stderr,
2456 "WARNING: Line %d: expected lower-case member identifier, "
2457 "found an unnamed %s.\n"
2458 "WARNING: Obsolete X.208 syntax detected, "
2459 "please give the member a name.\n",
2460 yylineno, expr->Identifier ? expr->Identifier : "type");
2461
2462 if(!expr->Identifier)
2463 expr->Identifier = "unnamed";
2464 expr->Identifier = strdup(expr->Identifier);
2465 assert(expr->Identifier);
2466 /* Make a lowercase identifier from the type name */
2467 for(p = expr->Identifier; *p; p++) {
2468 switch(*p) {
2469 case 'A' ... 'Z': *p += 32; break;
2470 case ' ': *p = '_'; break;
2471 case '-': *p = '_'; break;
2472 }
2473 }
2474 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2475 "Name clash may occur later.\n",
2476 expr->Identifier);
2477}
2478
Lev Walkinf15320b2004-06-03 03:38:44 +00002479int
2480yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002481 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002482 fprintf(stderr,
2483 "ASN.1 grammar parse error "
2484 "near line %d (token \"%s\"): %s\n",
Lev Walkinceb20e72004-09-05 10:40:41 +00002485 yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002486 return -1;
2487}
2488