blob: 0b1c9e40751fab76dfad5a45475fadd5be951e0f [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001%{
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <string.h>
Lev Walkin0c686452017-09-07 22:59:36 -07006#include <stdarg.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00007#include <errno.h>
8#include <assert.h>
9
10#include "asn1parser.h"
11
12#define YYPARSE_PARAM param
Lev Walkin4354b442005-06-07 21:25:42 +000013#define YYPARSE_PARAM_TYPE void **
Lev Walkinf15320b2004-06-03 03:38:44 +000014#define YYERROR_VERBOSE
Lev Walkin0c686452017-09-07 22:59:36 -070015#define YYDEBUG 1
16#define YYFPRINTF prefixed_fprintf
17
18/*
19 * Prefix parser debug with "PARSER: " for easier human eye scanning.
20 */
21static int
22__attribute__((format(printf, 2, 3)))
23prefixed_fprintf(FILE *f, const char *fmt, ...) {
24 static int line_ended = 1;
25 va_list ap;
26 va_start(ap, fmt);
27 if(line_ended) {
28 fprintf(f, "PARSER: ");
29 line_ended = 0;
30 }
31 size_t len = strlen(fmt);
32 if(len && fmt[len-1] == '\n') {
33 line_ended = 1;
34 }
35 int ret = vfprintf(f, fmt, ap);
36 va_end(ap);
37 return ret;
38}
Lev Walkinf15320b2004-06-03 03:38:44 +000039
40int yylex(void);
Lev Walkin59165cf2017-09-11 06:24:45 -070041static int yyerror(const char *msg);
42
Lev Walkin8daab912005-06-07 21:32:16 +000043#ifdef YYBYACC
44int yyparse(void **param); /* byacc does not produce a prototype */
45#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000046void asn1p_lexer_hack_push_opaque_state(void);
47void asn1p_lexer_hack_enable_with_syntax(void);
Lev Walkinf59d0752004-08-18 04:59:12 +000048void asn1p_lexer_hack_push_encoding_control(void);
Lev Walkinf15320b2004-06-03 03:38:44 +000049#define yylineno asn1p_lineno
50extern int asn1p_lineno;
Lev Walkind523ea42017-09-06 22:15:08 -070051const char *asn1p_parse_debug_filename;
52#define ASN_FILENAME asn1p_parse_debug_filename
Lev Walkinf15320b2004-06-03 03:38:44 +000053
Lev Walkin1ed22092005-08-12 10:06:17 +000054/*
Lev Walkinef625402005-09-05 05:17:57 +000055 * Process directives as <ASN1C:RepresentAsPointer>
Lev Walkin4696c742005-08-22 12:23:54 +000056 */
57extern int asn1p_as_pointer;
Lev Walkin4696c742005-08-22 12:23:54 +000058
59/*
Lev Walkin1ed22092005-08-12 10:06:17 +000060 * This temporary variable is used to solve the shortcomings of 1-lookahead
61 * parser.
62 */
63static struct AssignedIdentifier *saved_aid;
Lev Walkinf15320b2004-06-03 03:38:44 +000064
Lev Walkin2e9bd5c2005-08-13 09:07:11 +000065static asn1p_value_t *_convert_bitstring2binary(char *str, int base);
66static void _fixup_anonymous_identifier(asn1p_expr_t *expr);
Lev Walkinf15320b2004-06-03 03:38:44 +000067
Lev Walkina9532f42006-09-17 04:52:50 +000068static asn1p_module_t *currentModule;
69#define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule))
70
Lev Walkin1ed22092005-08-12 10:06:17 +000071#define checkmem(ptr) do { \
72 if(!(ptr)) \
73 return yyerror("Memory failure"); \
Lev Walkinf15320b2004-06-03 03:38:44 +000074 } while(0)
75
Lev Walkin2c14a692005-08-12 10:08:45 +000076#define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \
Lev Walkin1ed22092005-08-12 10:06:17 +000077 if(arg1->type != constr_type) { \
78 int __ret; \
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +080079 root = asn1p_constraint_new(yylineno, currentModule); \
Lev Walkin1ed22092005-08-12 10:06:17 +000080 checkmem(root); \
81 root->type = constr_type; \
82 __ret = asn1p_constraint_insert(root, \
83 arg1); \
84 checkmem(__ret == 0); \
85 } else { \
86 root = arg1; \
87 } \
88 if(arg2) { \
89 int __ret \
90 = asn1p_constraint_insert(root, arg2); \
91 checkmem(__ret == 0); \
92 } \
Lev Walkinf15320b2004-06-03 03:38:44 +000093 } while(0)
94
Lev Walkin866bd7f2006-09-14 10:35:20 +000095#ifdef AL_IMPORT
96#error AL_IMPORT DEFINED ELSEWHERE!
97#endif
Lev Walkin1a49ced2017-11-06 00:07:00 -080098#define AL_IMPORT(to, where, from, field) \
99 do { \
100 if(!(from)) break; \
101 while(TQ_FIRST(&((from)->where))) { \
102 TQ_ADD(&((to)->where), TQ_REMOVE(&((from)->where), field), field); \
103 } \
104 assert(TQ_FIRST(&((from)->where)) == 0); \
105 } while(0)
Lev Walkin866bd7f2006-09-14 10:35:20 +0000106
Lev Walkinf15320b2004-06-03 03:38:44 +0000107%}
108
109
110/*
111 * Token value definition.
112 * a_*: ASN-specific types.
113 * tv_*: Locally meaningful types.
114 */
115%union {
116 asn1p_t *a_grammar;
117 asn1p_module_flags_e a_module_flags;
118 asn1p_module_t *a_module;
119 asn1p_expr_type_e a_type; /* ASN.1 Type */
120 asn1p_expr_t *a_expr; /* Constructed collection */
121 asn1p_constraint_t *a_constr; /* Constraint */
122 enum asn1p_constraint_type_e a_ctype;/* Constraint type */
123 asn1p_xports_t *a_xports; /* IMports/EXports */
Lev Walkin1ed22092005-08-12 10:06:17 +0000124 struct AssignedIdentifier a_aid; /* Assigned Identifier */
Lev Walkinf15320b2004-06-03 03:38:44 +0000125 asn1p_oid_t *a_oid; /* Object Identifier */
126 asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */
127 struct asn1p_type_tag_s a_tag; /* A tag */
128 asn1p_ref_t *a_ref; /* Reference to custom type */
129 asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */
130 asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */
131 struct asn1p_ref_component_s a_refcomp; /* Component of a reference */
132 asn1p_value_t *a_value; /* Number, DefinedValue, etc */
133 struct asn1p_param_s a_parg; /* A parameter argument */
134 asn1p_paramlist_t *a_plist; /* A pargs list */
Lev Walkin9c974182004-09-15 11:59:51 +0000135 struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
Lev Walkinf15320b2004-06-03 03:38:44 +0000136 enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
Lev Walkin144db9b2004-10-12 23:26:53 +0000137 asn1c_integer_t a_int;
Lev Walkinadf863f2006-09-05 16:18:34 +0000138 double a_dbl;
Lev Walkinf15320b2004-06-03 03:38:44 +0000139 char *tv_str;
140 struct {
141 char *buf;
142 int len;
143 } tv_opaque;
144 struct {
145 char *name;
146 struct asn1p_type_tag_s tag;
147 } tv_nametag;
148};
149
150/*
151 * Token types returned by scanner.
152 */
153%token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */
Lev Walkin0e90aa02013-03-19 16:17:13 -0700154%token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */
Lev Walkin57074f12006-03-16 05:11:14 +0000155%token <tv_opaque> TOK_whitespace /* A span of whitespace */
Lev Walkinf15320b2004-06-03 03:38:44 +0000156%token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */
157%token <tv_str> TOK_bstring
158%token <tv_opaque> TOK_cstring
159%token <tv_str> TOK_hstring
Lev Walkinbe518fa2017-09-07 02:05:28 -0700160%token <tv_str> TOK_identifier "identifier"
161%token <a_int> TOK_number "number"
162%token <a_int> TOK_number_negative "negative number"
Lev Walkinadf863f2006-09-05 16:18:34 +0000163%token <a_dbl> TOK_realnumber
Lev Walkind9574ae2005-03-24 16:22:35 +0000164%token <a_int> TOK_tuple
165%token <a_int> TOK_quadruple
Lev Walkinf15320b2004-06-03 03:38:44 +0000166%token <tv_str> TOK_typereference
Lev Walkinf59d0752004-08-18 04:59:12 +0000167%token <tv_str> TOK_capitalreference /* "CLASS1" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000168%token <tv_str> TOK_typefieldreference /* "&Pork" */
169%token <tv_str> TOK_valuefieldreference /* "&id" */
Lev Walkin9d542d22006-03-14 16:31:37 +0000170%token <tv_str> TOK_Literal /* "BY" */
Lev Walkinf15320b2004-06-03 03:38:44 +0000171
172/*
Lev Walkinbe518fa2017-09-07 02:05:28 -0700173 * Tokens available with asn1p_lexer_hack_push_extended_values().
174 */
175%token TOK_ExtValue_BIT_STRING
176
177/*
Lev Walkinf15320b2004-06-03 03:38:44 +0000178 * Token types representing ASN.1 standard keywords.
179 */
180%token TOK_ABSENT
181%token TOK_ABSTRACT_SYNTAX
182%token TOK_ALL
183%token TOK_ANY
184%token TOK_APPLICATION
185%token TOK_AUTOMATIC
186%token TOK_BEGIN
187%token TOK_BIT
188%token TOK_BMPString
189%token TOK_BOOLEAN
190%token TOK_BY
191%token TOK_CHARACTER
192%token TOK_CHOICE
193%token TOK_CLASS
194%token TOK_COMPONENT
195%token TOK_COMPONENTS
196%token TOK_CONSTRAINED
197%token TOK_CONTAINING
198%token TOK_DEFAULT
199%token TOK_DEFINITIONS
200%token TOK_DEFINED
201%token TOK_EMBEDDED
202%token TOK_ENCODED
Lev Walkinf59d0752004-08-18 04:59:12 +0000203%token TOK_ENCODING_CONTROL
Lev Walkinf15320b2004-06-03 03:38:44 +0000204%token TOK_END
205%token TOK_ENUMERATED
206%token TOK_EXPLICIT
207%token TOK_EXPORTS
208%token TOK_EXTENSIBILITY
209%token TOK_EXTERNAL
210%token TOK_FALSE
211%token TOK_FROM
212%token TOK_GeneralizedTime
213%token TOK_GeneralString
214%token TOK_GraphicString
215%token TOK_IA5String
216%token TOK_IDENTIFIER
217%token TOK_IMPLICIT
218%token TOK_IMPLIED
219%token TOK_IMPORTS
220%token TOK_INCLUDES
221%token TOK_INSTANCE
Lev Walkinf59d0752004-08-18 04:59:12 +0000222%token TOK_INSTRUCTIONS
Lev Walkinf15320b2004-06-03 03:38:44 +0000223%token TOK_INTEGER
224%token TOK_ISO646String
225%token TOK_MAX
226%token TOK_MIN
227%token TOK_MINUS_INFINITY
228%token TOK_NULL
229%token TOK_NumericString
230%token TOK_OBJECT
231%token TOK_ObjectDescriptor
232%token TOK_OCTET
233%token TOK_OF
234%token TOK_OPTIONAL
235%token TOK_PATTERN
236%token TOK_PDV
237%token TOK_PLUS_INFINITY
238%token TOK_PRESENT
239%token TOK_PrintableString
240%token TOK_PRIVATE
241%token TOK_REAL
242%token TOK_RELATIVE_OID
243%token TOK_SEQUENCE
244%token TOK_SET
245%token TOK_SIZE
246%token TOK_STRING
247%token TOK_SYNTAX
248%token TOK_T61String
249%token TOK_TAGS
250%token TOK_TeletexString
251%token TOK_TRUE
252%token TOK_TYPE_IDENTIFIER
253%token TOK_UNIQUE
254%token TOK_UNIVERSAL
255%token TOK_UniversalString
256%token TOK_UTCTime
257%token TOK_UTF8String
258%token TOK_VideotexString
259%token TOK_VisibleString
260%token TOK_WITH
Lev Walkin752e9732017-08-04 02:06:22 -0700261%token UTF8_BOM "UTF-8 byte order mark"
Lev Walkinf15320b2004-06-03 03:38:44 +0000262
Lev Walkinf1727152006-09-21 01:50:37 +0000263%nonassoc TOK_EXCEPT
Lev Walkinf59d0752004-08-18 04:59:12 +0000264%left '^' TOK_INTERSECTION
265%left '|' TOK_UNION
Lev Walkinf15320b2004-06-03 03:38:44 +0000266
267/* Misc tags */
Lev Walkinbe518fa2017-09-07 02:05:28 -0700268%token TOK_TwoDots ".."
269%token TOK_ThreeDots "..."
Lev Walkinf15320b2004-06-03 03:38:44 +0000270
271
272/*
273 * Types defined herein.
274 */
275%type <a_grammar> ModuleList
Lev Walkin866bd7f2006-09-14 10:35:20 +0000276%type <a_module> ModuleDefinition
277%type <a_module> ModuleBody
278%type <a_module> AssignmentList
279%type <a_module> Assignment
280%type <a_module> optModuleBody /* Optional */
281%type <a_module_flags> optModuleDefinitionFlags
282%type <a_module_flags> ModuleDefinitionFlags /* Set of FL */
283%type <a_module_flags> ModuleDefinitionFlag /* Single FL */
284%type <a_module> optImports
285%type <a_module> optExports
Lev Walkinf15320b2004-06-03 03:38:44 +0000286%type <a_module> ImportsDefinition
Lev Walkin4a4543f2006-10-13 12:37:39 +0000287%type <a_module> optImportsBundleSet
Lev Walkinf15320b2004-06-03 03:38:44 +0000288%type <a_module> ImportsBundleSet
289%type <a_xports> ImportsBundle
290%type <a_xports> ImportsList
291%type <a_xports> ExportsDefinition
292%type <a_xports> ExportsBody
293%type <a_expr> ImportsElement
294%type <a_expr> ExportsElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000295%type <a_expr> ExtensionAndException
Lev Walkina9532f42006-09-17 04:52:50 +0000296%type <a_expr> Type
Lev Walkin59165cf2017-09-11 06:24:45 -0700297%type <a_expr> TaggedType
298%type <a_expr> MaybeIndirectTaggedType
299%type <a_expr> UntaggedType
300%type <a_expr> DefinedUntaggedType
301%type <a_expr> ConcreteTypeDeclaration "concrete TypeDeclaration"
Lev Walkin070a52d2004-08-22 03:19:54 +0000302%type <a_expr> TypeDeclaration
Lev Walkin59165cf2017-09-11 06:24:45 -0700303%type <a_expr> MaybeIndirectTypeDeclaration
Lev Walkinf15320b2004-06-03 03:38:44 +0000304%type <a_ref> ComplexTypeReference
305%type <a_ref> ComplexTypeReferenceAmpList
306%type <a_refcomp> ComplexTypeReferenceElement
Lev Walkind370e9f2006-03-16 10:03:35 +0000307%type <a_refcomp> PrimitiveFieldReference
Lev Walkin9c2285a2006-03-09 08:49:26 +0000308%type <a_expr> FieldSpec
309%type <a_ref> FieldName
310%type <a_ref> DefinedObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000311%type <a_expr> ClassField
Lev Walkin9c2285a2006-03-09 08:49:26 +0000312%type <a_expr> ObjectClass
Lev Walkinf15320b2004-06-03 03:38:44 +0000313%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000314%type <a_expr> DefinedType
Lev Walkin557f27d2006-03-21 07:46:48 +0000315%type <a_constr> ValueSet /* {a|b|c}*/
316%type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000317%type <a_expr> ValueAssignment /* val INTEGER ::= 1*/
Lev Walkin9c974182004-09-15 11:59:51 +0000318%type <a_value> Value
Lev Walkin0c0bca62006-03-21 04:48:15 +0000319%type <a_value> SimpleValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000320%type <a_value> DefinedValue
321%type <a_value> SignedNumber
Lev Walkinadf863f2006-09-05 16:18:34 +0000322%type <a_value> RealValue
Lev Walkin1c8d5aa2006-10-27 05:37:39 +0000323%type <a_value> BitStringValue
Lev Walkin144db9b2004-10-12 23:26:53 +0000324%type <a_expr> optComponentTypeLists
Lev Walkin070a52d2004-08-22 03:19:54 +0000325%type <a_expr> ComponentTypeLists
326%type <a_expr> ComponentType
327%type <a_expr> AlternativeTypeLists
328%type <a_expr> AlternativeType
Lev Walkinf15320b2004-06-03 03:38:44 +0000329%type <a_expr> UniverationList
Lev Walkinbe518fa2017-09-07 02:05:28 -0700330%type <a_expr> Enumerations
331%type <a_expr> NamedBitList
332%type <a_expr> NamedBit
333%type <a_expr> NamedNumberList
334%type <a_expr> NamedNumber
335%type <a_expr> IdentifierList
336%type <a_expr> IdentifierElement
Lev Walkinf15320b2004-06-03 03:38:44 +0000337%type <a_expr> UniverationElement
338%type <tv_str> TypeRefName
Lev Walkinf15320b2004-06-03 03:38:44 +0000339%type <tv_str> Identifier
Lev Walkind523ea42017-09-06 22:15:08 -0700340%type <a_ref> IdentifierAsReference
341%type <a_value> IdentifierAsValue
Lev Walkin83cac2f2004-09-22 16:03:36 +0000342%type <tv_str> optIdentifier
Lev Walkinf15320b2004-06-03 03:38:44 +0000343%type <a_parg> ParameterArgumentName
344%type <a_plist> ParameterArgumentList
Lev Walkin5045dfa2006-03-21 09:41:28 +0000345%type <a_expr> ActualParameter
346%type <a_expr> ActualParameterList
Lev Walkin1ed22092005-08-12 10:06:17 +0000347%type <a_aid> AssignedIdentifier /* OID/DefinedValue */
Lev Walkinf15320b2004-06-03 03:38:44 +0000348%type <a_oid> ObjectIdentifier /* OID */
349%type <a_oid> optObjectIdentifier /* Optional OID */
350%type <a_oid> ObjectIdentifierBody
351%type <a_oid_arc> ObjectIdentifierElement
Lev Walkin59165cf2017-09-11 06:24:45 -0700352%type <a_expr> BuiltinType
Lev Walkinf15320b2004-06-03 03:38:44 +0000353%type <a_type> BasicTypeId
354%type <a_type> BasicTypeId_UniverationCompatible
355%type <a_type> BasicString
356%type <tv_opaque> Opaque
Lev Walkinbf979152017-09-07 23:36:11 -0700357%type <tv_opaque> OpaqueFirstToken
Lev Walkinc603f102005-01-23 09:51:44 +0000358%type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */
359%type <a_tag> TagClass TagTypeValue TagPlicit
Lev Walkinf15320b2004-06-03 03:38:44 +0000360%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
Lev Walkin0c686452017-09-07 22:59:36 -0700361%type <a_constr> optConstraint
362%type <a_constr> optManyConstraints /* Only for Type */
363%type <a_constr> ManyConstraints
364%type <a_constr> optSizeOrConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000365%type <a_constr> Constraint
Lev Walkin0c686452017-09-07 22:59:36 -0700366%type <a_constr> PermittedAlphabet
367%type <a_constr> SizeConstraint
Lev Walkind523ea42017-09-06 22:15:08 -0700368%type <a_constr> SingleTypeConstraint
369%type <a_constr> MultipleTypeConstraints
370%type <a_constr> NamedConstraint
371%type <a_constr> FullSpecification
372%type <a_constr> PartialSpecification
373%type <a_constr> TypeConstraints
374%type <a_constr> ConstraintSpec
Lev Walkina9532f42006-09-17 04:52:50 +0000375%type <a_constr> SubtypeConstraint
376%type <a_constr> GeneralConstraint
Lev Walkinf59d0752004-08-18 04:59:12 +0000377%type <a_constr> ElementSetSpecs /* 1..2,...,3 */
Lev Walkin0c686452017-09-07 22:59:36 -0700378%type <a_constr> ElementSetSpec /* 1..2 */
Lev Walkinf1727152006-09-21 01:50:37 +0000379%type <a_constr> Unions
380%type <a_constr> Intersections
381%type <a_constr> IntersectionElements
Lev Walkin0c686452017-09-07 22:59:36 -0700382%type <a_constr> Elements
383%type <a_constr> SubtypeElements /* 1..2 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000384%type <a_constr> SimpleTableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000385%type <a_constr> UserDefinedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +0000386%type <a_constr> TableConstraint
Lev Walkina9532f42006-09-17 04:52:50 +0000387%type <a_constr> ContentsConstraint
Lev Walkin5c541f12006-10-18 18:40:14 +0000388%type <a_constr> PatternConstraint
Lev Walkin0c686452017-09-07 22:59:36 -0700389%type <a_constr> InnerTypeConstraints
390%type <a_constr> ValueRange
Lev Walkinf15320b2004-06-03 03:38:44 +0000391%type <a_constr> ComponentRelationConstraint
392%type <a_constr> AtNotationList
393%type <a_ref> AtNotationElement
Lev Walkinff7dd142005-03-20 12:58:00 +0000394%type <a_value> SingleValue
Lev Walkin0c686452017-09-07 22:59:36 -0700395%type <a_value> LowerEndValue
396%type <a_value> UpperEndValue
Lev Walkinff7dd142005-03-20 12:58:00 +0000397%type <a_value> ContainedSubtype
Lev Walkinf15320b2004-06-03 03:38:44 +0000398%type <a_ctype> ConstraintRangeSpec
Lev Walkin1e448d32005-03-24 14:26:38 +0000399%type <a_value> RestrictedCharacterStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +0000400%type <a_wsynt> optWithSyntax
401%type <a_wsynt> WithSyntax
Lev Walkin9d542d22006-03-14 16:31:37 +0000402%type <a_wsynt> WithSyntaxList
403%type <a_wchunk> WithSyntaxToken
Lev Walkinf15320b2004-06-03 03:38:44 +0000404%type <a_marker> optMarker Marker
Lev Walkin0c686452017-09-07 22:59:36 -0700405%type <a_int> optUNIQUE
Lev Walkinf15320b2004-06-03 03:38:44 +0000406%type <a_pres> optPresenceConstraint PresenceConstraint
407%type <tv_str> ComponentIdList
Lev Walkinef625402005-09-05 05:17:57 +0000408%type <a_int> NSTD_IndirectMarker
Lev Walkinf15320b2004-06-03 03:38:44 +0000409
Lev Walkinf15320b2004-06-03 03:38:44 +0000410%%
411
412
413ParsedGrammar:
Lev Walkin752e9732017-08-04 02:06:22 -0700414 UTF8_BOM ModuleList {
415 *(void **)param = $2;
416 }
417 | ModuleList {
Lev Walkinf15320b2004-06-03 03:38:44 +0000418 *(void **)param = $1;
419 }
420 ;
421
422ModuleList:
Lev Walkin866bd7f2006-09-14 10:35:20 +0000423 ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000424 $$ = asn1p_new();
425 checkmem($$);
426 TQ_ADD(&($$->modules), $1, mod_next);
427 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000428 | ModuleList ModuleDefinition {
Lev Walkinf15320b2004-06-03 03:38:44 +0000429 $$ = $1;
430 TQ_ADD(&($$->modules), $2, mod_next);
431 }
432 ;
433
434/*
435 * ASN module definition.
436 * === EXAMPLE ===
437 * MySyntax DEFINITIONS AUTOMATIC TAGS ::=
438 * BEGIN
439 * ...
440 * END
441 * === EOF ===
442 */
443
Lev Walkin866bd7f2006-09-14 10:35:20 +0000444ModuleDefinition:
Lev Walkina9532f42006-09-17 04:52:50 +0000445 TypeRefName { currentModule = asn1p_module_new(); }
446 optObjectIdentifier TOK_DEFINITIONS
Lev Walkin866bd7f2006-09-14 10:35:20 +0000447 optModuleDefinitionFlags
Lev Walkinf15320b2004-06-03 03:38:44 +0000448 TOK_PPEQ TOK_BEGIN
Lev Walkin866bd7f2006-09-14 10:35:20 +0000449 optModuleBody
Lev Walkinf15320b2004-06-03 03:38:44 +0000450 TOK_END {
451
Lev Walkina9532f42006-09-17 04:52:50 +0000452 $$ = currentModule;
453
454 if($8) {
455 asn1p_module_t tmp = *($$);
456 *($$) = *($8);
457 *($8) = tmp;
458 asn1p_module_free($8);
Lev Walkinf15320b2004-06-03 03:38:44 +0000459 } else {
460 /* There's a chance that a module is just plain empty */
Lev Walkinf15320b2004-06-03 03:38:44 +0000461 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000462
Lev Walkin1ed22092005-08-12 10:06:17 +0000463 $$->ModuleName = $1;
Lev Walkina9532f42006-09-17 04:52:50 +0000464 $$->module_oid = $3;
465 $$->module_flags = $5;
Lev Walkinf15320b2004-06-03 03:38:44 +0000466 }
467 ;
468
469/*
470 * Object Identifier Definition
471 * { iso member-body(2) 3 }
472 */
473optObjectIdentifier:
474 { $$ = 0; }
475 | ObjectIdentifier { $$ = $1; }
476 ;
477
478ObjectIdentifier:
479 '{' ObjectIdentifierBody '}' {
480 $$ = $2;
481 }
482 | '{' '}' {
483 $$ = 0;
484 }
485 ;
486
487ObjectIdentifierBody:
488 ObjectIdentifierElement {
489 $$ = asn1p_oid_new();
490 asn1p_oid_add_arc($$, &$1);
491 if($1.name)
492 free($1.name);
493 }
494 | ObjectIdentifierBody ObjectIdentifierElement {
495 $$ = $1;
496 asn1p_oid_add_arc($$, &$2);
497 if($2.name)
498 free($2.name);
499 }
500 ;
501
502ObjectIdentifierElement:
503 Identifier { /* iso */
504 $$.name = $1;
505 $$.number = -1;
506 }
507 | Identifier '(' TOK_number ')' { /* iso(1) */
508 $$.name = $1;
509 $$.number = $3;
510 }
511 | TOK_number { /* 1 */
512 $$.name = 0;
513 $$.number = $1;
514 }
515 ;
516
517/*
518 * Optional module flags.
519 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000520optModuleDefinitionFlags:
Lev Walkinf15320b2004-06-03 03:38:44 +0000521 { $$ = MSF_NOFLAGS; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000522 | ModuleDefinitionFlags {
Lev Walkinf15320b2004-06-03 03:38:44 +0000523 $$ = $1;
524 }
525 ;
526
527/*
528 * Module flags.
529 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000530ModuleDefinitionFlags:
531 ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000532 $$ = $1;
533 }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000534 | ModuleDefinitionFlags ModuleDefinitionFlag {
Lev Walkinf15320b2004-06-03 03:38:44 +0000535 $$ = $1 | $2;
536 }
537 ;
538
539/*
540 * Single module flag.
541 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000542ModuleDefinitionFlag:
Lev Walkinf15320b2004-06-03 03:38:44 +0000543 TOK_EXPLICIT TOK_TAGS {
544 $$ = MSF_EXPLICIT_TAGS;
545 }
546 | TOK_IMPLICIT TOK_TAGS {
547 $$ = MSF_IMPLICIT_TAGS;
548 }
549 | TOK_AUTOMATIC TOK_TAGS {
550 $$ = MSF_AUTOMATIC_TAGS;
551 }
552 | TOK_EXTENSIBILITY TOK_IMPLIED {
553 $$ = MSF_EXTENSIBILITY_IMPLIED;
554 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000555 /* EncodingReferenceDefault */
556 | TOK_capitalreference TOK_INSTRUCTIONS {
557 /* X.680Amd1 specifies TAG and XER */
558 if(strcmp($1, "TAG") == 0) {
559 $$ = MSF_TAG_INSTRUCTIONS;
560 } else if(strcmp($1, "XER") == 0) {
561 $$ = MSF_XER_INSTRUCTIONS;
562 } else {
563 fprintf(stderr,
Lev Walkind523ea42017-09-06 22:15:08 -0700564 "WARNING: %s INSTRUCTIONS at %s:%d: "
Lev Walkinf59d0752004-08-18 04:59:12 +0000565 "Unrecognized encoding reference\n",
Lev Walkind523ea42017-09-06 22:15:08 -0700566 $1, ASN_FILENAME, yylineno);
Lev Walkinf59d0752004-08-18 04:59:12 +0000567 $$ = MSF_unk_INSTRUCTIONS;
568 }
569 free($1);
570 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000571 ;
572
573/*
574 * Optional module body.
575 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000576optModuleBody:
Lev Walkinf15320b2004-06-03 03:38:44 +0000577 { $$ = 0; }
Lev Walkin866bd7f2006-09-14 10:35:20 +0000578 | ModuleBody {
Lev Walkinf15320b2004-06-03 03:38:44 +0000579 $$ = $1;
580 }
581 ;
582
583/*
584 * ASN.1 Module body.
585 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000586ModuleBody:
587 optExports optImports AssignmentList {
588 $$ = asn1p_module_new();
589 AL_IMPORT($$, exports, $1, xp_next);
590 AL_IMPORT($$, imports, $2, xp_next);
Lev Walkin1a49ced2017-11-06 00:07:00 -0800591 asn1p_module_move_members($$, $3);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800592
593 asn1p_module_free($1);
594 asn1p_module_free($2);
595 asn1p_module_free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000596 }
597 ;
598
Lev Walkin866bd7f2006-09-14 10:35:20 +0000599AssignmentList:
600 Assignment {
601 $$ = $1;
602 }
603 | AssignmentList Assignment {
604 if($1) {
605 $$ = $1;
606 } else {
607 $$ = $2;
608 break;
609 }
Lev Walkin1a49ced2017-11-06 00:07:00 -0800610 asn1p_module_move_members($$, $2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800611 asn1p_module_free($2);
Lev Walkin866bd7f2006-09-14 10:35:20 +0000612 }
613 ;
614
615
Lev Walkinf15320b2004-06-03 03:38:44 +0000616/*
617 * One of the elements of ASN.1 module specification.
618 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000619Assignment:
620 DataTypeReference {
Lev Walkinf15320b2004-06-03 03:38:44 +0000621 $$ = asn1p_module_new();
622 checkmem($$);
623 assert($1->expr_type != A1TC_INVALID);
624 assert($1->meta_type != AMT_INVALID);
Lev Walkin1a49ced2017-11-06 00:07:00 -0800625 asn1p_module_member_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000626 }
Lev Walkinc6ab03c2006-10-21 05:54:49 +0000627 | ValueAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000628 $$ = asn1p_module_new();
629 checkmem($$);
630 assert($1->expr_type != A1TC_INVALID);
631 assert($1->meta_type != AMT_INVALID);
Lev Walkin1a49ced2017-11-06 00:07:00 -0800632 asn1p_module_member_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000633 }
634 /*
635 * Value set definition
636 * === EXAMPLE ===
637 * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 }
638 * === EOF ===
Lev Walkine700b202017-08-06 23:21:32 -0700639 * Also ObjectClassSet.
Lev Walkinf15320b2004-06-03 03:38:44 +0000640 */
Lev Walkin557f27d2006-03-21 07:46:48 +0000641 | ValueSetTypeAssignment {
Lev Walkinf15320b2004-06-03 03:38:44 +0000642 $$ = asn1p_module_new();
643 checkmem($$);
644 assert($1->expr_type != A1TC_INVALID);
645 assert($1->meta_type != AMT_INVALID);
Lev Walkin1a49ced2017-11-06 00:07:00 -0800646 asn1p_module_member_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000647 }
Lev Walkinf59d0752004-08-18 04:59:12 +0000648 | TOK_ENCODING_CONTROL TOK_capitalreference
649 { asn1p_lexer_hack_push_encoding_control(); }
650 {
651 fprintf(stderr,
652 "WARNING: ENCODING-CONTROL %s "
Lev Walkind523ea42017-09-06 22:15:08 -0700653 "specification at %s:%d ignored\n",
654 $2, ASN_FILENAME, yylineno);
Lev Walkinf59d0752004-08-18 04:59:12 +0000655 free($2);
656 $$ = 0;
657 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000658
659 /*
660 * Erroneous attemps
661 */
662 | BasicString {
663 return yyerror(
Lev Walkin70853052005-11-26 11:21:55 +0000664 "Attempt to redefine a standard basic string type, "
665 "please comment out or remove this type redefinition.");
Lev Walkinf15320b2004-06-03 03:38:44 +0000666 }
667 ;
668
669/*
670 * === EXAMPLE ===
671 * IMPORTS Type1, value FROM Module { iso standard(0) } ;
672 * === EOF ===
673 */
Lev Walkin866bd7f2006-09-14 10:35:20 +0000674optImports:
675 { $$ = 0; }
676 | ImportsDefinition;
677
Lev Walkinf15320b2004-06-03 03:38:44 +0000678ImportsDefinition:
Lev Walkin4a4543f2006-10-13 12:37:39 +0000679 TOK_IMPORTS optImportsBundleSet ';' {
Lev Walkin1ed22092005-08-12 10:06:17 +0000680 if(!saved_aid && 0)
681 return yyerror("Unterminated IMPORTS FROM, "
682 "expected semicolon ';'");
683 saved_aid = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +0000684 $$ = $2;
685 }
686 /*
687 * Some error cases.
688 */
689 | TOK_IMPORTS TOK_FROM /* ... */ {
690 return yyerror("Empty IMPORTS list");
691 }
692 ;
693
Lev Walkin4a4543f2006-10-13 12:37:39 +0000694optImportsBundleSet:
695 { $$ = asn1p_module_new(); }
696 | ImportsBundleSet;
697
Lev Walkinf15320b2004-06-03 03:38:44 +0000698ImportsBundleSet:
699 ImportsBundle {
700 $$ = asn1p_module_new();
701 checkmem($$);
702 TQ_ADD(&($$->imports), $1, xp_next);
703 }
704 | ImportsBundleSet ImportsBundle {
705 $$ = $1;
706 TQ_ADD(&($$->imports), $2, xp_next);
707 }
708 ;
709
Lev Walkin1ed22092005-08-12 10:06:17 +0000710AssignedIdentifier:
711 { memset(&$$, 0, sizeof($$)); }
712 | ObjectIdentifier { $$.oid = $1; };
713 /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */
714
Lev Walkinf15320b2004-06-03 03:38:44 +0000715ImportsBundle:
Lev Walkin1ed22092005-08-12 10:06:17 +0000716 ImportsList TOK_FROM TypeRefName AssignedIdentifier {
Lev Walkinf15320b2004-06-03 03:38:44 +0000717 $$ = $1;
Lev Walkin1ed22092005-08-12 10:06:17 +0000718 $$->fromModuleName = $3;
719 $$->identifier = $4;
720 /* This stupid thing is used for look-back hack. */
721 saved_aid = $$->identifier.oid ? 0 : &($$->identifier);
Lev Walkinf15320b2004-06-03 03:38:44 +0000722 checkmem($$);
723 }
724 ;
725
726ImportsList:
727 ImportsElement {
728 $$ = asn1p_xports_new();
729 checkmem($$);
Lev Walkin1a49ced2017-11-06 00:07:00 -0800730 TQ_ADD(&($$->xp_members), $1, next);
Lev Walkinf15320b2004-06-03 03:38:44 +0000731 }
732 | ImportsList ',' ImportsElement {
733 $$ = $1;
Lev Walkin1a49ced2017-11-06 00:07:00 -0800734 TQ_ADD(&($$->xp_members), $3, next);
Lev Walkinf15320b2004-06-03 03:38:44 +0000735 }
736 ;
737
738ImportsElement:
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_REFERENCE;
744 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000745 | TypeRefName '{' '}' { /* Completely equivalent to above */
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_REFERENCE;
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_REFERENCE;
756 }
757 ;
758
Lev Walkin866bd7f2006-09-14 10:35:20 +0000759
760optExports:
761 { $$ = 0; }
762 | ExportsDefinition {
763 $$ = asn1p_module_new();
764 checkmem($$);
765 if($1) {
766 TQ_ADD(&($$->exports), $1, xp_next);
767 } else {
768 /* "EXPORTS ALL;" */
769 }
770 }
771 ;
772
Lev Walkinf15320b2004-06-03 03:38:44 +0000773ExportsDefinition:
774 TOK_EXPORTS ExportsBody ';' {
775 $$ = $2;
776 }
777 | TOK_EXPORTS TOK_ALL ';' {
778 $$ = 0;
779 }
780 | TOK_EXPORTS ';' {
781 /* Empty EXPORTS clause effectively prohibits export. */
782 $$ = asn1p_xports_new();
783 checkmem($$);
784 }
785 ;
786
787ExportsBody:
788 ExportsElement {
789 $$ = asn1p_xports_new();
790 assert($$);
Lev Walkin1a49ced2017-11-06 00:07:00 -0800791 TQ_ADD(&($$->xp_members), $1, next);
Lev Walkinf15320b2004-06-03 03:38:44 +0000792 }
793 | ExportsBody ',' ExportsElement {
794 $$ = $1;
Lev Walkin1a49ced2017-11-06 00:07:00 -0800795 TQ_ADD(&($$->xp_members), $3, next);
Lev Walkinf15320b2004-06-03 03:38:44 +0000796 }
797 ;
798
799ExportsElement:
800 TypeRefName {
Lev Walkina9532f42006-09-17 04:52:50 +0000801 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000802 checkmem($$);
803 $$->Identifier = $1;
804 $$->expr_type = A1TC_EXPORTVAR;
805 }
Lev Walkin144db9b2004-10-12 23:26:53 +0000806 | TypeRefName '{' '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000807 $$ = NEW_EXPR();
Lev Walkin144db9b2004-10-12 23:26:53 +0000808 checkmem($$);
809 $$->Identifier = $1;
810 $$->expr_type = A1TC_EXPORTVAR;
811 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000812 | Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +0000813 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000814 checkmem($$);
815 $$->Identifier = $1;
816 $$->expr_type = A1TC_EXPORTVAR;
817 }
818 ;
819
820
Lev Walkin418298d2006-07-13 08:24:20 +0000821ValueSet: '{' ElementSetSpecs '}' { $$ = $2; };
Lev Walkin557f27d2006-03-21 07:46:48 +0000822
823ValueSetTypeAssignment:
Lev Walkin59165cf2017-09-11 06:24:45 -0700824 TypeRefName Type TOK_PPEQ ValueSet {
Lev Walkinf15320b2004-06-03 03:38:44 +0000825 $$ = $2;
826 assert($$->Identifier == 0);
827 $$->Identifier = $1;
828 $$->meta_type = AMT_VALUESET;
Lev Walkin557f27d2006-03-21 07:46:48 +0000829 $$->constraints = $4;
Lev Walkinf15320b2004-06-03 03:38:44 +0000830 }
831 ;
832
Lev Walkin0c0bca62006-03-21 04:48:15 +0000833DefinedType:
Lev Walkin0c0bca62006-03-21 04:48:15 +0000834 /*
835 * A DefinedType reference.
836 * "CLASS1.&id.&id2"
837 * or
838 * "Module.Type"
839 * or
840 * "Module.identifier"
841 * or
842 * "Type"
843 */
Lev Walkin59165cf2017-09-11 06:24:45 -0700844 ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +0000845 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000846 checkmem($$);
847 $$->reference = $1;
848 $$->expr_type = A1TC_REFERENCE;
849 $$->meta_type = AMT_TYPEREF;
850 }
Lev Walkin0c0bca62006-03-21 04:48:15 +0000851 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000852 * A parameterized assignment.
Lev Walkin0c0bca62006-03-21 04:48:15 +0000853 */
Lev Walkin5045dfa2006-03-21 09:41:28 +0000854 | ComplexTypeReference '{' ActualParameterList '}' {
Lev Walkina9532f42006-09-17 04:52:50 +0000855 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000856 checkmem($$);
Lev Walkin0c0bca62006-03-21 04:48:15 +0000857 $$->reference = $1;
858 $$->rhs_pspecs = $3;
859 $$->expr_type = A1TC_REFERENCE;
860 $$->meta_type = AMT_TYPEREF;
Lev Walkinf15320b2004-06-03 03:38:44 +0000861 }
862 ;
863
Lev Walkinf15320b2004-06-03 03:38:44 +0000864/*
865 * Data Type Reference.
866 * === EXAMPLE ===
867 * Type3 ::= CHOICE { a Type1, b Type 2 }
868 * === EOF ===
869 */
Lev Walkinf15320b2004-06-03 03:38:44 +0000870DataTypeReference:
871 /*
872 * Optionally tagged type definition.
873 */
Lev Walkin9c2285a2006-03-09 08:49:26 +0000874 TypeRefName TOK_PPEQ Type {
Lev Walkinaf120f72004-09-14 02:36:39 +0000875 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000876 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000877 assert($$->expr_type);
878 assert($$->meta_type);
879 }
Lev Walkin9c2285a2006-03-09 08:49:26 +0000880 | TypeRefName TOK_PPEQ ObjectClass {
Lev Walkinf15320b2004-06-03 03:38:44 +0000881 $$ = $3;
882 $$->Identifier = $1;
883 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +0000884 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +0000885 }
886 /*
Lev Walkin5045dfa2006-03-21 09:41:28 +0000887 * Parameterized <Type> declaration:
Lev Walkinf15320b2004-06-03 03:38:44 +0000888 * === EXAMPLE ===
889 * SIGNED { ToBeSigned } ::= SEQUENCE {
890 * toBeSigned ToBeSigned,
891 * algorithm AlgorithmIdentifier,
892 * signature BIT STRING
893 * }
894 * === EOF ===
895 */
Lev Walkin070a52d2004-08-22 03:19:54 +0000896 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
Lev Walkinf15320b2004-06-03 03:38:44 +0000897 $$ = $6;
Lev Walkin5045dfa2006-03-21 09:41:28 +0000898 $$->Identifier = $1;
899 $$->lhs_params = $3;
900 }
901 /* Parameterized CLASS declaration */
902 | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass {
903 $$ = $6;
Lev Walkinf15320b2004-06-03 03:38:44 +0000904 $$->Identifier = $1;
Lev Walkina00d6b32006-03-21 03:40:38 +0000905 $$->lhs_params = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +0000906 }
907 ;
908
909ParameterArgumentList:
910 ParameterArgumentName {
911 int ret;
912 $$ = asn1p_paramlist_new(yylineno);
913 checkmem($$);
914 ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument);
915 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700916 asn1p_ref_free($1.governor);
917 free($1.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000918 }
919 | ParameterArgumentList ',' ParameterArgumentName {
920 int ret;
921 $$ = $1;
922 ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument);
923 checkmem(ret == 0);
Lev Walkina964e032017-03-26 03:48:06 -0700924 asn1p_ref_free($3.governor);
925 free($3.argument);
Lev Walkinf15320b2004-06-03 03:38:44 +0000926 }
927 ;
928
929ParameterArgumentName:
930 TypeRefName {
931 $$.governor = NULL;
932 $$.argument = $1;
933 }
934 | TypeRefName ':' Identifier {
935 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800936 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000937 ret = asn1p_ref_add_component($$.governor, $1, 0);
938 checkmem(ret == 0);
939 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800940 free($1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000941 }
Lev Walkinc8092cb2005-02-18 16:34:21 +0000942 | TypeRefName ':' TypeRefName {
943 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800944 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000945 ret = asn1p_ref_add_component($$.governor, $1, 0);
946 checkmem(ret == 0);
947 $$.argument = $3;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800948 free($1);
Lev Walkinc8092cb2005-02-18 16:34:21 +0000949 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000950 | BasicTypeId ':' Identifier {
951 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800952 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +0000953 ret = asn1p_ref_add_component($$.governor,
954 ASN_EXPR_TYPE2STR($1), 1);
955 checkmem(ret == 0);
956 $$.argument = $3;
957 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000958 | BasicTypeId ':' TypeRefName {
959 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800960 $$.governor = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +0000961 ret = asn1p_ref_add_component($$.governor,
962 ASN_EXPR_TYPE2STR($1), 1);
963 checkmem(ret == 0);
964 $$.argument = $3;
965 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000966 ;
967
Lev Walkin5045dfa2006-03-21 09:41:28 +0000968ActualParameterList:
969 ActualParameter {
Lev Walkina9532f42006-09-17 04:52:50 +0000970 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000971 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +0000972 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +0000973 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000974 | ActualParameterList ',' ActualParameter {
Lev Walkinf15320b2004-06-03 03:38:44 +0000975 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +0000976 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +0000977 }
978 ;
979
Lev Walkin5045dfa2006-03-21 09:41:28 +0000980ActualParameter:
Lev Walkin59165cf2017-09-11 06:24:45 -0700981 UntaggedType /* act. Type */
Lev Walkin0c0bca62006-03-21 04:48:15 +0000982 | SimpleValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000983 $$ = NEW_EXPR();
Lev Walkin0c0bca62006-03-21 04:48:15 +0000984 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +0800985 $$->Identifier = strdup("?");
Lev Walkin0c0bca62006-03-21 04:48:15 +0000986 $$->expr_type = A1TC_REFERENCE;
987 $$->meta_type = AMT_VALUE;
988 $$->value = $1;
989 }
Lev Walkin59165cf2017-09-11 06:24:45 -0700990 | DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +0000991 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +0000992 checkmem($$);
Lev Walkin59165cf2017-09-11 06:24:45 -0700993 $$->Identifier = strdup("?");
Lev Walkinf15320b2004-06-03 03:38:44 +0000994 $$->expr_type = A1TC_REFERENCE;
995 $$->meta_type = AMT_VALUE;
Lev Walkin59165cf2017-09-11 06:24:45 -0700996 $$->value = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +0000997 }
Lev Walkin5045dfa2006-03-21 09:41:28 +0000998 | ValueSet {
Lev Walkina9532f42006-09-17 04:52:50 +0000999 $$ = NEW_EXPR();
Lev Walkin5045dfa2006-03-21 09:41:28 +00001000 $$->expr_type = A1TC_VALUESET;
1001 $$->meta_type = AMT_VALUESET;
1002 $$->constraints = $1;
1003 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001004 ;
1005
1006/*
Lev Walkin5045dfa2006-03-21 09:41:28 +00001007 | '{' ActualParameter '}' {
Lev Walkina9532f42006-09-17 04:52:50 +00001008 $$ = NEW_EXPR();
Lev Walkinc8092cb2005-02-18 16:34:21 +00001009 checkmem($$);
1010 asn1p_expr_add($$, $2);
1011 $$->expr_type = A1TC_PARAMETRIZED;
1012 $$->meta_type = AMT_TYPE;
1013 }
1014 ;
1015*/
1016
1017/*
Lev Walkinf15320b2004-06-03 03:38:44 +00001018 * A collection of constructed data type members.
1019 */
Lev Walkin144db9b2004-10-12 23:26:53 +00001020optComponentTypeLists:
Lev Walkina9532f42006-09-17 04:52:50 +00001021 { $$ = NEW_EXPR(); }
Lev Walkin144db9b2004-10-12 23:26:53 +00001022 | ComponentTypeLists { $$ = $1; };
1023
Lev Walkin070a52d2004-08-22 03:19:54 +00001024ComponentTypeLists:
1025 ComponentType {
Lev Walkina9532f42006-09-17 04:52:50 +00001026 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001027 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001028 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001029 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001030 | ComponentTypeLists ',' ComponentType {
Lev Walkinf15320b2004-06-03 03:38:44 +00001031 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001032 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001033 }
Lev Walkin0e90aa02013-03-19 16:17:13 -07001034 | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight {
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001035 $$ = $1;
Lev Walkin0e90aa02013-03-19 16:17:13 -07001036 asn1p_expr_add_many($$, $4);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001037 asn1p_expr_free($4);
Lev Walkin0e90aa02013-03-19 16:17:13 -07001038 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001039 ;
1040
Lev Walkin070a52d2004-08-22 03:19:54 +00001041ComponentType:
Lev Walkin59165cf2017-09-11 06:24:45 -07001042 Identifier MaybeIndirectTaggedType optMarker {
Lev Walkin070a52d2004-08-22 03:19:54 +00001043 $$ = $2;
1044 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001045 $$->Identifier = $1;
Lev Walkinef625402005-09-05 05:17:57 +00001046 $3.flags |= $$->marker.flags;
Lev Walkin070a52d2004-08-22 03:19:54 +00001047 $$->marker = $3;
1048 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001049 | MaybeIndirectTaggedType optMarker {
Lev Walkinef625402005-09-05 05:17:57 +00001050 $$ = $1;
1051 $2.flags |= $$->marker.flags;
1052 $$->marker = $2;
1053 _fixup_anonymous_identifier($$);
1054 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001055 | TOK_COMPONENTS TOK_OF MaybeIndirectTaggedType {
Lev Walkina9532f42006-09-17 04:52:50 +00001056 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001057 checkmem($$);
1058 $$->meta_type = $3->meta_type;
1059 $$->expr_type = A1TC_COMPONENTS_OF;
Lev Walkin1004aa92004-09-08 00:28:11 +00001060 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001061 }
1062 | ExtensionAndException {
1063 $$ = $1;
1064 }
1065 ;
1066
1067AlternativeTypeLists:
1068 AlternativeType {
Lev Walkina9532f42006-09-17 04:52:50 +00001069 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001070 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00001071 asn1p_expr_add($$, $1);
Lev Walkin070a52d2004-08-22 03:19:54 +00001072 }
1073 | AlternativeTypeLists ',' AlternativeType {
1074 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001075 asn1p_expr_add($$, $3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001076 }
1077 ;
1078
1079AlternativeType:
Lev Walkin59165cf2017-09-11 06:24:45 -07001080 Identifier MaybeIndirectTaggedType {
Lev Walkin070a52d2004-08-22 03:19:54 +00001081 $$ = $2;
1082 assert($$->Identifier == 0);
Lev Walkinaf120f72004-09-14 02:36:39 +00001083 $$->Identifier = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001084 }
1085 | ExtensionAndException {
1086 $$ = $1;
1087 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001088 | MaybeIndirectTaggedType {
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00001089 $$ = $1;
1090 _fixup_anonymous_identifier($$);
1091 }
Lev Walkin070a52d2004-08-22 03:19:54 +00001092 ;
1093
Lev Walkin9c2285a2006-03-09 08:49:26 +00001094ObjectClass:
1095 TOK_CLASS '{' FieldSpec '}' optWithSyntax {
Lev Walkinf15320b2004-06-03 03:38:44 +00001096 $$ = $3;
1097 checkmem($$);
1098 $$->with_syntax = $5;
1099 assert($$->expr_type == A1TC_CLASSDEF);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001100 assert($$->meta_type == AMT_OBJECTCLASS);
Lev Walkinf15320b2004-06-03 03:38:44 +00001101 }
1102 ;
1103
Lev Walkin0c686452017-09-07 22:59:36 -07001104optUNIQUE:
Lev Walkinf15320b2004-06-03 03:38:44 +00001105 { $$ = 0; }
1106 | TOK_UNIQUE { $$ = 1; }
1107 ;
1108
Lev Walkin9c2285a2006-03-09 08:49:26 +00001109FieldSpec:
Lev Walkinf15320b2004-06-03 03:38:44 +00001110 ClassField {
Lev Walkina9532f42006-09-17 04:52:50 +00001111 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001112 checkmem($$);
1113 $$->expr_type = A1TC_CLASSDEF;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001114 $$->meta_type = AMT_OBJECTCLASS;
Lev Walkin1004aa92004-09-08 00:28:11 +00001115 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001116 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001117 | FieldSpec ',' ClassField {
Lev Walkinf15320b2004-06-03 03:38:44 +00001118 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00001119 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001120 }
1121 ;
1122
Lev Walkin9c2285a2006-03-09 08:49:26 +00001123 /* X.681 */
Lev Walkinf15320b2004-06-03 03:38:44 +00001124ClassField:
Lev Walkin9c2285a2006-03-09 08:49:26 +00001125
1126 /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */
1127 TOK_typefieldreference optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001128 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001129 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001130 $$->Identifier = $1;
Lev Walkinf15320b2004-06-03 03:38:44 +00001131 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001132 $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */
Lev Walkinf15320b2004-06-03 03:38:44 +00001133 $$->marker = $2;
1134 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001135
1136 /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */
Lev Walkin0c686452017-09-07 22:59:36 -07001137 | TOK_valuefieldreference Type optUNIQUE optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001138 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001139 $$->Identifier = $1;
1140 $$->meta_type = AMT_OBJECTFIELD;
1141 $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */
Lev Walkinb7c45ca2004-11-24 17:43:29 +00001142 $$->unique = $3;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001143 $$->marker = $4;
1144 asn1p_expr_add($$, $2);
Lev Walkinf15320b2004-06-03 03:38:44 +00001145 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001146
1147 /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */
1148 | TOK_valuefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001149 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001150 $$->Identifier = $1;
1151 $$->meta_type = AMT_OBJECTFIELD;
1152 $$->expr_type = A1TC_CLASSFIELD_VTVFS;
1153 $$->reference = $2;
1154 $$->marker = $3;
1155 }
1156
Lev Walkin9c2285a2006-03-09 08:49:26 +00001157 /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1158 | TOK_valuefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001159 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001160 checkmem($$);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001161 $$->Identifier = $1;
1162 $$->reference = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00001163 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001164 $$->expr_type = A1TC_CLASSFIELD_OFS;
1165 $$->marker = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00001166 }
Lev Walkin9c2285a2006-03-09 08:49:26 +00001167
Lev Walkin54868752006-03-09 09:08:49 +00001168 /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */
1169 | TOK_typefieldreference FieldName optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001170 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001171 $$->Identifier = $1;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001172 $$->meta_type = AMT_OBJECTFIELD;
Lev Walkin54868752006-03-09 09:08:49 +00001173 $$->expr_type = A1TC_CLASSFIELD_VTVSFS;
1174 $$->reference = $2;
Lev Walkin9c2285a2006-03-09 08:49:26 +00001175 $$->marker = $3;
1176 }
1177
1178 /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */
1179 | TOK_typefieldreference Type optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001180 $$ = NEW_EXPR();
Lev Walkin9c2285a2006-03-09 08:49:26 +00001181 checkmem($$);
1182 $$->Identifier = $1;
1183 $$->meta_type = AMT_OBJECTFIELD;
1184 $$->expr_type = A1TC_CLASSFIELD_FTVSFS;
1185 asn1p_expr_add($$, $2);
1186 $$->marker = $3;
1187 }
1188
Lev Walkin54868752006-03-09 09:08:49 +00001189 /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */
1190 | TOK_typefieldreference DefinedObjectClass optMarker {
Lev Walkina9532f42006-09-17 04:52:50 +00001191 $$ = NEW_EXPR();
Lev Walkin54868752006-03-09 09:08:49 +00001192 checkmem($$);
1193 $$->Identifier = $1;
1194 $$->reference = $2;
1195 $$->meta_type = AMT_OBJECTFIELD;
1196 $$->expr_type = A1TC_CLASSFIELD_OSFS;
1197 $$->marker = $3;
1198 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001199 ;
1200
1201optWithSyntax:
1202 { $$ = 0; }
1203 | WithSyntax {
1204 $$ = $1;
1205 }
1206 ;
1207
1208WithSyntax:
1209 TOK_WITH TOK_SYNTAX '{'
1210 { asn1p_lexer_hack_enable_with_syntax(); }
Lev Walkin9d542d22006-03-14 16:31:37 +00001211 WithSyntaxList
Lev Walkinf15320b2004-06-03 03:38:44 +00001212 '}' {
1213 $$ = $5;
1214 }
1215 ;
1216
Lev Walkin9d542d22006-03-14 16:31:37 +00001217WithSyntaxList:
1218 WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001219 $$ = asn1p_wsyntx_new();
1220 TQ_ADD(&($$->chunks), $1, next);
1221 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001222 | WithSyntaxList WithSyntaxToken {
Lev Walkinf15320b2004-06-03 03:38:44 +00001223 $$ = $1;
1224 TQ_ADD(&($$->chunks), $2, next);
1225 }
1226 ;
1227
Lev Walkin9d542d22006-03-14 16:31:37 +00001228WithSyntaxToken:
Lev Walkin57074f12006-03-16 05:11:14 +00001229 TOK_whitespace {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001230 $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0);
Lev Walkin57074f12006-03-16 05:11:14 +00001231 $$->type = WC_WHITESPACE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001232 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001233 | TOK_Literal {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001234 $$ = asn1p_wsyntx_chunk_fromstring($1, 0);
Lev Walkin9d542d22006-03-14 16:31:37 +00001235 }
Lev Walkind370e9f2006-03-16 10:03:35 +00001236 | PrimitiveFieldReference {
Lev Walkinc46b7cb2006-08-18 02:27:55 +00001237 $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0);
Lev Walkind370e9f2006-03-16 10:03:35 +00001238 $$->type = WC_FIELD;
Lev Walkinf15320b2004-06-03 03:38:44 +00001239 }
Lev Walkin9d542d22006-03-14 16:31:37 +00001240 | '[' WithSyntaxList ']' {
1241 $$ = asn1p_wsyntx_chunk_fromsyntax($2);
1242 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001243 ;
1244
Lev Walkinf15320b2004-06-03 03:38:44 +00001245ExtensionAndException:
1246 TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00001247 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001248 checkmem($$);
1249 $$->Identifier = strdup("...");
1250 checkmem($$->Identifier);
1251 $$->expr_type = A1TC_EXTENSIBLE;
1252 $$->meta_type = AMT_TYPE;
1253 }
1254 | TOK_ThreeDots '!' DefinedValue {
Lev Walkina9532f42006-09-17 04:52:50 +00001255 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001256 checkmem($$);
1257 $$->Identifier = strdup("...");
1258 checkmem($$->Identifier);
1259 $$->value = $3;
1260 $$->expr_type = A1TC_EXTENSIBLE;
1261 $$->meta_type = AMT_TYPE;
1262 }
1263 | TOK_ThreeDots '!' SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00001264 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001265 checkmem($$);
1266 $$->Identifier = strdup("...");
1267 $$->value = $3;
1268 checkmem($$->Identifier);
1269 $$->expr_type = A1TC_EXTENSIBLE;
1270 $$->meta_type = AMT_TYPE;
1271 }
1272 ;
1273
Lev Walkin59165cf2017-09-11 06:24:45 -07001274Type: TaggedType;
1275
1276TaggedType:
1277 optTag UntaggedType {
1278 $$ = $2;
1279 $$->tag = $1;
1280 }
1281 ;
1282
1283DefinedUntaggedType:
1284 DefinedType optManyConstraints {
1285 $$ = $1;
1286 /*
1287 * Outer constraint for SEQUENCE OF and SET OF applies
1288 * to the inner type.
1289 */
1290 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1291 || $$->expr_type == ASN_CONSTR_SET_OF) {
1292 assert(!TQ_FIRST(&($$->members))->constraints);
1293 TQ_FIRST(&($$->members))->constraints = $2;
1294 } else {
1295 if($$->constraints) {
1296 assert(!$2);
1297 /* Check this : optManyConstraints is not used ?! */
1298 asn1p_constraint_free($2);
1299 } else {
1300 $$->constraints = $2;
1301 }
1302 }
1303 }
1304 ;
1305
1306UntaggedType:
1307 TypeDeclaration optManyConstraints {
1308 $$ = $1;
1309 /*
1310 * Outer constraint for SEQUENCE OF and SET OF applies
1311 * to the inner type.
1312 */
1313 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1314 || $$->expr_type == ASN_CONSTR_SET_OF) {
1315 assert(!TQ_FIRST(&($$->members))->constraints);
1316 TQ_FIRST(&($$->members))->constraints = $2;
1317 } else {
1318 if($$->constraints) {
1319 assert(!$2);
1320 /* Check this : optManyConstraints is not used ?! */
1321 asn1p_constraint_free($2);
1322 } else {
1323 $$->constraints = $2;
1324 }
1325 }
1326 }
1327 ;
1328
1329MaybeIndirectTaggedType:
1330 optTag MaybeIndirectTypeDeclaration optManyConstraints {
Lev Walkinaf120f72004-09-14 02:36:39 +00001331 $$ = $2;
1332 $$->tag = $1;
Lev Walkin070a52d2004-08-22 03:19:54 +00001333 /*
1334 * Outer constraint for SEQUENCE OF and SET OF applies
1335 * to the inner type.
1336 */
1337 if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
1338 || $$->expr_type == ASN_CONSTR_SET_OF) {
1339 assert(!TQ_FIRST(&($$->members))->constraints);
Lev Walkinaf120f72004-09-14 02:36:39 +00001340 TQ_FIRST(&($$->members))->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001341 } else {
1342 if($$->constraints) {
1343 assert(!$2);
Lev Walkin0c686452017-09-07 22:59:36 -07001344 /* Check this : optManyConstraints is not used ?! */
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001345 asn1p_constraint_free($3);
Lev Walkin070a52d2004-08-22 03:19:54 +00001346 } else {
Lev Walkinaf120f72004-09-14 02:36:39 +00001347 $$->constraints = $3;
Lev Walkin070a52d2004-08-22 03:19:54 +00001348 }
1349 }
Lev Walkinef625402005-09-05 05:17:57 +00001350 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001351 ;
Lev Walkinef625402005-09-05 05:17:57 +00001352
1353NSTD_IndirectMarker:
1354 {
1355 $$ = asn1p_as_pointer ? EM_INDIRECT : 0;
1356 asn1p_as_pointer = 0;
Lev Walkin070a52d2004-08-22 03:19:54 +00001357 }
1358 ;
1359
Lev Walkin59165cf2017-09-11 06:24:45 -07001360MaybeIndirectTypeDeclaration:
1361 NSTD_IndirectMarker TypeDeclaration {
1362 $$ = $2;
Lev Walkinef625402005-09-05 05:17:57 +00001363 $$->marker.flags |= $1;
1364
1365 if(($$->marker.flags & EM_INDIRECT)
1366 && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
1367 fprintf(stderr,
1368 "INFO: Directive <ASN1C:RepresentAsPointer> "
Lev Walkind523ea42017-09-06 22:15:08 -07001369 "applied to %s at %s:%d\n",
Lev Walkinef625402005-09-05 05:17:57 +00001370 ASN_EXPR_TYPE2STR($$->expr_type)
1371 ? ASN_EXPR_TYPE2STR($$->expr_type)
1372 : "member",
Lev Walkind523ea42017-09-06 22:15:08 -07001373 ASN_FILENAME, $$->_lineno
Lev Walkinef625402005-09-05 05:17:57 +00001374 );
1375 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001376 }
1377 ;
Lev Walkin4696c742005-08-22 12:23:54 +00001378
Lev Walkin59165cf2017-09-11 06:24:45 -07001379TypeDeclaration:
1380 ConcreteTypeDeclaration
1381 | DefinedType;
1382
1383ConcreteTypeDeclaration:
1384 BuiltinType
Lev Walkinef625402005-09-05 05:17:57 +00001385 | TOK_CHOICE '{' AlternativeTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001386 $$ = $3;
1387 assert($$->expr_type == A1TC_INVALID);
1388 $$->expr_type = ASN_CONSTR_CHOICE;
1389 $$->meta_type = AMT_TYPE;
Lev Walkinf15320b2004-06-03 03:38:44 +00001390 }
Lev Walkinef625402005-09-05 05:17:57 +00001391 | TOK_SEQUENCE '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001392 $$ = $3;
1393 assert($$->expr_type == A1TC_INVALID);
1394 $$->expr_type = ASN_CONSTR_SEQUENCE;
1395 $$->meta_type = AMT_TYPE;
1396 }
Lev Walkinef625402005-09-05 05:17:57 +00001397 | TOK_SET '{' optComponentTypeLists '}' {
Lev Walkin070a52d2004-08-22 03:19:54 +00001398 $$ = $3;
1399 assert($$->expr_type == A1TC_INVALID);
1400 $$->expr_type = ASN_CONSTR_SET;
1401 $$->meta_type = AMT_TYPE;
1402 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001403 | TOK_SEQUENCE optSizeOrConstraint TOK_OF optIdentifier optTag MaybeIndirectTypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001404 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001405 checkmem($$);
1406 $$->constraints = $2;
1407 $$->expr_type = ASN_CONSTR_SEQUENCE_OF;
1408 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001409 $6->Identifier = $4;
1410 $6->tag = $5;
1411 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001412 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001413 | TOK_SET optSizeOrConstraint TOK_OF optIdentifier optTag MaybeIndirectTypeDeclaration {
Lev Walkina9532f42006-09-17 04:52:50 +00001414 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001415 checkmem($$);
1416 $$->constraints = $2;
1417 $$->expr_type = ASN_CONSTR_SET_OF;
1418 $$->meta_type = AMT_TYPE;
Lev Walkin83cac2f2004-09-22 16:03:36 +00001419 $6->Identifier = $4;
1420 $6->tag = $5;
1421 asn1p_expr_add($$, $6);
Lev Walkin070a52d2004-08-22 03:19:54 +00001422 }
1423 | TOK_ANY {
Lev Walkina9532f42006-09-17 04:52:50 +00001424 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001425 checkmem($$);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001426 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001427 $$->meta_type = AMT_TYPE;
1428 }
1429 | TOK_ANY TOK_DEFINED TOK_BY Identifier {
1430 int ret;
Lev Walkina9532f42006-09-17 04:52:50 +00001431 $$ = NEW_EXPR();
Lev Walkin070a52d2004-08-22 03:19:54 +00001432 checkmem($$);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001433 $$->reference = asn1p_ref_new(yylineno, currentModule);
Lev Walkin070a52d2004-08-22 03:19:54 +00001434 ret = asn1p_ref_add_component($$->reference,
1435 $4, RLT_lowercase);
1436 checkmem(ret == 0);
Lev Walkin609ccbb2004-09-04 04:49:21 +00001437 $$->expr_type = ASN_TYPE_ANY;
Lev Walkin070a52d2004-08-22 03:19:54 +00001438 $$->meta_type = AMT_TYPE;
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001439 free($4);
Lev Walkin070a52d2004-08-22 03:19:54 +00001440 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001441 | TOK_INSTANCE TOK_OF ComplexTypeReference {
Lev Walkina9532f42006-09-17 04:52:50 +00001442 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001443 checkmem($$);
1444 $$->reference = $3;
1445 $$->expr_type = A1TC_INSTANCE;
1446 $$->meta_type = AMT_TYPE;
1447 }
1448 ;
1449
1450/*
1451 * A type name consisting of several components.
1452 * === EXAMPLE ===
1453 * === EOF ===
1454 */
1455ComplexTypeReference:
1456 TOK_typereference {
1457 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001458 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001459 checkmem($$);
1460 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1461 checkmem(ret == 0);
1462 free($1);
1463 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001464 | TOK_capitalreference {
1465 int ret;
1466 $$ = asn1p_ref_new(yylineno, currentModule);
1467 checkmem($$);
1468 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1469 free($1);
1470 checkmem(ret == 0);
1471 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001472 | TOK_typereference '.' TypeRefName {
1473 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001474 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001475 checkmem($$);
1476 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1477 checkmem(ret == 0);
1478 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1479 checkmem(ret == 0);
1480 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001481 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001482 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001483 | TOK_capitalreference '.' TypeRefName {
Lev Walkin9c974182004-09-15 11:59:51 +00001484 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001485 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c974182004-09-15 11:59:51 +00001486 checkmem($$);
1487 ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
1488 checkmem(ret == 0);
1489 ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
1490 checkmem(ret == 0);
1491 free($1);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001492 free($3);
Lev Walkin9c974182004-09-15 11:59:51 +00001493 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001494 | TOK_capitalreference '.' ComplexTypeReferenceAmpList {
Lev Walkinf15320b2004-06-03 03:38:44 +00001495 int ret;
1496 $$ = $3;
1497 ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS);
1498 free($1);
1499 checkmem(ret == 0);
1500 /*
1501 * Move the last element infront.
1502 */
1503 {
1504 struct asn1p_ref_component_s tmp_comp;
1505 tmp_comp = $$->components[$$->comp_count-1];
1506 memmove(&$$->components[1],
1507 &$$->components[0],
1508 sizeof($$->components[0])
1509 * ($$->comp_count - 1));
1510 $$->components[0] = tmp_comp;
1511 }
1512 }
1513 ;
1514
1515ComplexTypeReferenceAmpList:
1516 ComplexTypeReferenceElement {
1517 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001518 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001519 checkmem($$);
1520 ret = asn1p_ref_add_component($$, $1.name, $1.lex_type);
1521 free($1.name);
1522 checkmem(ret == 0);
1523 }
1524 | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement {
1525 int ret;
1526 $$ = $1;
1527 ret = asn1p_ref_add_component($$, $3.name, $3.lex_type);
1528 free($3.name);
1529 checkmem(ret == 0);
1530 }
1531 ;
1532
Lev Walkind370e9f2006-03-16 10:03:35 +00001533ComplexTypeReferenceElement: PrimitiveFieldReference;
Lev Walkinf15320b2004-06-03 03:38:44 +00001534
Lev Walkind370e9f2006-03-16 10:03:35 +00001535PrimitiveFieldReference:
Lev Walkinf15320b2004-06-03 03:38:44 +00001536 /* "&Type1" */
1537 TOK_typefieldreference {
1538 $$.lex_type = RLT_AmpUppercase;
1539 $$.name = $1;
1540 }
1541 /* "&id" */
1542 | TOK_valuefieldreference {
1543 $$.lex_type = RLT_Amplowercase;
1544 $$.name = $1;
1545 }
1546 ;
1547
1548
Lev Walkin9c2285a2006-03-09 08:49:26 +00001549FieldName:
1550 /* "&Type1" */
1551 TOK_typefieldreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001552 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001553 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001554 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001555 }
1556 | FieldName '.' TOK_typefieldreference {
1557 $$ = $$;
1558 asn1p_ref_add_component($$, $3, RLT_AmpUppercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001559 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001560 }
1561 | FieldName '.' TOK_valuefieldreference {
1562 $$ = $$;
1563 asn1p_ref_add_component($$, $3, RLT_Amplowercase);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001564 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001565 }
1566 ;
1567
1568DefinedObjectClass:
1569 TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001570 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001571 asn1p_ref_add_component($$, $1, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001572 free($1);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001573 }
Lev Walkin54868752006-03-09 09:08:49 +00001574/*
Lev Walkin9c2285a2006-03-09 08:49:26 +00001575 | TypeRefName '.' TOK_capitalreference {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001576 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001577 asn1p_ref_add_component($$, $1, RLT_AmpUppercase);
1578 asn1p_ref_add_component($$, $3, RLT_CAPITALS);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001579 free($1);
1580 free($3);
Lev Walkin9c2285a2006-03-09 08:49:26 +00001581 }
Lev Walkin54868752006-03-09 09:08:49 +00001582*/
Lev Walkin9c2285a2006-03-09 08:49:26 +00001583 ;
1584
1585
Lev Walkinf15320b2004-06-03 03:38:44 +00001586/*
1587 * === EXAMPLE ===
1588 * value INTEGER ::= 1
1589 * === EOF ===
1590 */
Lev Walkinc6ab03c2006-10-21 05:54:49 +00001591ValueAssignment:
1592 Identifier Type TOK_PPEQ Value {
Lev Walkinf15320b2004-06-03 03:38:44 +00001593 $$ = $2;
1594 assert($$->Identifier == NULL);
1595 $$->Identifier = $1;
1596 $$->meta_type = AMT_VALUE;
1597 $$->value = $4;
1598 }
1599 ;
1600
Lev Walkin9c974182004-09-15 11:59:51 +00001601Value:
Lev Walkin0c0bca62006-03-21 04:48:15 +00001602 SimpleValue
1603 | DefinedValue
Lev Walkinbf979152017-09-07 23:36:11 -07001604 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque {
Lev Walkinf15320b2004-06-03 03:38:44 +00001605 $$ = asn1p_value_frombuf($3.buf, $3.len, 0);
1606 checkmem($$);
1607 $$->type = ATV_UNPARSED;
1608 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001609 ;
1610
1611SimpleValue:
1612 TOK_NULL {
Lev Walkin9c974182004-09-15 11:59:51 +00001613 $$ = asn1p_value_fromint(0);
1614 checkmem($$);
1615 $$->type = ATV_NULL;
1616 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001617 | TOK_FALSE {
Lev Walkin9c974182004-09-15 11:59:51 +00001618 $$ = asn1p_value_fromint(0);
1619 checkmem($$);
1620 $$->type = ATV_FALSE;
1621 }
1622 | TOK_TRUE {
Lev Walkin59165cf2017-09-11 06:24:45 -07001623 $$ = asn1p_value_fromint(1);
Lev Walkin9c974182004-09-15 11:59:51 +00001624 checkmem($$);
1625 $$->type = ATV_TRUE;
1626 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001627 | SignedNumber
1628 | RealValue
1629 | RestrictedCharacterStringValue
1630 | BitStringValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001631 ;
1632
1633DefinedValue:
Lev Walkin59165cf2017-09-11 06:24:45 -07001634 IdentifierAsValue
Lev Walkinf15320b2004-06-03 03:38:44 +00001635 | TypeRefName '.' Identifier {
1636 asn1p_ref_t *ref;
1637 int ret;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001638 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001639 checkmem(ref);
1640 ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
1641 checkmem(ret == 0);
1642 ret = asn1p_ref_add_component(ref, $3, RLT_lowercase);
1643 checkmem(ret == 0);
1644 $$ = asn1p_value_fromref(ref, 0);
1645 checkmem($$);
1646 free($1);
1647 free($3);
1648 }
1649 ;
1650
Lev Walkin1e448d32005-03-24 14:26:38 +00001651
1652RestrictedCharacterStringValue:
1653 TOK_cstring {
1654 $$ = asn1p_value_frombuf($1.buf, $1.len, 0);
1655 checkmem($$);
1656 }
Lev Walkind9574ae2005-03-24 16:22:35 +00001657 | TOK_tuple {
1658 $$ = asn1p_value_fromint($1);
1659 checkmem($$);
1660 $$->type = ATV_TUPLE;
1661 }
1662 | TOK_quadruple {
1663 $$ = asn1p_value_fromint($1);
1664 checkmem($$);
1665 $$->type = ATV_QUADRUPLE;
1666 }
Lev Walkin1e448d32005-03-24 14:26:38 +00001667 ;
1668
Lev Walkinf15320b2004-06-03 03:38:44 +00001669Opaque:
Lev Walkinbf979152017-09-07 23:36:11 -07001670 OpaqueFirstToken {
Lev Walkin1893ddf2005-03-20 14:28:32 +00001671 $$.len = $1.len + 1;
Lev Walkinbf979152017-09-07 23:36:11 -07001672 $$.buf = malloc(1 + $$.len + 1);
Lev Walkinf15320b2004-06-03 03:38:44 +00001673 checkmem($$.buf);
1674 $$.buf[0] = '{';
Lev Walkin1893ddf2005-03-20 14:28:32 +00001675 memcpy($$.buf + 1, $1.buf, $1.len);
Lev Walkinf15320b2004-06-03 03:38:44 +00001676 $$.buf[$$.len] = '\0';
1677 free($1.buf);
Lev Walkinbf979152017-09-07 23:36:11 -07001678 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001679 | Opaque TOK_opaque {
1680 int newsize = $1.len + $2.len;
1681 char *p = malloc(newsize + 1);
1682 checkmem(p);
1683 memcpy(p , $1.buf, $1.len);
1684 memcpy(p + $1.len, $2.buf, $2.len);
1685 p[newsize] = '\0';
1686 free($1.buf);
1687 free($2.buf);
1688 $$.buf = p;
1689 $$.len = newsize;
1690 }
1691 ;
1692
Lev Walkinbf979152017-09-07 23:36:11 -07001693OpaqueFirstToken:
1694 TOK_opaque
1695 | Identifier {
1696 $$.len = strlen($1);
1697 $$.buf = $1;
1698 };
1699
Lev Walkinf15320b2004-06-03 03:38:44 +00001700BasicTypeId:
1701 TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
1702 | TOK_NULL { $$ = ASN_BASIC_NULL; }
1703 | TOK_REAL { $$ = ASN_BASIC_REAL; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001704 | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
1705 | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
1706 | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
1707 | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; }
1708 | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; }
1709 | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
1710 | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
1711 | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001712 | BasicString
1713 | BasicTypeId_UniverationCompatible
Lev Walkinf15320b2004-06-03 03:38:44 +00001714 ;
1715
1716/*
1717 * A type identifier which may be used with "{ a(1), b(2) }" clause.
1718 */
1719BasicTypeId_UniverationCompatible:
1720 TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
Lev Walkina25584b2017-10-01 13:43:17 -07001721 | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; }
Lev Walkinf15320b2004-06-03 03:38:44 +00001722 | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
1723 ;
1724
Lev Walkin59165cf2017-09-11 06:24:45 -07001725BuiltinType:
Lev Walkinf15320b2004-06-03 03:38:44 +00001726 BasicTypeId {
Lev Walkina9532f42006-09-17 04:52:50 +00001727 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00001728 checkmem($$);
1729 $$->expr_type = $1;
1730 $$->meta_type = AMT_TYPE;
1731 }
Lev Walkinbe518fa2017-09-07 02:05:28 -07001732 | TOK_INTEGER '{' NamedNumberList '}' {
1733 $$ = $3;
1734 $$->expr_type = ASN_BASIC_INTEGER;
1735 $$->meta_type = AMT_TYPE;
1736 }
1737 | TOK_ENUMERATED '{' Enumerations '}' {
1738 $$ = $3;
1739 $$->expr_type = ASN_BASIC_ENUMERATED;
1740 $$->meta_type = AMT_TYPE;
1741 }
1742 | TOK_BIT TOK_STRING '{' NamedBitList '}' {
1743 $$ = $4;
1744 $$->expr_type = ASN_BASIC_BIT_STRING;
1745 $$->meta_type = AMT_TYPE;
1746 }
1747 | TOK_ExtValue_BIT_STRING '{' IdentifierList '}' {
1748 $$ = $3;
1749 $$->expr_type = ASN_BASIC_BIT_STRING;
1750 $$->meta_type = AMT_TYPE;
1751 }
1752 | TOK_ExtValue_BIT_STRING '{' '}' {
1753 $$ = NEW_EXPR();
1754 checkmem($$);
1755 $$->expr_type = ASN_BASIC_BIT_STRING;
1756 $$->meta_type = AMT_TYPE;
1757 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001758 ;
1759
1760BasicString:
1761 TOK_BMPString { $$ = ASN_STRING_BMPString; }
1762 | TOK_GeneralString {
1763 $$ = ASN_STRING_GeneralString;
Lev Walkin9c974182004-09-15 11:59:51 +00001764 fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001765 }
1766 | TOK_GraphicString {
1767 $$ = ASN_STRING_GraphicString;
Lev Walkin9c974182004-09-15 11:59:51 +00001768 fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001769 }
1770 | TOK_IA5String { $$ = ASN_STRING_IA5String; }
1771 | TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
1772 | TOK_NumericString { $$ = ASN_STRING_NumericString; }
1773 | TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
1774 | TOK_T61String {
1775 $$ = ASN_STRING_T61String;
Lev Walkin9c974182004-09-15 11:59:51 +00001776 fprintf(stderr, "WARNING: T61String is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001777 }
1778 | TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
1779 | TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
1780 | TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
1781 | TOK_VideotexString {
1782 $$ = ASN_STRING_VideotexString;
Lev Walkin9c974182004-09-15 11:59:51 +00001783 fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
Lev Walkinf15320b2004-06-03 03:38:44 +00001784 }
1785 | TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
1786 | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
1787 ;
1788
Lev Walkind2ea1de2004-08-20 13:25:29 +00001789
Lev Walkinf15320b2004-06-03 03:38:44 +00001790/*
1791 * Data type constraints.
1792 */
Lev Walkinf1727152006-09-21 01:50:37 +00001793UnionMark: '|' | TOK_UNION;
1794IntersectionMark: '^' | TOK_INTERSECTION;
Lev Walkinf15320b2004-06-03 03:38:44 +00001795
Lev Walkind523ea42017-09-06 22:15:08 -07001796/* empty | Constraint */
Lev Walkin0c686452017-09-07 22:59:36 -07001797optConstraint:
Lev Walkinf59d0752004-08-18 04:59:12 +00001798 { $$ = 0; }
Lev Walkind523ea42017-09-06 22:15:08 -07001799 | Constraint;
Lev Walkind2ea1de2004-08-20 13:25:29 +00001800
Lev Walkin0c686452017-09-07 22:59:36 -07001801/* empty | Constraint... */
1802optManyConstraints:
1803 { $$ = 0; }
1804 | ManyConstraints;
1805
Lev Walkind523ea42017-09-06 22:15:08 -07001806/* empty | Constraint | SIZE(...) */
Lev Walkin0c686452017-09-07 22:59:36 -07001807optSizeOrConstraint:
Lev Walkind523ea42017-09-06 22:15:08 -07001808 { $$ = 0; }
1809 | Constraint
Lev Walkin0c686452017-09-07 22:59:36 -07001810 | SizeConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +00001811 ;
1812
Lev Walkind523ea42017-09-06 22:15:08 -07001813Constraint:
Lev Walkin0c686452017-09-07 22:59:36 -07001814 '(' ConstraintSpec ')' {
1815 CONSTRAINT_INSERT($$, ACT_CA_SET, $2, 0);
Lev Walkind523ea42017-09-06 22:15:08 -07001816 }
1817 ;
1818
Lev Walkin0c686452017-09-07 22:59:36 -07001819ManyConstraints:
1820 Constraint
1821 | ManyConstraints Constraint {
1822 if($2->type == ACT_CA_SET && $2->el_count == 1) {
1823 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $2->elements[0]);
1824 } else {
1825 CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $2);
1826 }
Lev Walkinf59d0752004-08-18 04:59:12 +00001827 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001828 ;
1829
Lev Walkind523ea42017-09-06 22:15:08 -07001830ConstraintSpec: SubtypeConstraint | GeneralConstraint;
1831
1832SubtypeConstraint: ElementSetSpecs;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001833
Lev Walkinf59d0752004-08-18 04:59:12 +00001834ElementSetSpecs:
Lev Walkin5045dfa2006-03-21 09:41:28 +00001835 TOK_ThreeDots {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001836 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5045dfa2006-03-21 09:41:28 +00001837 $$->type = ACT_EL_EXT;
1838 }
Lev Walkin0c686452017-09-07 22:59:36 -07001839 | ElementSetSpec
1840 | ElementSetSpec ',' TOK_ThreeDots {
1841 asn1p_constraint_t *ct;
1842 ct = asn1p_constraint_new(yylineno, currentModule);
1843 ct->type = ACT_EL_EXT;
1844 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1845 }
1846 | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec {
1847 asn1p_constraint_t *ct;
1848 ct = asn1p_constraint_new(yylineno, currentModule);
1849 ct->type = ACT_EL_EXT;
1850 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
1851 ct = $$;
1852 CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5);
1853 }
1854;
Lev Walkinf15320b2004-06-03 03:38:44 +00001855
Lev Walkinf59d0752004-08-18 04:59:12 +00001856ElementSetSpec:
Lev Walkinf1727152006-09-21 01:50:37 +00001857 Unions
Lev Walkin0c686452017-09-07 22:59:36 -07001858 | TOK_ALL TOK_EXCEPT Elements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001859 CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0);
Lev Walkin1e448d32005-03-24 14:26:38 +00001860 }
Lev Walkinf1727152006-09-21 01:50:37 +00001861 ;
1862
1863Unions:
1864 Intersections
1865 | Unions UnionMark Intersections {
Lev Walkin2c14a692005-08-12 10:08:45 +00001866 CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001867 }
Lev Walkinf1727152006-09-21 01:50:37 +00001868 ;
1869
1870Intersections:
1871 IntersectionElements
1872 | Intersections IntersectionMark IntersectionElements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001873 CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001874 }
Lev Walkinf1727152006-09-21 01:50:37 +00001875 ;
1876
1877
1878IntersectionElements:
Lev Walkin0c686452017-09-07 22:59:36 -07001879 Elements
1880 | Elements TOK_EXCEPT Elements {
Lev Walkin2c14a692005-08-12 10:08:45 +00001881 CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00001882 }
1883 ;
1884
Lev Walkin0c686452017-09-07 22:59:36 -07001885Elements:
1886 SubtypeElements
1887 | '(' ElementSetSpec ')' {
1888 int ret;
1889 $$ = asn1p_constraint_new(yylineno, currentModule);
1890 checkmem($$);
1891 $$->type = ACT_CA_SET;
1892 ret = asn1p_constraint_insert($$, $2);
1893 checkmem(ret == 0);
1894 }
1895 ;
1896
1897SubtypeElements:
1898 SingleValue {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001899 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00001900 checkmem($$);
1901 $$->type = ACT_EL_VALUE;
1902 $$->value = $1;
1903 }
Lev Walkinff7dd142005-03-20 12:58:00 +00001904 | ContainedSubtype {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001905 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinff7dd142005-03-20 12:58:00 +00001906 checkmem($$);
1907 $$->type = ACT_EL_TYPE;
1908 $$->containedSubtype = $1;
1909 }
Lev Walkin0c686452017-09-07 22:59:36 -07001910 | PermittedAlphabet /* FROM ... */
1911 | SizeConstraint /* SIZE ... */
1912 /* | TypeConstraint is via ContainedSubtype */
1913 | InnerTypeConstraints /* WITH COMPONENT[S] ... */
1914 | PatternConstraint /* PATTERN ... */
1915 | ValueRange
Lev Walkin5c541f12006-10-18 18:40:14 +00001916 ;
1917
Lev Walkin0c686452017-09-07 22:59:36 -07001918
1919PermittedAlphabet:
1920 TOK_FROM Constraint {
1921 CONSTRAINT_INSERT($$, ACT_CT_FROM, $2, 0);
1922 };
1923
1924SizeConstraint:
1925 TOK_SIZE Constraint {
1926 CONSTRAINT_INSERT($$, ACT_CT_SIZE, $2, 0);
1927 };
1928
Lev Walkin5c541f12006-10-18 18:40:14 +00001929PatternConstraint:
1930 TOK_PATTERN TOK_cstring {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001931 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001932 $$->type = ACT_CT_PATTERN;
1933 $$->value = asn1p_value_frombuf($2.buf, $2.len, 0);
1934 }
1935 | TOK_PATTERN Identifier {
1936 asn1p_ref_t *ref;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001937 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001938 $$->type = ACT_CT_PATTERN;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001939 ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkin5c541f12006-10-18 18:40:14 +00001940 asn1p_ref_add_component(ref, $2, RLT_lowercase);
1941 $$->value = asn1p_value_fromref(ref, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001942 free($2);
Lev Walkin5c541f12006-10-18 18:40:14 +00001943 }
Lev Walkinf15320b2004-06-03 03:38:44 +00001944 ;
1945
Lev Walkin0c686452017-09-07 22:59:36 -07001946ValueRange:
1947 LowerEndValue ConstraintRangeSpec UpperEndValue {
1948 $$ = asn1p_constraint_new(yylineno, currentModule);
1949 checkmem($$);
1950 $$->type = $2;
1951 $$->range_start = $1;
1952 $$->range_stop = $3;
1953 };
1954
1955LowerEndValue:
1956 SingleValue
1957 | TOK_MIN {
1958 $$ = asn1p_value_fromint(-123);
1959 $$->type = ATV_MIN;
1960 };
1961
1962UpperEndValue:
1963 SingleValue
1964 | TOK_MAX {
1965 $$ = asn1p_value_fromint(321);
1966 $$->type = ATV_MAX;
1967 };
Lev Walkinf15320b2004-06-03 03:38:44 +00001968
Lev Walkin59165cf2017-09-11 06:24:45 -07001969SingleValue: Value;
Lev Walkinff7dd142005-03-20 12:58:00 +00001970
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001971BitStringValue:
1972 TOK_bstring {
1973 $$ = _convert_bitstring2binary($1, 'B');
1974 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001975 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001976 }
1977 | TOK_hstring {
1978 $$ = _convert_bitstring2binary($1, 'H');
1979 checkmem($$);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08001980 free($1);
Lev Walkin1c8d5aa2006-10-27 05:37:39 +00001981 }
1982 ;
1983
Lev Walkinff7dd142005-03-20 12:58:00 +00001984ContainedSubtype:
Lev Walkin59165cf2017-09-11 06:24:45 -07001985 TOK_INCLUDES Type {
Lev Walkin0c686452017-09-07 22:59:36 -07001986 $$ = asn1p_value_fromtype($2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08001987 checkmem($$);
Lev Walkined409e22017-09-26 18:07:40 -07001988 asn1p_expr_free($2);
Lev Walkind523ea42017-09-06 22:15:08 -07001989 }
Lev Walkin59165cf2017-09-11 06:24:45 -07001990 /* Can't put Type here because of conflicts. Simplified subset */
1991 | DefinedUntaggedType {
1992 $$ = asn1p_value_fromtype($1);
1993 checkmem($$);
Lev Walkined409e22017-09-26 18:07:40 -07001994 asn1p_expr_free($1);
Lev Walkin59165cf2017-09-11 06:24:45 -07001995 }
Lev Walkin0c686452017-09-07 22:59:36 -07001996 ;
1997
Lev Walkind523ea42017-09-06 22:15:08 -07001998/*
1999 * X.680 08/2015
2000 * #51.8.5
2001 */
Lev Walkin0c686452017-09-07 22:59:36 -07002002InnerTypeConstraints:
Lev Walkind523ea42017-09-06 22:15:08 -07002003 TOK_WITH TOK_COMPONENT SingleTypeConstraint {
Lev Walkin2c14a692005-08-12 10:08:45 +00002004 CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
Lev Walkine596bf02005-03-28 15:01:27 +00002005 }
Lev Walkind523ea42017-09-06 22:15:08 -07002006 | TOK_WITH TOK_COMPONENTS MultipleTypeConstraints {
2007 assert($3->type == ACT_CA_CSV);
2008 $3->type = ACT_CT_WCOMPS;
2009 $$ = $3;
Lev Walkinf15320b2004-06-03 03:38:44 +00002010 }
2011 ;
Lev Walkind523ea42017-09-06 22:15:08 -07002012SingleTypeConstraint: Constraint;
2013MultipleTypeConstraints: FullSpecification | PartialSpecification;
2014FullSpecification: '{' TypeConstraints '}' { $$ = $2; };
2015PartialSpecification:
2016 '{' TOK_ThreeDots ',' TypeConstraints '}' {
2017 assert($4->type == ACT_CA_CSV);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002018 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkind523ea42017-09-06 22:15:08 -07002019 $$->type = ACT_CA_CSV;
2020 asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002021 checkmem($$);
Lev Walkind523ea42017-09-06 22:15:08 -07002022 ct->type = ACT_EL_EXT;
2023 asn1p_constraint_insert($$, ct);
2024 for(unsigned i = 0; i < $4->el_count; i++) {
2025 asn1p_constraint_insert($$, $4->elements[i]);
2026 }
2027 };
2028TypeConstraints:
2029 NamedConstraint {
2030 $$ = asn1p_constraint_new(yylineno, currentModule);
2031 $$->type = ACT_CA_CSV;
2032 asn1p_constraint_insert($$, $1);
2033 }
2034 | TypeConstraints ',' NamedConstraint {
2035 $$ = $1;
2036 asn1p_constraint_insert($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002037 }
2038 ;
Lev Walkind523ea42017-09-06 22:15:08 -07002039NamedConstraint:
Lev Walkin0c686452017-09-07 22:59:36 -07002040 IdentifierAsValue optConstraint optPresenceConstraint {
Lev Walkind523ea42017-09-06 22:15:08 -07002041 $$ = asn1p_constraint_new(yylineno, currentModule);
2042 checkmem($$);
2043 $$->type = ACT_EL_VALUE;
2044 $$->value = $1;
2045 if($2) asn1p_constraint_insert($$, $2);
2046 $$->presence = $3;
2047 }
2048 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002049
2050/*
Lev Walkind523ea42017-09-06 22:15:08 -07002051 * presence constraint for NamedConstraint
Lev Walkinf15320b2004-06-03 03:38:44 +00002052 */
2053optPresenceConstraint:
2054 { $$ = ACPRES_DEFAULT; }
2055 | PresenceConstraint { $$ = $1; }
2056 ;
2057
2058PresenceConstraint:
2059 TOK_PRESENT {
2060 $$ = ACPRES_PRESENT;
2061 }
2062 | TOK_ABSENT {
2063 $$ = ACPRES_ABSENT;
2064 }
2065 | TOK_OPTIONAL {
2066 $$ = ACPRES_OPTIONAL;
2067 }
2068 ;
2069
Lev Walkina9532f42006-09-17 04:52:50 +00002070
2071/* X.682 */
2072GeneralConstraint:
2073 UserDefinedConstraint
2074 | TableConstraint
2075 | ContentsConstraint
2076 ;
2077
2078UserDefinedConstraint:
2079 TOK_CONSTRAINED TOK_BY '{'
2080 { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002081 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002082 checkmem($$);
2083 $$->type = ACT_CT_CTDBY;
2084 $$->value = asn1p_value_frombuf($5.buf, $5.len, 0);
2085 checkmem($$->value);
2086 $$->value->type = ATV_UNPARSED;
2087 }
2088 ;
2089
2090ContentsConstraint:
2091 TOK_CONTAINING Type {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002092 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkina9532f42006-09-17 04:52:50 +00002093 $$->type = ACT_CT_CTNG;
2094 $$->value = asn1p_value_fromtype($2);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002095 asn1p_expr_free($2);
Lev Walkina9532f42006-09-17 04:52:50 +00002096 }
2097 ;
2098
2099ConstraintRangeSpec:
2100 TOK_TwoDots { $$ = ACT_EL_RANGE; }
2101 | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; }
2102 | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; }
2103 | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; }
2104 ;
Lev Walkinf15320b2004-06-03 03:38:44 +00002105TableConstraint:
2106 SimpleTableConstraint {
2107 $$ = $1;
2108 }
2109 | ComponentRelationConstraint {
2110 $$ = $1;
2111 }
2112 ;
2113
2114/*
2115 * "{ExtensionSet}"
2116 */
2117SimpleTableConstraint:
2118 '{' TypeRefName '}' {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002119 asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002120 asn1p_constraint_t *ct;
2121 int ret;
2122 ret = asn1p_ref_add_component(ref, $2, 0);
2123 checkmem(ret == 0);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002124 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002125 checkmem($$);
2126 ct->type = ACT_EL_VALUE;
2127 ct->value = asn1p_value_fromref(ref, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002128 CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0);
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002129 free($2);
Lev Walkinf15320b2004-06-03 03:38:44 +00002130 }
2131 ;
2132
2133ComponentRelationConstraint:
2134 SimpleTableConstraint '{' AtNotationList '}' {
Lev Walkin2c14a692005-08-12 10:08:45 +00002135 CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002136 }
2137 ;
2138
2139AtNotationList:
2140 AtNotationElement {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002141 $$ = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002142 checkmem($$);
2143 $$->type = ACT_EL_VALUE;
2144 $$->value = asn1p_value_fromref($1, 0);
2145 }
2146 | AtNotationList ',' AtNotationElement {
2147 asn1p_constraint_t *ct;
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002148 ct = asn1p_constraint_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002149 checkmem(ct);
2150 ct->type = ACT_EL_VALUE;
2151 ct->value = asn1p_value_fromref($3, 0);
Lev Walkin2c14a692005-08-12 10:08:45 +00002152 CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct);
Lev Walkinf15320b2004-06-03 03:38:44 +00002153 }
2154 ;
2155
2156/*
2157 * @blah
2158 */
2159AtNotationElement:
2160 '@' ComponentIdList {
2161 char *p = malloc(strlen($2) + 2);
2162 int ret;
2163 *p = '@';
2164 strcpy(p + 1, $2);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002165 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002166 ret = asn1p_ref_add_component($$, p, 0);
2167 checkmem(ret == 0);
2168 free(p);
2169 free($2);
2170 }
2171 | '@' '.' ComponentIdList {
2172 char *p = malloc(strlen($3) + 3);
2173 int ret;
2174 p[0] = '@';
2175 p[1] = '.';
2176 strcpy(p + 2, $3);
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +08002177 $$ = asn1p_ref_new(yylineno, currentModule);
Lev Walkinf15320b2004-06-03 03:38:44 +00002178 ret = asn1p_ref_add_component($$, p, 0);
2179 checkmem(ret == 0);
2180 free(p);
2181 free($3);
2182 }
2183 ;
2184
2185/* identifier "." ... */
2186ComponentIdList:
2187 Identifier {
2188 $$ = $1;
2189 }
2190 | ComponentIdList '.' Identifier {
2191 int l1 = strlen($1);
2192 int l3 = strlen($3);
2193 $$ = malloc(l1 + 1 + l3 + 1);
2194 memcpy($$, $1, l1);
2195 $$[l1] = '.';
2196 memcpy($$ + l1 + 1, $3, l3);
2197 $$[l1 + 1 + l3] = '\0';
Bi-Ruei, Chiu3dcf05b2017-05-04 21:45:05 +08002198 free($1);
2199 free($3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002200 }
2201 ;
2202
2203
2204
2205/*
2206 * MARKERS
2207 */
2208
2209optMarker:
Lev Walkin9c974182004-09-15 11:59:51 +00002210 {
2211 $$.flags = EM_NOMARK;
2212 $$.default_value = 0;
2213 }
Lev Walkinf15320b2004-06-03 03:38:44 +00002214 | Marker { $$ = $1; }
2215 ;
2216
2217Marker:
2218 TOK_OPTIONAL {
Lev Walkin70853052005-11-26 11:21:55 +00002219 $$.flags = EM_OPTIONAL | EM_INDIRECT;
Lev Walkin9c974182004-09-15 11:59:51 +00002220 $$.default_value = 0;
Lev Walkinf15320b2004-06-03 03:38:44 +00002221 }
Lev Walkin9c974182004-09-15 11:59:51 +00002222 | TOK_DEFAULT Value {
2223 $$.flags = EM_DEFAULT;
2224 $$.default_value = $2;
Lev Walkinf15320b2004-06-03 03:38:44 +00002225 }
2226 ;
2227
Lev Walkinbe518fa2017-09-07 02:05:28 -07002228IdentifierList:
2229 IdentifierElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002230 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002231 checkmem($$);
Lev Walkinbe518fa2017-09-07 02:05:28 -07002232 asn1p_expr_add($$, $1);
2233 }
2234 | IdentifierList ',' IdentifierElement {
2235 $$ = $1;
2236 asn1p_expr_add($$, $3);
2237 };
2238
2239IdentifierElement:
2240 Identifier {
2241 $$ = NEW_EXPR();
2242 checkmem($$);
2243 $$->expr_type = A1TC_UNIVERVAL;
2244 $$->meta_type = AMT_VALUE;
2245 $$->Identifier = $1;
2246 }
2247
2248NamedNumberList:
2249 NamedNumber {
2250 $$ = NEW_EXPR();
2251 checkmem($$);
2252 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002253 }
Lev Walkinbe518fa2017-09-07 02:05:28 -07002254 | NamedNumberList ',' NamedNumber {
2255 $$ = $1;
2256 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002257 }
2258 ;
2259
Lev Walkinbe518fa2017-09-07 02:05:28 -07002260NamedNumber:
2261 Identifier '(' SignedNumber ')' {
2262 $$ = NEW_EXPR();
2263 checkmem($$);
2264 $$->expr_type = A1TC_UNIVERVAL;
2265 $$->meta_type = AMT_VALUE;
2266 $$->Identifier = $1;
2267 $$->value = $3;
2268 }
2269 | Identifier '(' DefinedValue ')' {
2270 $$ = NEW_EXPR();
2271 checkmem($$);
2272 $$->expr_type = A1TC_UNIVERVAL;
2273 $$->meta_type = AMT_VALUE;
2274 $$->Identifier = $1;
2275 $$->value = $3;
2276 };
2277
2278NamedBitList:
2279 NamedBit {
2280 $$ = NEW_EXPR();
2281 checkmem($$);
2282 asn1p_expr_add($$, $1);
2283 }
2284 | NamedBitList ',' NamedBit {
2285 $$ = $1;
2286 asn1p_expr_add($$, $3);
2287 }
2288 ;
2289
2290NamedBit:
2291 Identifier '(' TOK_number ')' {
2292 $$ = NEW_EXPR();
2293 checkmem($$);
2294 $$->expr_type = A1TC_UNIVERVAL;
2295 $$->meta_type = AMT_VALUE;
2296 $$->Identifier = $1;
2297 $$->value = asn1p_value_fromint($3);
2298 }
2299 | Identifier '(' DefinedValue ')' {
2300 $$ = NEW_EXPR();
2301 checkmem($$);
2302 $$->expr_type = A1TC_UNIVERVAL;
2303 $$->meta_type = AMT_VALUE;
2304 $$->Identifier = $1;
2305 $$->value = $3;
2306 };
2307
2308Enumerations:
2309 UniverationList {
2310 $$ = $1;
2311 asn1p_expr_t *first_memb = TQ_FIRST(&($$->members));
2312 if(first_memb) {
2313 if(first_memb->expr_type == A1TC_EXTENSIBLE) {
2314 return yyerror(
2315 "The ENUMERATION cannot start with extension (...).");
2316 }
2317 } else {
2318 return yyerror(
2319 "The ENUMERATION list cannot be empty.");
2320 }
2321 }
2322
Lev Walkinf15320b2004-06-03 03:38:44 +00002323UniverationList:
2324 UniverationElement {
Lev Walkina9532f42006-09-17 04:52:50 +00002325 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002326 checkmem($$);
Lev Walkin1004aa92004-09-08 00:28:11 +00002327 asn1p_expr_add($$, $1);
Lev Walkinf15320b2004-06-03 03:38:44 +00002328 }
2329 | UniverationList ',' UniverationElement {
2330 $$ = $1;
Lev Walkin1004aa92004-09-08 00:28:11 +00002331 asn1p_expr_add($$, $3);
Lev Walkinf15320b2004-06-03 03:38:44 +00002332 }
2333 ;
2334
2335UniverationElement:
2336 Identifier {
Lev Walkina9532f42006-09-17 04:52:50 +00002337 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002338 checkmem($$);
2339 $$->expr_type = A1TC_UNIVERVAL;
2340 $$->meta_type = AMT_VALUE;
2341 $$->Identifier = $1;
2342 }
2343 | Identifier '(' SignedNumber ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002344 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002345 checkmem($$);
2346 $$->expr_type = A1TC_UNIVERVAL;
2347 $$->meta_type = AMT_VALUE;
2348 $$->Identifier = $1;
2349 $$->value = $3;
2350 }
2351 | Identifier '(' DefinedValue ')' {
Lev Walkina9532f42006-09-17 04:52:50 +00002352 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002353 checkmem($$);
2354 $$->expr_type = A1TC_UNIVERVAL;
2355 $$->meta_type = AMT_VALUE;
2356 $$->Identifier = $1;
2357 $$->value = $3;
2358 }
2359 | SignedNumber {
Lev Walkina9532f42006-09-17 04:52:50 +00002360 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002361 checkmem($$);
2362 $$->expr_type = A1TC_UNIVERVAL;
2363 $$->meta_type = AMT_VALUE;
2364 $$->value = $1;
2365 }
2366 | TOK_ThreeDots {
Lev Walkina9532f42006-09-17 04:52:50 +00002367 $$ = NEW_EXPR();
Lev Walkinf15320b2004-06-03 03:38:44 +00002368 checkmem($$);
2369 $$->Identifier = strdup("...");
2370 checkmem($$->Identifier);
2371 $$->expr_type = A1TC_EXTENSIBLE;
2372 $$->meta_type = AMT_VALUE;
2373 }
2374 ;
2375
2376SignedNumber:
2377 TOK_number {
2378 $$ = asn1p_value_fromint($1);
2379 checkmem($$);
2380 }
2381 | TOK_number_negative {
2382 $$ = asn1p_value_fromint($1);
2383 checkmem($$);
2384 }
2385 ;
2386
Lev Walkinadf863f2006-09-05 16:18:34 +00002387RealValue:
Lev Walkin59165cf2017-09-11 06:24:45 -07002388 TOK_realnumber {
Lev Walkinadf863f2006-09-05 16:18:34 +00002389 $$ = asn1p_value_fromdouble($1);
2390 checkmem($$);
2391 }
2392 ;
2393
Lev Walkinf15320b2004-06-03 03:38:44 +00002394/*
2395 * SEQUENCE definition.
2396 * === EXAMPLE ===
2397 * Struct1 ::= SEQUENCE {
2398 * memb1 Struct2,
2399 * memb2 SEQUENCE OF {
2400 * memb2-1 Struct 3
2401 * }
2402 * }
2403 * === EOF ===
2404 */
2405
2406
2407
2408/*
2409 * SET definition.
2410 * === EXAMPLE ===
2411 * Person ::= SET {
2412 * name [0] PrintableString (SIZE(1..20)),
2413 * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country,
2414 * }
2415 * === EOF ===
2416 */
2417
2418optTag:
2419 { memset(&$$, 0, sizeof($$)); }
2420 | Tag { $$ = $1; }
2421 ;
2422
2423Tag:
Lev Walkinc603f102005-01-23 09:51:44 +00002424 TagTypeValue TagPlicit {
Lev Walkinf15320b2004-06-03 03:38:44 +00002425 $$ = $1;
Lev Walkinc603f102005-01-23 09:51:44 +00002426 $$.tag_mode = $2.tag_mode;
Lev Walkinf15320b2004-06-03 03:38:44 +00002427 }
Lev Walkinc603f102005-01-23 09:51:44 +00002428 ;
2429
2430TagTypeValue:
2431 '[' TagClass TOK_number ']' {
2432 $$ = $2;
2433 $$.tag_value = $3;
2434 };
2435
2436TagClass:
2437 { $$.tag_class = TC_CONTEXT_SPECIFIC; }
2438 | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; }
2439 | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; }
2440 | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; }
2441 ;
2442
2443TagPlicit:
2444 { $$.tag_mode = TM_DEFAULT; }
2445 | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; }
2446 | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; }
Lev Walkinf15320b2004-06-03 03:38:44 +00002447 ;
2448
2449TypeRefName:
2450 TOK_typereference {
2451 checkmem($1);
2452 $$ = $1;
2453 }
Lev Walkinf59d0752004-08-18 04:59:12 +00002454 | TOK_capitalreference {
Lev Walkinf15320b2004-06-03 03:38:44 +00002455 checkmem($1);
2456 $$ = $1;
2457 }
2458 ;
2459
Lev Walkinf59d0752004-08-18 04:59:12 +00002460
Lev Walkin83cac2f2004-09-22 16:03:36 +00002461optIdentifier:
2462 { $$ = 0; }
2463 | Identifier {
2464 $$ = $1;
2465 }
Lev Walkin8f294e02005-06-06 08:28:58 +00002466 ;
Lev Walkin83cac2f2004-09-22 16:03:36 +00002467
Lev Walkinf15320b2004-06-03 03:38:44 +00002468Identifier:
2469 TOK_identifier {
2470 checkmem($1);
2471 $$ = $1;
2472 }
2473 ;
2474
Lev Walkind523ea42017-09-06 22:15:08 -07002475IdentifierAsReference:
2476 Identifier {
2477 $$ = asn1p_ref_new(yylineno, currentModule);
2478 asn1p_ref_add_component($$, $1, RLT_lowercase);
Lev Walkined409e22017-09-26 18:07:40 -07002479 free($1);
Lev Walkind523ea42017-09-06 22:15:08 -07002480 };
2481
2482IdentifierAsValue:
2483 IdentifierAsReference {
2484 $$ = asn1p_value_fromref($1, 0);
2485 };
2486
Lev Walkinf15320b2004-06-03 03:38:44 +00002487%%
2488
2489
2490/*
2491 * Convert Xstring ('0101'B or '5'H) to the binary vector.
2492 */
2493static asn1p_value_t *
2494_convert_bitstring2binary(char *str, int base) {
2495 asn1p_value_t *val;
2496 int slen;
2497 int memlen;
2498 int baselen;
2499 int bits;
2500 uint8_t *binary_vector;
2501 uint8_t *bv_ptr;
2502 uint8_t cur_val;
2503
2504 assert(str);
2505 assert(str[0] == '\'');
2506
2507 switch(base) {
2508 case 'B':
2509 baselen = 1;
2510 break;
2511 case 'H':
2512 baselen = 4;
2513 break;
2514 default:
2515 assert(base == 'B' || base == 'H');
2516 errno = EINVAL;
2517 return NULL;
2518 }
2519
2520 slen = strlen(str);
2521 assert(str[slen - 1] == base);
2522 assert(str[slen - 2] == '\'');
2523
2524 memlen = slen / (8 / baselen); /* Conservative estimate */
2525
2526 bv_ptr = binary_vector = malloc(memlen + 1);
2527 if(bv_ptr == NULL)
2528 /* ENOMEM */
2529 return NULL;
2530
2531 cur_val = 0;
2532 bits = 0;
2533 while(*(++str) != '\'') {
2534 switch(baselen) {
2535 case 1:
2536 switch(*str) {
2537 case '1':
2538 cur_val |= 1 << (7 - (bits % 8));
2539 case '0':
2540 break;
2541 default:
2542 assert(!"_y UNREACH1");
2543 case ' ': case '\r': case '\n':
2544 continue;
2545 }
2546 break;
2547 case 4:
2548 switch(*str) {
2549 case '0': case '1': case '2': case '3': case '4':
2550 case '5': case '6': case '7': case '8': case '9':
2551 cur_val |= (*str - '0') << (4 - (bits % 8));
2552 break;
2553 case 'A': case 'B': case 'C':
2554 case 'D': case 'E': case 'F':
2555 cur_val |= ((*str - 'A') + 10)
2556 << (4 - (bits % 8));
2557 break;
2558 default:
2559 assert(!"_y UNREACH2");
2560 case ' ': case '\r': case '\n':
2561 continue;
2562 }
2563 break;
2564 }
2565
2566 bits += baselen;
2567 if((bits % 8) == 0) {
2568 *bv_ptr++ = cur_val;
2569 cur_val = 0;
2570 }
2571 }
2572
2573 *bv_ptr = cur_val;
2574 assert((bv_ptr - binary_vector) <= memlen);
2575
2576 val = asn1p_value_frombits(binary_vector, bits, 0);
2577 if(val == NULL) {
2578 free(binary_vector);
2579 }
2580
2581 return val;
2582}
2583
Lev Walkin2e9bd5c2005-08-13 09:07:11 +00002584/*
2585 * For unnamed types (used in old X.208 compliant modules)
2586 * generate some sort of interim names, to not to force human being to fix
2587 * the specification's compliance to modern ASN.1 standards.
2588 */
2589static void
2590_fixup_anonymous_identifier(asn1p_expr_t *expr) {
2591 char *p;
2592 assert(expr->Identifier == 0);
2593
2594 /*
2595 * Try to figure out the type name
2596 * without going too much into details
2597 */
2598 expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type);
2599 if(expr->reference && expr->reference->comp_count > 0)
2600 expr->Identifier = expr->reference->components[0].name;
2601
2602 fprintf(stderr,
2603 "WARNING: Line %d: expected lower-case member identifier, "
2604 "found an unnamed %s.\n"
2605 "WARNING: Obsolete X.208 syntax detected, "
2606 "please give the member a name.\n",
2607 yylineno, expr->Identifier ? expr->Identifier : "type");
2608
2609 if(!expr->Identifier)
2610 expr->Identifier = "unnamed";
2611 expr->Identifier = strdup(expr->Identifier);
2612 assert(expr->Identifier);
2613 /* Make a lowercase identifier from the type name */
2614 for(p = expr->Identifier; *p; p++) {
2615 switch(*p) {
2616 case 'A' ... 'Z': *p += 32; break;
2617 case ' ': *p = '_'; break;
2618 case '-': *p = '_'; break;
2619 }
2620 }
2621 fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". "
2622 "Name clash may occur later.\n",
2623 expr->Identifier);
2624}
2625
Lev Walkin59165cf2017-09-11 06:24:45 -07002626static int
Lev Walkinf15320b2004-06-03 03:38:44 +00002627yyerror(const char *msg) {
Lev Walkin9d542d22006-03-14 16:31:37 +00002628 extern char *asn1p_text;
Lev Walkinf15320b2004-06-03 03:38:44 +00002629 fprintf(stderr,
2630 "ASN.1 grammar parse error "
Lev Walkind523ea42017-09-06 22:15:08 -07002631 "near %s:%d (token \"%s\"): %s\n",
2632 ASN_FILENAME, yylineno, asn1p_text, msg);
Lev Walkinf15320b2004-06-03 03:38:44 +00002633 return -1;
2634}
2635