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