Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | %{ |
| 2 | |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <errno.h> |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include "asn1parser.h" |
| 10 | |
| 11 | #define YYPARSE_PARAM param |
Lev Walkin | 4354b44 | 2005-06-07 21:25:42 +0000 | [diff] [blame] | 12 | #define YYPARSE_PARAM_TYPE void ** |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 13 | #define YYERROR_VERBOSE |
| 14 | |
| 15 | int yylex(void); |
| 16 | int yyerror(const char *msg); |
Lev Walkin | 8daab91 | 2005-06-07 21:32:16 +0000 | [diff] [blame] | 17 | #ifdef YYBYACC |
| 18 | int yyparse(void **param); /* byacc does not produce a prototype */ |
| 19 | #endif |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | void asn1p_lexer_hack_push_opaque_state(void); |
| 21 | void asn1p_lexer_hack_enable_with_syntax(void); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 22 | void asn1p_lexer_hack_push_encoding_control(void); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | #define yylineno asn1p_lineno |
| 24 | extern int asn1p_lineno; |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 25 | const char *asn1p_parse_debug_filename; |
| 26 | #define ASN_FILENAME asn1p_parse_debug_filename |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 28 | /* |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 29 | * Process directives as <ASN1C:RepresentAsPointer> |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 30 | */ |
| 31 | extern int asn1p_as_pointer; |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 34 | * This temporary variable is used to solve the shortcomings of 1-lookahead |
| 35 | * parser. |
| 36 | */ |
| 37 | static struct AssignedIdentifier *saved_aid; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | |
Lev Walkin | 2e9bd5c | 2005-08-13 09:07:11 +0000 | [diff] [blame] | 39 | static asn1p_value_t *_convert_bitstring2binary(char *str, int base); |
| 40 | static void _fixup_anonymous_identifier(asn1p_expr_t *expr); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 41 | |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 42 | static asn1p_module_t *currentModule; |
| 43 | #define NEW_EXPR() (asn1p_expr_new(yylineno, currentModule)) |
| 44 | |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 45 | #define checkmem(ptr) do { \ |
| 46 | if(!(ptr)) \ |
| 47 | return yyerror("Memory failure"); \ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 48 | } while(0) |
| 49 | |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 50 | #define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \ |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 51 | if(arg1->type != constr_type) { \ |
| 52 | int __ret; \ |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 53 | root = asn1p_constraint_new(yylineno, currentModule); \ |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 54 | checkmem(root); \ |
| 55 | root->type = constr_type; \ |
| 56 | __ret = asn1p_constraint_insert(root, \ |
| 57 | arg1); \ |
| 58 | checkmem(__ret == 0); \ |
| 59 | } else { \ |
| 60 | root = arg1; \ |
| 61 | } \ |
| 62 | if(arg2) { \ |
| 63 | int __ret \ |
| 64 | = asn1p_constraint_insert(root, arg2); \ |
| 65 | checkmem(__ret == 0); \ |
| 66 | } \ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 67 | } while(0) |
| 68 | |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 69 | #ifdef AL_IMPORT |
| 70 | #error AL_IMPORT DEFINED ELSEWHERE! |
| 71 | #endif |
| 72 | #define AL_IMPORT(to,where,from,field) do { \ |
| 73 | if(!(from)) break; \ |
| 74 | while(TQ_FIRST(&((from)->where))) { \ |
| 75 | TQ_ADD(&((to)->where), \ |
| 76 | TQ_REMOVE(&((from)->where), field), \ |
| 77 | field); \ |
| 78 | } \ |
| 79 | assert(TQ_FIRST(&((from)->where)) == 0); \ |
| 80 | } while(0) |
| 81 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 82 | %} |
| 83 | |
| 84 | |
| 85 | /* |
| 86 | * Token value definition. |
| 87 | * a_*: ASN-specific types. |
| 88 | * tv_*: Locally meaningful types. |
| 89 | */ |
| 90 | %union { |
| 91 | asn1p_t *a_grammar; |
| 92 | asn1p_module_flags_e a_module_flags; |
| 93 | asn1p_module_t *a_module; |
| 94 | asn1p_expr_type_e a_type; /* ASN.1 Type */ |
| 95 | asn1p_expr_t *a_expr; /* Constructed collection */ |
| 96 | asn1p_constraint_t *a_constr; /* Constraint */ |
| 97 | enum asn1p_constraint_type_e a_ctype;/* Constraint type */ |
| 98 | asn1p_xports_t *a_xports; /* IMports/EXports */ |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 99 | struct AssignedIdentifier a_aid; /* Assigned Identifier */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 100 | asn1p_oid_t *a_oid; /* Object Identifier */ |
| 101 | asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */ |
| 102 | struct asn1p_type_tag_s a_tag; /* A tag */ |
| 103 | asn1p_ref_t *a_ref; /* Reference to custom type */ |
| 104 | asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */ |
| 105 | asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */ |
| 106 | struct asn1p_ref_component_s a_refcomp; /* Component of a reference */ |
| 107 | asn1p_value_t *a_value; /* Number, DefinedValue, etc */ |
| 108 | struct asn1p_param_s a_parg; /* A parameter argument */ |
| 109 | asn1p_paramlist_t *a_plist; /* A pargs list */ |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 110 | struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 111 | enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */ |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 112 | asn1c_integer_t a_int; |
Lev Walkin | adf863f | 2006-09-05 16:18:34 +0000 | [diff] [blame] | 113 | double a_dbl; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 114 | char *tv_str; |
| 115 | struct { |
| 116 | char *buf; |
| 117 | int len; |
| 118 | } tv_opaque; |
| 119 | struct { |
| 120 | char *name; |
| 121 | struct asn1p_type_tag_s tag; |
| 122 | } tv_nametag; |
| 123 | }; |
| 124 | |
| 125 | /* |
| 126 | * Token types returned by scanner. |
| 127 | */ |
| 128 | %token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */ |
Lev Walkin | 0e90aa0 | 2013-03-19 16:17:13 -0700 | [diff] [blame] | 129 | %token TOK_VBracketLeft TOK_VBracketRight /* "[[", "]]" */ |
Lev Walkin | 57074f1 | 2006-03-16 05:11:14 +0000 | [diff] [blame] | 130 | %token <tv_opaque> TOK_whitespace /* A span of whitespace */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 131 | %token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */ |
| 132 | %token <tv_str> TOK_bstring |
| 133 | %token <tv_opaque> TOK_cstring |
| 134 | %token <tv_str> TOK_hstring |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 135 | %token <tv_str> TOK_identifier "identifier" |
| 136 | %token <a_int> TOK_number "number" |
| 137 | %token <a_int> TOK_number_negative "negative number" |
Lev Walkin | adf863f | 2006-09-05 16:18:34 +0000 | [diff] [blame] | 138 | %token <a_dbl> TOK_realnumber |
Lev Walkin | d9574ae | 2005-03-24 16:22:35 +0000 | [diff] [blame] | 139 | %token <a_int> TOK_tuple |
| 140 | %token <a_int> TOK_quadruple |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 141 | %token <tv_str> TOK_typereference |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 142 | %token <tv_str> TOK_capitalreference /* "CLASS1" */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 143 | %token <tv_str> TOK_typefieldreference /* "&Pork" */ |
| 144 | %token <tv_str> TOK_valuefieldreference /* "&id" */ |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 145 | %token <tv_str> TOK_Literal /* "BY" */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 146 | |
| 147 | /* |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 148 | * Tokens available with asn1p_lexer_hack_push_extended_values(). |
| 149 | */ |
| 150 | %token TOK_ExtValue_BIT_STRING |
| 151 | |
| 152 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 153 | * Token types representing ASN.1 standard keywords. |
| 154 | */ |
| 155 | %token TOK_ABSENT |
| 156 | %token TOK_ABSTRACT_SYNTAX |
| 157 | %token TOK_ALL |
| 158 | %token TOK_ANY |
| 159 | %token TOK_APPLICATION |
| 160 | %token TOK_AUTOMATIC |
| 161 | %token TOK_BEGIN |
| 162 | %token TOK_BIT |
| 163 | %token TOK_BMPString |
| 164 | %token TOK_BOOLEAN |
| 165 | %token TOK_BY |
| 166 | %token TOK_CHARACTER |
| 167 | %token TOK_CHOICE |
| 168 | %token TOK_CLASS |
| 169 | %token TOK_COMPONENT |
| 170 | %token TOK_COMPONENTS |
| 171 | %token TOK_CONSTRAINED |
| 172 | %token TOK_CONTAINING |
| 173 | %token TOK_DEFAULT |
| 174 | %token TOK_DEFINITIONS |
| 175 | %token TOK_DEFINED |
| 176 | %token TOK_EMBEDDED |
| 177 | %token TOK_ENCODED |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 178 | %token TOK_ENCODING_CONTROL |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 179 | %token TOK_END |
| 180 | %token TOK_ENUMERATED |
| 181 | %token TOK_EXPLICIT |
| 182 | %token TOK_EXPORTS |
| 183 | %token TOK_EXTENSIBILITY |
| 184 | %token TOK_EXTERNAL |
| 185 | %token TOK_FALSE |
| 186 | %token TOK_FROM |
| 187 | %token TOK_GeneralizedTime |
| 188 | %token TOK_GeneralString |
| 189 | %token TOK_GraphicString |
| 190 | %token TOK_IA5String |
| 191 | %token TOK_IDENTIFIER |
| 192 | %token TOK_IMPLICIT |
| 193 | %token TOK_IMPLIED |
| 194 | %token TOK_IMPORTS |
| 195 | %token TOK_INCLUDES |
| 196 | %token TOK_INSTANCE |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 197 | %token TOK_INSTRUCTIONS |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 198 | %token TOK_INTEGER |
| 199 | %token TOK_ISO646String |
| 200 | %token TOK_MAX |
| 201 | %token TOK_MIN |
| 202 | %token TOK_MINUS_INFINITY |
| 203 | %token TOK_NULL |
| 204 | %token TOK_NumericString |
| 205 | %token TOK_OBJECT |
| 206 | %token TOK_ObjectDescriptor |
| 207 | %token TOK_OCTET |
| 208 | %token TOK_OF |
| 209 | %token TOK_OPTIONAL |
| 210 | %token TOK_PATTERN |
| 211 | %token TOK_PDV |
| 212 | %token TOK_PLUS_INFINITY |
| 213 | %token TOK_PRESENT |
| 214 | %token TOK_PrintableString |
| 215 | %token TOK_PRIVATE |
| 216 | %token TOK_REAL |
| 217 | %token TOK_RELATIVE_OID |
| 218 | %token TOK_SEQUENCE |
| 219 | %token TOK_SET |
| 220 | %token TOK_SIZE |
| 221 | %token TOK_STRING |
| 222 | %token TOK_SYNTAX |
| 223 | %token TOK_T61String |
| 224 | %token TOK_TAGS |
| 225 | %token TOK_TeletexString |
| 226 | %token TOK_TRUE |
| 227 | %token TOK_TYPE_IDENTIFIER |
| 228 | %token TOK_UNIQUE |
| 229 | %token TOK_UNIVERSAL |
| 230 | %token TOK_UniversalString |
| 231 | %token TOK_UTCTime |
| 232 | %token TOK_UTF8String |
| 233 | %token TOK_VideotexString |
| 234 | %token TOK_VisibleString |
| 235 | %token TOK_WITH |
Lev Walkin | 752e973 | 2017-08-04 02:06:22 -0700 | [diff] [blame] | 236 | %token UTF8_BOM "UTF-8 byte order mark" |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 237 | |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 238 | %nonassoc TOK_EXCEPT |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 239 | %left '^' TOK_INTERSECTION |
| 240 | %left '|' TOK_UNION |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 241 | |
| 242 | /* Misc tags */ |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 243 | %token TOK_TwoDots ".." |
| 244 | %token TOK_ThreeDots "..." |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 245 | |
| 246 | |
| 247 | /* |
| 248 | * Types defined herein. |
| 249 | */ |
| 250 | %type <a_grammar> ModuleList |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 251 | %type <a_module> ModuleDefinition |
| 252 | %type <a_module> ModuleBody |
| 253 | %type <a_module> AssignmentList |
| 254 | %type <a_module> Assignment |
| 255 | %type <a_module> optModuleBody /* Optional */ |
| 256 | %type <a_module_flags> optModuleDefinitionFlags |
| 257 | %type <a_module_flags> ModuleDefinitionFlags /* Set of FL */ |
| 258 | %type <a_module_flags> ModuleDefinitionFlag /* Single FL */ |
| 259 | %type <a_module> optImports |
| 260 | %type <a_module> optExports |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 261 | %type <a_module> ImportsDefinition |
Lev Walkin | 4a4543f | 2006-10-13 12:37:39 +0000 | [diff] [blame] | 262 | %type <a_module> optImportsBundleSet |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 263 | %type <a_module> ImportsBundleSet |
| 264 | %type <a_xports> ImportsBundle |
| 265 | %type <a_xports> ImportsList |
| 266 | %type <a_xports> ExportsDefinition |
| 267 | %type <a_xports> ExportsBody |
| 268 | %type <a_expr> ImportsElement |
| 269 | %type <a_expr> ExportsElement |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 270 | %type <a_expr> ExtensionAndException |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 271 | %type <a_expr> Type |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 272 | %type <a_expr> TypeDeclaration |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 273 | %type <a_expr> TypeDeclarationSet |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 274 | %type <a_ref> ComplexTypeReference |
| 275 | %type <a_ref> ComplexTypeReferenceAmpList |
| 276 | %type <a_refcomp> ComplexTypeReferenceElement |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 277 | %type <a_refcomp> PrimitiveFieldReference |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 278 | %type <a_expr> FieldSpec |
| 279 | %type <a_ref> FieldName |
| 280 | %type <a_ref> DefinedObjectClass |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 281 | %type <a_expr> ClassField |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 282 | %type <a_expr> ObjectClass |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 283 | %type <a_expr> DataTypeReference /* Type1 ::= Type2 */ |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 284 | %type <a_expr> DefinedType |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 285 | %type <a_constr> ValueSet /* {a|b|c}*/ |
| 286 | %type <a_expr> ValueSetTypeAssignment /* Val INTEGER ::= {1|2} */ |
Lev Walkin | c6ab03c | 2006-10-21 05:54:49 +0000 | [diff] [blame] | 287 | %type <a_expr> ValueAssignment /* val INTEGER ::= 1*/ |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 288 | %type <a_value> Value |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 289 | %type <a_value> SimpleValue |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 290 | %type <a_value> DefinedValue |
| 291 | %type <a_value> SignedNumber |
Lev Walkin | adf863f | 2006-09-05 16:18:34 +0000 | [diff] [blame] | 292 | %type <a_value> RealValue |
Lev Walkin | 1c8d5aa | 2006-10-27 05:37:39 +0000 | [diff] [blame] | 293 | %type <a_value> BitStringValue |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 294 | %type <a_expr> optComponentTypeLists |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 295 | %type <a_expr> ComponentTypeLists |
| 296 | %type <a_expr> ComponentType |
| 297 | %type <a_expr> AlternativeTypeLists |
| 298 | %type <a_expr> AlternativeType |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 299 | %type <a_expr> UniverationList |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 300 | %type <a_expr> Enumerations |
| 301 | %type <a_expr> NamedBitList |
| 302 | %type <a_expr> NamedBit |
| 303 | %type <a_expr> NamedNumberList |
| 304 | %type <a_expr> NamedNumber |
| 305 | %type <a_expr> IdentifierList |
| 306 | %type <a_expr> IdentifierElement |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 307 | %type <a_expr> UniverationElement |
| 308 | %type <tv_str> TypeRefName |
| 309 | %type <tv_str> ObjectClassReference |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 310 | %type <tv_str> Identifier |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 311 | %type <a_ref> IdentifierAsReference |
| 312 | %type <a_value> IdentifierAsValue |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 313 | %type <tv_str> optIdentifier |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 314 | %type <a_parg> ParameterArgumentName |
| 315 | %type <a_plist> ParameterArgumentList |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 316 | %type <a_expr> ActualParameter |
| 317 | %type <a_expr> ActualParameterList |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 318 | %type <a_aid> AssignedIdentifier /* OID/DefinedValue */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 319 | %type <a_oid> ObjectIdentifier /* OID */ |
| 320 | %type <a_oid> optObjectIdentifier /* Optional OID */ |
| 321 | %type <a_oid> ObjectIdentifierBody |
| 322 | %type <a_oid_arc> ObjectIdentifierElement |
| 323 | %type <a_expr> BasicType |
| 324 | %type <a_type> BasicTypeId |
| 325 | %type <a_type> BasicTypeId_UniverationCompatible |
| 326 | %type <a_type> BasicString |
| 327 | %type <tv_opaque> Opaque |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 328 | %type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */ |
| 329 | %type <a_tag> TagClass TagTypeValue TagPlicit |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 330 | %type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */ |
| 331 | %type <a_constr> optConstraints |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 332 | %type <a_constr> optSizeConstraints |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 333 | %type <a_constr> Constraint |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 334 | %type <a_constr> SingleTypeConstraint |
| 335 | %type <a_constr> MultipleTypeConstraints |
| 336 | %type <a_constr> NamedConstraint |
| 337 | %type <a_constr> FullSpecification |
| 338 | %type <a_constr> PartialSpecification |
| 339 | %type <a_constr> TypeConstraints |
| 340 | %type <a_constr> ConstraintSpec |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 341 | %type <a_constr> SubtypeConstraint |
| 342 | %type <a_constr> GeneralConstraint |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 343 | %type <a_constr> SetOfConstraints |
| 344 | %type <a_constr> ElementSetSpecs /* 1..2,...,3 */ |
| 345 | %type <a_constr> ElementSetSpec /* 1..2,...,3 */ |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 346 | %type <a_constr> Unions |
| 347 | %type <a_constr> Intersections |
| 348 | %type <a_constr> IntersectionElements |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 349 | %type <a_constr> ConstraintSubtypeElement /* 1..2 */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 350 | %type <a_constr> SimpleTableConstraint |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 351 | %type <a_constr> UserDefinedConstraint |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 352 | %type <a_constr> TableConstraint |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 353 | %type <a_constr> ContentsConstraint |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 354 | %type <a_constr> PatternConstraint |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 355 | %type <a_constr> InnerTypeConstraint |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 356 | %type <a_constr> ComponentRelationConstraint |
| 357 | %type <a_constr> AtNotationList |
| 358 | %type <a_ref> AtNotationElement |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 359 | %type <a_value> SingleValue |
| 360 | %type <a_value> ContainedSubtype |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 361 | %type <a_ctype> ConstraintType |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 362 | %type <a_ctype> ConstraintRangeSpec |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 363 | %type <a_value> RestrictedCharacterStringValue |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 364 | %type <a_wsynt> optWithSyntax |
| 365 | %type <a_wsynt> WithSyntax |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 366 | %type <a_wsynt> WithSyntaxList |
| 367 | %type <a_wchunk> WithSyntaxToken |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 368 | %type <a_marker> optMarker Marker |
| 369 | %type <a_int> optUnique |
| 370 | %type <a_pres> optPresenceConstraint PresenceConstraint |
| 371 | %type <tv_str> ComponentIdList |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 372 | %type <a_int> NSTD_IndirectMarker |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 373 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 374 | %% |
| 375 | |
| 376 | |
| 377 | ParsedGrammar: |
Lev Walkin | 752e973 | 2017-08-04 02:06:22 -0700 | [diff] [blame] | 378 | UTF8_BOM ModuleList { |
| 379 | *(void **)param = $2; |
| 380 | } |
| 381 | | ModuleList { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 382 | *(void **)param = $1; |
| 383 | } |
| 384 | ; |
| 385 | |
| 386 | ModuleList: |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 387 | ModuleDefinition { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 388 | $$ = asn1p_new(); |
| 389 | checkmem($$); |
| 390 | TQ_ADD(&($$->modules), $1, mod_next); |
| 391 | } |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 392 | | ModuleList ModuleDefinition { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 393 | $$ = $1; |
| 394 | TQ_ADD(&($$->modules), $2, mod_next); |
| 395 | } |
| 396 | ; |
| 397 | |
| 398 | /* |
| 399 | * ASN module definition. |
| 400 | * === EXAMPLE === |
| 401 | * MySyntax DEFINITIONS AUTOMATIC TAGS ::= |
| 402 | * BEGIN |
| 403 | * ... |
| 404 | * END |
| 405 | * === EOF === |
| 406 | */ |
| 407 | |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 408 | ModuleDefinition: |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 409 | TypeRefName { currentModule = asn1p_module_new(); } |
| 410 | optObjectIdentifier TOK_DEFINITIONS |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 411 | optModuleDefinitionFlags |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 412 | TOK_PPEQ TOK_BEGIN |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 413 | optModuleBody |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 414 | TOK_END { |
| 415 | |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 416 | $$ = currentModule; |
| 417 | |
| 418 | if($8) { |
| 419 | asn1p_module_t tmp = *($$); |
| 420 | *($$) = *($8); |
| 421 | *($8) = tmp; |
| 422 | asn1p_module_free($8); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 423 | } else { |
| 424 | /* There's a chance that a module is just plain empty */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 425 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 426 | |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 427 | $$->ModuleName = $1; |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 428 | $$->module_oid = $3; |
| 429 | $$->module_flags = $5; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 430 | } |
| 431 | ; |
| 432 | |
| 433 | /* |
| 434 | * Object Identifier Definition |
| 435 | * { iso member-body(2) 3 } |
| 436 | */ |
| 437 | optObjectIdentifier: |
| 438 | { $$ = 0; } |
| 439 | | ObjectIdentifier { $$ = $1; } |
| 440 | ; |
| 441 | |
| 442 | ObjectIdentifier: |
| 443 | '{' ObjectIdentifierBody '}' { |
| 444 | $$ = $2; |
| 445 | } |
| 446 | | '{' '}' { |
| 447 | $$ = 0; |
| 448 | } |
| 449 | ; |
| 450 | |
| 451 | ObjectIdentifierBody: |
| 452 | ObjectIdentifierElement { |
| 453 | $$ = asn1p_oid_new(); |
| 454 | asn1p_oid_add_arc($$, &$1); |
| 455 | if($1.name) |
| 456 | free($1.name); |
| 457 | } |
| 458 | | ObjectIdentifierBody ObjectIdentifierElement { |
| 459 | $$ = $1; |
| 460 | asn1p_oid_add_arc($$, &$2); |
| 461 | if($2.name) |
| 462 | free($2.name); |
| 463 | } |
| 464 | ; |
| 465 | |
| 466 | ObjectIdentifierElement: |
| 467 | Identifier { /* iso */ |
| 468 | $$.name = $1; |
| 469 | $$.number = -1; |
| 470 | } |
| 471 | | Identifier '(' TOK_number ')' { /* iso(1) */ |
| 472 | $$.name = $1; |
| 473 | $$.number = $3; |
| 474 | } |
| 475 | | TOK_number { /* 1 */ |
| 476 | $$.name = 0; |
| 477 | $$.number = $1; |
| 478 | } |
| 479 | ; |
| 480 | |
| 481 | /* |
| 482 | * Optional module flags. |
| 483 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 484 | optModuleDefinitionFlags: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 485 | { $$ = MSF_NOFLAGS; } |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 486 | | ModuleDefinitionFlags { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 487 | $$ = $1; |
| 488 | } |
| 489 | ; |
| 490 | |
| 491 | /* |
| 492 | * Module flags. |
| 493 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 494 | ModuleDefinitionFlags: |
| 495 | ModuleDefinitionFlag { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 496 | $$ = $1; |
| 497 | } |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 498 | | ModuleDefinitionFlags ModuleDefinitionFlag { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 499 | $$ = $1 | $2; |
| 500 | } |
| 501 | ; |
| 502 | |
| 503 | /* |
| 504 | * Single module flag. |
| 505 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 506 | ModuleDefinitionFlag: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 507 | TOK_EXPLICIT TOK_TAGS { |
| 508 | $$ = MSF_EXPLICIT_TAGS; |
| 509 | } |
| 510 | | TOK_IMPLICIT TOK_TAGS { |
| 511 | $$ = MSF_IMPLICIT_TAGS; |
| 512 | } |
| 513 | | TOK_AUTOMATIC TOK_TAGS { |
| 514 | $$ = MSF_AUTOMATIC_TAGS; |
| 515 | } |
| 516 | | TOK_EXTENSIBILITY TOK_IMPLIED { |
| 517 | $$ = MSF_EXTENSIBILITY_IMPLIED; |
| 518 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 519 | /* EncodingReferenceDefault */ |
| 520 | | TOK_capitalreference TOK_INSTRUCTIONS { |
| 521 | /* X.680Amd1 specifies TAG and XER */ |
| 522 | if(strcmp($1, "TAG") == 0) { |
| 523 | $$ = MSF_TAG_INSTRUCTIONS; |
| 524 | } else if(strcmp($1, "XER") == 0) { |
| 525 | $$ = MSF_XER_INSTRUCTIONS; |
| 526 | } else { |
| 527 | fprintf(stderr, |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 528 | "WARNING: %s INSTRUCTIONS at %s:%d: " |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 529 | "Unrecognized encoding reference\n", |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 530 | $1, ASN_FILENAME, yylineno); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 531 | $$ = MSF_unk_INSTRUCTIONS; |
| 532 | } |
| 533 | free($1); |
| 534 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 535 | ; |
| 536 | |
| 537 | /* |
| 538 | * Optional module body. |
| 539 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 540 | optModuleBody: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 541 | { $$ = 0; } |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 542 | | ModuleBody { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 543 | $$ = $1; |
| 544 | } |
| 545 | ; |
| 546 | |
| 547 | /* |
| 548 | * ASN.1 Module body. |
| 549 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 550 | ModuleBody: |
| 551 | optExports optImports AssignmentList { |
| 552 | $$ = asn1p_module_new(); |
| 553 | AL_IMPORT($$, exports, $1, xp_next); |
| 554 | AL_IMPORT($$, imports, $2, xp_next); |
| 555 | AL_IMPORT($$, members, $3, next); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 556 | |
| 557 | asn1p_module_free($1); |
| 558 | asn1p_module_free($2); |
| 559 | asn1p_module_free($3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 560 | } |
| 561 | ; |
| 562 | |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 563 | AssignmentList: |
| 564 | Assignment { |
| 565 | $$ = $1; |
| 566 | } |
| 567 | | AssignmentList Assignment { |
| 568 | if($1) { |
| 569 | $$ = $1; |
| 570 | } else { |
| 571 | $$ = $2; |
| 572 | break; |
| 573 | } |
| 574 | AL_IMPORT($$, members, $2, next); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 575 | asn1p_module_free($2); |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 576 | } |
| 577 | ; |
| 578 | |
| 579 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 580 | /* |
| 581 | * One of the elements of ASN.1 module specification. |
| 582 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 583 | Assignment: |
| 584 | DataTypeReference { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 585 | $$ = asn1p_module_new(); |
| 586 | checkmem($$); |
| 587 | assert($1->expr_type != A1TC_INVALID); |
| 588 | assert($1->meta_type != AMT_INVALID); |
| 589 | TQ_ADD(&($$->members), $1, next); |
| 590 | } |
Lev Walkin | c6ab03c | 2006-10-21 05:54:49 +0000 | [diff] [blame] | 591 | | ValueAssignment { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 592 | $$ = asn1p_module_new(); |
| 593 | checkmem($$); |
| 594 | assert($1->expr_type != A1TC_INVALID); |
| 595 | assert($1->meta_type != AMT_INVALID); |
| 596 | TQ_ADD(&($$->members), $1, next); |
| 597 | } |
| 598 | /* |
| 599 | * Value set definition |
| 600 | * === EXAMPLE === |
| 601 | * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 } |
| 602 | * === EOF === |
Lev Walkin | e700b20 | 2017-08-06 23:21:32 -0700 | [diff] [blame] | 603 | * Also ObjectClassSet. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 604 | */ |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 605 | | ValueSetTypeAssignment { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 606 | $$ = asn1p_module_new(); |
| 607 | checkmem($$); |
| 608 | assert($1->expr_type != A1TC_INVALID); |
| 609 | assert($1->meta_type != AMT_INVALID); |
| 610 | TQ_ADD(&($$->members), $1, next); |
| 611 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 612 | | TOK_ENCODING_CONTROL TOK_capitalreference |
| 613 | { asn1p_lexer_hack_push_encoding_control(); } |
| 614 | { |
| 615 | fprintf(stderr, |
| 616 | "WARNING: ENCODING-CONTROL %s " |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 617 | "specification at %s:%d ignored\n", |
| 618 | $2, ASN_FILENAME, yylineno); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 619 | free($2); |
| 620 | $$ = 0; |
| 621 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 622 | |
| 623 | /* |
| 624 | * Erroneous attemps |
| 625 | */ |
| 626 | | BasicString { |
| 627 | return yyerror( |
Lev Walkin | 7085305 | 2005-11-26 11:21:55 +0000 | [diff] [blame] | 628 | "Attempt to redefine a standard basic string type, " |
| 629 | "please comment out or remove this type redefinition."); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 630 | } |
| 631 | ; |
| 632 | |
| 633 | /* |
| 634 | * === EXAMPLE === |
| 635 | * IMPORTS Type1, value FROM Module { iso standard(0) } ; |
| 636 | * === EOF === |
| 637 | */ |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 638 | optImports: |
| 639 | { $$ = 0; } |
| 640 | | ImportsDefinition; |
| 641 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 642 | ImportsDefinition: |
Lev Walkin | 4a4543f | 2006-10-13 12:37:39 +0000 | [diff] [blame] | 643 | TOK_IMPORTS optImportsBundleSet ';' { |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 644 | if(!saved_aid && 0) |
| 645 | return yyerror("Unterminated IMPORTS FROM, " |
| 646 | "expected semicolon ';'"); |
| 647 | saved_aid = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 648 | $$ = $2; |
| 649 | } |
| 650 | /* |
| 651 | * Some error cases. |
| 652 | */ |
| 653 | | TOK_IMPORTS TOK_FROM /* ... */ { |
| 654 | return yyerror("Empty IMPORTS list"); |
| 655 | } |
| 656 | ; |
| 657 | |
Lev Walkin | 4a4543f | 2006-10-13 12:37:39 +0000 | [diff] [blame] | 658 | optImportsBundleSet: |
| 659 | { $$ = asn1p_module_new(); } |
| 660 | | ImportsBundleSet; |
| 661 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 662 | ImportsBundleSet: |
| 663 | ImportsBundle { |
| 664 | $$ = asn1p_module_new(); |
| 665 | checkmem($$); |
| 666 | TQ_ADD(&($$->imports), $1, xp_next); |
| 667 | } |
| 668 | | ImportsBundleSet ImportsBundle { |
| 669 | $$ = $1; |
| 670 | TQ_ADD(&($$->imports), $2, xp_next); |
| 671 | } |
| 672 | ; |
| 673 | |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 674 | AssignedIdentifier: |
| 675 | { memset(&$$, 0, sizeof($$)); } |
| 676 | | ObjectIdentifier { $$.oid = $1; }; |
| 677 | /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */ |
| 678 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 679 | ImportsBundle: |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 680 | ImportsList TOK_FROM TypeRefName AssignedIdentifier { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 681 | $$ = $1; |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 682 | $$->fromModuleName = $3; |
| 683 | $$->identifier = $4; |
| 684 | /* This stupid thing is used for look-back hack. */ |
| 685 | saved_aid = $$->identifier.oid ? 0 : &($$->identifier); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 686 | checkmem($$); |
| 687 | } |
| 688 | ; |
| 689 | |
| 690 | ImportsList: |
| 691 | ImportsElement { |
| 692 | $$ = asn1p_xports_new(); |
| 693 | checkmem($$); |
| 694 | TQ_ADD(&($$->members), $1, next); |
| 695 | } |
| 696 | | ImportsList ',' ImportsElement { |
| 697 | $$ = $1; |
| 698 | TQ_ADD(&($$->members), $3, next); |
| 699 | } |
| 700 | ; |
| 701 | |
| 702 | ImportsElement: |
| 703 | TypeRefName { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 704 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 705 | checkmem($$); |
| 706 | $$->Identifier = $1; |
| 707 | $$->expr_type = A1TC_REFERENCE; |
| 708 | } |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 709 | | TypeRefName '{' '}' { /* Completely equivalent to above */ |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 710 | $$ = NEW_EXPR(); |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 711 | checkmem($$); |
| 712 | $$->Identifier = $1; |
| 713 | $$->expr_type = A1TC_REFERENCE; |
| 714 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 715 | | Identifier { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 716 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 717 | checkmem($$); |
| 718 | $$->Identifier = $1; |
| 719 | $$->expr_type = A1TC_REFERENCE; |
| 720 | } |
| 721 | ; |
| 722 | |
Lev Walkin | 866bd7f | 2006-09-14 10:35:20 +0000 | [diff] [blame] | 723 | |
| 724 | optExports: |
| 725 | { $$ = 0; } |
| 726 | | ExportsDefinition { |
| 727 | $$ = asn1p_module_new(); |
| 728 | checkmem($$); |
| 729 | if($1) { |
| 730 | TQ_ADD(&($$->exports), $1, xp_next); |
| 731 | } else { |
| 732 | /* "EXPORTS ALL;" */ |
| 733 | } |
| 734 | } |
| 735 | ; |
| 736 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 737 | ExportsDefinition: |
| 738 | TOK_EXPORTS ExportsBody ';' { |
| 739 | $$ = $2; |
| 740 | } |
| 741 | | TOK_EXPORTS TOK_ALL ';' { |
| 742 | $$ = 0; |
| 743 | } |
| 744 | | TOK_EXPORTS ';' { |
| 745 | /* Empty EXPORTS clause effectively prohibits export. */ |
| 746 | $$ = asn1p_xports_new(); |
| 747 | checkmem($$); |
| 748 | } |
| 749 | ; |
| 750 | |
| 751 | ExportsBody: |
| 752 | ExportsElement { |
| 753 | $$ = asn1p_xports_new(); |
| 754 | assert($$); |
| 755 | TQ_ADD(&($$->members), $1, next); |
| 756 | } |
| 757 | | ExportsBody ',' ExportsElement { |
| 758 | $$ = $1; |
| 759 | TQ_ADD(&($$->members), $3, next); |
| 760 | } |
| 761 | ; |
| 762 | |
| 763 | ExportsElement: |
| 764 | TypeRefName { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 765 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 766 | checkmem($$); |
| 767 | $$->Identifier = $1; |
| 768 | $$->expr_type = A1TC_EXPORTVAR; |
| 769 | } |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 770 | | TypeRefName '{' '}' { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 771 | $$ = NEW_EXPR(); |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 772 | checkmem($$); |
| 773 | $$->Identifier = $1; |
| 774 | $$->expr_type = A1TC_EXPORTVAR; |
| 775 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 776 | | Identifier { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 777 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 778 | checkmem($$); |
| 779 | $$->Identifier = $1; |
| 780 | $$->expr_type = A1TC_EXPORTVAR; |
| 781 | } |
| 782 | ; |
| 783 | |
| 784 | |
Lev Walkin | 418298d | 2006-07-13 08:24:20 +0000 | [diff] [blame] | 785 | ValueSet: '{' ElementSetSpecs '}' { $$ = $2; }; |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 786 | |
| 787 | ValueSetTypeAssignment: |
| 788 | TypeRefName DefinedType TOK_PPEQ ValueSet { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 789 | $$ = $2; |
| 790 | assert($$->Identifier == 0); |
| 791 | $$->Identifier = $1; |
| 792 | $$->meta_type = AMT_VALUESET; |
Lev Walkin | 557f27d | 2006-03-21 07:46:48 +0000 | [diff] [blame] | 793 | $$->constraints = $4; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 794 | } |
| 795 | ; |
| 796 | |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 797 | DefinedType: |
| 798 | BasicType { |
| 799 | $$ = $1; |
| 800 | } |
| 801 | /* |
| 802 | * A DefinedType reference. |
| 803 | * "CLASS1.&id.&id2" |
| 804 | * or |
| 805 | * "Module.Type" |
| 806 | * or |
| 807 | * "Module.identifier" |
| 808 | * or |
| 809 | * "Type" |
| 810 | */ |
| 811 | | ComplexTypeReference { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 812 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 813 | checkmem($$); |
| 814 | $$->reference = $1; |
| 815 | $$->expr_type = A1TC_REFERENCE; |
| 816 | $$->meta_type = AMT_TYPEREF; |
| 817 | } |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 818 | /* |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 819 | * A parameterized assignment. |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 820 | */ |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 821 | | ComplexTypeReference '{' ActualParameterList '}' { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 822 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 823 | checkmem($$); |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 824 | $$->reference = $1; |
| 825 | $$->rhs_pspecs = $3; |
| 826 | $$->expr_type = A1TC_REFERENCE; |
| 827 | $$->meta_type = AMT_TYPEREF; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 828 | } |
| 829 | ; |
| 830 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 831 | /* |
| 832 | * Data Type Reference. |
| 833 | * === EXAMPLE === |
| 834 | * Type3 ::= CHOICE { a Type1, b Type 2 } |
| 835 | * === EOF === |
| 836 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 837 | DataTypeReference: |
| 838 | /* |
| 839 | * Optionally tagged type definition. |
| 840 | */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 841 | TypeRefName TOK_PPEQ Type { |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 842 | $$ = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 843 | $$->Identifier = $1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 844 | assert($$->expr_type); |
| 845 | assert($$->meta_type); |
| 846 | } |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 847 | | TypeRefName TOK_PPEQ ObjectClass { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 848 | $$ = $3; |
| 849 | $$->Identifier = $1; |
| 850 | assert($$->expr_type == A1TC_CLASSDEF); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 851 | assert($$->meta_type == AMT_OBJECTCLASS); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 852 | } |
| 853 | /* |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 854 | * Parameterized <Type> declaration: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 855 | * === EXAMPLE === |
| 856 | * SIGNED { ToBeSigned } ::= SEQUENCE { |
| 857 | * toBeSigned ToBeSigned, |
| 858 | * algorithm AlgorithmIdentifier, |
| 859 | * signature BIT STRING |
| 860 | * } |
| 861 | * === EOF === |
| 862 | */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 863 | | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 864 | $$ = $6; |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 865 | $$->Identifier = $1; |
| 866 | $$->lhs_params = $3; |
| 867 | } |
| 868 | /* Parameterized CLASS declaration */ |
| 869 | | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ ObjectClass { |
| 870 | $$ = $6; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 871 | $$->Identifier = $1; |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 872 | $$->lhs_params = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 873 | } |
| 874 | ; |
| 875 | |
| 876 | ParameterArgumentList: |
| 877 | ParameterArgumentName { |
| 878 | int ret; |
| 879 | $$ = asn1p_paramlist_new(yylineno); |
| 880 | checkmem($$); |
| 881 | ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument); |
| 882 | checkmem(ret == 0); |
Lev Walkin | a964e03 | 2017-03-26 03:48:06 -0700 | [diff] [blame] | 883 | asn1p_ref_free($1.governor); |
| 884 | free($1.argument); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 885 | } |
| 886 | | ParameterArgumentList ',' ParameterArgumentName { |
| 887 | int ret; |
| 888 | $$ = $1; |
| 889 | ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument); |
| 890 | checkmem(ret == 0); |
Lev Walkin | a964e03 | 2017-03-26 03:48:06 -0700 | [diff] [blame] | 891 | asn1p_ref_free($3.governor); |
| 892 | free($3.argument); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 893 | } |
| 894 | ; |
| 895 | |
| 896 | ParameterArgumentName: |
| 897 | TypeRefName { |
| 898 | $$.governor = NULL; |
| 899 | $$.argument = $1; |
| 900 | } |
| 901 | | TypeRefName ':' Identifier { |
| 902 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 903 | $$.governor = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 904 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 905 | checkmem(ret == 0); |
| 906 | $$.argument = $3; |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 907 | free($1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 908 | } |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 909 | | TypeRefName ':' TypeRefName { |
| 910 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 911 | $$.governor = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 912 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 913 | checkmem(ret == 0); |
| 914 | $$.argument = $3; |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 915 | free($1); |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 916 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 917 | | BasicTypeId ':' Identifier { |
| 918 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 919 | $$.governor = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 920 | ret = asn1p_ref_add_component($$.governor, |
| 921 | ASN_EXPR_TYPE2STR($1), 1); |
| 922 | checkmem(ret == 0); |
| 923 | $$.argument = $3; |
| 924 | } |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 925 | | BasicTypeId ':' TypeRefName { |
| 926 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 927 | $$.governor = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 928 | ret = asn1p_ref_add_component($$.governor, |
| 929 | ASN_EXPR_TYPE2STR($1), 1); |
| 930 | checkmem(ret == 0); |
| 931 | $$.argument = $3; |
| 932 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 933 | ; |
| 934 | |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 935 | ActualParameterList: |
| 936 | ActualParameter { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 937 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 938 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 939 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 940 | } |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 941 | | ActualParameterList ',' ActualParameter { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 942 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 943 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 944 | } |
| 945 | ; |
| 946 | |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 947 | ActualParameter: |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 948 | Type { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 949 | $$ = $1; |
| 950 | } |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 951 | | SimpleValue { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 952 | $$ = NEW_EXPR(); |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 953 | checkmem($$); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 954 | $$->Identifier = strdup("?"); |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 955 | $$->expr_type = A1TC_REFERENCE; |
| 956 | $$->meta_type = AMT_VALUE; |
| 957 | $$->value = $1; |
| 958 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 959 | | Identifier { |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 960 | asn1p_ref_t *ref; |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 961 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 962 | checkmem($$); |
| 963 | $$->Identifier = $1; |
| 964 | $$->expr_type = A1TC_REFERENCE; |
| 965 | $$->meta_type = AMT_VALUE; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 966 | ref = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 967 | asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 968 | $$->value = asn1p_value_fromref(ref, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 969 | } |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 970 | | ValueSet { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 971 | $$ = NEW_EXPR(); |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 972 | $$->expr_type = A1TC_VALUESET; |
| 973 | $$->meta_type = AMT_VALUESET; |
| 974 | $$->constraints = $1; |
| 975 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 976 | ; |
| 977 | |
| 978 | /* |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 979 | | '{' ActualParameter '}' { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 980 | $$ = NEW_EXPR(); |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 981 | checkmem($$); |
| 982 | asn1p_expr_add($$, $2); |
| 983 | $$->expr_type = A1TC_PARAMETRIZED; |
| 984 | $$->meta_type = AMT_TYPE; |
| 985 | } |
| 986 | ; |
| 987 | */ |
| 988 | |
| 989 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 990 | * A collection of constructed data type members. |
| 991 | */ |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 992 | optComponentTypeLists: |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 993 | { $$ = NEW_EXPR(); } |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 994 | | ComponentTypeLists { $$ = $1; }; |
| 995 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 996 | ComponentTypeLists: |
| 997 | ComponentType { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 998 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 999 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1000 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1001 | } |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1002 | | ComponentTypeLists ',' ComponentType { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1003 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1004 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1005 | } |
Lev Walkin | 0e90aa0 | 2013-03-19 16:17:13 -0700 | [diff] [blame] | 1006 | | ComponentTypeLists ',' TOK_VBracketLeft ComponentTypeLists TOK_VBracketRight { |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1007 | $$ = $1; |
Lev Walkin | 0e90aa0 | 2013-03-19 16:17:13 -0700 | [diff] [blame] | 1008 | asn1p_expr_add_many($$, $4); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1009 | asn1p_expr_free($4); |
Lev Walkin | 0e90aa0 | 2013-03-19 16:17:13 -0700 | [diff] [blame] | 1010 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1011 | ; |
| 1012 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1013 | ComponentType: |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1014 | Identifier Type optMarker { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1015 | $$ = $2; |
| 1016 | assert($$->Identifier == 0); |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1017 | $$->Identifier = $1; |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1018 | $3.flags |= $$->marker.flags; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1019 | $$->marker = $3; |
| 1020 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1021 | | Type optMarker { |
| 1022 | $$ = $1; |
| 1023 | $2.flags |= $$->marker.flags; |
| 1024 | $$->marker = $2; |
| 1025 | _fixup_anonymous_identifier($$); |
| 1026 | } |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1027 | | TOK_COMPONENTS TOK_OF Type { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1028 | $$ = NEW_EXPR(); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1029 | checkmem($$); |
| 1030 | $$->meta_type = $3->meta_type; |
| 1031 | $$->expr_type = A1TC_COMPONENTS_OF; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1032 | asn1p_expr_add($$, $3); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1033 | } |
| 1034 | | ExtensionAndException { |
| 1035 | $$ = $1; |
| 1036 | } |
| 1037 | ; |
| 1038 | |
| 1039 | AlternativeTypeLists: |
| 1040 | AlternativeType { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1041 | $$ = NEW_EXPR(); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1042 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1043 | asn1p_expr_add($$, $1); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1044 | } |
| 1045 | | AlternativeTypeLists ',' AlternativeType { |
| 1046 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1047 | asn1p_expr_add($$, $3); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1048 | } |
| 1049 | ; |
| 1050 | |
| 1051 | AlternativeType: |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1052 | Identifier Type { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1053 | $$ = $2; |
| 1054 | assert($$->Identifier == 0); |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1055 | $$->Identifier = $1; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1056 | } |
| 1057 | | ExtensionAndException { |
| 1058 | $$ = $1; |
| 1059 | } |
Lev Walkin | 2e9bd5c | 2005-08-13 09:07:11 +0000 | [diff] [blame] | 1060 | | Type { |
| 1061 | $$ = $1; |
| 1062 | _fixup_anonymous_identifier($$); |
| 1063 | } |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1064 | ; |
| 1065 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1066 | ObjectClass: |
| 1067 | TOK_CLASS '{' FieldSpec '}' optWithSyntax { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1068 | $$ = $3; |
| 1069 | checkmem($$); |
| 1070 | $$->with_syntax = $5; |
| 1071 | assert($$->expr_type == A1TC_CLASSDEF); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1072 | assert($$->meta_type == AMT_OBJECTCLASS); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1073 | } |
| 1074 | ; |
| 1075 | |
| 1076 | optUnique: |
| 1077 | { $$ = 0; } |
| 1078 | | TOK_UNIQUE { $$ = 1; } |
| 1079 | ; |
| 1080 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1081 | FieldSpec: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1082 | ClassField { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1083 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1084 | checkmem($$); |
| 1085 | $$->expr_type = A1TC_CLASSDEF; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1086 | $$->meta_type = AMT_OBJECTCLASS; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1087 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1088 | } |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1089 | | FieldSpec ',' ClassField { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1090 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1091 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1092 | } |
| 1093 | ; |
| 1094 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1095 | /* X.681 */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1096 | ClassField: |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* TypeFieldSpec ::= typefieldreference TypeOptionalitySpec? */ |
| 1099 | TOK_typefieldreference optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1100 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1101 | checkmem($$); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1102 | $$->Identifier = $1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1103 | $$->meta_type = AMT_OBJECTFIELD; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1104 | $$->expr_type = A1TC_CLASSFIELD_TFS; /* TypeFieldSpec */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1105 | $$->marker = $2; |
| 1106 | } |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1107 | |
| 1108 | /* FixedTypeValueFieldSpec ::= valuefieldreference Type UNIQUE ? ValueOptionalitySpec ? */ |
| 1109 | | TOK_valuefieldreference Type optUnique optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1110 | $$ = NEW_EXPR(); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1111 | $$->Identifier = $1; |
| 1112 | $$->meta_type = AMT_OBJECTFIELD; |
| 1113 | $$->expr_type = A1TC_CLASSFIELD_FTVFS; /* FixedTypeValueFieldSpec */ |
Lev Walkin | b7c45ca | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 1114 | $$->unique = $3; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1115 | $$->marker = $4; |
| 1116 | asn1p_expr_add($$, $2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1117 | } |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1118 | |
| 1119 | /* VariableTypeValueFieldSpec ::= valuefieldreference FieldName ValueOptionalitySpec ? */ |
| 1120 | | TOK_valuefieldreference FieldName optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1121 | $$ = NEW_EXPR(); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1122 | $$->Identifier = $1; |
| 1123 | $$->meta_type = AMT_OBJECTFIELD; |
| 1124 | $$->expr_type = A1TC_CLASSFIELD_VTVFS; |
| 1125 | $$->reference = $2; |
| 1126 | $$->marker = $3; |
| 1127 | } |
| 1128 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1129 | /* ObjectFieldSpec ::= objectfieldreference DefinedObjectClass ObjectOptionalitySpec ? */ |
| 1130 | | TOK_valuefieldreference DefinedObjectClass optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1131 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1132 | checkmem($$); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1133 | $$->Identifier = $1; |
| 1134 | $$->reference = $2; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1135 | $$->meta_type = AMT_OBJECTFIELD; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1136 | $$->expr_type = A1TC_CLASSFIELD_OFS; |
| 1137 | $$->marker = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1138 | } |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1139 | |
Lev Walkin | 5486875 | 2006-03-09 09:08:49 +0000 | [diff] [blame] | 1140 | /* VariableTypeValueSetFieldSpec ::= valuesetfieldreference FieldName ValueOptionalitySpec ? */ |
| 1141 | | TOK_typefieldreference FieldName optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1142 | $$ = NEW_EXPR(); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1143 | $$->Identifier = $1; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1144 | $$->meta_type = AMT_OBJECTFIELD; |
Lev Walkin | 5486875 | 2006-03-09 09:08:49 +0000 | [diff] [blame] | 1145 | $$->expr_type = A1TC_CLASSFIELD_VTVSFS; |
| 1146 | $$->reference = $2; |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1147 | $$->marker = $3; |
| 1148 | } |
| 1149 | |
| 1150 | /* FixedTypeValueSetFieldSpec ::= valuesetfieldreference Type ValueSetOptionalitySpec ? */ |
| 1151 | | TOK_typefieldreference Type optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1152 | $$ = NEW_EXPR(); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1153 | checkmem($$); |
| 1154 | $$->Identifier = $1; |
| 1155 | $$->meta_type = AMT_OBJECTFIELD; |
| 1156 | $$->expr_type = A1TC_CLASSFIELD_FTVSFS; |
| 1157 | asn1p_expr_add($$, $2); |
| 1158 | $$->marker = $3; |
| 1159 | } |
| 1160 | |
Lev Walkin | 5486875 | 2006-03-09 09:08:49 +0000 | [diff] [blame] | 1161 | /* ObjectSetFieldSpec ::= objectsetfieldreference DefinedObjectClass ObjectOptionalitySpec ? */ |
| 1162 | | TOK_typefieldreference DefinedObjectClass optMarker { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1163 | $$ = NEW_EXPR(); |
Lev Walkin | 5486875 | 2006-03-09 09:08:49 +0000 | [diff] [blame] | 1164 | checkmem($$); |
| 1165 | $$->Identifier = $1; |
| 1166 | $$->reference = $2; |
| 1167 | $$->meta_type = AMT_OBJECTFIELD; |
| 1168 | $$->expr_type = A1TC_CLASSFIELD_OSFS; |
| 1169 | $$->marker = $3; |
| 1170 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1171 | ; |
| 1172 | |
| 1173 | optWithSyntax: |
| 1174 | { $$ = 0; } |
| 1175 | | WithSyntax { |
| 1176 | $$ = $1; |
| 1177 | } |
| 1178 | ; |
| 1179 | |
| 1180 | WithSyntax: |
| 1181 | TOK_WITH TOK_SYNTAX '{' |
| 1182 | { asn1p_lexer_hack_enable_with_syntax(); } |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1183 | WithSyntaxList |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1184 | '}' { |
| 1185 | $$ = $5; |
| 1186 | } |
| 1187 | ; |
| 1188 | |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1189 | WithSyntaxList: |
| 1190 | WithSyntaxToken { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1191 | $$ = asn1p_wsyntx_new(); |
| 1192 | TQ_ADD(&($$->chunks), $1, next); |
| 1193 | } |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1194 | | WithSyntaxList WithSyntaxToken { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1195 | $$ = $1; |
| 1196 | TQ_ADD(&($$->chunks), $2, next); |
| 1197 | } |
| 1198 | ; |
| 1199 | |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1200 | WithSyntaxToken: |
Lev Walkin | 57074f1 | 2006-03-16 05:11:14 +0000 | [diff] [blame] | 1201 | TOK_whitespace { |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 1202 | $$ = asn1p_wsyntx_chunk_fromstring($1.buf, 0); |
Lev Walkin | 57074f1 | 2006-03-16 05:11:14 +0000 | [diff] [blame] | 1203 | $$->type = WC_WHITESPACE; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1204 | } |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1205 | | TOK_Literal { |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 1206 | $$ = asn1p_wsyntx_chunk_fromstring($1, 0); |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1207 | } |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 1208 | | PrimitiveFieldReference { |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 1209 | $$ = asn1p_wsyntx_chunk_fromstring($1.name, 0); |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 1210 | $$->type = WC_FIELD; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1211 | } |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 1212 | | '[' WithSyntaxList ']' { |
| 1213 | $$ = asn1p_wsyntx_chunk_fromsyntax($2); |
| 1214 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1215 | ; |
| 1216 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1217 | ExtensionAndException: |
| 1218 | TOK_ThreeDots { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1219 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1220 | checkmem($$); |
| 1221 | $$->Identifier = strdup("..."); |
| 1222 | checkmem($$->Identifier); |
| 1223 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1224 | $$->meta_type = AMT_TYPE; |
| 1225 | } |
| 1226 | | TOK_ThreeDots '!' DefinedValue { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1227 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1228 | checkmem($$); |
| 1229 | $$->Identifier = strdup("..."); |
| 1230 | checkmem($$->Identifier); |
| 1231 | $$->value = $3; |
| 1232 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1233 | $$->meta_type = AMT_TYPE; |
| 1234 | } |
| 1235 | | TOK_ThreeDots '!' SignedNumber { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1236 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1237 | checkmem($$); |
| 1238 | $$->Identifier = strdup("..."); |
| 1239 | $$->value = $3; |
| 1240 | checkmem($$->Identifier); |
| 1241 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1242 | $$->meta_type = AMT_TYPE; |
| 1243 | } |
| 1244 | ; |
| 1245 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1246 | Type: |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1247 | optTag TypeDeclaration optConstraints { |
| 1248 | $$ = $2; |
| 1249 | $$->tag = $1; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1250 | /* |
| 1251 | * Outer constraint for SEQUENCE OF and SET OF applies |
| 1252 | * to the inner type. |
| 1253 | */ |
| 1254 | if($$->expr_type == ASN_CONSTR_SEQUENCE_OF |
| 1255 | || $$->expr_type == ASN_CONSTR_SET_OF) { |
| 1256 | assert(!TQ_FIRST(&($$->members))->constraints); |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1257 | TQ_FIRST(&($$->members))->constraints = $3; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1258 | } else { |
| 1259 | if($$->constraints) { |
| 1260 | assert(!$2); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1261 | /* Check this : optConstraints is not used ?! */ |
| 1262 | asn1p_constraint_free($3); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1263 | } else { |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1264 | $$->constraints = $3; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1267 | } |
| 1268 | ; |
| 1269 | |
| 1270 | NSTD_IndirectMarker: |
| 1271 | { |
| 1272 | $$ = asn1p_as_pointer ? EM_INDIRECT : 0; |
| 1273 | asn1p_as_pointer = 0; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1274 | } |
| 1275 | ; |
| 1276 | |
| 1277 | TypeDeclaration: |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1278 | NSTD_IndirectMarker TypeDeclarationSet { |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 1279 | $$ = $2; |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1280 | $$->marker.flags |= $1; |
| 1281 | |
| 1282 | if(($$->marker.flags & EM_INDIRECT) |
| 1283 | && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) { |
| 1284 | fprintf(stderr, |
| 1285 | "INFO: Directive <ASN1C:RepresentAsPointer> " |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1286 | "applied to %s at %s:%d\n", |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1287 | ASN_EXPR_TYPE2STR($$->expr_type) |
| 1288 | ? ASN_EXPR_TYPE2STR($$->expr_type) |
| 1289 | : "member", |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1290 | ASN_FILENAME, $$->_lineno |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1291 | ); |
| 1292 | } |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 1293 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1294 | ; |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 1295 | |
| 1296 | TypeDeclarationSet: |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 1297 | DefinedType { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1298 | $$ = $1; |
| 1299 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1300 | | TOK_CHOICE '{' AlternativeTypeLists '}' { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1301 | $$ = $3; |
| 1302 | assert($$->expr_type == A1TC_INVALID); |
| 1303 | $$->expr_type = ASN_CONSTR_CHOICE; |
| 1304 | $$->meta_type = AMT_TYPE; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1305 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1306 | | TOK_SEQUENCE '{' optComponentTypeLists '}' { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1307 | $$ = $3; |
| 1308 | assert($$->expr_type == A1TC_INVALID); |
| 1309 | $$->expr_type = ASN_CONSTR_SEQUENCE; |
| 1310 | $$->meta_type = AMT_TYPE; |
| 1311 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1312 | | TOK_SET '{' optComponentTypeLists '}' { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1313 | $$ = $3; |
| 1314 | assert($$->expr_type == A1TC_INVALID); |
| 1315 | $$->expr_type = ASN_CONSTR_SET; |
| 1316 | $$->meta_type = AMT_TYPE; |
| 1317 | } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1318 | | TOK_SEQUENCE optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1319 | $$ = NEW_EXPR(); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1320 | checkmem($$); |
| 1321 | $$->constraints = $2; |
| 1322 | $$->expr_type = ASN_CONSTR_SEQUENCE_OF; |
| 1323 | $$->meta_type = AMT_TYPE; |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1324 | $6->Identifier = $4; |
| 1325 | $6->tag = $5; |
| 1326 | asn1p_expr_add($$, $6); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1327 | } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1328 | | TOK_SET optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1329 | $$ = NEW_EXPR(); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1330 | checkmem($$); |
| 1331 | $$->constraints = $2; |
| 1332 | $$->expr_type = ASN_CONSTR_SET_OF; |
| 1333 | $$->meta_type = AMT_TYPE; |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1334 | $6->Identifier = $4; |
| 1335 | $6->tag = $5; |
| 1336 | asn1p_expr_add($$, $6); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1337 | } |
| 1338 | | TOK_ANY { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1339 | $$ = NEW_EXPR(); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1340 | checkmem($$); |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 1341 | $$->expr_type = ASN_TYPE_ANY; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1342 | $$->meta_type = AMT_TYPE; |
| 1343 | } |
| 1344 | | TOK_ANY TOK_DEFINED TOK_BY Identifier { |
| 1345 | int ret; |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1346 | $$ = NEW_EXPR(); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1347 | checkmem($$); |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1348 | $$->reference = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1349 | ret = asn1p_ref_add_component($$->reference, |
| 1350 | $4, RLT_lowercase); |
| 1351 | checkmem(ret == 0); |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 1352 | $$->expr_type = ASN_TYPE_ANY; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1353 | $$->meta_type = AMT_TYPE; |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1354 | free($4); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1355 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1356 | | TOK_INSTANCE TOK_OF ComplexTypeReference { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1357 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1358 | checkmem($$); |
| 1359 | $$->reference = $3; |
| 1360 | $$->expr_type = A1TC_INSTANCE; |
| 1361 | $$->meta_type = AMT_TYPE; |
| 1362 | } |
| 1363 | ; |
| 1364 | |
| 1365 | /* |
| 1366 | * A type name consisting of several components. |
| 1367 | * === EXAMPLE === |
| 1368 | * === EOF === |
| 1369 | */ |
| 1370 | ComplexTypeReference: |
| 1371 | TOK_typereference { |
| 1372 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1373 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1374 | checkmem($$); |
| 1375 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1376 | checkmem(ret == 0); |
| 1377 | free($1); |
| 1378 | } |
| 1379 | | TOK_typereference '.' TypeRefName { |
| 1380 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1381 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1382 | checkmem($$); |
| 1383 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1384 | checkmem(ret == 0); |
| 1385 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1386 | checkmem(ret == 0); |
| 1387 | free($1); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1388 | free($3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1389 | } |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1390 | | ObjectClassReference '.' TypeRefName { |
| 1391 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1392 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1393 | checkmem($$); |
| 1394 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1395 | checkmem(ret == 0); |
| 1396 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1397 | checkmem(ret == 0); |
| 1398 | free($1); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1399 | free($3); |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1400 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1401 | | TOK_typereference '.' Identifier { |
| 1402 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1403 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1404 | checkmem($$); |
| 1405 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1406 | checkmem(ret == 0); |
| 1407 | ret = asn1p_ref_add_component($$, $3, RLT_lowercase); |
| 1408 | checkmem(ret == 0); |
| 1409 | free($1); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1410 | free($3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1411 | } |
| 1412 | | ObjectClassReference { |
| 1413 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1414 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1415 | checkmem($$); |
| 1416 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1417 | free($1); |
| 1418 | checkmem(ret == 0); |
| 1419 | } |
| 1420 | | ObjectClassReference '.' ComplexTypeReferenceAmpList { |
| 1421 | int ret; |
| 1422 | $$ = $3; |
| 1423 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1424 | free($1); |
| 1425 | checkmem(ret == 0); |
| 1426 | /* |
| 1427 | * Move the last element infront. |
| 1428 | */ |
| 1429 | { |
| 1430 | struct asn1p_ref_component_s tmp_comp; |
| 1431 | tmp_comp = $$->components[$$->comp_count-1]; |
| 1432 | memmove(&$$->components[1], |
| 1433 | &$$->components[0], |
| 1434 | sizeof($$->components[0]) |
| 1435 | * ($$->comp_count - 1)); |
| 1436 | $$->components[0] = tmp_comp; |
| 1437 | } |
| 1438 | } |
| 1439 | ; |
| 1440 | |
| 1441 | ComplexTypeReferenceAmpList: |
| 1442 | ComplexTypeReferenceElement { |
| 1443 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1444 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1445 | checkmem($$); |
| 1446 | ret = asn1p_ref_add_component($$, $1.name, $1.lex_type); |
| 1447 | free($1.name); |
| 1448 | checkmem(ret == 0); |
| 1449 | } |
| 1450 | | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement { |
| 1451 | int ret; |
| 1452 | $$ = $1; |
| 1453 | ret = asn1p_ref_add_component($$, $3.name, $3.lex_type); |
| 1454 | free($3.name); |
| 1455 | checkmem(ret == 0); |
| 1456 | } |
| 1457 | ; |
| 1458 | |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 1459 | ComplexTypeReferenceElement: PrimitiveFieldReference; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1460 | |
Lev Walkin | d370e9f | 2006-03-16 10:03:35 +0000 | [diff] [blame] | 1461 | PrimitiveFieldReference: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1462 | /* "&Type1" */ |
| 1463 | TOK_typefieldreference { |
| 1464 | $$.lex_type = RLT_AmpUppercase; |
| 1465 | $$.name = $1; |
| 1466 | } |
| 1467 | /* "&id" */ |
| 1468 | | TOK_valuefieldreference { |
| 1469 | $$.lex_type = RLT_Amplowercase; |
| 1470 | $$.name = $1; |
| 1471 | } |
| 1472 | ; |
| 1473 | |
| 1474 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1475 | FieldName: |
| 1476 | /* "&Type1" */ |
| 1477 | TOK_typefieldreference { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1478 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1479 | asn1p_ref_add_component($$, $1, RLT_AmpUppercase); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1480 | free($1); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1481 | } |
| 1482 | | FieldName '.' TOK_typefieldreference { |
| 1483 | $$ = $$; |
| 1484 | asn1p_ref_add_component($$, $3, RLT_AmpUppercase); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1485 | free($3); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1486 | } |
| 1487 | | FieldName '.' TOK_valuefieldreference { |
| 1488 | $$ = $$; |
| 1489 | asn1p_ref_add_component($$, $3, RLT_Amplowercase); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1490 | free($3); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1491 | } |
| 1492 | ; |
| 1493 | |
| 1494 | DefinedObjectClass: |
| 1495 | TOK_capitalreference { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1496 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1497 | asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1498 | free($1); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1499 | } |
Lev Walkin | 5486875 | 2006-03-09 09:08:49 +0000 | [diff] [blame] | 1500 | /* |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1501 | | TypeRefName '.' TOK_capitalreference { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1502 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1503 | asn1p_ref_add_component($$, $1, RLT_AmpUppercase); |
| 1504 | asn1p_ref_add_component($$, $3, RLT_CAPITALS); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1505 | free($1); |
| 1506 | free($3); |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1507 | } |
Lev Walkin | 5486875 | 2006-03-09 09:08:49 +0000 | [diff] [blame] | 1508 | */ |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 1509 | ; |
| 1510 | |
| 1511 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1512 | /* |
| 1513 | * === EXAMPLE === |
| 1514 | * value INTEGER ::= 1 |
| 1515 | * === EOF === |
| 1516 | */ |
Lev Walkin | c6ab03c | 2006-10-21 05:54:49 +0000 | [diff] [blame] | 1517 | ValueAssignment: |
| 1518 | Identifier Type TOK_PPEQ Value { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1519 | $$ = $2; |
| 1520 | assert($$->Identifier == NULL); |
| 1521 | $$->Identifier = $1; |
| 1522 | $$->meta_type = AMT_VALUE; |
| 1523 | $$->value = $4; |
| 1524 | } |
| 1525 | ; |
| 1526 | |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1527 | Value: |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 1528 | SimpleValue |
| 1529 | | DefinedValue |
| 1530 | | Identifier ':' Value { |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1531 | $$ = asn1p_value_fromint(0); |
| 1532 | checkmem($$); |
| 1533 | $$->type = ATV_CHOICE_IDENTIFIER; |
| 1534 | $$->value.choice_identifier.identifier = $1; |
| 1535 | $$->value.choice_identifier.value = $3; |
| 1536 | } |
Lev Walkin | cbad251 | 2005-03-24 16:27:02 +0000 | [diff] [blame] | 1537 | | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1538 | $$ = asn1p_value_frombuf($3.buf, $3.len, 0); |
| 1539 | checkmem($$); |
| 1540 | $$->type = ATV_UNPARSED; |
| 1541 | } |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1542 | | TOK_NULL { |
| 1543 | $$ = asn1p_value_fromint(0); |
| 1544 | checkmem($$); |
| 1545 | $$->type = ATV_NULL; |
| 1546 | } |
Lev Walkin | 0c0bca6 | 2006-03-21 04:48:15 +0000 | [diff] [blame] | 1547 | ; |
| 1548 | |
| 1549 | SimpleValue: |
| 1550 | TOK_FALSE { |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1551 | $$ = asn1p_value_fromint(0); |
| 1552 | checkmem($$); |
| 1553 | $$->type = ATV_FALSE; |
| 1554 | } |
| 1555 | | TOK_TRUE { |
| 1556 | $$ = asn1p_value_fromint(0); |
| 1557 | checkmem($$); |
| 1558 | $$->type = ATV_TRUE; |
| 1559 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1560 | | TOK_bstring { |
| 1561 | $$ = _convert_bitstring2binary($1, 'B'); |
| 1562 | checkmem($$); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1563 | free($1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1564 | } |
| 1565 | | TOK_hstring { |
| 1566 | $$ = _convert_bitstring2binary($1, 'H'); |
| 1567 | checkmem($$); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1568 | free($1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1569 | } |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1570 | | RestrictedCharacterStringValue { |
| 1571 | $$ = $$; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1572 | } |
| 1573 | | SignedNumber { |
| 1574 | $$ = $1; |
| 1575 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1576 | ; |
| 1577 | |
| 1578 | DefinedValue: |
| 1579 | Identifier { |
| 1580 | asn1p_ref_t *ref; |
| 1581 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1582 | ref = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1583 | checkmem(ref); |
| 1584 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1585 | checkmem(ret == 0); |
| 1586 | $$ = asn1p_value_fromref(ref, 0); |
| 1587 | checkmem($$); |
| 1588 | free($1); |
| 1589 | } |
| 1590 | | TypeRefName '.' Identifier { |
| 1591 | asn1p_ref_t *ref; |
| 1592 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1593 | ref = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1594 | checkmem(ref); |
| 1595 | ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); |
| 1596 | checkmem(ret == 0); |
| 1597 | ret = asn1p_ref_add_component(ref, $3, RLT_lowercase); |
| 1598 | checkmem(ret == 0); |
| 1599 | $$ = asn1p_value_fromref(ref, 0); |
| 1600 | checkmem($$); |
| 1601 | free($1); |
| 1602 | free($3); |
| 1603 | } |
| 1604 | ; |
| 1605 | |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1606 | |
| 1607 | RestrictedCharacterStringValue: |
| 1608 | TOK_cstring { |
| 1609 | $$ = asn1p_value_frombuf($1.buf, $1.len, 0); |
| 1610 | checkmem($$); |
| 1611 | } |
Lev Walkin | d9574ae | 2005-03-24 16:22:35 +0000 | [diff] [blame] | 1612 | | TOK_tuple { |
| 1613 | $$ = asn1p_value_fromint($1); |
| 1614 | checkmem($$); |
| 1615 | $$->type = ATV_TUPLE; |
| 1616 | } |
| 1617 | | TOK_quadruple { |
| 1618 | $$ = asn1p_value_fromint($1); |
| 1619 | checkmem($$); |
| 1620 | $$->type = ATV_QUADRUPLE; |
| 1621 | } |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1622 | ; |
| 1623 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1624 | Opaque: |
| 1625 | TOK_opaque { |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 1626 | $$.len = $1.len + 1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1627 | $$.buf = malloc($$.len + 1); |
| 1628 | checkmem($$.buf); |
| 1629 | $$.buf[0] = '{'; |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 1630 | memcpy($$.buf + 1, $1.buf, $1.len); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1631 | $$.buf[$$.len] = '\0'; |
| 1632 | free($1.buf); |
| 1633 | } |
| 1634 | | Opaque TOK_opaque { |
| 1635 | int newsize = $1.len + $2.len; |
| 1636 | char *p = malloc(newsize + 1); |
| 1637 | checkmem(p); |
| 1638 | memcpy(p , $1.buf, $1.len); |
| 1639 | memcpy(p + $1.len, $2.buf, $2.len); |
| 1640 | p[newsize] = '\0'; |
| 1641 | free($1.buf); |
| 1642 | free($2.buf); |
| 1643 | $$.buf = p; |
| 1644 | $$.len = newsize; |
| 1645 | } |
| 1646 | ; |
| 1647 | |
| 1648 | BasicTypeId: |
| 1649 | TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; } |
| 1650 | | TOK_NULL { $$ = ASN_BASIC_NULL; } |
| 1651 | | TOK_REAL { $$ = ASN_BASIC_REAL; } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1652 | | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; } |
| 1653 | | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; } |
| 1654 | | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; } |
| 1655 | | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; } |
| 1656 | | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; } |
| 1657 | | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; } |
| 1658 | | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; } |
| 1659 | | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; } |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 1660 | | BasicString |
| 1661 | | BasicTypeId_UniverationCompatible |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1662 | ; |
| 1663 | |
| 1664 | /* |
| 1665 | * A type identifier which may be used with "{ a(1), b(2) }" clause. |
| 1666 | */ |
| 1667 | BasicTypeId_UniverationCompatible: |
| 1668 | TOK_INTEGER { $$ = ASN_BASIC_INTEGER; } |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 1669 | | TOK_ENUMERATED { $$ = ASN_BASIC_INTEGER; } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1670 | | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; } |
| 1671 | ; |
| 1672 | |
| 1673 | BasicType: |
| 1674 | BasicTypeId { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 1675 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1676 | checkmem($$); |
| 1677 | $$->expr_type = $1; |
| 1678 | $$->meta_type = AMT_TYPE; |
| 1679 | } |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 1680 | | TOK_INTEGER '{' NamedNumberList '}' { |
| 1681 | $$ = $3; |
| 1682 | $$->expr_type = ASN_BASIC_INTEGER; |
| 1683 | $$->meta_type = AMT_TYPE; |
| 1684 | } |
| 1685 | | TOK_ENUMERATED '{' Enumerations '}' { |
| 1686 | $$ = $3; |
| 1687 | $$->expr_type = ASN_BASIC_ENUMERATED; |
| 1688 | $$->meta_type = AMT_TYPE; |
| 1689 | } |
| 1690 | | TOK_BIT TOK_STRING '{' NamedBitList '}' { |
| 1691 | $$ = $4; |
| 1692 | $$->expr_type = ASN_BASIC_BIT_STRING; |
| 1693 | $$->meta_type = AMT_TYPE; |
| 1694 | } |
| 1695 | | TOK_ExtValue_BIT_STRING '{' IdentifierList '}' { |
| 1696 | $$ = $3; |
| 1697 | $$->expr_type = ASN_BASIC_BIT_STRING; |
| 1698 | $$->meta_type = AMT_TYPE; |
| 1699 | } |
| 1700 | | TOK_ExtValue_BIT_STRING '{' '}' { |
| 1701 | $$ = NEW_EXPR(); |
| 1702 | checkmem($$); |
| 1703 | $$->expr_type = ASN_BASIC_BIT_STRING; |
| 1704 | $$->meta_type = AMT_TYPE; |
| 1705 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1706 | ; |
| 1707 | |
| 1708 | BasicString: |
| 1709 | TOK_BMPString { $$ = ASN_STRING_BMPString; } |
| 1710 | | TOK_GeneralString { |
| 1711 | $$ = ASN_STRING_GeneralString; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1712 | fprintf(stderr, "WARNING: GeneralString is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1713 | } |
| 1714 | | TOK_GraphicString { |
| 1715 | $$ = ASN_STRING_GraphicString; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1716 | fprintf(stderr, "WARNING: GraphicString is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1717 | } |
| 1718 | | TOK_IA5String { $$ = ASN_STRING_IA5String; } |
| 1719 | | TOK_ISO646String { $$ = ASN_STRING_ISO646String; } |
| 1720 | | TOK_NumericString { $$ = ASN_STRING_NumericString; } |
| 1721 | | TOK_PrintableString { $$ = ASN_STRING_PrintableString; } |
| 1722 | | TOK_T61String { |
| 1723 | $$ = ASN_STRING_T61String; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1724 | fprintf(stderr, "WARNING: T61String is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1725 | } |
| 1726 | | TOK_TeletexString { $$ = ASN_STRING_TeletexString; } |
| 1727 | | TOK_UniversalString { $$ = ASN_STRING_UniversalString; } |
| 1728 | | TOK_UTF8String { $$ = ASN_STRING_UTF8String; } |
| 1729 | | TOK_VideotexString { |
| 1730 | $$ = ASN_STRING_VideotexString; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1731 | fprintf(stderr, "WARNING: VideotexString is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1732 | } |
| 1733 | | TOK_VisibleString { $$ = ASN_STRING_VisibleString; } |
| 1734 | | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; } |
| 1735 | ; |
| 1736 | |
Lev Walkin | d2ea1de | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1737 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1738 | /* |
| 1739 | * Data type constraints. |
| 1740 | */ |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 1741 | UnionMark: '|' | TOK_UNION; |
| 1742 | IntersectionMark: '^' | TOK_INTERSECTION; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1743 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1744 | /* empty | Constraint */ |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1745 | optConstraints: |
| 1746 | { $$ = 0; } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1747 | | Constraint; |
Lev Walkin | d2ea1de | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1748 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1749 | /* empty | Constraint | SIZE(...) */ |
| 1750 | optSizeConstraints: |
| 1751 | { $$ = 0; } |
| 1752 | | Constraint |
| 1753 | | TOK_SIZE '(' ConstraintSpec ')' { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1754 | CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1755 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1756 | ; |
| 1757 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1758 | Constraint: |
| 1759 | SetOfConstraints { |
| 1760 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0); |
| 1761 | } |
| 1762 | ; |
| 1763 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1764 | SetOfConstraints: |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1765 | '(' ConstraintSpec ')' { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1766 | $$ = $2; |
| 1767 | } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1768 | | SetOfConstraints '(' ConstraintSpec ')' { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1769 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1770 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1771 | ; |
| 1772 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1773 | ConstraintSpec: SubtypeConstraint | GeneralConstraint; |
| 1774 | |
| 1775 | SubtypeConstraint: ElementSetSpecs; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1776 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1777 | ElementSetSpecs: |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 1778 | TOK_ThreeDots { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1779 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 1780 | $$->type = ACT_EL_EXT; |
| 1781 | } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1782 | | ElementSetSpec |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1783 | | ElementSetSpec ',' TOK_ThreeDots { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1784 | asn1p_constraint_t *ct; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1785 | ct = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1786 | ct->type = ACT_EL_EXT; |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1787 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1788 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1789 | | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1790 | asn1p_constraint_t *ct; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1791 | ct = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1792 | ct->type = ACT_EL_EXT; |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1793 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
Lev Walkin | b4fcdd2 | 2004-08-13 12:35:09 +0000 | [diff] [blame] | 1794 | ct = $$; |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1795 | CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1796 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1797 | ; |
| 1798 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1799 | ElementSetSpec: |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 1800 | Unions |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1801 | | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1802 | CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0); |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1803 | } |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 1804 | ; |
| 1805 | |
| 1806 | Unions: |
| 1807 | Intersections |
| 1808 | | Unions UnionMark Intersections { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1809 | CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1810 | } |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 1811 | ; |
| 1812 | |
| 1813 | Intersections: |
| 1814 | IntersectionElements |
| 1815 | | Intersections IntersectionMark IntersectionElements { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1816 | CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1817 | } |
Lev Walkin | f172715 | 2006-09-21 01:50:37 +0000 | [diff] [blame] | 1818 | ; |
| 1819 | |
| 1820 | |
| 1821 | IntersectionElements: |
| 1822 | ConstraintSubtypeElement |
| 1823 | | ConstraintSubtypeElement TOK_EXCEPT ConstraintSubtypeElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1824 | CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1825 | } |
| 1826 | ; |
| 1827 | |
| 1828 | ConstraintSubtypeElement: |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1829 | ConstraintType '(' ElementSetSpecs ')' { |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1830 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1831 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1832 | checkmem($$); |
| 1833 | $$->type = $1; |
| 1834 | ret = asn1p_constraint_insert($$, $3); |
| 1835 | checkmem(ret == 0); |
| 1836 | } |
| 1837 | | '(' ElementSetSpecs ')' { |
| 1838 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1839 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1840 | checkmem($$); |
| 1841 | $$->type = ACT_CA_SET; |
| 1842 | ret = asn1p_constraint_insert($$, $2); |
| 1843 | checkmem(ret == 0); |
| 1844 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1845 | | SingleValue { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1846 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1847 | checkmem($$); |
| 1848 | $$->type = ACT_EL_VALUE; |
| 1849 | $$->value = $1; |
| 1850 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1851 | | ContainedSubtype { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1852 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1853 | checkmem($$); |
| 1854 | $$->type = ACT_EL_TYPE; |
| 1855 | $$->containedSubtype = $1; |
| 1856 | } |
| 1857 | | SingleValue ConstraintRangeSpec SingleValue { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1858 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1859 | checkmem($$); |
| 1860 | $$->type = $2; |
| 1861 | $$->range_start = $1; |
| 1862 | $$->range_stop = $3; |
| 1863 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1864 | | TOK_MIN ConstraintRangeSpec SingleValue { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1865 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1866 | checkmem($$); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1867 | $$->type = $2; |
| 1868 | $$->range_start = asn1p_value_fromint(-123); |
| 1869 | $$->range_stop = $3; |
| 1870 | $$->range_start->type = ATV_MIN; |
| 1871 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1872 | | SingleValue ConstraintRangeSpec TOK_MAX { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1873 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1874 | checkmem($$); |
| 1875 | $$->type = $2; |
| 1876 | $$->range_start = $1; |
| 1877 | $$->range_stop = asn1p_value_fromint(321); |
| 1878 | $$->range_stop->type = ATV_MAX; |
| 1879 | } |
| 1880 | | TOK_MIN ConstraintRangeSpec TOK_MAX { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1881 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1882 | checkmem($$); |
| 1883 | $$->type = $2; |
| 1884 | $$->range_start = asn1p_value_fromint(-123); |
| 1885 | $$->range_stop = asn1p_value_fromint(321); |
| 1886 | $$->range_start->type = ATV_MIN; |
| 1887 | $$->range_stop->type = ATV_MAX; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1888 | } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1889 | | InnerTypeConstraint |
| 1890 | | PatternConstraint |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1891 | | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
| 1892 | $$ = asn1p_constraint_new(yylineno, currentModule); |
| 1893 | checkmem($$); |
| 1894 | $$->type = ACT_EL_VALUE; |
| 1895 | $$->value = asn1p_value_frombuf($3.buf, $3.len, 0); |
| 1896 | $$->value->type = ATV_UNPARSED; |
| 1897 | } |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 1898 | ; |
| 1899 | |
| 1900 | PatternConstraint: |
| 1901 | TOK_PATTERN TOK_cstring { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1902 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 1903 | $$->type = ACT_CT_PATTERN; |
| 1904 | $$->value = asn1p_value_frombuf($2.buf, $2.len, 0); |
| 1905 | } |
| 1906 | | TOK_PATTERN Identifier { |
| 1907 | asn1p_ref_t *ref; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1908 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 1909 | $$->type = ACT_CT_PATTERN; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1910 | ref = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 1911 | asn1p_ref_add_component(ref, $2, RLT_lowercase); |
| 1912 | $$->value = asn1p_value_fromref(ref, 0); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1913 | free($2); |
Lev Walkin | 5c541f1 | 2006-10-18 18:40:14 +0000 | [diff] [blame] | 1914 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1915 | ; |
| 1916 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1917 | ConstraintType: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1918 | TOK_SIZE { |
| 1919 | $$ = ACT_CT_SIZE; |
| 1920 | } |
| 1921 | | TOK_FROM { |
| 1922 | $$ = ACT_CT_FROM; |
| 1923 | } |
| 1924 | ; |
| 1925 | |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1926 | SingleValue: |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1927 | TOK_FALSE { |
| 1928 | $$ = asn1p_value_fromint(0); |
| 1929 | checkmem($$); |
| 1930 | $$->type = ATV_FALSE; |
| 1931 | } |
| 1932 | | TOK_TRUE { |
| 1933 | $$ = asn1p_value_fromint(1); |
| 1934 | checkmem($$); |
| 1935 | $$->type = ATV_TRUE; |
| 1936 | } |
Lev Walkin | adf863f | 2006-09-05 16:18:34 +0000 | [diff] [blame] | 1937 | | RealValue |
| 1938 | | RestrictedCharacterStringValue |
Lev Walkin | 1c8d5aa | 2006-10-27 05:37:39 +0000 | [diff] [blame] | 1939 | | BitStringValue |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1940 | | Identifier { |
| 1941 | asn1p_ref_t *ref; |
| 1942 | int ret; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1943 | ref = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1944 | checkmem(ref); |
| 1945 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1946 | checkmem(ret == 0); |
| 1947 | $$ = asn1p_value_fromref(ref, 0); |
| 1948 | checkmem($$); |
| 1949 | free($1); |
| 1950 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1951 | ; |
| 1952 | |
Lev Walkin | 1c8d5aa | 2006-10-27 05:37:39 +0000 | [diff] [blame] | 1953 | BitStringValue: |
| 1954 | TOK_bstring { |
| 1955 | $$ = _convert_bitstring2binary($1, 'B'); |
| 1956 | checkmem($$); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1957 | free($1); |
Lev Walkin | 1c8d5aa | 2006-10-27 05:37:39 +0000 | [diff] [blame] | 1958 | } |
| 1959 | | TOK_hstring { |
| 1960 | $$ = _convert_bitstring2binary($1, 'H'); |
| 1961 | checkmem($$); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 1962 | free($1); |
Lev Walkin | 1c8d5aa | 2006-10-27 05:37:39 +0000 | [diff] [blame] | 1963 | } |
| 1964 | ; |
| 1965 | |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1966 | ContainedSubtype: |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1967 | Type { |
| 1968 | $$ = asn1p_value_fromtype($1); |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1969 | checkmem($$); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1970 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1971 | ; |
| 1972 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1973 | /* |
| 1974 | * X.680 08/2015 |
| 1975 | * #51.8.5 |
| 1976 | */ |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1977 | InnerTypeConstraint: |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1978 | TOK_WITH TOK_COMPONENT SingleTypeConstraint { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1979 | CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1980 | } |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1981 | | TOK_WITH TOK_COMPONENTS MultipleTypeConstraints { |
| 1982 | assert($3->type == ACT_CA_CSV); |
| 1983 | $3->type = ACT_CT_WCOMPS; |
| 1984 | $$ = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1985 | } |
| 1986 | ; |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1987 | SingleTypeConstraint: Constraint; |
| 1988 | MultipleTypeConstraints: FullSpecification | PartialSpecification; |
| 1989 | FullSpecification: '{' TypeConstraints '}' { $$ = $2; }; |
| 1990 | PartialSpecification: |
| 1991 | '{' TOK_ThreeDots ',' TypeConstraints '}' { |
| 1992 | assert($4->type == ACT_CA_CSV); |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 1993 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1994 | $$->type = ACT_CA_CSV; |
| 1995 | asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1996 | checkmem($$); |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 1997 | ct->type = ACT_EL_EXT; |
| 1998 | asn1p_constraint_insert($$, ct); |
| 1999 | for(unsigned i = 0; i < $4->el_count; i++) { |
| 2000 | asn1p_constraint_insert($$, $4->elements[i]); |
| 2001 | } |
| 2002 | }; |
| 2003 | TypeConstraints: |
| 2004 | NamedConstraint { |
| 2005 | $$ = asn1p_constraint_new(yylineno, currentModule); |
| 2006 | $$->type = ACT_CA_CSV; |
| 2007 | asn1p_constraint_insert($$, $1); |
| 2008 | } |
| 2009 | | TypeConstraints ',' NamedConstraint { |
| 2010 | $$ = $1; |
| 2011 | asn1p_constraint_insert($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2012 | } |
| 2013 | ; |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 2014 | NamedConstraint: |
| 2015 | IdentifierAsValue optConstraints optPresenceConstraint { |
| 2016 | $$ = asn1p_constraint_new(yylineno, currentModule); |
| 2017 | checkmem($$); |
| 2018 | $$->type = ACT_EL_VALUE; |
| 2019 | $$->value = $1; |
| 2020 | if($2) asn1p_constraint_insert($$, $2); |
| 2021 | $$->presence = $3; |
| 2022 | } |
| 2023 | ; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2024 | |
| 2025 | /* |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 2026 | * presence constraint for NamedConstraint |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2027 | */ |
| 2028 | optPresenceConstraint: |
| 2029 | { $$ = ACPRES_DEFAULT; } |
| 2030 | | PresenceConstraint { $$ = $1; } |
| 2031 | ; |
| 2032 | |
| 2033 | PresenceConstraint: |
| 2034 | TOK_PRESENT { |
| 2035 | $$ = ACPRES_PRESENT; |
| 2036 | } |
| 2037 | | TOK_ABSENT { |
| 2038 | $$ = ACPRES_ABSENT; |
| 2039 | } |
| 2040 | | TOK_OPTIONAL { |
| 2041 | $$ = ACPRES_OPTIONAL; |
| 2042 | } |
| 2043 | ; |
| 2044 | |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2045 | |
| 2046 | /* X.682 */ |
| 2047 | GeneralConstraint: |
| 2048 | UserDefinedConstraint |
| 2049 | | TableConstraint |
| 2050 | | ContentsConstraint |
| 2051 | ; |
| 2052 | |
| 2053 | UserDefinedConstraint: |
| 2054 | TOK_CONSTRAINED TOK_BY '{' |
| 2055 | { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2056 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2057 | checkmem($$); |
| 2058 | $$->type = ACT_CT_CTDBY; |
| 2059 | $$->value = asn1p_value_frombuf($5.buf, $5.len, 0); |
| 2060 | checkmem($$->value); |
| 2061 | $$->value->type = ATV_UNPARSED; |
| 2062 | } |
| 2063 | ; |
| 2064 | |
| 2065 | ContentsConstraint: |
| 2066 | TOK_CONTAINING Type { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2067 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2068 | $$->type = ACT_CT_CTNG; |
| 2069 | $$->value = asn1p_value_fromtype($2); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 2070 | asn1p_expr_free($2); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2071 | } |
| 2072 | ; |
| 2073 | |
| 2074 | ConstraintRangeSpec: |
| 2075 | TOK_TwoDots { $$ = ACT_EL_RANGE; } |
| 2076 | | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; } |
| 2077 | | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; } |
| 2078 | | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; } |
| 2079 | ; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2080 | TableConstraint: |
| 2081 | SimpleTableConstraint { |
| 2082 | $$ = $1; |
| 2083 | } |
| 2084 | | ComponentRelationConstraint { |
| 2085 | $$ = $1; |
| 2086 | } |
| 2087 | ; |
| 2088 | |
| 2089 | /* |
| 2090 | * "{ExtensionSet}" |
| 2091 | */ |
| 2092 | SimpleTableConstraint: |
| 2093 | '{' TypeRefName '}' { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2094 | asn1p_ref_t *ref = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2095 | asn1p_constraint_t *ct; |
| 2096 | int ret; |
| 2097 | ret = asn1p_ref_add_component(ref, $2, 0); |
| 2098 | checkmem(ret == 0); |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2099 | ct = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2100 | checkmem($$); |
| 2101 | ct->type = ACT_EL_VALUE; |
| 2102 | ct->value = asn1p_value_fromref(ref, 0); |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 2103 | CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0); |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 2104 | free($2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2105 | } |
| 2106 | ; |
| 2107 | |
| 2108 | ComponentRelationConstraint: |
| 2109 | SimpleTableConstraint '{' AtNotationList '}' { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 2110 | CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2111 | } |
| 2112 | ; |
| 2113 | |
| 2114 | AtNotationList: |
| 2115 | AtNotationElement { |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2116 | $$ = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2117 | checkmem($$); |
| 2118 | $$->type = ACT_EL_VALUE; |
| 2119 | $$->value = asn1p_value_fromref($1, 0); |
| 2120 | } |
| 2121 | | AtNotationList ',' AtNotationElement { |
| 2122 | asn1p_constraint_t *ct; |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2123 | ct = asn1p_constraint_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2124 | checkmem(ct); |
| 2125 | ct->type = ACT_EL_VALUE; |
| 2126 | ct->value = asn1p_value_fromref($3, 0); |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 2127 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2128 | } |
| 2129 | ; |
| 2130 | |
| 2131 | /* |
| 2132 | * @blah |
| 2133 | */ |
| 2134 | AtNotationElement: |
| 2135 | '@' ComponentIdList { |
| 2136 | char *p = malloc(strlen($2) + 2); |
| 2137 | int ret; |
| 2138 | *p = '@'; |
| 2139 | strcpy(p + 1, $2); |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2140 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2141 | ret = asn1p_ref_add_component($$, p, 0); |
| 2142 | checkmem(ret == 0); |
| 2143 | free(p); |
| 2144 | free($2); |
| 2145 | } |
| 2146 | | '@' '.' ComponentIdList { |
| 2147 | char *p = malloc(strlen($3) + 3); |
| 2148 | int ret; |
| 2149 | p[0] = '@'; |
| 2150 | p[1] = '.'; |
| 2151 | strcpy(p + 2, $3); |
Bi-Ruei, Chiu | 80fd306 | 2017-05-07 21:00:51 +0800 | [diff] [blame] | 2152 | $$ = asn1p_ref_new(yylineno, currentModule); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2153 | ret = asn1p_ref_add_component($$, p, 0); |
| 2154 | checkmem(ret == 0); |
| 2155 | free(p); |
| 2156 | free($3); |
| 2157 | } |
| 2158 | ; |
| 2159 | |
| 2160 | /* identifier "." ... */ |
| 2161 | ComponentIdList: |
| 2162 | Identifier { |
| 2163 | $$ = $1; |
| 2164 | } |
| 2165 | | ComponentIdList '.' Identifier { |
| 2166 | int l1 = strlen($1); |
| 2167 | int l3 = strlen($3); |
| 2168 | $$ = malloc(l1 + 1 + l3 + 1); |
| 2169 | memcpy($$, $1, l1); |
| 2170 | $$[l1] = '.'; |
| 2171 | memcpy($$ + l1 + 1, $3, l3); |
| 2172 | $$[l1 + 1 + l3] = '\0'; |
Bi-Ruei, Chiu | 3dcf05b | 2017-05-04 21:45:05 +0800 | [diff] [blame] | 2173 | free($1); |
| 2174 | free($3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2175 | } |
| 2176 | ; |
| 2177 | |
| 2178 | |
| 2179 | |
| 2180 | /* |
| 2181 | * MARKERS |
| 2182 | */ |
| 2183 | |
| 2184 | optMarker: |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 2185 | { |
| 2186 | $$.flags = EM_NOMARK; |
| 2187 | $$.default_value = 0; |
| 2188 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2189 | | Marker { $$ = $1; } |
| 2190 | ; |
| 2191 | |
| 2192 | Marker: |
| 2193 | TOK_OPTIONAL { |
Lev Walkin | 7085305 | 2005-11-26 11:21:55 +0000 | [diff] [blame] | 2194 | $$.flags = EM_OPTIONAL | EM_INDIRECT; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 2195 | $$.default_value = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2196 | } |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 2197 | | TOK_DEFAULT Value { |
| 2198 | $$.flags = EM_DEFAULT; |
| 2199 | $$.default_value = $2; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2200 | } |
| 2201 | ; |
| 2202 | |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 2203 | IdentifierList: |
| 2204 | IdentifierElement { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2205 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2206 | checkmem($$); |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 2207 | asn1p_expr_add($$, $1); |
| 2208 | } |
| 2209 | | IdentifierList ',' IdentifierElement { |
| 2210 | $$ = $1; |
| 2211 | asn1p_expr_add($$, $3); |
| 2212 | }; |
| 2213 | |
| 2214 | IdentifierElement: |
| 2215 | Identifier { |
| 2216 | $$ = NEW_EXPR(); |
| 2217 | checkmem($$); |
| 2218 | $$->expr_type = A1TC_UNIVERVAL; |
| 2219 | $$->meta_type = AMT_VALUE; |
| 2220 | $$->Identifier = $1; |
| 2221 | } |
| 2222 | |
| 2223 | NamedNumberList: |
| 2224 | NamedNumber { |
| 2225 | $$ = NEW_EXPR(); |
| 2226 | checkmem($$); |
| 2227 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2228 | } |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 2229 | | NamedNumberList ',' NamedNumber { |
| 2230 | $$ = $1; |
| 2231 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2232 | } |
| 2233 | ; |
| 2234 | |
Lev Walkin | be518fa | 2017-09-07 02:05:28 -0700 | [diff] [blame] | 2235 | NamedNumber: |
| 2236 | Identifier '(' SignedNumber ')' { |
| 2237 | $$ = NEW_EXPR(); |
| 2238 | checkmem($$); |
| 2239 | $$->expr_type = A1TC_UNIVERVAL; |
| 2240 | $$->meta_type = AMT_VALUE; |
| 2241 | $$->Identifier = $1; |
| 2242 | $$->value = $3; |
| 2243 | } |
| 2244 | | Identifier '(' DefinedValue ')' { |
| 2245 | $$ = NEW_EXPR(); |
| 2246 | checkmem($$); |
| 2247 | $$->expr_type = A1TC_UNIVERVAL; |
| 2248 | $$->meta_type = AMT_VALUE; |
| 2249 | $$->Identifier = $1; |
| 2250 | $$->value = $3; |
| 2251 | }; |
| 2252 | |
| 2253 | NamedBitList: |
| 2254 | NamedBit { |
| 2255 | $$ = NEW_EXPR(); |
| 2256 | checkmem($$); |
| 2257 | asn1p_expr_add($$, $1); |
| 2258 | } |
| 2259 | | NamedBitList ',' NamedBit { |
| 2260 | $$ = $1; |
| 2261 | asn1p_expr_add($$, $3); |
| 2262 | } |
| 2263 | ; |
| 2264 | |
| 2265 | NamedBit: |
| 2266 | Identifier '(' TOK_number ')' { |
| 2267 | $$ = NEW_EXPR(); |
| 2268 | checkmem($$); |
| 2269 | $$->expr_type = A1TC_UNIVERVAL; |
| 2270 | $$->meta_type = AMT_VALUE; |
| 2271 | $$->Identifier = $1; |
| 2272 | $$->value = asn1p_value_fromint($3); |
| 2273 | } |
| 2274 | | Identifier '(' DefinedValue ')' { |
| 2275 | $$ = NEW_EXPR(); |
| 2276 | checkmem($$); |
| 2277 | $$->expr_type = A1TC_UNIVERVAL; |
| 2278 | $$->meta_type = AMT_VALUE; |
| 2279 | $$->Identifier = $1; |
| 2280 | $$->value = $3; |
| 2281 | }; |
| 2282 | |
| 2283 | Enumerations: |
| 2284 | UniverationList { |
| 2285 | $$ = $1; |
| 2286 | asn1p_expr_t *first_memb = TQ_FIRST(&($$->members)); |
| 2287 | if(first_memb) { |
| 2288 | if(first_memb->expr_type == A1TC_EXTENSIBLE) { |
| 2289 | return yyerror( |
| 2290 | "The ENUMERATION cannot start with extension (...)."); |
| 2291 | } |
| 2292 | } else { |
| 2293 | return yyerror( |
| 2294 | "The ENUMERATION list cannot be empty."); |
| 2295 | } |
| 2296 | } |
| 2297 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2298 | UniverationList: |
| 2299 | UniverationElement { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2300 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2301 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 2302 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2303 | } |
| 2304 | | UniverationList ',' UniverationElement { |
| 2305 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 2306 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2307 | } |
| 2308 | ; |
| 2309 | |
| 2310 | UniverationElement: |
| 2311 | Identifier { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2312 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2313 | checkmem($$); |
| 2314 | $$->expr_type = A1TC_UNIVERVAL; |
| 2315 | $$->meta_type = AMT_VALUE; |
| 2316 | $$->Identifier = $1; |
| 2317 | } |
| 2318 | | Identifier '(' SignedNumber ')' { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2319 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2320 | checkmem($$); |
| 2321 | $$->expr_type = A1TC_UNIVERVAL; |
| 2322 | $$->meta_type = AMT_VALUE; |
| 2323 | $$->Identifier = $1; |
| 2324 | $$->value = $3; |
| 2325 | } |
| 2326 | | Identifier '(' DefinedValue ')' { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2327 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2328 | checkmem($$); |
| 2329 | $$->expr_type = A1TC_UNIVERVAL; |
| 2330 | $$->meta_type = AMT_VALUE; |
| 2331 | $$->Identifier = $1; |
| 2332 | $$->value = $3; |
| 2333 | } |
| 2334 | | SignedNumber { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2335 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2336 | checkmem($$); |
| 2337 | $$->expr_type = A1TC_UNIVERVAL; |
| 2338 | $$->meta_type = AMT_VALUE; |
| 2339 | $$->value = $1; |
| 2340 | } |
| 2341 | | TOK_ThreeDots { |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 2342 | $$ = NEW_EXPR(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2343 | checkmem($$); |
| 2344 | $$->Identifier = strdup("..."); |
| 2345 | checkmem($$->Identifier); |
| 2346 | $$->expr_type = A1TC_EXTENSIBLE; |
| 2347 | $$->meta_type = AMT_VALUE; |
| 2348 | } |
| 2349 | ; |
| 2350 | |
| 2351 | SignedNumber: |
| 2352 | TOK_number { |
| 2353 | $$ = asn1p_value_fromint($1); |
| 2354 | checkmem($$); |
| 2355 | } |
| 2356 | | TOK_number_negative { |
| 2357 | $$ = asn1p_value_fromint($1); |
| 2358 | checkmem($$); |
| 2359 | } |
| 2360 | ; |
| 2361 | |
Lev Walkin | adf863f | 2006-09-05 16:18:34 +0000 | [diff] [blame] | 2362 | RealValue: |
| 2363 | SignedNumber |
| 2364 | | TOK_realnumber { |
| 2365 | $$ = asn1p_value_fromdouble($1); |
| 2366 | checkmem($$); |
| 2367 | } |
| 2368 | ; |
| 2369 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2370 | /* |
| 2371 | * SEQUENCE definition. |
| 2372 | * === EXAMPLE === |
| 2373 | * Struct1 ::= SEQUENCE { |
| 2374 | * memb1 Struct2, |
| 2375 | * memb2 SEQUENCE OF { |
| 2376 | * memb2-1 Struct 3 |
| 2377 | * } |
| 2378 | * } |
| 2379 | * === EOF === |
| 2380 | */ |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 | /* |
| 2385 | * SET definition. |
| 2386 | * === EXAMPLE === |
| 2387 | * Person ::= SET { |
| 2388 | * name [0] PrintableString (SIZE(1..20)), |
| 2389 | * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country, |
| 2390 | * } |
| 2391 | * === EOF === |
| 2392 | */ |
| 2393 | |
| 2394 | optTag: |
| 2395 | { memset(&$$, 0, sizeof($$)); } |
| 2396 | | Tag { $$ = $1; } |
| 2397 | ; |
| 2398 | |
| 2399 | Tag: |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 2400 | TagTypeValue TagPlicit { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2401 | $$ = $1; |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 2402 | $$.tag_mode = $2.tag_mode; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2403 | } |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 2404 | ; |
| 2405 | |
| 2406 | TagTypeValue: |
| 2407 | '[' TagClass TOK_number ']' { |
| 2408 | $$ = $2; |
| 2409 | $$.tag_value = $3; |
| 2410 | }; |
| 2411 | |
| 2412 | TagClass: |
| 2413 | { $$.tag_class = TC_CONTEXT_SPECIFIC; } |
| 2414 | | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; } |
| 2415 | | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; } |
| 2416 | | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; } |
| 2417 | ; |
| 2418 | |
| 2419 | TagPlicit: |
| 2420 | { $$.tag_mode = TM_DEFAULT; } |
| 2421 | | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; } |
| 2422 | | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2423 | ; |
| 2424 | |
| 2425 | TypeRefName: |
| 2426 | TOK_typereference { |
| 2427 | checkmem($1); |
| 2428 | $$ = $1; |
| 2429 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2430 | | TOK_capitalreference { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2431 | checkmem($1); |
| 2432 | $$ = $1; |
| 2433 | } |
| 2434 | ; |
| 2435 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2436 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2437 | ObjectClassReference: |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2438 | TOK_capitalreference { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2439 | checkmem($1); |
| 2440 | $$ = $1; |
| 2441 | } |
| 2442 | ; |
| 2443 | |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 2444 | optIdentifier: |
| 2445 | { $$ = 0; } |
| 2446 | | Identifier { |
| 2447 | $$ = $1; |
| 2448 | } |
Lev Walkin | 8f294e0 | 2005-06-06 08:28:58 +0000 | [diff] [blame] | 2449 | ; |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 2450 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2451 | Identifier: |
| 2452 | TOK_identifier { |
| 2453 | checkmem($1); |
| 2454 | $$ = $1; |
| 2455 | } |
| 2456 | ; |
| 2457 | |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 2458 | IdentifierAsReference: |
| 2459 | Identifier { |
| 2460 | $$ = asn1p_ref_new(yylineno, currentModule); |
| 2461 | asn1p_ref_add_component($$, $1, RLT_lowercase); |
| 2462 | }; |
| 2463 | |
| 2464 | IdentifierAsValue: |
| 2465 | IdentifierAsReference { |
| 2466 | $$ = asn1p_value_fromref($1, 0); |
| 2467 | }; |
| 2468 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2469 | %% |
| 2470 | |
| 2471 | |
| 2472 | /* |
| 2473 | * Convert Xstring ('0101'B or '5'H) to the binary vector. |
| 2474 | */ |
| 2475 | static asn1p_value_t * |
| 2476 | _convert_bitstring2binary(char *str, int base) { |
| 2477 | asn1p_value_t *val; |
| 2478 | int slen; |
| 2479 | int memlen; |
| 2480 | int baselen; |
| 2481 | int bits; |
| 2482 | uint8_t *binary_vector; |
| 2483 | uint8_t *bv_ptr; |
| 2484 | uint8_t cur_val; |
| 2485 | |
| 2486 | assert(str); |
| 2487 | assert(str[0] == '\''); |
| 2488 | |
| 2489 | switch(base) { |
| 2490 | case 'B': |
| 2491 | baselen = 1; |
| 2492 | break; |
| 2493 | case 'H': |
| 2494 | baselen = 4; |
| 2495 | break; |
| 2496 | default: |
| 2497 | assert(base == 'B' || base == 'H'); |
| 2498 | errno = EINVAL; |
| 2499 | return NULL; |
| 2500 | } |
| 2501 | |
| 2502 | slen = strlen(str); |
| 2503 | assert(str[slen - 1] == base); |
| 2504 | assert(str[slen - 2] == '\''); |
| 2505 | |
| 2506 | memlen = slen / (8 / baselen); /* Conservative estimate */ |
| 2507 | |
| 2508 | bv_ptr = binary_vector = malloc(memlen + 1); |
| 2509 | if(bv_ptr == NULL) |
| 2510 | /* ENOMEM */ |
| 2511 | return NULL; |
| 2512 | |
| 2513 | cur_val = 0; |
| 2514 | bits = 0; |
| 2515 | while(*(++str) != '\'') { |
| 2516 | switch(baselen) { |
| 2517 | case 1: |
| 2518 | switch(*str) { |
| 2519 | case '1': |
| 2520 | cur_val |= 1 << (7 - (bits % 8)); |
| 2521 | case '0': |
| 2522 | break; |
| 2523 | default: |
| 2524 | assert(!"_y UNREACH1"); |
| 2525 | case ' ': case '\r': case '\n': |
| 2526 | continue; |
| 2527 | } |
| 2528 | break; |
| 2529 | case 4: |
| 2530 | switch(*str) { |
| 2531 | case '0': case '1': case '2': case '3': case '4': |
| 2532 | case '5': case '6': case '7': case '8': case '9': |
| 2533 | cur_val |= (*str - '0') << (4 - (bits % 8)); |
| 2534 | break; |
| 2535 | case 'A': case 'B': case 'C': |
| 2536 | case 'D': case 'E': case 'F': |
| 2537 | cur_val |= ((*str - 'A') + 10) |
| 2538 | << (4 - (bits % 8)); |
| 2539 | break; |
| 2540 | default: |
| 2541 | assert(!"_y UNREACH2"); |
| 2542 | case ' ': case '\r': case '\n': |
| 2543 | continue; |
| 2544 | } |
| 2545 | break; |
| 2546 | } |
| 2547 | |
| 2548 | bits += baselen; |
| 2549 | if((bits % 8) == 0) { |
| 2550 | *bv_ptr++ = cur_val; |
| 2551 | cur_val = 0; |
| 2552 | } |
| 2553 | } |
| 2554 | |
| 2555 | *bv_ptr = cur_val; |
| 2556 | assert((bv_ptr - binary_vector) <= memlen); |
| 2557 | |
| 2558 | val = asn1p_value_frombits(binary_vector, bits, 0); |
| 2559 | if(val == NULL) { |
| 2560 | free(binary_vector); |
| 2561 | } |
| 2562 | |
| 2563 | return val; |
| 2564 | } |
| 2565 | |
Lev Walkin | 2e9bd5c | 2005-08-13 09:07:11 +0000 | [diff] [blame] | 2566 | /* |
| 2567 | * For unnamed types (used in old X.208 compliant modules) |
| 2568 | * generate some sort of interim names, to not to force human being to fix |
| 2569 | * the specification's compliance to modern ASN.1 standards. |
| 2570 | */ |
| 2571 | static void |
| 2572 | _fixup_anonymous_identifier(asn1p_expr_t *expr) { |
| 2573 | char *p; |
| 2574 | assert(expr->Identifier == 0); |
| 2575 | |
| 2576 | /* |
| 2577 | * Try to figure out the type name |
| 2578 | * without going too much into details |
| 2579 | */ |
| 2580 | expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type); |
| 2581 | if(expr->reference && expr->reference->comp_count > 0) |
| 2582 | expr->Identifier = expr->reference->components[0].name; |
| 2583 | |
| 2584 | fprintf(stderr, |
| 2585 | "WARNING: Line %d: expected lower-case member identifier, " |
| 2586 | "found an unnamed %s.\n" |
| 2587 | "WARNING: Obsolete X.208 syntax detected, " |
| 2588 | "please give the member a name.\n", |
| 2589 | yylineno, expr->Identifier ? expr->Identifier : "type"); |
| 2590 | |
| 2591 | if(!expr->Identifier) |
| 2592 | expr->Identifier = "unnamed"; |
| 2593 | expr->Identifier = strdup(expr->Identifier); |
| 2594 | assert(expr->Identifier); |
| 2595 | /* Make a lowercase identifier from the type name */ |
| 2596 | for(p = expr->Identifier; *p; p++) { |
| 2597 | switch(*p) { |
| 2598 | case 'A' ... 'Z': *p += 32; break; |
| 2599 | case ' ': *p = '_'; break; |
| 2600 | case '-': *p = '_'; break; |
| 2601 | } |
| 2602 | } |
| 2603 | fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". " |
| 2604 | "Name clash may occur later.\n", |
| 2605 | expr->Identifier); |
| 2606 | } |
| 2607 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2608 | int |
| 2609 | yyerror(const char *msg) { |
Lev Walkin | 9d542d2 | 2006-03-14 16:31:37 +0000 | [diff] [blame] | 2610 | extern char *asn1p_text; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2611 | fprintf(stderr, |
| 2612 | "ASN.1 grammar parse error " |
Lev Walkin | d523ea4 | 2017-09-06 22:15:08 -0700 | [diff] [blame] | 2613 | "near %s:%d (token \"%s\"): %s\n", |
| 2614 | ASN_FILENAME, yylineno, asn1p_text, msg); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2615 | return -1; |
| 2616 | } |
| 2617 | |