vlm | fa67ddc | 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 |
| 12 | #define YYERROR_VERBOSE |
| 13 | |
| 14 | int yylex(void); |
| 15 | int yyerror(const char *msg); |
| 16 | void asn1p_lexer_hack_push_opaque_state(void); |
| 17 | void asn1p_lexer_hack_enable_with_syntax(void); |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 18 | void asn1p_lexer_hack_push_encoding_control(void); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | #define yylineno asn1p_lineno |
| 20 | extern int asn1p_lineno; |
| 21 | |
| 22 | |
| 23 | static asn1p_value_t * |
| 24 | _convert_bitstring2binary(char *str, int base); |
| 25 | |
| 26 | #define checkmem(ptr) do { \ |
| 27 | if(!(ptr)) \ |
| 28 | return yyerror("Memory failure"); \ |
| 29 | } while(0) |
| 30 | |
| 31 | #define CONSTRAINT_INSERT(root, constr_type, arg1, arg2) do { \ |
| 32 | if(arg1->type != constr_type) { \ |
| 33 | int __ret; \ |
| 34 | root = asn1p_constraint_new(yylineno); \ |
| 35 | checkmem(root); \ |
| 36 | root->type = constr_type; \ |
| 37 | __ret = asn1p_constraint_insert(root, \ |
| 38 | arg1); \ |
| 39 | checkmem(__ret == 0); \ |
| 40 | } else { \ |
| 41 | root = arg1; \ |
| 42 | } \ |
| 43 | if(arg2) { \ |
| 44 | int __ret \ |
| 45 | = asn1p_constraint_insert(root, arg2); \ |
| 46 | checkmem(__ret == 0); \ |
| 47 | } \ |
| 48 | } while(0) |
| 49 | |
| 50 | %} |
| 51 | |
| 52 | |
| 53 | /* |
| 54 | * Token value definition. |
| 55 | * a_*: ASN-specific types. |
| 56 | * tv_*: Locally meaningful types. |
| 57 | */ |
| 58 | %union { |
| 59 | asn1p_t *a_grammar; |
| 60 | asn1p_module_flags_e a_module_flags; |
| 61 | asn1p_module_t *a_module; |
| 62 | asn1p_expr_type_e a_type; /* ASN.1 Type */ |
| 63 | asn1p_expr_t *a_expr; /* Constructed collection */ |
| 64 | asn1p_constraint_t *a_constr; /* Constraint */ |
| 65 | enum asn1p_constraint_type_e a_ctype;/* Constraint type */ |
| 66 | asn1p_xports_t *a_xports; /* IMports/EXports */ |
| 67 | asn1p_oid_t *a_oid; /* Object Identifier */ |
| 68 | asn1p_oid_arc_t a_oid_arc; /* Single OID's arc */ |
| 69 | struct asn1p_type_tag_s a_tag; /* A tag */ |
| 70 | asn1p_ref_t *a_ref; /* Reference to custom type */ |
| 71 | asn1p_wsyntx_t *a_wsynt; /* WITH SYNTAX contents */ |
| 72 | asn1p_wsyntx_chunk_t *a_wchunk; /* WITH SYNTAX chunk */ |
| 73 | struct asn1p_ref_component_s a_refcomp; /* Component of a reference */ |
| 74 | asn1p_value_t *a_value; /* Number, DefinedValue, etc */ |
| 75 | struct asn1p_param_s a_parg; /* A parameter argument */ |
| 76 | asn1p_paramlist_t *a_plist; /* A pargs list */ |
| 77 | enum asn1p_expr_marker_e a_marker; /* OPTIONAL/DEFAULT */ |
| 78 | enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */ |
| 79 | asn1_integer_t a_int; |
| 80 | char *tv_str; |
| 81 | struct { |
| 82 | char *buf; |
| 83 | int len; |
| 84 | } tv_opaque; |
| 85 | struct { |
| 86 | char *name; |
| 87 | struct asn1p_type_tag_s tag; |
| 88 | } tv_nametag; |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * Token types returned by scanner. |
| 93 | */ |
| 94 | %token TOK_PPEQ /* "::=", Pseudo Pascal EQuality */ |
| 95 | %token <tv_opaque> TOK_opaque /* opaque data (driven from .y) */ |
| 96 | %token <tv_str> TOK_bstring |
| 97 | %token <tv_opaque> TOK_cstring |
| 98 | %token <tv_str> TOK_hstring |
| 99 | %token <tv_str> TOK_identifier |
| 100 | %token <a_int> TOK_number |
| 101 | %token <a_int> TOK_number_negative |
| 102 | %token <tv_str> TOK_typereference |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 103 | %token <tv_str> TOK_capitalreference /* "CLASS1" */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 104 | %token <tv_str> TOK_typefieldreference /* "&Pork" */ |
| 105 | %token <tv_str> TOK_valuefieldreference /* "&id" */ |
| 106 | |
| 107 | /* |
| 108 | * Token types representing ASN.1 standard keywords. |
| 109 | */ |
| 110 | %token TOK_ABSENT |
| 111 | %token TOK_ABSTRACT_SYNTAX |
| 112 | %token TOK_ALL |
| 113 | %token TOK_ANY |
| 114 | %token TOK_APPLICATION |
| 115 | %token TOK_AUTOMATIC |
| 116 | %token TOK_BEGIN |
| 117 | %token TOK_BIT |
| 118 | %token TOK_BMPString |
| 119 | %token TOK_BOOLEAN |
| 120 | %token TOK_BY |
| 121 | %token TOK_CHARACTER |
| 122 | %token TOK_CHOICE |
| 123 | %token TOK_CLASS |
| 124 | %token TOK_COMPONENT |
| 125 | %token TOK_COMPONENTS |
| 126 | %token TOK_CONSTRAINED |
| 127 | %token TOK_CONTAINING |
| 128 | %token TOK_DEFAULT |
| 129 | %token TOK_DEFINITIONS |
| 130 | %token TOK_DEFINED |
| 131 | %token TOK_EMBEDDED |
| 132 | %token TOK_ENCODED |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 133 | %token TOK_ENCODING_CONTROL |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 134 | %token TOK_END |
| 135 | %token TOK_ENUMERATED |
| 136 | %token TOK_EXPLICIT |
| 137 | %token TOK_EXPORTS |
| 138 | %token TOK_EXTENSIBILITY |
| 139 | %token TOK_EXTERNAL |
| 140 | %token TOK_FALSE |
| 141 | %token TOK_FROM |
| 142 | %token TOK_GeneralizedTime |
| 143 | %token TOK_GeneralString |
| 144 | %token TOK_GraphicString |
| 145 | %token TOK_IA5String |
| 146 | %token TOK_IDENTIFIER |
| 147 | %token TOK_IMPLICIT |
| 148 | %token TOK_IMPLIED |
| 149 | %token TOK_IMPORTS |
| 150 | %token TOK_INCLUDES |
| 151 | %token TOK_INSTANCE |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 152 | %token TOK_INSTRUCTIONS |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 153 | %token TOK_INTEGER |
| 154 | %token TOK_ISO646String |
| 155 | %token TOK_MAX |
| 156 | %token TOK_MIN |
| 157 | %token TOK_MINUS_INFINITY |
| 158 | %token TOK_NULL |
| 159 | %token TOK_NumericString |
| 160 | %token TOK_OBJECT |
| 161 | %token TOK_ObjectDescriptor |
| 162 | %token TOK_OCTET |
| 163 | %token TOK_OF |
| 164 | %token TOK_OPTIONAL |
| 165 | %token TOK_PATTERN |
| 166 | %token TOK_PDV |
| 167 | %token TOK_PLUS_INFINITY |
| 168 | %token TOK_PRESENT |
| 169 | %token TOK_PrintableString |
| 170 | %token TOK_PRIVATE |
| 171 | %token TOK_REAL |
| 172 | %token TOK_RELATIVE_OID |
| 173 | %token TOK_SEQUENCE |
| 174 | %token TOK_SET |
| 175 | %token TOK_SIZE |
| 176 | %token TOK_STRING |
| 177 | %token TOK_SYNTAX |
| 178 | %token TOK_T61String |
| 179 | %token TOK_TAGS |
| 180 | %token TOK_TeletexString |
| 181 | %token TOK_TRUE |
| 182 | %token TOK_TYPE_IDENTIFIER |
| 183 | %token TOK_UNIQUE |
| 184 | %token TOK_UNIVERSAL |
| 185 | %token TOK_UniversalString |
| 186 | %token TOK_UTCTime |
| 187 | %token TOK_UTF8String |
| 188 | %token TOK_VideotexString |
| 189 | %token TOK_VisibleString |
| 190 | %token TOK_WITH |
| 191 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 192 | %left TOK_EXCEPT |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 193 | %left '^' TOK_INTERSECTION |
| 194 | %left '|' TOK_UNION |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 195 | |
| 196 | /* Misc tags */ |
| 197 | %token TOK_TwoDots /* .. */ |
| 198 | %token TOK_ThreeDots /* ... */ |
| 199 | %token <a_tag> TOK_tag /* [0] */ |
| 200 | |
| 201 | |
| 202 | /* |
| 203 | * Types defined herein. |
| 204 | */ |
| 205 | %type <a_grammar> ModuleList |
| 206 | %type <a_module> ModuleSpecification |
| 207 | %type <a_module> ModuleSpecificationBody |
| 208 | %type <a_module> ModuleSpecificationElement |
| 209 | %type <a_module> optModuleSpecificationBody /* Optional */ |
| 210 | %type <a_module_flags> optModuleSpecificationFlags |
| 211 | %type <a_module_flags> ModuleSpecificationFlags /* Set of FL */ |
| 212 | %type <a_module_flags> ModuleSpecificationFlag /* Single FL */ |
| 213 | %type <a_module> ImportsDefinition |
| 214 | %type <a_module> ImportsBundleSet |
| 215 | %type <a_xports> ImportsBundle |
| 216 | %type <a_xports> ImportsList |
| 217 | %type <a_xports> ExportsDefinition |
| 218 | %type <a_xports> ExportsBody |
| 219 | %type <a_expr> ImportsElement |
| 220 | %type <a_expr> ExportsElement |
| 221 | %type <a_expr> DataTypeMember |
| 222 | %type <a_expr> ExtensionAndException |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 223 | %type <a_expr> UnconstrainedTypeDeclaration |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 224 | %type <a_ref> ComplexTypeReference |
| 225 | %type <a_ref> ComplexTypeReferenceAmpList |
| 226 | %type <a_refcomp> ComplexTypeReferenceElement |
| 227 | %type <a_refcomp> ClassFieldIdentifier |
| 228 | %type <a_refcomp> ClassFieldName |
| 229 | %type <a_expr> ClassFieldList |
| 230 | %type <a_expr> ClassField |
| 231 | %type <a_expr> ClassDeclaration |
| 232 | %type <a_expr> ConstrainedTypeDeclaration |
| 233 | %type <a_expr> DataTypeReference /* Type1 ::= Type2 */ |
| 234 | %type <a_expr> DefinedTypeRef |
| 235 | %type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */ |
| 236 | %type <a_expr> ValueDefinition /* val INTEGER ::= 1*/ |
| 237 | %type <a_value> optValueSetBody |
| 238 | %type <a_value> InlineOrDefinedValue |
| 239 | %type <a_value> DefinedValue |
| 240 | %type <a_value> SignedNumber |
| 241 | %type <a_expr> ConstructedType |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 242 | %type <a_expr> ConstructedTypeConstrained |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 243 | %type <a_expr> ConstructedDataTypeDefinition |
| 244 | //%type <a_expr> optUniverationDefinition |
| 245 | %type <a_expr> UniverationDefinition |
| 246 | %type <a_expr> UniverationList |
| 247 | %type <a_expr> UniverationElement |
| 248 | %type <tv_str> TypeRefName |
| 249 | %type <tv_str> ObjectClassReference |
| 250 | %type <tv_nametag> TaggedIdentifier |
| 251 | %type <tv_str> Identifier |
| 252 | %type <a_parg> ParameterArgumentName |
| 253 | %type <a_plist> ParameterArgumentList |
| 254 | %type <a_expr> ActualParameter |
| 255 | %type <a_expr> ActualParameterList |
| 256 | %type <a_oid> ObjectIdentifier /* OID */ |
| 257 | %type <a_oid> optObjectIdentifier /* Optional OID */ |
| 258 | %type <a_oid> ObjectIdentifierBody |
| 259 | %type <a_oid_arc> ObjectIdentifierElement |
| 260 | %type <a_expr> BasicType |
| 261 | %type <a_type> BasicTypeId |
| 262 | %type <a_type> BasicTypeId_UniverationCompatible |
| 263 | %type <a_type> BasicString |
| 264 | %type <tv_opaque> Opaque |
| 265 | //%type <tv_opaque> StringValue |
| 266 | %type <a_tag> Tag /* [UNIVERSAL 0] IMPLICIT */ |
| 267 | %type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */ |
| 268 | %type <a_constr> optConstraints |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 269 | %type <a_constr> Constraints |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 270 | %type <a_constr> SetOfConstraints |
| 271 | %type <a_constr> ElementSetSpecs /* 1..2,...,3 */ |
| 272 | %type <a_constr> ElementSetSpec /* 1..2,...,3 */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 273 | %type <a_constr> ConstraintSubtypeElement /* 1..2 */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 274 | %type <a_constr> SimpleTableConstraint |
| 275 | %type <a_constr> TableConstraint |
| 276 | %type <a_constr> WithComponents |
| 277 | %type <a_constr> WithComponentsList |
| 278 | %type <a_constr> WithComponentsElement |
| 279 | %type <a_constr> ComponentRelationConstraint |
| 280 | %type <a_constr> AtNotationList |
| 281 | %type <a_ref> AtNotationElement |
| 282 | %type <a_value> ConstraintValue |
| 283 | %type <a_ctype> ConstraintSpec |
| 284 | %type <a_ctype> ConstraintRangeSpec |
| 285 | %type <a_wsynt> optWithSyntax |
| 286 | %type <a_wsynt> WithSyntax |
| 287 | %type <a_wsynt> WithSyntaxFormat |
| 288 | %type <a_wchunk> WithSyntaxFormatToken |
| 289 | %type <a_marker> optMarker Marker |
| 290 | %type <a_int> optUnique |
| 291 | %type <a_pres> optPresenceConstraint PresenceConstraint |
| 292 | %type <tv_str> ComponentIdList |
| 293 | |
| 294 | |
| 295 | %% |
| 296 | |
| 297 | |
| 298 | ParsedGrammar: |
| 299 | ModuleList { |
| 300 | *(void **)param = $1; |
| 301 | } |
| 302 | ; |
| 303 | |
| 304 | ModuleList: |
| 305 | ModuleSpecification { |
| 306 | $$ = asn1p_new(); |
| 307 | checkmem($$); |
| 308 | TQ_ADD(&($$->modules), $1, mod_next); |
| 309 | } |
| 310 | | ModuleList ModuleSpecification { |
| 311 | $$ = $1; |
| 312 | TQ_ADD(&($$->modules), $2, mod_next); |
| 313 | } |
| 314 | ; |
| 315 | |
| 316 | /* |
| 317 | * ASN module definition. |
| 318 | * === EXAMPLE === |
| 319 | * MySyntax DEFINITIONS AUTOMATIC TAGS ::= |
| 320 | * BEGIN |
| 321 | * ... |
| 322 | * END |
| 323 | * === EOF === |
| 324 | */ |
| 325 | |
| 326 | ModuleSpecification: |
| 327 | TypeRefName optObjectIdentifier TOK_DEFINITIONS |
| 328 | optModuleSpecificationFlags |
| 329 | TOK_PPEQ TOK_BEGIN |
| 330 | optModuleSpecificationBody |
| 331 | TOK_END { |
| 332 | |
| 333 | if($7) { |
| 334 | $$ = $7; |
| 335 | } else { |
| 336 | /* There's a chance that a module is just plain empty */ |
| 337 | $$ = asn1p_module_new(); |
| 338 | } |
| 339 | checkmem($$); |
| 340 | |
| 341 | $$->Identifier = $1; |
| 342 | $$->module_oid = $2; |
| 343 | $$->module_flags = $4; |
| 344 | } |
| 345 | ; |
| 346 | |
| 347 | /* |
| 348 | * Object Identifier Definition |
| 349 | * { iso member-body(2) 3 } |
| 350 | */ |
| 351 | optObjectIdentifier: |
| 352 | { $$ = 0; } |
| 353 | | ObjectIdentifier { $$ = $1; } |
| 354 | ; |
| 355 | |
| 356 | ObjectIdentifier: |
| 357 | '{' ObjectIdentifierBody '}' { |
| 358 | $$ = $2; |
| 359 | } |
| 360 | | '{' '}' { |
| 361 | $$ = 0; |
| 362 | } |
| 363 | ; |
| 364 | |
| 365 | ObjectIdentifierBody: |
| 366 | ObjectIdentifierElement { |
| 367 | $$ = asn1p_oid_new(); |
| 368 | asn1p_oid_add_arc($$, &$1); |
| 369 | if($1.name) |
| 370 | free($1.name); |
| 371 | } |
| 372 | | ObjectIdentifierBody ObjectIdentifierElement { |
| 373 | $$ = $1; |
| 374 | asn1p_oid_add_arc($$, &$2); |
| 375 | if($2.name) |
| 376 | free($2.name); |
| 377 | } |
| 378 | ; |
| 379 | |
| 380 | ObjectIdentifierElement: |
| 381 | Identifier { /* iso */ |
| 382 | $$.name = $1; |
| 383 | $$.number = -1; |
| 384 | } |
| 385 | | Identifier '(' TOK_number ')' { /* iso(1) */ |
| 386 | $$.name = $1; |
| 387 | $$.number = $3; |
| 388 | } |
| 389 | | TOK_number { /* 1 */ |
| 390 | $$.name = 0; |
| 391 | $$.number = $1; |
| 392 | } |
| 393 | ; |
| 394 | |
| 395 | /* |
| 396 | * Optional module flags. |
| 397 | */ |
| 398 | optModuleSpecificationFlags: |
| 399 | { $$ = MSF_NOFLAGS; } |
| 400 | | ModuleSpecificationFlags { |
| 401 | $$ = $1; |
| 402 | } |
| 403 | ; |
| 404 | |
| 405 | /* |
| 406 | * Module flags. |
| 407 | */ |
| 408 | ModuleSpecificationFlags: |
| 409 | ModuleSpecificationFlag { |
| 410 | $$ = $1; |
| 411 | } |
| 412 | | ModuleSpecificationFlags ModuleSpecificationFlag { |
| 413 | $$ = $1 | $2; |
| 414 | } |
| 415 | ; |
| 416 | |
| 417 | /* |
| 418 | * Single module flag. |
| 419 | */ |
| 420 | ModuleSpecificationFlag: |
| 421 | TOK_EXPLICIT TOK_TAGS { |
| 422 | $$ = MSF_EXPLICIT_TAGS; |
| 423 | } |
| 424 | | TOK_IMPLICIT TOK_TAGS { |
| 425 | $$ = MSF_IMPLICIT_TAGS; |
| 426 | } |
| 427 | | TOK_AUTOMATIC TOK_TAGS { |
| 428 | $$ = MSF_AUTOMATIC_TAGS; |
| 429 | } |
| 430 | | TOK_EXTENSIBILITY TOK_IMPLIED { |
| 431 | $$ = MSF_EXTENSIBILITY_IMPLIED; |
| 432 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 433 | /* EncodingReferenceDefault */ |
| 434 | | TOK_capitalreference TOK_INSTRUCTIONS { |
| 435 | /* X.680Amd1 specifies TAG and XER */ |
| 436 | if(strcmp($1, "TAG") == 0) { |
| 437 | $$ = MSF_TAG_INSTRUCTIONS; |
| 438 | } else if(strcmp($1, "XER") == 0) { |
| 439 | $$ = MSF_XER_INSTRUCTIONS; |
| 440 | } else { |
| 441 | fprintf(stderr, |
| 442 | "WARNING: %s INSTRUCTIONS at line %d: " |
| 443 | "Unrecognized encoding reference\n", |
| 444 | $1, yylineno); |
| 445 | $$ = MSF_unk_INSTRUCTIONS; |
| 446 | } |
| 447 | free($1); |
| 448 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 449 | ; |
| 450 | |
| 451 | /* |
| 452 | * Optional module body. |
| 453 | */ |
| 454 | optModuleSpecificationBody: |
| 455 | { $$ = 0; } |
| 456 | | ModuleSpecificationBody { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 457 | $$ = $1; |
| 458 | } |
| 459 | ; |
| 460 | |
| 461 | /* |
| 462 | * ASN.1 Module body. |
| 463 | */ |
| 464 | ModuleSpecificationBody: |
| 465 | ModuleSpecificationElement { |
| 466 | $$ = $1; |
| 467 | } |
| 468 | | ModuleSpecificationBody ModuleSpecificationElement { |
| 469 | $$ = $1; |
| 470 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 471 | /* Behave well when one of them is skipped. */ |
| 472 | if(!($1)) { |
| 473 | if($2) $$ = $2; |
| 474 | break; |
| 475 | } |
| 476 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 477 | #ifdef MY_IMPORT |
| 478 | #error MY_IMPORT DEFINED ELSEWHERE! |
| 479 | #endif |
| 480 | #define MY_IMPORT(foo,field) do { \ |
vlm | 97ed715 | 2004-08-13 12:31:09 +0000 | [diff] [blame] | 481 | while(TQ_FIRST(&($2->foo))) { \ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 482 | TQ_ADD(&($$->foo), \ |
| 483 | TQ_REMOVE(&($2->foo), field), \ |
| 484 | field); \ |
vlm | 97ed715 | 2004-08-13 12:31:09 +0000 | [diff] [blame] | 485 | } \ |
| 486 | assert(TQ_FIRST(&($2->foo)) == 0); \ |
| 487 | } while(0) |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 488 | |
| 489 | MY_IMPORT(imports, xp_next); |
| 490 | MY_IMPORT(exports, xp_next); |
| 491 | MY_IMPORT(members, next); |
| 492 | #undef MY_IMPORT |
| 493 | |
| 494 | } |
| 495 | ; |
| 496 | |
| 497 | /* |
| 498 | * One of the elements of ASN.1 module specification. |
| 499 | */ |
| 500 | ModuleSpecificationElement: |
| 501 | ImportsDefinition { |
| 502 | $$ = $1; |
| 503 | } |
| 504 | | ExportsDefinition { |
| 505 | $$ = asn1p_module_new(); |
| 506 | checkmem($$); |
| 507 | if($1) { |
| 508 | TQ_ADD(&($$->exports), $1, xp_next); |
| 509 | } else { |
| 510 | /* "EXPORTS ALL;" ? */ |
| 511 | } |
| 512 | } |
| 513 | | DataTypeReference { |
| 514 | $$ = asn1p_module_new(); |
| 515 | checkmem($$); |
| 516 | assert($1->expr_type != A1TC_INVALID); |
| 517 | assert($1->meta_type != AMT_INVALID); |
| 518 | TQ_ADD(&($$->members), $1, next); |
| 519 | } |
| 520 | | ValueDefinition { |
| 521 | $$ = asn1p_module_new(); |
| 522 | checkmem($$); |
| 523 | assert($1->expr_type != A1TC_INVALID); |
| 524 | assert($1->meta_type != AMT_INVALID); |
| 525 | TQ_ADD(&($$->members), $1, next); |
| 526 | } |
| 527 | /* |
| 528 | * Value set definition |
| 529 | * === EXAMPLE === |
| 530 | * EvenNumbers INTEGER ::= { 2 | 4 | 6 | 8 } |
| 531 | * === EOF === |
| 532 | */ |
| 533 | | ValueSetDefinition { |
| 534 | $$ = asn1p_module_new(); |
| 535 | checkmem($$); |
| 536 | assert($1->expr_type != A1TC_INVALID); |
| 537 | assert($1->meta_type != AMT_INVALID); |
| 538 | TQ_ADD(&($$->members), $1, next); |
| 539 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 540 | | TOK_ENCODING_CONTROL TOK_capitalreference |
| 541 | { asn1p_lexer_hack_push_encoding_control(); } |
| 542 | { |
| 543 | fprintf(stderr, |
| 544 | "WARNING: ENCODING-CONTROL %s " |
| 545 | "specification at line %d ignored\n", |
| 546 | $2, yylineno); |
| 547 | free($2); |
| 548 | $$ = 0; |
| 549 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * Erroneous attemps |
| 553 | */ |
| 554 | | BasicString { |
| 555 | return yyerror( |
| 556 | "Attempt to redefine a standard basic type, " |
| 557 | "use -ftypesXY to switch back " |
| 558 | "to older version of ASN.1 standard"); |
| 559 | } |
| 560 | ; |
| 561 | |
| 562 | /* |
| 563 | * === EXAMPLE === |
| 564 | * IMPORTS Type1, value FROM Module { iso standard(0) } ; |
| 565 | * === EOF === |
| 566 | */ |
| 567 | ImportsDefinition: |
| 568 | TOK_IMPORTS ImportsBundleSet ';' { |
| 569 | $$ = $2; |
| 570 | } |
| 571 | /* |
| 572 | * Some error cases. |
| 573 | */ |
| 574 | | TOK_IMPORTS TOK_FROM /* ... */ { |
| 575 | return yyerror("Empty IMPORTS list"); |
| 576 | } |
| 577 | ; |
| 578 | |
| 579 | ImportsBundleSet: |
| 580 | ImportsBundle { |
| 581 | $$ = asn1p_module_new(); |
| 582 | checkmem($$); |
| 583 | TQ_ADD(&($$->imports), $1, xp_next); |
| 584 | } |
| 585 | | ImportsBundleSet ImportsBundle { |
| 586 | $$ = $1; |
| 587 | TQ_ADD(&($$->imports), $2, xp_next); |
| 588 | } |
| 589 | ; |
| 590 | |
| 591 | ImportsBundle: |
| 592 | ImportsList TOK_FROM TypeRefName optObjectIdentifier { |
| 593 | $$ = $1; |
| 594 | $$->from = $3; |
| 595 | $$->from_oid = $4; |
| 596 | checkmem($$); |
| 597 | } |
| 598 | ; |
| 599 | |
| 600 | ImportsList: |
| 601 | ImportsElement { |
| 602 | $$ = asn1p_xports_new(); |
| 603 | checkmem($$); |
| 604 | TQ_ADD(&($$->members), $1, next); |
| 605 | } |
| 606 | | ImportsList ',' ImportsElement { |
| 607 | $$ = $1; |
| 608 | TQ_ADD(&($$->members), $3, next); |
| 609 | } |
| 610 | ; |
| 611 | |
| 612 | ImportsElement: |
| 613 | TypeRefName { |
| 614 | $$ = asn1p_expr_new(yylineno); |
| 615 | checkmem($$); |
| 616 | $$->Identifier = $1; |
| 617 | $$->expr_type = A1TC_REFERENCE; |
| 618 | } |
| 619 | | Identifier { |
| 620 | $$ = asn1p_expr_new(yylineno); |
| 621 | checkmem($$); |
| 622 | $$->Identifier = $1; |
| 623 | $$->expr_type = A1TC_REFERENCE; |
| 624 | } |
| 625 | ; |
| 626 | |
| 627 | ExportsDefinition: |
| 628 | TOK_EXPORTS ExportsBody ';' { |
| 629 | $$ = $2; |
| 630 | } |
| 631 | | TOK_EXPORTS TOK_ALL ';' { |
| 632 | $$ = 0; |
| 633 | } |
| 634 | | TOK_EXPORTS ';' { |
| 635 | /* Empty EXPORTS clause effectively prohibits export. */ |
| 636 | $$ = asn1p_xports_new(); |
| 637 | checkmem($$); |
| 638 | } |
| 639 | ; |
| 640 | |
| 641 | ExportsBody: |
| 642 | ExportsElement { |
| 643 | $$ = asn1p_xports_new(); |
| 644 | assert($$); |
| 645 | TQ_ADD(&($$->members), $1, next); |
| 646 | } |
| 647 | | ExportsBody ',' ExportsElement { |
| 648 | $$ = $1; |
| 649 | TQ_ADD(&($$->members), $3, next); |
| 650 | } |
| 651 | ; |
| 652 | |
| 653 | ExportsElement: |
| 654 | TypeRefName { |
| 655 | $$ = asn1p_expr_new(yylineno); |
| 656 | checkmem($$); |
| 657 | $$->Identifier = $1; |
| 658 | $$->expr_type = A1TC_EXPORTVAR; |
| 659 | } |
| 660 | | Identifier { |
| 661 | $$ = asn1p_expr_new(yylineno); |
| 662 | checkmem($$); |
| 663 | $$->Identifier = $1; |
| 664 | $$->expr_type = A1TC_EXPORTVAR; |
| 665 | } |
| 666 | ; |
| 667 | |
| 668 | |
| 669 | ValueSetDefinition: |
| 670 | TypeRefName DefinedTypeRef TOK_PPEQ '{' optValueSetBody '}' { |
| 671 | $$ = $2; |
| 672 | assert($$->Identifier == 0); |
| 673 | $$->Identifier = $1; |
| 674 | $$->meta_type = AMT_VALUESET; |
| 675 | // take care of optValueSetBody |
| 676 | } |
| 677 | ; |
| 678 | |
| 679 | DefinedTypeRef: |
| 680 | ComplexTypeReference { |
| 681 | $$ = asn1p_expr_new(yylineno); |
| 682 | checkmem($$); |
| 683 | $$->reference = $1; |
| 684 | $$->expr_type = A1TC_REFERENCE; |
| 685 | $$->meta_type = AMT_TYPEREF; |
| 686 | } |
| 687 | | BasicTypeId { |
| 688 | $$ = asn1p_expr_new(yylineno); |
| 689 | checkmem($$); |
| 690 | $$->expr_type = $1; |
| 691 | $$->meta_type = AMT_TYPE; |
| 692 | } |
| 693 | ; |
| 694 | |
| 695 | optValueSetBody: |
| 696 | { } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 697 | | ElementSetSpecs { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 698 | } |
| 699 | ; |
| 700 | |
| 701 | |
| 702 | /* |
| 703 | * Data Type Reference. |
| 704 | * === EXAMPLE === |
| 705 | * Type3 ::= CHOICE { a Type1, b Type 2 } |
| 706 | * === EOF === |
| 707 | */ |
| 708 | |
| 709 | DataTypeReference: |
| 710 | /* |
| 711 | * Optionally tagged type definition. |
| 712 | */ |
| 713 | TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER { |
| 714 | $$ = asn1p_expr_new(yylineno); |
| 715 | checkmem($$); |
| 716 | $$->Identifier = $1; |
| 717 | $$->tag = $3; |
| 718 | $$->expr_type = A1TC_TYPEID; |
| 719 | $$->meta_type = AMT_TYPE; |
| 720 | } |
| 721 | | TypeRefName TOK_PPEQ optTag ConstrainedTypeDeclaration { |
| 722 | $$ = $4; |
| 723 | $$->Identifier = $1; |
| 724 | $$->tag = $3; |
| 725 | assert($$->expr_type); |
| 726 | assert($$->meta_type); |
| 727 | } |
| 728 | | TypeRefName TOK_PPEQ ClassDeclaration { |
| 729 | $$ = $3; |
| 730 | $$->Identifier = $1; |
| 731 | assert($$->expr_type == A1TC_CLASSDEF); |
| 732 | assert($$->meta_type == AMT_OBJECT); |
| 733 | } |
| 734 | /* |
| 735 | * Parametrized <Type> declaration: |
| 736 | * === EXAMPLE === |
| 737 | * SIGNED { ToBeSigned } ::= SEQUENCE { |
| 738 | * toBeSigned ToBeSigned, |
| 739 | * algorithm AlgorithmIdentifier, |
| 740 | * signature BIT STRING |
| 741 | * } |
| 742 | * === EOF === |
| 743 | */ |
| 744 | | TypeRefName '{' ParameterArgumentList '}' |
| 745 | TOK_PPEQ ConstrainedTypeDeclaration { |
| 746 | $$ = $6; |
| 747 | assert($$->Identifier == 0); |
| 748 | $$->Identifier = $1; |
| 749 | $$->params = $3; |
| 750 | $$->meta_type = AMT_PARAMTYPE; |
| 751 | } |
| 752 | ; |
| 753 | |
| 754 | ParameterArgumentList: |
| 755 | ParameterArgumentName { |
| 756 | int ret; |
| 757 | $$ = asn1p_paramlist_new(yylineno); |
| 758 | checkmem($$); |
| 759 | ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument); |
| 760 | checkmem(ret == 0); |
| 761 | if($1.governor) asn1p_ref_free($1.governor); |
| 762 | if($1.argument) free($1.argument); |
| 763 | } |
| 764 | | ParameterArgumentList ',' ParameterArgumentName { |
| 765 | int ret; |
| 766 | $$ = $1; |
| 767 | ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument); |
| 768 | checkmem(ret == 0); |
| 769 | if($3.governor) asn1p_ref_free($3.governor); |
| 770 | if($3.argument) free($3.argument); |
| 771 | } |
| 772 | ; |
| 773 | |
| 774 | ParameterArgumentName: |
| 775 | TypeRefName { |
| 776 | $$.governor = NULL; |
| 777 | $$.argument = $1; |
| 778 | } |
| 779 | | TypeRefName ':' Identifier { |
| 780 | int ret; |
| 781 | $$.governor = asn1p_ref_new(yylineno); |
| 782 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 783 | checkmem(ret == 0); |
| 784 | $$.argument = $3; |
| 785 | } |
| 786 | | BasicTypeId ':' Identifier { |
| 787 | int ret; |
| 788 | $$.governor = asn1p_ref_new(yylineno); |
| 789 | ret = asn1p_ref_add_component($$.governor, |
| 790 | ASN_EXPR_TYPE2STR($1), 1); |
| 791 | checkmem(ret == 0); |
| 792 | $$.argument = $3; |
| 793 | } |
| 794 | ; |
| 795 | |
| 796 | ActualParameterList: |
| 797 | ActualParameter { |
| 798 | $$ = asn1p_expr_new(yylineno); |
| 799 | checkmem($$); |
| 800 | TQ_ADD(&($$->members), $1, next); |
| 801 | } |
| 802 | | ActualParameterList ',' ActualParameter { |
| 803 | $$ = $1; |
| 804 | TQ_ADD(&($$->members), $3, next); |
| 805 | } |
| 806 | ; |
| 807 | |
| 808 | ActualParameter: |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 809 | UnconstrainedTypeDeclaration { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 810 | $$ = $1; |
| 811 | } |
| 812 | | Identifier { |
| 813 | $$ = asn1p_expr_new(yylineno); |
| 814 | checkmem($$); |
| 815 | $$->Identifier = $1; |
| 816 | $$->expr_type = A1TC_REFERENCE; |
| 817 | $$->meta_type = AMT_VALUE; |
| 818 | } |
| 819 | ; |
| 820 | |
| 821 | /* |
| 822 | * A collection of constructed data type members. |
| 823 | */ |
| 824 | ConstructedDataTypeDefinition: |
| 825 | DataTypeMember { |
| 826 | $$ = asn1p_expr_new(yylineno); |
| 827 | checkmem($$); |
| 828 | TQ_ADD(&($$->members), $1, next); |
| 829 | } |
| 830 | | ConstructedDataTypeDefinition ',' DataTypeMember { |
| 831 | $$ = $1; |
| 832 | TQ_ADD(&($$->members), $3, next); |
| 833 | } |
| 834 | ; |
| 835 | |
| 836 | ClassDeclaration: |
| 837 | TOK_CLASS '{' ClassFieldList '}' optWithSyntax { |
| 838 | $$ = $3; |
| 839 | checkmem($$); |
| 840 | $$->with_syntax = $5; |
| 841 | assert($$->expr_type == A1TC_CLASSDEF); |
| 842 | assert($$->meta_type == AMT_OBJECT); |
| 843 | } |
| 844 | ; |
| 845 | |
| 846 | optUnique: |
| 847 | { $$ = 0; } |
| 848 | | TOK_UNIQUE { $$ = 1; } |
| 849 | ; |
| 850 | |
| 851 | ClassFieldList: |
| 852 | ClassField { |
| 853 | $$ = asn1p_expr_new(yylineno); |
| 854 | checkmem($$); |
| 855 | $$->expr_type = A1TC_CLASSDEF; |
| 856 | $$->meta_type = AMT_OBJECT; |
| 857 | TQ_ADD(&($$->members), $1, next); |
| 858 | } |
| 859 | | ClassFieldList ',' ClassField { |
| 860 | $$ = $1; |
| 861 | TQ_ADD(&($$->members), $3, next); |
| 862 | } |
| 863 | ; |
| 864 | |
| 865 | ClassField: |
| 866 | ClassFieldIdentifier optMarker { |
| 867 | $$ = asn1p_expr_new(yylineno); |
| 868 | checkmem($$); |
| 869 | $$->Identifier = $1.name; |
| 870 | $$->expr_type = A1TC_CLASSFIELD; |
| 871 | $$->meta_type = AMT_OBJECTFIELD; |
| 872 | $$->marker = $2; |
| 873 | } |
| 874 | | ClassFieldIdentifier ConstrainedTypeDeclaration optUnique { |
| 875 | $$ = $2; |
| 876 | $$->Identifier = $1.name; |
| 877 | $$->unique = $3; |
| 878 | } |
| 879 | | ClassFieldIdentifier ClassFieldIdentifier optMarker optUnique { |
| 880 | int ret; |
| 881 | $$ = asn1p_expr_new(yylineno); |
| 882 | checkmem($$); |
| 883 | $$->Identifier = $1.name; |
| 884 | $$->reference = asn1p_ref_new(yylineno); |
| 885 | checkmem($$->reference); |
| 886 | ret = asn1p_ref_add_component($$->reference, |
| 887 | $2.name, $2.lex_type); |
| 888 | checkmem(ret == 0); |
| 889 | $$->expr_type = A1TC_CLASSFIELD; |
| 890 | $$->meta_type = AMT_OBJECTFIELD; |
| 891 | $$->marker = $3; |
| 892 | $$->unique = $4; |
| 893 | } |
| 894 | ; |
| 895 | |
| 896 | optWithSyntax: |
| 897 | { $$ = 0; } |
| 898 | | WithSyntax { |
| 899 | $$ = $1; |
| 900 | } |
| 901 | ; |
| 902 | |
| 903 | WithSyntax: |
| 904 | TOK_WITH TOK_SYNTAX '{' |
| 905 | { asn1p_lexer_hack_enable_with_syntax(); } |
| 906 | WithSyntaxFormat |
| 907 | '}' { |
| 908 | $$ = $5; |
| 909 | } |
| 910 | ; |
| 911 | |
| 912 | WithSyntaxFormat: |
| 913 | WithSyntaxFormatToken { |
| 914 | $$ = asn1p_wsyntx_new(); |
| 915 | TQ_ADD(&($$->chunks), $1, next); |
| 916 | } |
| 917 | | WithSyntaxFormat WithSyntaxFormatToken { |
| 918 | $$ = $1; |
| 919 | TQ_ADD(&($$->chunks), $2, next); |
| 920 | } |
| 921 | ; |
| 922 | |
| 923 | WithSyntaxFormatToken: |
| 924 | TOK_opaque { |
| 925 | $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0); |
| 926 | } |
| 927 | | ClassFieldIdentifier { |
| 928 | asn1p_ref_t *ref; |
| 929 | int ret; |
| 930 | ref = asn1p_ref_new(yylineno); |
| 931 | checkmem(ref); |
| 932 | ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type); |
| 933 | checkmem(ret == 0); |
| 934 | $$ = asn1p_wsyntx_chunk_fromref(ref, 0); |
| 935 | } |
| 936 | ; |
| 937 | |
| 938 | /* |
| 939 | * A data type member goes like this |
| 940 | * === |
| 941 | * memb1 [0] Type1 { a(1), b(2) } (2) |
| 942 | * === |
| 943 | * Therefore, we propose a split. |
| 944 | * ^^^^^^^^^ ^^^^^^^^^^ |
| 945 | * ^TaggedIdentifier ^TypeDeclaration |
| 946 | * ^ConstrainedTypeDeclaration |
| 947 | */ |
| 948 | |
| 949 | /* |
| 950 | * A member of a constructed data type ("a" or "b" in above example). |
| 951 | */ |
| 952 | DataTypeMember: |
| 953 | TaggedIdentifier ConstrainedTypeDeclaration { |
| 954 | $$ = $2; |
| 955 | assert($$->Identifier == 0); |
| 956 | $$->Identifier = $1.name; |
| 957 | $$->tag = $1.tag; |
| 958 | } |
| 959 | | ExtensionAndException { |
| 960 | $$ = $1; |
| 961 | } |
| 962 | ; |
| 963 | |
| 964 | ConstrainedTypeDeclaration: |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 965 | UnconstrainedTypeDeclaration optConstraints optMarker { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 966 | $$ = $1; |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 967 | if($$->constraints) { |
| 968 | assert(!$2); |
| 969 | } else { |
| 970 | $$->constraints = $2; |
| 971 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 972 | $$->marker = $3; |
| 973 | } |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 974 | | ConstructedTypeConstrained { |
| 975 | /* This type includes constraints on its own */ |
| 976 | $$ = $1; |
| 977 | checkmem($$); |
| 978 | assert($$->meta_type); |
| 979 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 980 | ; |
| 981 | |
| 982 | ExtensionAndException: |
| 983 | TOK_ThreeDots { |
| 984 | $$ = asn1p_expr_new(asn1p_lineno); |
| 985 | checkmem($$); |
| 986 | $$->Identifier = strdup("..."); |
| 987 | checkmem($$->Identifier); |
| 988 | $$->expr_type = A1TC_EXTENSIBLE; |
| 989 | $$->meta_type = AMT_TYPE; |
| 990 | } |
| 991 | | TOK_ThreeDots '!' DefinedValue { |
| 992 | $$ = asn1p_expr_new(asn1p_lineno); |
| 993 | checkmem($$); |
| 994 | $$->Identifier = strdup("..."); |
| 995 | checkmem($$->Identifier); |
| 996 | $$->value = $3; |
| 997 | $$->expr_type = A1TC_EXTENSIBLE; |
| 998 | $$->meta_type = AMT_TYPE; |
| 999 | } |
| 1000 | | TOK_ThreeDots '!' SignedNumber { |
| 1001 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1002 | checkmem($$); |
| 1003 | $$->Identifier = strdup("..."); |
| 1004 | $$->value = $3; |
| 1005 | checkmem($$->Identifier); |
| 1006 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1007 | $$->meta_type = AMT_TYPE; |
| 1008 | } |
| 1009 | ; |
| 1010 | |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1011 | UnconstrainedTypeDeclaration: |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1012 | BasicType { |
| 1013 | $$ = $1; |
| 1014 | } |
| 1015 | | BasicString { |
| 1016 | $$ = asn1p_expr_new(yylineno); |
| 1017 | checkmem($$); |
| 1018 | $$->expr_type = $1; |
| 1019 | $$->meta_type = AMT_TYPE; |
| 1020 | } |
| 1021 | | ConstructedType { |
| 1022 | $$ = $1; |
| 1023 | checkmem($$); |
| 1024 | assert($$->meta_type); |
| 1025 | } |
| 1026 | /* |
| 1027 | * A parametrized assignment. |
| 1028 | */ |
| 1029 | | TypeRefName '{' ActualParameterList '}' { |
| 1030 | int ret; |
| 1031 | $$ = $3; |
| 1032 | assert($$->expr_type == 0); |
| 1033 | assert($$->meta_type == 0); |
| 1034 | assert($$->reference == 0); |
| 1035 | $$->reference = asn1p_ref_new(yylineno); |
| 1036 | checkmem($$->reference); |
| 1037 | ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN); |
| 1038 | checkmem(ret == 0); |
| 1039 | free($1); |
| 1040 | $$->expr_type = A1TC_PARAMETRIZED; |
| 1041 | $$->meta_type = AMT_TYPE; |
| 1042 | } |
| 1043 | /* |
| 1044 | * A DefinedType reference. |
| 1045 | * "CLASS1.&id.&id2" |
| 1046 | * or |
| 1047 | * "Module.Type" |
| 1048 | * or |
| 1049 | * "Module.identifier" |
| 1050 | * or |
| 1051 | * "Type" |
| 1052 | */ |
| 1053 | | ComplexTypeReference { |
| 1054 | $$ = asn1p_expr_new(yylineno); |
| 1055 | checkmem($$); |
| 1056 | $$->reference = $1; |
| 1057 | $$->expr_type = A1TC_REFERENCE; |
| 1058 | $$->meta_type = AMT_TYPEREF; |
| 1059 | } |
| 1060 | | TOK_INSTANCE TOK_OF ComplexTypeReference { |
| 1061 | $$ = asn1p_expr_new(yylineno); |
| 1062 | checkmem($$); |
| 1063 | $$->reference = $3; |
| 1064 | $$->expr_type = A1TC_INSTANCE; |
| 1065 | $$->meta_type = AMT_TYPE; |
| 1066 | } |
| 1067 | ; |
| 1068 | |
| 1069 | /* |
| 1070 | * A type name consisting of several components. |
| 1071 | * === EXAMPLE === |
| 1072 | * === EOF === |
| 1073 | */ |
| 1074 | ComplexTypeReference: |
| 1075 | TOK_typereference { |
| 1076 | int ret; |
| 1077 | $$ = asn1p_ref_new(yylineno); |
| 1078 | checkmem($$); |
| 1079 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1080 | checkmem(ret == 0); |
| 1081 | free($1); |
| 1082 | } |
| 1083 | | TOK_typereference '.' TypeRefName { |
| 1084 | int ret; |
| 1085 | $$ = asn1p_ref_new(yylineno); |
| 1086 | checkmem($$); |
| 1087 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1088 | checkmem(ret == 0); |
| 1089 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1090 | checkmem(ret == 0); |
| 1091 | free($1); |
| 1092 | } |
| 1093 | | TOK_typereference '.' Identifier { |
| 1094 | int ret; |
| 1095 | $$ = asn1p_ref_new(yylineno); |
| 1096 | checkmem($$); |
| 1097 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1098 | checkmem(ret == 0); |
| 1099 | ret = asn1p_ref_add_component($$, $3, RLT_lowercase); |
| 1100 | checkmem(ret == 0); |
| 1101 | free($1); |
| 1102 | } |
| 1103 | | ObjectClassReference { |
| 1104 | int ret; |
| 1105 | $$ = asn1p_ref_new(yylineno); |
| 1106 | checkmem($$); |
| 1107 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1108 | free($1); |
| 1109 | checkmem(ret == 0); |
| 1110 | } |
| 1111 | | ObjectClassReference '.' ComplexTypeReferenceAmpList { |
| 1112 | int ret; |
| 1113 | $$ = $3; |
| 1114 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1115 | free($1); |
| 1116 | checkmem(ret == 0); |
| 1117 | /* |
| 1118 | * Move the last element infront. |
| 1119 | */ |
| 1120 | { |
| 1121 | struct asn1p_ref_component_s tmp_comp; |
| 1122 | tmp_comp = $$->components[$$->comp_count-1]; |
| 1123 | memmove(&$$->components[1], |
| 1124 | &$$->components[0], |
| 1125 | sizeof($$->components[0]) |
| 1126 | * ($$->comp_count - 1)); |
| 1127 | $$->components[0] = tmp_comp; |
| 1128 | } |
| 1129 | } |
| 1130 | ; |
| 1131 | |
| 1132 | ComplexTypeReferenceAmpList: |
| 1133 | ComplexTypeReferenceElement { |
| 1134 | int ret; |
| 1135 | $$ = asn1p_ref_new(yylineno); |
| 1136 | checkmem($$); |
| 1137 | ret = asn1p_ref_add_component($$, $1.name, $1.lex_type); |
| 1138 | free($1.name); |
| 1139 | checkmem(ret == 0); |
| 1140 | } |
| 1141 | | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement { |
| 1142 | int ret; |
| 1143 | $$ = $1; |
| 1144 | ret = asn1p_ref_add_component($$, $3.name, $3.lex_type); |
| 1145 | free($3.name); |
| 1146 | checkmem(ret == 0); |
| 1147 | } |
| 1148 | ; |
| 1149 | |
| 1150 | ComplexTypeReferenceElement: ClassFieldName; |
| 1151 | ClassFieldIdentifier: ClassFieldName; |
| 1152 | |
| 1153 | ClassFieldName: |
| 1154 | /* "&Type1" */ |
| 1155 | TOK_typefieldreference { |
| 1156 | $$.lex_type = RLT_AmpUppercase; |
| 1157 | $$.name = $1; |
| 1158 | } |
| 1159 | /* "&id" */ |
| 1160 | | TOK_valuefieldreference { |
| 1161 | $$.lex_type = RLT_Amplowercase; |
| 1162 | $$.name = $1; |
| 1163 | } |
| 1164 | ; |
| 1165 | |
| 1166 | |
| 1167 | /* |
| 1168 | * === EXAMPLE === |
| 1169 | * value INTEGER ::= 1 |
| 1170 | * === EOF === |
| 1171 | */ |
| 1172 | ValueDefinition: |
| 1173 | Identifier DefinedTypeRef TOK_PPEQ InlineOrDefinedValue { |
| 1174 | $$ = $2; |
| 1175 | assert($$->Identifier == NULL); |
| 1176 | $$->Identifier = $1; |
| 1177 | $$->meta_type = AMT_VALUE; |
| 1178 | $$->value = $4; |
| 1179 | } |
| 1180 | ; |
| 1181 | |
| 1182 | InlineOrDefinedValue: |
| 1183 | '{' { asn1p_lexer_hack_push_opaque_state(); } |
| 1184 | Opaque /* '}' */ { |
| 1185 | $$ = asn1p_value_frombuf($3.buf, $3.len, 0); |
| 1186 | checkmem($$); |
| 1187 | $$->type = ATV_UNPARSED; |
| 1188 | } |
| 1189 | | TOK_bstring { |
| 1190 | $$ = _convert_bitstring2binary($1, 'B'); |
| 1191 | checkmem($$); |
| 1192 | } |
| 1193 | | TOK_hstring { |
| 1194 | $$ = _convert_bitstring2binary($1, 'H'); |
| 1195 | checkmem($$); |
| 1196 | } |
| 1197 | | TOK_cstring { |
| 1198 | $$ = asn1p_value_frombuf($1.buf, $1.len, 0); |
| 1199 | checkmem($$); |
| 1200 | } |
| 1201 | | SignedNumber { |
| 1202 | $$ = $1; |
| 1203 | } |
| 1204 | | DefinedValue { |
| 1205 | $$ = $1; |
| 1206 | } |
| 1207 | ; |
| 1208 | |
| 1209 | DefinedValue: |
| 1210 | Identifier { |
| 1211 | asn1p_ref_t *ref; |
| 1212 | int ret; |
| 1213 | ref = asn1p_ref_new(yylineno); |
| 1214 | checkmem(ref); |
| 1215 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1216 | checkmem(ret == 0); |
| 1217 | $$ = asn1p_value_fromref(ref, 0); |
| 1218 | checkmem($$); |
| 1219 | free($1); |
| 1220 | } |
| 1221 | | TypeRefName '.' Identifier { |
| 1222 | asn1p_ref_t *ref; |
| 1223 | int ret; |
| 1224 | ref = asn1p_ref_new(yylineno); |
| 1225 | checkmem(ref); |
| 1226 | ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); |
| 1227 | checkmem(ret == 0); |
| 1228 | ret = asn1p_ref_add_component(ref, $3, RLT_lowercase); |
| 1229 | checkmem(ret == 0); |
| 1230 | $$ = asn1p_value_fromref(ref, 0); |
| 1231 | checkmem($$); |
| 1232 | free($1); |
| 1233 | free($3); |
| 1234 | } |
| 1235 | ; |
| 1236 | |
| 1237 | Opaque: |
| 1238 | TOK_opaque { |
| 1239 | $$.len = $1.len + 2; |
| 1240 | $$.buf = malloc($$.len + 1); |
| 1241 | checkmem($$.buf); |
| 1242 | $$.buf[0] = '{'; |
| 1243 | $$.buf[1] = ' '; |
| 1244 | memcpy($$.buf + 2, $1.buf, $1.len); |
| 1245 | $$.buf[$$.len] = '\0'; |
| 1246 | free($1.buf); |
| 1247 | } |
| 1248 | | Opaque TOK_opaque { |
| 1249 | int newsize = $1.len + $2.len; |
| 1250 | char *p = malloc(newsize + 1); |
| 1251 | checkmem(p); |
| 1252 | memcpy(p , $1.buf, $1.len); |
| 1253 | memcpy(p + $1.len, $2.buf, $2.len); |
| 1254 | p[newsize] = '\0'; |
| 1255 | free($1.buf); |
| 1256 | free($2.buf); |
| 1257 | $$.buf = p; |
| 1258 | $$.len = newsize; |
| 1259 | } |
| 1260 | ; |
| 1261 | |
| 1262 | BasicTypeId: |
| 1263 | TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; } |
| 1264 | | TOK_NULL { $$ = ASN_BASIC_NULL; } |
| 1265 | | TOK_REAL { $$ = ASN_BASIC_REAL; } |
| 1266 | | BasicTypeId_UniverationCompatible { $$ = $1; } |
| 1267 | | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; } |
| 1268 | | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; } |
| 1269 | | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; } |
| 1270 | | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; } |
| 1271 | | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; } |
| 1272 | | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; } |
| 1273 | | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; } |
| 1274 | | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; } |
| 1275 | ; |
| 1276 | |
| 1277 | /* |
| 1278 | * A type identifier which may be used with "{ a(1), b(2) }" clause. |
| 1279 | */ |
| 1280 | BasicTypeId_UniverationCompatible: |
| 1281 | TOK_INTEGER { $$ = ASN_BASIC_INTEGER; } |
| 1282 | | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; } |
| 1283 | | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; } |
| 1284 | ; |
| 1285 | |
| 1286 | BasicType: |
| 1287 | BasicTypeId { |
| 1288 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1289 | checkmem($$); |
| 1290 | $$->expr_type = $1; |
| 1291 | $$->meta_type = AMT_TYPE; |
| 1292 | } |
| 1293 | | BasicTypeId_UniverationCompatible UniverationDefinition { |
| 1294 | if($2) { |
| 1295 | $$ = $2; |
| 1296 | } else { |
| 1297 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1298 | checkmem($$); |
| 1299 | } |
| 1300 | $$->expr_type = $1; |
| 1301 | $$->meta_type = AMT_TYPE; |
| 1302 | } |
| 1303 | ; |
| 1304 | |
| 1305 | BasicString: |
| 1306 | TOK_BMPString { $$ = ASN_STRING_BMPString; } |
| 1307 | | TOK_GeneralString { |
| 1308 | $$ = ASN_STRING_GeneralString; |
| 1309 | return yyerror("GeneralString is not supported"); |
| 1310 | } |
| 1311 | | TOK_GraphicString { |
| 1312 | $$ = ASN_STRING_GraphicString; |
| 1313 | return yyerror("GraphicString is not supported"); |
| 1314 | } |
| 1315 | | TOK_IA5String { $$ = ASN_STRING_IA5String; } |
| 1316 | | TOK_ISO646String { $$ = ASN_STRING_ISO646String; } |
| 1317 | | TOK_NumericString { $$ = ASN_STRING_NumericString; } |
| 1318 | | TOK_PrintableString { $$ = ASN_STRING_PrintableString; } |
| 1319 | | TOK_T61String { |
| 1320 | $$ = ASN_STRING_T61String; |
| 1321 | return yyerror("T61String not implemented yet"); |
| 1322 | } |
| 1323 | | TOK_TeletexString { $$ = ASN_STRING_TeletexString; } |
| 1324 | | TOK_UniversalString { $$ = ASN_STRING_UniversalString; } |
| 1325 | | TOK_UTF8String { $$ = ASN_STRING_UTF8String; } |
| 1326 | | TOK_VideotexString { |
| 1327 | $$ = ASN_STRING_VideotexString; |
| 1328 | return yyerror("VideotexString is no longer supported"); |
| 1329 | } |
| 1330 | | TOK_VisibleString { $$ = ASN_STRING_VisibleString; } |
| 1331 | | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; } |
| 1332 | ; |
| 1333 | |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1334 | |
| 1335 | ConstructedTypeConstrained: |
| 1336 | TOK_SEQUENCE optConstraints TOK_OF ConstrainedTypeDeclaration { |
| 1337 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1338 | checkmem($$); |
| 1339 | $$->constraints = $2; |
| 1340 | $$->expr_type = ASN_CONSTR_SEQUENCE_OF; |
| 1341 | $$->meta_type = AMT_TYPE; |
| 1342 | TQ_ADD(&($$->members), $4, next); |
| 1343 | } |
| 1344 | | TOK_SET optConstraints TOK_OF ConstrainedTypeDeclaration { |
| 1345 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1346 | checkmem($$); |
| 1347 | $$->constraints = $2; |
| 1348 | $$->expr_type = ASN_CONSTR_SET_OF; |
| 1349 | $$->meta_type = AMT_TYPE; |
| 1350 | TQ_ADD(&($$->members), $4, next); |
| 1351 | } |
| 1352 | ; |
| 1353 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1354 | ConstructedType: |
| 1355 | TOK_CHOICE '{' ConstructedDataTypeDefinition '}' { |
| 1356 | $$ = $3; |
| 1357 | assert($$->expr_type == A1TC_INVALID); |
| 1358 | $$->expr_type = ASN_CONSTR_CHOICE; |
| 1359 | $$->meta_type = AMT_TYPE; |
| 1360 | } |
| 1361 | | TOK_SEQUENCE '{' ConstructedDataTypeDefinition '}' { |
| 1362 | $$ = $3; |
| 1363 | assert($$->expr_type == A1TC_INVALID); |
| 1364 | $$->expr_type = ASN_CONSTR_SEQUENCE; |
| 1365 | $$->meta_type = AMT_TYPE; |
| 1366 | } |
| 1367 | | TOK_SET '{' ConstructedDataTypeDefinition '}' { |
| 1368 | $$ = $3; |
| 1369 | assert($$->expr_type == A1TC_INVALID); |
| 1370 | $$->expr_type = ASN_CONSTR_SET; |
| 1371 | $$->meta_type = AMT_TYPE; |
| 1372 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1373 | | TOK_ANY { |
| 1374 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1375 | checkmem($$); |
| 1376 | $$->expr_type = ASN_CONSTR_ANY; |
| 1377 | $$->meta_type = AMT_TYPE; |
| 1378 | } |
| 1379 | | TOK_ANY TOK_DEFINED TOK_BY Identifier { |
| 1380 | int ret; |
| 1381 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1382 | checkmem($$); |
| 1383 | $$->reference = asn1p_ref_new(yylineno); |
| 1384 | ret = asn1p_ref_add_component($$->reference, |
| 1385 | $4, RLT_lowercase); |
| 1386 | checkmem(ret == 0); |
| 1387 | $$->expr_type = ASN_CONSTR_ANY; |
| 1388 | $$->meta_type = AMT_TYPE; |
| 1389 | } |
| 1390 | ; |
| 1391 | |
| 1392 | /* |
| 1393 | * Data type constraints. |
| 1394 | */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1395 | Union: '|' | TOK_UNION; |
| 1396 | Intersection: '^' | TOK_INTERSECTION; |
| 1397 | Except: TOK_EXCEPT; |
| 1398 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1399 | optConstraints: |
| 1400 | { $$ = 0; } |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1401 | | Constraints { |
| 1402 | $$ = $1; |
| 1403 | } |
| 1404 | ; |
| 1405 | |
| 1406 | Constraints: |
| 1407 | SetOfConstraints { |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1408 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0); |
| 1409 | } |
| 1410 | | TOK_SIZE '(' ElementSetSpecs ')' { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1411 | /* |
| 1412 | * This is a special case, for compatibility purposes. |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1413 | * It goes without parentheses. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1414 | */ |
vlm | 5f0128b | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1415 | CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1416 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1417 | ; |
| 1418 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1419 | SetOfConstraints: |
| 1420 | '(' ElementSetSpecs ')' { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1421 | $$ = $2; |
| 1422 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1423 | | SetOfConstraints '(' ElementSetSpecs ')' { |
| 1424 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3); |
| 1425 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1426 | ; |
| 1427 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1428 | ElementSetSpecs: |
| 1429 | ElementSetSpec { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1430 | $$ = $1; |
| 1431 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1432 | | ElementSetSpec ',' TOK_ThreeDots { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1433 | asn1p_constraint_t *ct; |
| 1434 | ct = asn1p_constraint_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1435 | ct->type = ACT_EL_EXT; |
| 1436 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
| 1437 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1438 | | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1439 | asn1p_constraint_t *ct; |
| 1440 | ct = asn1p_constraint_new(yylineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1441 | ct->type = ACT_EL_EXT; |
| 1442 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
vlm | 6f5eb0b | 2004-08-13 12:35:09 +0000 | [diff] [blame] | 1443 | ct = $$; |
| 1444 | CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1445 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1446 | ; |
| 1447 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1448 | ElementSetSpec: |
| 1449 | ConstraintSubtypeElement { |
| 1450 | $$ = $1; |
| 1451 | } |
| 1452 | | ElementSetSpec Union ConstraintSubtypeElement { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1453 | CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3); |
| 1454 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1455 | | ElementSetSpec Intersection ConstraintSubtypeElement { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1456 | CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3); |
| 1457 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1458 | | ConstraintSubtypeElement Except ConstraintSubtypeElement { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1459 | CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3); |
| 1460 | } |
| 1461 | ; |
| 1462 | |
| 1463 | ConstraintSubtypeElement: |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1464 | ConstraintSpec '(' ElementSetSpecs ')' { |
| 1465 | int ret; |
| 1466 | $$ = asn1p_constraint_new(yylineno); |
| 1467 | checkmem($$); |
| 1468 | $$->type = $1; |
| 1469 | ret = asn1p_constraint_insert($$, $3); |
| 1470 | checkmem(ret == 0); |
| 1471 | } |
| 1472 | | '(' ElementSetSpecs ')' { |
| 1473 | int ret; |
| 1474 | $$ = asn1p_constraint_new(yylineno); |
| 1475 | checkmem($$); |
| 1476 | $$->type = ACT_CA_SET; |
| 1477 | ret = asn1p_constraint_insert($$, $2); |
| 1478 | checkmem(ret == 0); |
| 1479 | } |
| 1480 | | ConstraintValue { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1481 | $$ = asn1p_constraint_new(yylineno); |
| 1482 | checkmem($$); |
| 1483 | $$->type = ACT_EL_VALUE; |
| 1484 | $$->value = $1; |
| 1485 | } |
| 1486 | | ConstraintValue ConstraintRangeSpec ConstraintValue { |
| 1487 | $$ = asn1p_constraint_new(yylineno); |
| 1488 | checkmem($$); |
| 1489 | $$->type = $2; |
| 1490 | $$->range_start = $1; |
| 1491 | $$->range_stop = $3; |
| 1492 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1493 | | TOK_MIN ConstraintRangeSpec ConstraintValue { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1494 | $$ = asn1p_constraint_new(yylineno); |
| 1495 | checkmem($$); |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1496 | $$->type = $2; |
| 1497 | $$->range_start = asn1p_value_fromint(-123); |
| 1498 | $$->range_stop = $3; |
| 1499 | $$->range_start->type = ATV_MIN; |
| 1500 | } |
| 1501 | | ConstraintValue ConstraintRangeSpec TOK_MAX { |
| 1502 | $$ = asn1p_constraint_new(yylineno); |
| 1503 | checkmem($$); |
| 1504 | $$->type = $2; |
| 1505 | $$->range_start = $1; |
| 1506 | $$->range_stop = asn1p_value_fromint(321); |
| 1507 | $$->range_stop->type = ATV_MAX; |
| 1508 | } |
| 1509 | | TOK_MIN ConstraintRangeSpec TOK_MAX { |
| 1510 | $$ = asn1p_constraint_new(yylineno); |
| 1511 | checkmem($$); |
| 1512 | $$->type = $2; |
| 1513 | $$->range_start = asn1p_value_fromint(-123); |
| 1514 | $$->range_stop = asn1p_value_fromint(321); |
| 1515 | $$->range_start->type = ATV_MIN; |
| 1516 | $$->range_stop->type = ATV_MAX; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1517 | } |
| 1518 | | TableConstraint { |
| 1519 | $$ = $1; |
| 1520 | } |
| 1521 | | WithComponents { |
| 1522 | $$ = $1; |
| 1523 | } |
| 1524 | ; |
| 1525 | |
| 1526 | ConstraintRangeSpec: |
| 1527 | TOK_TwoDots { $$ = ACT_EL_RANGE; } |
| 1528 | | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; } |
| 1529 | | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; } |
| 1530 | | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; } |
| 1531 | ; |
| 1532 | |
| 1533 | ConstraintSpec: |
| 1534 | TOK_SIZE { |
| 1535 | $$ = ACT_CT_SIZE; |
| 1536 | } |
| 1537 | | TOK_FROM { |
| 1538 | $$ = ACT_CT_FROM; |
| 1539 | } |
| 1540 | ; |
| 1541 | |
| 1542 | ConstraintValue: |
| 1543 | SignedNumber { |
| 1544 | $$ = $1; |
| 1545 | } |
| 1546 | | Identifier { |
| 1547 | asn1p_ref_t *ref; |
| 1548 | int ret; |
| 1549 | ref = asn1p_ref_new(yylineno); |
| 1550 | checkmem(ref); |
| 1551 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1552 | checkmem(ret == 0); |
| 1553 | $$ = asn1p_value_fromref(ref, 0); |
| 1554 | checkmem($$); |
| 1555 | free($1); |
| 1556 | } |
| 1557 | | TOK_cstring { |
| 1558 | $$ = asn1p_value_frombuf($1.buf, $1.len, 0); |
| 1559 | checkmem($$); |
| 1560 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1561 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1562 | | TOK_FALSE { |
| 1563 | $$ = asn1p_value_fromint(0); |
| 1564 | checkmem($$); |
| 1565 | $$->type = ATV_FALSE; |
| 1566 | } |
| 1567 | | TOK_TRUE { |
| 1568 | $$ = asn1p_value_fromint(1); |
| 1569 | checkmem($$); |
| 1570 | $$->type = ATV_TRUE; |
| 1571 | } |
| 1572 | ; |
| 1573 | |
| 1574 | WithComponents: |
| 1575 | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' { |
| 1576 | CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0); |
| 1577 | } |
| 1578 | ; |
| 1579 | |
| 1580 | WithComponentsList: |
| 1581 | WithComponentsElement { |
| 1582 | $$ = $1; |
| 1583 | } |
| 1584 | | WithComponentsList ',' WithComponentsElement { |
| 1585 | CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3); |
| 1586 | } |
| 1587 | ; |
| 1588 | |
| 1589 | WithComponentsElement: |
| 1590 | TOK_ThreeDots { |
| 1591 | $$ = asn1p_constraint_new(yylineno); |
| 1592 | checkmem($$); |
| 1593 | $$->type = ACT_EL_EXT; |
| 1594 | } |
| 1595 | | Identifier optConstraints optPresenceConstraint { |
| 1596 | $$ = asn1p_constraint_new(yylineno); |
| 1597 | checkmem($$); |
| 1598 | $$->type = ACT_EL_VALUE; |
| 1599 | $$->value = asn1p_value_frombuf($1, strlen($1), 0); |
| 1600 | $$->presence = $3; |
| 1601 | } |
| 1602 | ; |
| 1603 | |
| 1604 | /* |
| 1605 | * presence constraint for WithComponents |
| 1606 | */ |
| 1607 | optPresenceConstraint: |
| 1608 | { $$ = ACPRES_DEFAULT; } |
| 1609 | | PresenceConstraint { $$ = $1; } |
| 1610 | ; |
| 1611 | |
| 1612 | PresenceConstraint: |
| 1613 | TOK_PRESENT { |
| 1614 | $$ = ACPRES_PRESENT; |
| 1615 | } |
| 1616 | | TOK_ABSENT { |
| 1617 | $$ = ACPRES_ABSENT; |
| 1618 | } |
| 1619 | | TOK_OPTIONAL { |
| 1620 | $$ = ACPRES_OPTIONAL; |
| 1621 | } |
| 1622 | ; |
| 1623 | |
| 1624 | TableConstraint: |
| 1625 | SimpleTableConstraint { |
| 1626 | $$ = $1; |
| 1627 | } |
| 1628 | | ComponentRelationConstraint { |
| 1629 | $$ = $1; |
| 1630 | } |
| 1631 | ; |
| 1632 | |
| 1633 | /* |
| 1634 | * "{ExtensionSet}" |
| 1635 | */ |
| 1636 | SimpleTableConstraint: |
| 1637 | '{' TypeRefName '}' { |
| 1638 | asn1p_ref_t *ref = asn1p_ref_new(yylineno); |
| 1639 | asn1p_constraint_t *ct; |
| 1640 | int ret; |
| 1641 | ret = asn1p_ref_add_component(ref, $2, 0); |
| 1642 | checkmem(ret == 0); |
| 1643 | ct = asn1p_constraint_new(yylineno); |
| 1644 | checkmem($$); |
| 1645 | ct->type = ACT_EL_VALUE; |
| 1646 | ct->value = asn1p_value_fromref(ref, 0); |
| 1647 | CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0); |
| 1648 | } |
| 1649 | ; |
| 1650 | |
| 1651 | ComponentRelationConstraint: |
| 1652 | SimpleTableConstraint '{' AtNotationList '}' { |
| 1653 | CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3); |
| 1654 | } |
| 1655 | ; |
| 1656 | |
| 1657 | AtNotationList: |
| 1658 | AtNotationElement { |
| 1659 | $$ = asn1p_constraint_new(yylineno); |
| 1660 | checkmem($$); |
| 1661 | $$->type = ACT_EL_VALUE; |
| 1662 | $$->value = asn1p_value_fromref($1, 0); |
| 1663 | } |
| 1664 | | AtNotationList ',' AtNotationElement { |
| 1665 | asn1p_constraint_t *ct; |
| 1666 | ct = asn1p_constraint_new(yylineno); |
| 1667 | checkmem(ct); |
| 1668 | ct->type = ACT_EL_VALUE; |
| 1669 | ct->value = asn1p_value_fromref($3, 0); |
| 1670 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
| 1671 | } |
| 1672 | ; |
| 1673 | |
| 1674 | /* |
| 1675 | * @blah |
| 1676 | */ |
| 1677 | AtNotationElement: |
| 1678 | '@' ComponentIdList { |
| 1679 | char *p = malloc(strlen($2) + 2); |
| 1680 | int ret; |
| 1681 | *p = '@'; |
| 1682 | strcpy(p + 1, $2); |
| 1683 | $$ = asn1p_ref_new(yylineno); |
| 1684 | ret = asn1p_ref_add_component($$, p, 0); |
| 1685 | checkmem(ret == 0); |
| 1686 | free(p); |
| 1687 | free($2); |
| 1688 | } |
| 1689 | | '@' '.' ComponentIdList { |
| 1690 | char *p = malloc(strlen($3) + 3); |
| 1691 | int ret; |
| 1692 | p[0] = '@'; |
| 1693 | p[1] = '.'; |
| 1694 | strcpy(p + 2, $3); |
| 1695 | $$ = asn1p_ref_new(yylineno); |
| 1696 | ret = asn1p_ref_add_component($$, p, 0); |
| 1697 | checkmem(ret == 0); |
| 1698 | free(p); |
| 1699 | free($3); |
| 1700 | } |
| 1701 | ; |
| 1702 | |
| 1703 | /* identifier "." ... */ |
| 1704 | ComponentIdList: |
| 1705 | Identifier { |
| 1706 | $$ = $1; |
| 1707 | } |
| 1708 | | ComponentIdList '.' Identifier { |
| 1709 | int l1 = strlen($1); |
| 1710 | int l3 = strlen($3); |
| 1711 | $$ = malloc(l1 + 1 + l3 + 1); |
| 1712 | memcpy($$, $1, l1); |
| 1713 | $$[l1] = '.'; |
| 1714 | memcpy($$ + l1 + 1, $3, l3); |
| 1715 | $$[l1 + 1 + l3] = '\0'; |
| 1716 | } |
| 1717 | ; |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | /* |
| 1722 | * MARKERS |
| 1723 | */ |
| 1724 | |
| 1725 | optMarker: |
| 1726 | { $$ = EM_NOMARK; } |
| 1727 | | Marker { $$ = $1; } |
| 1728 | ; |
| 1729 | |
| 1730 | Marker: |
| 1731 | TOK_OPTIONAL { |
| 1732 | $$ = EM_OPTIONAL; |
| 1733 | } |
| 1734 | | TOK_DEFAULT DefaultValue { |
| 1735 | $$ = EM_DEFAULT; |
| 1736 | /* FIXME: store DefaultValue somewhere */ |
| 1737 | } |
| 1738 | ; |
| 1739 | |
| 1740 | DefaultValue: |
| 1741 | ConstraintValue { |
| 1742 | } |
| 1743 | | BasicTypeId { |
| 1744 | } |
| 1745 | | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
| 1746 | } |
| 1747 | ; |
| 1748 | |
| 1749 | /* |
| 1750 | * Universal enumeration definition to use in INTEGER and ENUMERATED. |
| 1751 | * === EXAMPLE === |
| 1752 | * Gender ::= ENUMERATED { unknown(0), male(1), female(2) } |
| 1753 | * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) } |
| 1754 | * === EOF === |
| 1755 | */ |
| 1756 | /* |
| 1757 | optUniverationDefinition: |
| 1758 | { $$ = 0; } |
| 1759 | | UniverationDefinition { |
| 1760 | $$ = $1; |
| 1761 | } |
| 1762 | ; |
| 1763 | */ |
| 1764 | |
| 1765 | UniverationDefinition: |
| 1766 | '{' '}' { |
| 1767 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1768 | checkmem($$); |
| 1769 | } |
| 1770 | | '{' UniverationList '}' { |
| 1771 | $$ = $2; |
| 1772 | } |
| 1773 | ; |
| 1774 | |
| 1775 | UniverationList: |
| 1776 | UniverationElement { |
| 1777 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1778 | checkmem($$); |
| 1779 | TQ_ADD(&($$->members), $1, next); |
| 1780 | } |
| 1781 | | UniverationList ',' UniverationElement { |
| 1782 | $$ = $1; |
| 1783 | TQ_ADD(&($$->members), $3, next); |
| 1784 | } |
| 1785 | ; |
| 1786 | |
| 1787 | UniverationElement: |
| 1788 | Identifier { |
| 1789 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1790 | checkmem($$); |
| 1791 | $$->expr_type = A1TC_UNIVERVAL; |
| 1792 | $$->meta_type = AMT_VALUE; |
| 1793 | $$->Identifier = $1; |
| 1794 | } |
| 1795 | | Identifier '(' SignedNumber ')' { |
| 1796 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1797 | checkmem($$); |
| 1798 | $$->expr_type = A1TC_UNIVERVAL; |
| 1799 | $$->meta_type = AMT_VALUE; |
| 1800 | $$->Identifier = $1; |
| 1801 | $$->value = $3; |
| 1802 | } |
| 1803 | | Identifier '(' DefinedValue ')' { |
| 1804 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1805 | checkmem($$); |
| 1806 | $$->expr_type = A1TC_UNIVERVAL; |
| 1807 | $$->meta_type = AMT_VALUE; |
| 1808 | $$->Identifier = $1; |
| 1809 | $$->value = $3; |
| 1810 | } |
| 1811 | | SignedNumber { |
| 1812 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1813 | checkmem($$); |
| 1814 | $$->expr_type = A1TC_UNIVERVAL; |
| 1815 | $$->meta_type = AMT_VALUE; |
| 1816 | $$->value = $1; |
| 1817 | } |
| 1818 | | TOK_ThreeDots { |
| 1819 | $$ = asn1p_expr_new(asn1p_lineno); |
| 1820 | checkmem($$); |
| 1821 | $$->Identifier = strdup("..."); |
| 1822 | checkmem($$->Identifier); |
| 1823 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1824 | $$->meta_type = AMT_VALUE; |
| 1825 | } |
| 1826 | ; |
| 1827 | |
| 1828 | SignedNumber: |
| 1829 | TOK_number { |
| 1830 | $$ = asn1p_value_fromint($1); |
| 1831 | checkmem($$); |
| 1832 | } |
| 1833 | | TOK_number_negative { |
| 1834 | $$ = asn1p_value_fromint($1); |
| 1835 | checkmem($$); |
| 1836 | } |
| 1837 | ; |
| 1838 | |
| 1839 | /* |
| 1840 | * SEQUENCE definition. |
| 1841 | * === EXAMPLE === |
| 1842 | * Struct1 ::= SEQUENCE { |
| 1843 | * memb1 Struct2, |
| 1844 | * memb2 SEQUENCE OF { |
| 1845 | * memb2-1 Struct 3 |
| 1846 | * } |
| 1847 | * } |
| 1848 | * === EOF === |
| 1849 | */ |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | /* |
| 1854 | * SET definition. |
| 1855 | * === EXAMPLE === |
| 1856 | * Person ::= SET { |
| 1857 | * name [0] PrintableString (SIZE(1..20)), |
| 1858 | * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country, |
| 1859 | * } |
| 1860 | * === EOF === |
| 1861 | */ |
| 1862 | |
| 1863 | optTag: |
| 1864 | { memset(&$$, 0, sizeof($$)); } |
| 1865 | | Tag { $$ = $1; } |
| 1866 | ; |
| 1867 | |
| 1868 | Tag: |
| 1869 | TOK_tag { |
| 1870 | $$ = $1; |
| 1871 | $$.tag_mode = TM_DEFAULT; |
| 1872 | } |
| 1873 | | TOK_tag TOK_IMPLICIT { |
| 1874 | $$ = $1; |
| 1875 | $$.tag_mode = TM_IMPLICIT; |
| 1876 | } |
| 1877 | | TOK_tag TOK_EXPLICIT { |
| 1878 | $$ = $1; |
| 1879 | $$.tag_mode = TM_EXPLICIT; |
| 1880 | } |
| 1881 | ; |
| 1882 | |
| 1883 | TypeRefName: |
| 1884 | TOK_typereference { |
| 1885 | checkmem($1); |
| 1886 | $$ = $1; |
| 1887 | } |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1888 | | TOK_capitalreference { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1889 | checkmem($1); |
| 1890 | $$ = $1; |
| 1891 | } |
| 1892 | ; |
| 1893 | |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1894 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1895 | ObjectClassReference: |
vlm | 9283dbe | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1896 | TOK_capitalreference { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1897 | checkmem($1); |
| 1898 | $$ = $1; |
| 1899 | } |
| 1900 | ; |
| 1901 | |
| 1902 | Identifier: |
| 1903 | TOK_identifier { |
| 1904 | checkmem($1); |
| 1905 | $$ = $1; |
| 1906 | } |
| 1907 | ; |
| 1908 | |
| 1909 | TaggedIdentifier: |
| 1910 | Identifier { |
| 1911 | memset(&$$, 0, sizeof($$)); |
| 1912 | $$.name = $1; |
| 1913 | } |
| 1914 | | Identifier Tag { |
| 1915 | $$.name = $1; |
| 1916 | $$.tag = $2; |
| 1917 | } |
| 1918 | ; |
| 1919 | |
| 1920 | |
| 1921 | %% |
| 1922 | |
| 1923 | |
| 1924 | /* |
| 1925 | * Convert Xstring ('0101'B or '5'H) to the binary vector. |
| 1926 | */ |
| 1927 | static asn1p_value_t * |
| 1928 | _convert_bitstring2binary(char *str, int base) { |
| 1929 | asn1p_value_t *val; |
| 1930 | int slen; |
| 1931 | int memlen; |
| 1932 | int baselen; |
| 1933 | int bits; |
| 1934 | uint8_t *binary_vector; |
| 1935 | uint8_t *bv_ptr; |
| 1936 | uint8_t cur_val; |
| 1937 | |
| 1938 | assert(str); |
| 1939 | assert(str[0] == '\''); |
| 1940 | |
| 1941 | switch(base) { |
| 1942 | case 'B': |
| 1943 | baselen = 1; |
| 1944 | break; |
| 1945 | case 'H': |
| 1946 | baselen = 4; |
| 1947 | break; |
| 1948 | default: |
| 1949 | assert(base == 'B' || base == 'H'); |
| 1950 | errno = EINVAL; |
| 1951 | return NULL; |
| 1952 | } |
| 1953 | |
| 1954 | slen = strlen(str); |
| 1955 | assert(str[slen - 1] == base); |
| 1956 | assert(str[slen - 2] == '\''); |
| 1957 | |
| 1958 | memlen = slen / (8 / baselen); /* Conservative estimate */ |
| 1959 | |
| 1960 | bv_ptr = binary_vector = malloc(memlen + 1); |
| 1961 | if(bv_ptr == NULL) |
| 1962 | /* ENOMEM */ |
| 1963 | return NULL; |
| 1964 | |
| 1965 | cur_val = 0; |
| 1966 | bits = 0; |
| 1967 | while(*(++str) != '\'') { |
| 1968 | switch(baselen) { |
| 1969 | case 1: |
| 1970 | switch(*str) { |
| 1971 | case '1': |
| 1972 | cur_val |= 1 << (7 - (bits % 8)); |
| 1973 | case '0': |
| 1974 | break; |
| 1975 | default: |
| 1976 | assert(!"_y UNREACH1"); |
| 1977 | case ' ': case '\r': case '\n': |
| 1978 | continue; |
| 1979 | } |
| 1980 | break; |
| 1981 | case 4: |
| 1982 | switch(*str) { |
| 1983 | case '0': case '1': case '2': case '3': case '4': |
| 1984 | case '5': case '6': case '7': case '8': case '9': |
| 1985 | cur_val |= (*str - '0') << (4 - (bits % 8)); |
| 1986 | break; |
| 1987 | case 'A': case 'B': case 'C': |
| 1988 | case 'D': case 'E': case 'F': |
| 1989 | cur_val |= ((*str - 'A') + 10) |
| 1990 | << (4 - (bits % 8)); |
| 1991 | break; |
| 1992 | default: |
| 1993 | assert(!"_y UNREACH2"); |
| 1994 | case ' ': case '\r': case '\n': |
| 1995 | continue; |
| 1996 | } |
| 1997 | break; |
| 1998 | } |
| 1999 | |
| 2000 | bits += baselen; |
| 2001 | if((bits % 8) == 0) { |
| 2002 | *bv_ptr++ = cur_val; |
| 2003 | cur_val = 0; |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | *bv_ptr = cur_val; |
| 2008 | assert((bv_ptr - binary_vector) <= memlen); |
| 2009 | |
| 2010 | val = asn1p_value_frombits(binary_vector, bits, 0); |
| 2011 | if(val == NULL) { |
| 2012 | free(binary_vector); |
| 2013 | } |
| 2014 | |
| 2015 | return val; |
| 2016 | } |
| 2017 | |
| 2018 | extern char *asn1p_text; |
| 2019 | |
| 2020 | int |
| 2021 | yyerror(const char *msg) { |
| 2022 | fprintf(stderr, |
| 2023 | "ASN.1 grammar parse error " |
| 2024 | "near line %d (token \"%s\"): %s\n", |
| 2025 | asn1p_lineno, asn1p_text, msg); |
| 2026 | return -1; |
| 2027 | } |
| 2028 | |
| 2029 | |