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