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( |
Lev Walkin | 7085305 | 2005-11-26 11:21:55 +0000 | [diff] [blame] | 578 | "Attempt to redefine a standard basic string type, " |
| 579 | "please comment out or remove this type redefinition."); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 580 | } |
| 581 | ; |
| 582 | |
| 583 | /* |
| 584 | * === EXAMPLE === |
| 585 | * IMPORTS Type1, value FROM Module { iso standard(0) } ; |
| 586 | * === EOF === |
| 587 | */ |
| 588 | ImportsDefinition: |
| 589 | TOK_IMPORTS ImportsBundleSet ';' { |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 590 | if(!saved_aid && 0) |
| 591 | return yyerror("Unterminated IMPORTS FROM, " |
| 592 | "expected semicolon ';'"); |
| 593 | saved_aid = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 594 | $$ = $2; |
| 595 | } |
| 596 | /* |
| 597 | * Some error cases. |
| 598 | */ |
| 599 | | TOK_IMPORTS TOK_FROM /* ... */ { |
| 600 | return yyerror("Empty IMPORTS list"); |
| 601 | } |
| 602 | ; |
| 603 | |
| 604 | ImportsBundleSet: |
| 605 | ImportsBundle { |
| 606 | $$ = asn1p_module_new(); |
| 607 | checkmem($$); |
| 608 | TQ_ADD(&($$->imports), $1, xp_next); |
| 609 | } |
| 610 | | ImportsBundleSet ImportsBundle { |
| 611 | $$ = $1; |
| 612 | TQ_ADD(&($$->imports), $2, xp_next); |
| 613 | } |
| 614 | ; |
| 615 | |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 616 | AssignedIdentifier: |
| 617 | { memset(&$$, 0, sizeof($$)); } |
| 618 | | ObjectIdentifier { $$.oid = $1; }; |
| 619 | /* | DefinedValue { $$.value = $1; }; // Handled through saved_aid */ |
| 620 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 621 | ImportsBundle: |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 622 | ImportsList TOK_FROM TypeRefName AssignedIdentifier { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 623 | $$ = $1; |
Lev Walkin | 1ed2209 | 2005-08-12 10:06:17 +0000 | [diff] [blame] | 624 | $$->fromModuleName = $3; |
| 625 | $$->identifier = $4; |
| 626 | /* This stupid thing is used for look-back hack. */ |
| 627 | saved_aid = $$->identifier.oid ? 0 : &($$->identifier); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 628 | checkmem($$); |
| 629 | } |
| 630 | ; |
| 631 | |
| 632 | ImportsList: |
| 633 | ImportsElement { |
| 634 | $$ = asn1p_xports_new(); |
| 635 | checkmem($$); |
| 636 | TQ_ADD(&($$->members), $1, next); |
| 637 | } |
| 638 | | ImportsList ',' ImportsElement { |
| 639 | $$ = $1; |
| 640 | TQ_ADD(&($$->members), $3, next); |
| 641 | } |
| 642 | ; |
| 643 | |
| 644 | ImportsElement: |
| 645 | TypeRefName { |
| 646 | $$ = asn1p_expr_new(yylineno); |
| 647 | checkmem($$); |
| 648 | $$->Identifier = $1; |
| 649 | $$->expr_type = A1TC_REFERENCE; |
| 650 | } |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 651 | | TypeRefName '{' '}' { /* Completely equivalent to above */ |
| 652 | $$ = asn1p_expr_new(yylineno); |
| 653 | checkmem($$); |
| 654 | $$->Identifier = $1; |
| 655 | $$->expr_type = A1TC_REFERENCE; |
| 656 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 657 | | Identifier { |
| 658 | $$ = asn1p_expr_new(yylineno); |
| 659 | checkmem($$); |
| 660 | $$->Identifier = $1; |
| 661 | $$->expr_type = A1TC_REFERENCE; |
| 662 | } |
| 663 | ; |
| 664 | |
| 665 | ExportsDefinition: |
| 666 | TOK_EXPORTS ExportsBody ';' { |
| 667 | $$ = $2; |
| 668 | } |
| 669 | | TOK_EXPORTS TOK_ALL ';' { |
| 670 | $$ = 0; |
| 671 | } |
| 672 | | TOK_EXPORTS ';' { |
| 673 | /* Empty EXPORTS clause effectively prohibits export. */ |
| 674 | $$ = asn1p_xports_new(); |
| 675 | checkmem($$); |
| 676 | } |
| 677 | ; |
| 678 | |
| 679 | ExportsBody: |
| 680 | ExportsElement { |
| 681 | $$ = asn1p_xports_new(); |
| 682 | assert($$); |
| 683 | TQ_ADD(&($$->members), $1, next); |
| 684 | } |
| 685 | | ExportsBody ',' ExportsElement { |
| 686 | $$ = $1; |
| 687 | TQ_ADD(&($$->members), $3, next); |
| 688 | } |
| 689 | ; |
| 690 | |
| 691 | ExportsElement: |
| 692 | TypeRefName { |
| 693 | $$ = asn1p_expr_new(yylineno); |
| 694 | checkmem($$); |
| 695 | $$->Identifier = $1; |
| 696 | $$->expr_type = A1TC_EXPORTVAR; |
| 697 | } |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 698 | | TypeRefName '{' '}' { |
| 699 | $$ = asn1p_expr_new(yylineno); |
| 700 | checkmem($$); |
| 701 | $$->Identifier = $1; |
| 702 | $$->expr_type = A1TC_EXPORTVAR; |
| 703 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 704 | | Identifier { |
| 705 | $$ = asn1p_expr_new(yylineno); |
| 706 | checkmem($$); |
| 707 | $$->Identifier = $1; |
| 708 | $$->expr_type = A1TC_EXPORTVAR; |
| 709 | } |
| 710 | ; |
| 711 | |
| 712 | |
| 713 | ValueSetDefinition: |
Lev Walkin | 8ea9948 | 2005-03-31 21:48:13 +0000 | [diff] [blame] | 714 | TypeRefName DefinedTypeRef TOK_PPEQ |
| 715 | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 716 | $$ = $2; |
| 717 | assert($$->Identifier == 0); |
| 718 | $$->Identifier = $1; |
| 719 | $$->meta_type = AMT_VALUESET; |
Lev Walkin | 8ea9948 | 2005-03-31 21:48:13 +0000 | [diff] [blame] | 720 | // take care of ValueSet body |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 721 | } |
| 722 | ; |
| 723 | |
| 724 | DefinedTypeRef: |
| 725 | ComplexTypeReference { |
| 726 | $$ = asn1p_expr_new(yylineno); |
| 727 | checkmem($$); |
| 728 | $$->reference = $1; |
| 729 | $$->expr_type = A1TC_REFERENCE; |
| 730 | $$->meta_type = AMT_TYPEREF; |
| 731 | } |
| 732 | | BasicTypeId { |
| 733 | $$ = asn1p_expr_new(yylineno); |
| 734 | checkmem($$); |
| 735 | $$->expr_type = $1; |
| 736 | $$->meta_type = AMT_TYPE; |
| 737 | } |
| 738 | ; |
| 739 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 740 | /* |
| 741 | * Data Type Reference. |
| 742 | * === EXAMPLE === |
| 743 | * Type3 ::= CHOICE { a Type1, b Type 2 } |
| 744 | * === EOF === |
| 745 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 746 | DataTypeReference: |
| 747 | /* |
| 748 | * Optionally tagged type definition. |
| 749 | */ |
| 750 | TypeRefName TOK_PPEQ optTag TOK_TYPE_IDENTIFIER { |
| 751 | $$ = asn1p_expr_new(yylineno); |
| 752 | checkmem($$); |
| 753 | $$->Identifier = $1; |
| 754 | $$->tag = $3; |
| 755 | $$->expr_type = A1TC_TYPEID; |
| 756 | $$->meta_type = AMT_TYPE; |
| 757 | } |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 758 | | TypeRefName TOK_PPEQ Type { |
| 759 | $$ = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 760 | $$->Identifier = $1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 761 | assert($$->expr_type); |
| 762 | assert($$->meta_type); |
| 763 | } |
| 764 | | TypeRefName TOK_PPEQ ClassDeclaration { |
| 765 | $$ = $3; |
| 766 | $$->Identifier = $1; |
| 767 | assert($$->expr_type == A1TC_CLASSDEF); |
| 768 | assert($$->meta_type == AMT_OBJECT); |
| 769 | } |
| 770 | /* |
| 771 | * Parametrized <Type> declaration: |
| 772 | * === EXAMPLE === |
| 773 | * SIGNED { ToBeSigned } ::= SEQUENCE { |
| 774 | * toBeSigned ToBeSigned, |
| 775 | * algorithm AlgorithmIdentifier, |
| 776 | * signature BIT STRING |
| 777 | * } |
| 778 | * === EOF === |
| 779 | */ |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 780 | | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 781 | $$ = $6; |
| 782 | assert($$->Identifier == 0); |
| 783 | $$->Identifier = $1; |
| 784 | $$->params = $3; |
| 785 | $$->meta_type = AMT_PARAMTYPE; |
| 786 | } |
| 787 | ; |
| 788 | |
| 789 | ParameterArgumentList: |
| 790 | ParameterArgumentName { |
| 791 | int ret; |
| 792 | $$ = asn1p_paramlist_new(yylineno); |
| 793 | checkmem($$); |
| 794 | ret = asn1p_paramlist_add_param($$, $1.governor, $1.argument); |
| 795 | checkmem(ret == 0); |
| 796 | if($1.governor) asn1p_ref_free($1.governor); |
| 797 | if($1.argument) free($1.argument); |
| 798 | } |
| 799 | | ParameterArgumentList ',' ParameterArgumentName { |
| 800 | int ret; |
| 801 | $$ = $1; |
| 802 | ret = asn1p_paramlist_add_param($$, $3.governor, $3.argument); |
| 803 | checkmem(ret == 0); |
| 804 | if($3.governor) asn1p_ref_free($3.governor); |
| 805 | if($3.argument) free($3.argument); |
| 806 | } |
| 807 | ; |
| 808 | |
| 809 | ParameterArgumentName: |
| 810 | TypeRefName { |
| 811 | $$.governor = NULL; |
| 812 | $$.argument = $1; |
| 813 | } |
| 814 | | TypeRefName ':' Identifier { |
| 815 | int ret; |
| 816 | $$.governor = asn1p_ref_new(yylineno); |
| 817 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 818 | checkmem(ret == 0); |
| 819 | $$.argument = $3; |
| 820 | } |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 821 | | TypeRefName ':' TypeRefName { |
| 822 | int ret; |
| 823 | $$.governor = asn1p_ref_new(yylineno); |
| 824 | ret = asn1p_ref_add_component($$.governor, $1, 0); |
| 825 | checkmem(ret == 0); |
| 826 | $$.argument = $3; |
| 827 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 828 | | BasicTypeId ':' Identifier { |
| 829 | int ret; |
| 830 | $$.governor = asn1p_ref_new(yylineno); |
| 831 | ret = asn1p_ref_add_component($$.governor, |
| 832 | ASN_EXPR_TYPE2STR($1), 1); |
| 833 | checkmem(ret == 0); |
| 834 | $$.argument = $3; |
| 835 | } |
| 836 | ; |
| 837 | |
| 838 | ActualParameterList: |
| 839 | ActualParameter { |
| 840 | $$ = asn1p_expr_new(yylineno); |
| 841 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 842 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 843 | } |
| 844 | | ActualParameterList ',' ActualParameter { |
| 845 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 846 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 847 | } |
| 848 | ; |
| 849 | |
| 850 | ActualParameter: |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 851 | Type { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 852 | $$ = $1; |
| 853 | } |
| 854 | | Identifier { |
| 855 | $$ = asn1p_expr_new(yylineno); |
| 856 | checkmem($$); |
| 857 | $$->Identifier = $1; |
| 858 | $$->expr_type = A1TC_REFERENCE; |
| 859 | $$->meta_type = AMT_VALUE; |
| 860 | } |
| 861 | ; |
| 862 | |
| 863 | /* |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 864 | | '{' ActualParameter '}' { |
| 865 | $$ = asn1p_expr_new(yylineno); |
| 866 | checkmem($$); |
| 867 | asn1p_expr_add($$, $2); |
| 868 | $$->expr_type = A1TC_PARAMETRIZED; |
| 869 | $$->meta_type = AMT_TYPE; |
| 870 | } |
| 871 | ; |
| 872 | */ |
| 873 | |
| 874 | /* |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 875 | * A collection of constructed data type members. |
| 876 | */ |
Lev Walkin | 144db9b | 2004-10-12 23:26:53 +0000 | [diff] [blame] | 877 | optComponentTypeLists: |
| 878 | { $$ = asn1p_expr_new(yylineno); } |
| 879 | | ComponentTypeLists { $$ = $1; }; |
| 880 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 881 | ComponentTypeLists: |
| 882 | ComponentType { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 883 | $$ = asn1p_expr_new(yylineno); |
| 884 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 885 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 886 | } |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 887 | | ComponentTypeLists ',' ComponentType { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 888 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 889 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 890 | } |
| 891 | ; |
| 892 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 893 | ComponentType: |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 894 | Identifier Type optMarker { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 895 | $$ = $2; |
| 896 | assert($$->Identifier == 0); |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 897 | $$->Identifier = $1; |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 898 | $3.flags |= $$->marker.flags; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 899 | $$->marker = $3; |
| 900 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 901 | | Type optMarker { |
| 902 | $$ = $1; |
| 903 | $2.flags |= $$->marker.flags; |
| 904 | $$->marker = $2; |
| 905 | _fixup_anonymous_identifier($$); |
| 906 | } |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 907 | | TOK_COMPONENTS TOK_OF Type { |
| 908 | $$ = asn1p_expr_new(yylineno); |
| 909 | checkmem($$); |
| 910 | $$->meta_type = $3->meta_type; |
| 911 | $$->expr_type = A1TC_COMPONENTS_OF; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 912 | asn1p_expr_add($$, $3); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 913 | } |
| 914 | | ExtensionAndException { |
| 915 | $$ = $1; |
| 916 | } |
| 917 | ; |
| 918 | |
| 919 | AlternativeTypeLists: |
| 920 | AlternativeType { |
| 921 | $$ = asn1p_expr_new(yylineno); |
| 922 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 923 | asn1p_expr_add($$, $1); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 924 | } |
| 925 | | AlternativeTypeLists ',' AlternativeType { |
| 926 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 927 | asn1p_expr_add($$, $3); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 928 | } |
| 929 | ; |
| 930 | |
| 931 | AlternativeType: |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 932 | Identifier Type { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 933 | $$ = $2; |
| 934 | assert($$->Identifier == 0); |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 935 | $$->Identifier = $1; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 936 | } |
| 937 | | ExtensionAndException { |
| 938 | $$ = $1; |
| 939 | } |
Lev Walkin | 2e9bd5c | 2005-08-13 09:07:11 +0000 | [diff] [blame] | 940 | | Type { |
| 941 | $$ = $1; |
| 942 | _fixup_anonymous_identifier($$); |
| 943 | } |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 944 | ; |
| 945 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 946 | ClassDeclaration: |
| 947 | TOK_CLASS '{' ClassFieldList '}' optWithSyntax { |
| 948 | $$ = $3; |
| 949 | checkmem($$); |
| 950 | $$->with_syntax = $5; |
| 951 | assert($$->expr_type == A1TC_CLASSDEF); |
| 952 | assert($$->meta_type == AMT_OBJECT); |
| 953 | } |
| 954 | ; |
| 955 | |
| 956 | optUnique: |
| 957 | { $$ = 0; } |
| 958 | | TOK_UNIQUE { $$ = 1; } |
| 959 | ; |
| 960 | |
| 961 | ClassFieldList: |
| 962 | ClassField { |
| 963 | $$ = asn1p_expr_new(yylineno); |
| 964 | checkmem($$); |
| 965 | $$->expr_type = A1TC_CLASSDEF; |
| 966 | $$->meta_type = AMT_OBJECT; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 967 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 968 | } |
| 969 | | ClassFieldList ',' ClassField { |
| 970 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 971 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 972 | } |
| 973 | ; |
| 974 | |
| 975 | ClassField: |
| 976 | ClassFieldIdentifier optMarker { |
| 977 | $$ = asn1p_expr_new(yylineno); |
| 978 | checkmem($$); |
| 979 | $$->Identifier = $1.name; |
| 980 | $$->expr_type = A1TC_CLASSFIELD; |
| 981 | $$->meta_type = AMT_OBJECTFIELD; |
| 982 | $$->marker = $2; |
| 983 | } |
Lev Walkin | b7c45ca | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 984 | | ClassFieldIdentifier Type optUnique optMarker { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 985 | $$ = $2; |
| 986 | $$->Identifier = $1.name; |
Lev Walkin | b7c45ca | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 987 | $$->marker = $4; |
| 988 | $$->unique = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 989 | } |
Lev Walkin | b7c45ca | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 990 | | ClassFieldIdentifier ClassFieldIdentifier optUnique optMarker { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 991 | int ret; |
| 992 | $$ = asn1p_expr_new(yylineno); |
| 993 | checkmem($$); |
| 994 | $$->Identifier = $1.name; |
| 995 | $$->reference = asn1p_ref_new(yylineno); |
| 996 | checkmem($$->reference); |
| 997 | ret = asn1p_ref_add_component($$->reference, |
| 998 | $2.name, $2.lex_type); |
| 999 | checkmem(ret == 0); |
| 1000 | $$->expr_type = A1TC_CLASSFIELD; |
| 1001 | $$->meta_type = AMT_OBJECTFIELD; |
Lev Walkin | b7c45ca | 2004-11-24 17:43:29 +0000 | [diff] [blame] | 1002 | $$->marker = $4; |
| 1003 | $$->unique = $3; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1004 | } |
| 1005 | ; |
| 1006 | |
| 1007 | optWithSyntax: |
| 1008 | { $$ = 0; } |
| 1009 | | WithSyntax { |
| 1010 | $$ = $1; |
| 1011 | } |
| 1012 | ; |
| 1013 | |
| 1014 | WithSyntax: |
| 1015 | TOK_WITH TOK_SYNTAX '{' |
| 1016 | { asn1p_lexer_hack_enable_with_syntax(); } |
| 1017 | WithSyntaxFormat |
| 1018 | '}' { |
| 1019 | $$ = $5; |
| 1020 | } |
| 1021 | ; |
| 1022 | |
| 1023 | WithSyntaxFormat: |
| 1024 | WithSyntaxFormatToken { |
| 1025 | $$ = asn1p_wsyntx_new(); |
| 1026 | TQ_ADD(&($$->chunks), $1, next); |
| 1027 | } |
| 1028 | | WithSyntaxFormat WithSyntaxFormatToken { |
| 1029 | $$ = $1; |
| 1030 | TQ_ADD(&($$->chunks), $2, next); |
| 1031 | } |
| 1032 | ; |
| 1033 | |
| 1034 | WithSyntaxFormatToken: |
| 1035 | TOK_opaque { |
| 1036 | $$ = asn1p_wsyntx_chunk_frombuf($1.buf, $1.len, 0); |
| 1037 | } |
| 1038 | | ClassFieldIdentifier { |
| 1039 | asn1p_ref_t *ref; |
| 1040 | int ret; |
| 1041 | ref = asn1p_ref_new(yylineno); |
| 1042 | checkmem(ref); |
| 1043 | ret = asn1p_ref_add_component(ref, $1.name, $1.lex_type); |
| 1044 | checkmem(ret == 0); |
| 1045 | $$ = asn1p_wsyntx_chunk_fromref(ref, 0); |
| 1046 | } |
| 1047 | ; |
| 1048 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1049 | ExtensionAndException: |
| 1050 | TOK_ThreeDots { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1051 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1052 | checkmem($$); |
| 1053 | $$->Identifier = strdup("..."); |
| 1054 | checkmem($$->Identifier); |
| 1055 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1056 | $$->meta_type = AMT_TYPE; |
| 1057 | } |
| 1058 | | TOK_ThreeDots '!' DefinedValue { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1059 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1060 | checkmem($$); |
| 1061 | $$->Identifier = strdup("..."); |
| 1062 | checkmem($$->Identifier); |
| 1063 | $$->value = $3; |
| 1064 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1065 | $$->meta_type = AMT_TYPE; |
| 1066 | } |
| 1067 | | TOK_ThreeDots '!' SignedNumber { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1068 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1069 | checkmem($$); |
| 1070 | $$->Identifier = strdup("..."); |
| 1071 | $$->value = $3; |
| 1072 | checkmem($$->Identifier); |
| 1073 | $$->expr_type = A1TC_EXTENSIBLE; |
| 1074 | $$->meta_type = AMT_TYPE; |
| 1075 | } |
| 1076 | ; |
| 1077 | |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1078 | Type: |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1079 | optTag TypeDeclaration optConstraints { |
| 1080 | $$ = $2; |
| 1081 | $$->tag = $1; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1082 | /* |
| 1083 | * Outer constraint for SEQUENCE OF and SET OF applies |
| 1084 | * to the inner type. |
| 1085 | */ |
| 1086 | if($$->expr_type == ASN_CONSTR_SEQUENCE_OF |
| 1087 | || $$->expr_type == ASN_CONSTR_SET_OF) { |
| 1088 | assert(!TQ_FIRST(&($$->members))->constraints); |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1089 | TQ_FIRST(&($$->members))->constraints = $3; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1090 | } else { |
| 1091 | if($$->constraints) { |
| 1092 | assert(!$2); |
| 1093 | } else { |
Lev Walkin | af120f7 | 2004-09-14 02:36:39 +0000 | [diff] [blame] | 1094 | $$->constraints = $3; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1095 | } |
| 1096 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1097 | } |
| 1098 | ; |
| 1099 | |
| 1100 | NSTD_IndirectMarker: |
| 1101 | { |
| 1102 | $$ = asn1p_as_pointer ? EM_INDIRECT : 0; |
| 1103 | asn1p_as_pointer = 0; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1104 | } |
| 1105 | ; |
| 1106 | |
| 1107 | TypeDeclaration: |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1108 | NSTD_IndirectMarker TypeDeclarationSet { |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 1109 | $$ = $2; |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1110 | $$->marker.flags |= $1; |
| 1111 | |
| 1112 | if(($$->marker.flags & EM_INDIRECT) |
| 1113 | && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) { |
| 1114 | fprintf(stderr, |
| 1115 | "INFO: Directive <ASN1C:RepresentAsPointer> " |
| 1116 | "applied to %s at line %d\n", |
| 1117 | ASN_EXPR_TYPE2STR($$->expr_type) |
| 1118 | ? ASN_EXPR_TYPE2STR($$->expr_type) |
| 1119 | : "member", |
| 1120 | $$->_lineno |
| 1121 | ); |
| 1122 | } |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 1123 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1124 | ; |
Lev Walkin | 4696c74 | 2005-08-22 12:23:54 +0000 | [diff] [blame] | 1125 | |
| 1126 | TypeDeclarationSet: |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1127 | BasicType { |
| 1128 | $$ = $1; |
| 1129 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1130 | | TOK_CHOICE '{' AlternativeTypeLists '}' { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1131 | $$ = $3; |
| 1132 | assert($$->expr_type == A1TC_INVALID); |
| 1133 | $$->expr_type = ASN_CONSTR_CHOICE; |
| 1134 | $$->meta_type = AMT_TYPE; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1135 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1136 | | TOK_SEQUENCE '{' optComponentTypeLists '}' { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1137 | $$ = $3; |
| 1138 | assert($$->expr_type == A1TC_INVALID); |
| 1139 | $$->expr_type = ASN_CONSTR_SEQUENCE; |
| 1140 | $$->meta_type = AMT_TYPE; |
| 1141 | } |
Lev Walkin | ef62540 | 2005-09-05 05:17:57 +0000 | [diff] [blame] | 1142 | | TOK_SET '{' optComponentTypeLists '}' { |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1143 | $$ = $3; |
| 1144 | assert($$->expr_type == A1TC_INVALID); |
| 1145 | $$->expr_type = ASN_CONSTR_SET; |
| 1146 | $$->meta_type = AMT_TYPE; |
| 1147 | } |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1148 | | TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1149 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1150 | checkmem($$); |
| 1151 | $$->constraints = $2; |
| 1152 | $$->expr_type = ASN_CONSTR_SEQUENCE_OF; |
| 1153 | $$->meta_type = AMT_TYPE; |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1154 | $6->Identifier = $4; |
| 1155 | $6->tag = $5; |
| 1156 | asn1p_expr_add($$, $6); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1157 | } |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1158 | | TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1159 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1160 | checkmem($$); |
| 1161 | $$->constraints = $2; |
| 1162 | $$->expr_type = ASN_CONSTR_SET_OF; |
| 1163 | $$->meta_type = AMT_TYPE; |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 1164 | $6->Identifier = $4; |
| 1165 | $6->tag = $5; |
| 1166 | asn1p_expr_add($$, $6); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1167 | } |
| 1168 | | TOK_ANY { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1169 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1170 | checkmem($$); |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 1171 | $$->expr_type = ASN_TYPE_ANY; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1172 | $$->meta_type = AMT_TYPE; |
| 1173 | } |
| 1174 | | TOK_ANY TOK_DEFINED TOK_BY Identifier { |
| 1175 | int ret; |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1176 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1177 | checkmem($$); |
| 1178 | $$->reference = asn1p_ref_new(yylineno); |
| 1179 | ret = asn1p_ref_add_component($$->reference, |
| 1180 | $4, RLT_lowercase); |
| 1181 | checkmem(ret == 0); |
Lev Walkin | 609ccbb | 2004-09-04 04:49:21 +0000 | [diff] [blame] | 1182 | $$->expr_type = ASN_TYPE_ANY; |
Lev Walkin | 070a52d | 2004-08-22 03:19:54 +0000 | [diff] [blame] | 1183 | $$->meta_type = AMT_TYPE; |
| 1184 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1185 | /* |
| 1186 | * A parametrized assignment. |
| 1187 | */ |
| 1188 | | TypeRefName '{' ActualParameterList '}' { |
| 1189 | int ret; |
| 1190 | $$ = $3; |
| 1191 | assert($$->expr_type == 0); |
| 1192 | assert($$->meta_type == 0); |
| 1193 | assert($$->reference == 0); |
| 1194 | $$->reference = asn1p_ref_new(yylineno); |
| 1195 | checkmem($$->reference); |
| 1196 | ret = asn1p_ref_add_component($$->reference, $1, RLT_UNKNOWN); |
| 1197 | checkmem(ret == 0); |
| 1198 | free($1); |
| 1199 | $$->expr_type = A1TC_PARAMETRIZED; |
| 1200 | $$->meta_type = AMT_TYPE; |
| 1201 | } |
| 1202 | /* |
| 1203 | * A DefinedType reference. |
| 1204 | * "CLASS1.&id.&id2" |
| 1205 | * or |
| 1206 | * "Module.Type" |
| 1207 | * or |
| 1208 | * "Module.identifier" |
| 1209 | * or |
| 1210 | * "Type" |
| 1211 | */ |
| 1212 | | ComplexTypeReference { |
| 1213 | $$ = asn1p_expr_new(yylineno); |
| 1214 | checkmem($$); |
| 1215 | $$->reference = $1; |
| 1216 | $$->expr_type = A1TC_REFERENCE; |
| 1217 | $$->meta_type = AMT_TYPEREF; |
| 1218 | } |
| 1219 | | TOK_INSTANCE TOK_OF ComplexTypeReference { |
| 1220 | $$ = asn1p_expr_new(yylineno); |
| 1221 | checkmem($$); |
| 1222 | $$->reference = $3; |
| 1223 | $$->expr_type = A1TC_INSTANCE; |
| 1224 | $$->meta_type = AMT_TYPE; |
| 1225 | } |
| 1226 | ; |
| 1227 | |
| 1228 | /* |
| 1229 | * A type name consisting of several components. |
| 1230 | * === EXAMPLE === |
| 1231 | * === EOF === |
| 1232 | */ |
| 1233 | ComplexTypeReference: |
| 1234 | TOK_typereference { |
| 1235 | int ret; |
| 1236 | $$ = asn1p_ref_new(yylineno); |
| 1237 | checkmem($$); |
| 1238 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1239 | checkmem(ret == 0); |
| 1240 | free($1); |
| 1241 | } |
| 1242 | | TOK_typereference '.' TypeRefName { |
| 1243 | int ret; |
| 1244 | $$ = asn1p_ref_new(yylineno); |
| 1245 | checkmem($$); |
| 1246 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1247 | checkmem(ret == 0); |
| 1248 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1249 | checkmem(ret == 0); |
| 1250 | free($1); |
| 1251 | } |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1252 | | ObjectClassReference '.' TypeRefName { |
| 1253 | int ret; |
| 1254 | $$ = asn1p_ref_new(yylineno); |
| 1255 | checkmem($$); |
| 1256 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1257 | checkmem(ret == 0); |
| 1258 | ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN); |
| 1259 | checkmem(ret == 0); |
| 1260 | free($1); |
| 1261 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1262 | | TOK_typereference '.' Identifier { |
| 1263 | int ret; |
| 1264 | $$ = asn1p_ref_new(yylineno); |
| 1265 | checkmem($$); |
| 1266 | ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN); |
| 1267 | checkmem(ret == 0); |
| 1268 | ret = asn1p_ref_add_component($$, $3, RLT_lowercase); |
| 1269 | checkmem(ret == 0); |
| 1270 | free($1); |
| 1271 | } |
| 1272 | | ObjectClassReference { |
| 1273 | int ret; |
| 1274 | $$ = asn1p_ref_new(yylineno); |
| 1275 | checkmem($$); |
| 1276 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1277 | free($1); |
| 1278 | checkmem(ret == 0); |
| 1279 | } |
| 1280 | | ObjectClassReference '.' ComplexTypeReferenceAmpList { |
| 1281 | int ret; |
| 1282 | $$ = $3; |
| 1283 | ret = asn1p_ref_add_component($$, $1, RLT_CAPITALS); |
| 1284 | free($1); |
| 1285 | checkmem(ret == 0); |
| 1286 | /* |
| 1287 | * Move the last element infront. |
| 1288 | */ |
| 1289 | { |
| 1290 | struct asn1p_ref_component_s tmp_comp; |
| 1291 | tmp_comp = $$->components[$$->comp_count-1]; |
| 1292 | memmove(&$$->components[1], |
| 1293 | &$$->components[0], |
| 1294 | sizeof($$->components[0]) |
| 1295 | * ($$->comp_count - 1)); |
| 1296 | $$->components[0] = tmp_comp; |
| 1297 | } |
| 1298 | } |
| 1299 | ; |
| 1300 | |
| 1301 | ComplexTypeReferenceAmpList: |
| 1302 | ComplexTypeReferenceElement { |
| 1303 | int ret; |
| 1304 | $$ = asn1p_ref_new(yylineno); |
| 1305 | checkmem($$); |
| 1306 | ret = asn1p_ref_add_component($$, $1.name, $1.lex_type); |
| 1307 | free($1.name); |
| 1308 | checkmem(ret == 0); |
| 1309 | } |
| 1310 | | ComplexTypeReferenceAmpList '.' ComplexTypeReferenceElement { |
| 1311 | int ret; |
| 1312 | $$ = $1; |
| 1313 | ret = asn1p_ref_add_component($$, $3.name, $3.lex_type); |
| 1314 | free($3.name); |
| 1315 | checkmem(ret == 0); |
| 1316 | } |
| 1317 | ; |
| 1318 | |
| 1319 | ComplexTypeReferenceElement: ClassFieldName; |
| 1320 | ClassFieldIdentifier: ClassFieldName; |
| 1321 | |
| 1322 | ClassFieldName: |
| 1323 | /* "&Type1" */ |
| 1324 | TOK_typefieldreference { |
| 1325 | $$.lex_type = RLT_AmpUppercase; |
| 1326 | $$.name = $1; |
| 1327 | } |
| 1328 | /* "&id" */ |
| 1329 | | TOK_valuefieldreference { |
| 1330 | $$.lex_type = RLT_Amplowercase; |
| 1331 | $$.name = $1; |
| 1332 | } |
| 1333 | ; |
| 1334 | |
| 1335 | |
| 1336 | /* |
| 1337 | * === EXAMPLE === |
| 1338 | * value INTEGER ::= 1 |
| 1339 | * === EOF === |
| 1340 | */ |
| 1341 | ValueDefinition: |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1342 | Identifier DefinedTypeRef TOK_PPEQ Value { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1343 | $$ = $2; |
| 1344 | assert($$->Identifier == NULL); |
| 1345 | $$->Identifier = $1; |
| 1346 | $$->meta_type = AMT_VALUE; |
| 1347 | $$->value = $4; |
| 1348 | } |
| 1349 | ; |
| 1350 | |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1351 | Value: |
| 1352 | Identifier ':' Value { |
| 1353 | $$ = asn1p_value_fromint(0); |
| 1354 | checkmem($$); |
| 1355 | $$->type = ATV_CHOICE_IDENTIFIER; |
| 1356 | $$->value.choice_identifier.identifier = $1; |
| 1357 | $$->value.choice_identifier.value = $3; |
| 1358 | } |
Lev Walkin | cbad251 | 2005-03-24 16:27:02 +0000 | [diff] [blame] | 1359 | | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1360 | $$ = asn1p_value_frombuf($3.buf, $3.len, 0); |
| 1361 | checkmem($$); |
| 1362 | $$->type = ATV_UNPARSED; |
| 1363 | } |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1364 | | TOK_NULL { |
| 1365 | $$ = asn1p_value_fromint(0); |
| 1366 | checkmem($$); |
| 1367 | $$->type = ATV_NULL; |
| 1368 | } |
| 1369 | | TOK_FALSE { |
| 1370 | $$ = asn1p_value_fromint(0); |
| 1371 | checkmem($$); |
| 1372 | $$->type = ATV_FALSE; |
| 1373 | } |
| 1374 | | TOK_TRUE { |
| 1375 | $$ = asn1p_value_fromint(0); |
| 1376 | checkmem($$); |
| 1377 | $$->type = ATV_TRUE; |
| 1378 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1379 | | TOK_bstring { |
| 1380 | $$ = _convert_bitstring2binary($1, 'B'); |
| 1381 | checkmem($$); |
| 1382 | } |
| 1383 | | TOK_hstring { |
| 1384 | $$ = _convert_bitstring2binary($1, 'H'); |
| 1385 | checkmem($$); |
| 1386 | } |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1387 | | RestrictedCharacterStringValue { |
| 1388 | $$ = $$; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1389 | } |
| 1390 | | SignedNumber { |
| 1391 | $$ = $1; |
| 1392 | } |
| 1393 | | DefinedValue { |
| 1394 | $$ = $1; |
| 1395 | } |
| 1396 | ; |
| 1397 | |
| 1398 | DefinedValue: |
| 1399 | Identifier { |
| 1400 | asn1p_ref_t *ref; |
| 1401 | int ret; |
| 1402 | ref = asn1p_ref_new(yylineno); |
| 1403 | checkmem(ref); |
| 1404 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1405 | checkmem(ret == 0); |
| 1406 | $$ = asn1p_value_fromref(ref, 0); |
| 1407 | checkmem($$); |
| 1408 | free($1); |
| 1409 | } |
| 1410 | | TypeRefName '.' Identifier { |
| 1411 | asn1p_ref_t *ref; |
| 1412 | int ret; |
| 1413 | ref = asn1p_ref_new(yylineno); |
| 1414 | checkmem(ref); |
| 1415 | ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); |
| 1416 | checkmem(ret == 0); |
| 1417 | ret = asn1p_ref_add_component(ref, $3, RLT_lowercase); |
| 1418 | checkmem(ret == 0); |
| 1419 | $$ = asn1p_value_fromref(ref, 0); |
| 1420 | checkmem($$); |
| 1421 | free($1); |
| 1422 | free($3); |
| 1423 | } |
| 1424 | ; |
| 1425 | |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1426 | |
| 1427 | RestrictedCharacterStringValue: |
| 1428 | TOK_cstring { |
| 1429 | $$ = asn1p_value_frombuf($1.buf, $1.len, 0); |
| 1430 | checkmem($$); |
| 1431 | } |
Lev Walkin | d9574ae | 2005-03-24 16:22:35 +0000 | [diff] [blame] | 1432 | | TOK_tuple { |
| 1433 | $$ = asn1p_value_fromint($1); |
| 1434 | checkmem($$); |
| 1435 | $$->type = ATV_TUPLE; |
| 1436 | } |
| 1437 | | TOK_quadruple { |
| 1438 | $$ = asn1p_value_fromint($1); |
| 1439 | checkmem($$); |
| 1440 | $$->type = ATV_QUADRUPLE; |
| 1441 | } |
| 1442 | /* |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1443 | | '{' TOK_number ',' TOK_number '}' { |
| 1444 | asn1c_integer_t v = ($2 << 4) + $4; |
| 1445 | if($2 > 7) return yyerror("X.680:2003, #37.14 " |
| 1446 | "mandates 0..7 range for Tuple's TableColumn"); |
| 1447 | if($4 > 15) return yyerror("X.680:2003, #37.14 " |
| 1448 | "mandates 0..15 range for Tuple's TableRow"); |
| 1449 | $$ = asn1p_value_fromint(v); |
| 1450 | checkmem($$); |
| 1451 | $$->type = ATV_TUPLE; |
| 1452 | } |
| 1453 | | '{' TOK_number ',' TOK_number ',' TOK_number ',' TOK_number '}' { |
| 1454 | asn1c_integer_t v = ($2 << 24) | ($4 << 16) | ($6 << 8) | $8; |
| 1455 | if($2 > 127) return yyerror("X.680:2003, #37.12 " |
| 1456 | "mandates 0..127 range for Quadruple's Group"); |
| 1457 | if($4 > 255) return yyerror("X.680:2003, #37.12 " |
| 1458 | "mandates 0..255 range for Quadruple's Plane"); |
| 1459 | if($6 > 255) return yyerror("X.680:2003, #37.12 " |
| 1460 | "mandates 0..255 range for Quadruple's Row"); |
| 1461 | if($8 > 255) return yyerror("X.680:2003, #37.12 " |
| 1462 | "mandates 0..255 range for Quadruple's Cell"); |
| 1463 | $$ = asn1p_value_fromint(v); |
| 1464 | checkmem($$); |
| 1465 | $$->type = ATV_QUADRUPLE; |
| 1466 | } |
Lev Walkin | d9574ae | 2005-03-24 16:22:35 +0000 | [diff] [blame] | 1467 | */ |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1468 | ; |
| 1469 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1470 | Opaque: |
| 1471 | TOK_opaque { |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 1472 | $$.len = $1.len + 1; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1473 | $$.buf = malloc($$.len + 1); |
| 1474 | checkmem($$.buf); |
| 1475 | $$.buf[0] = '{'; |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 1476 | memcpy($$.buf + 1, $1.buf, $1.len); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1477 | $$.buf[$$.len] = '\0'; |
| 1478 | free($1.buf); |
| 1479 | } |
| 1480 | | Opaque TOK_opaque { |
| 1481 | int newsize = $1.len + $2.len; |
| 1482 | char *p = malloc(newsize + 1); |
| 1483 | checkmem(p); |
| 1484 | memcpy(p , $1.buf, $1.len); |
| 1485 | memcpy(p + $1.len, $2.buf, $2.len); |
| 1486 | p[newsize] = '\0'; |
| 1487 | free($1.buf); |
| 1488 | free($2.buf); |
| 1489 | $$.buf = p; |
| 1490 | $$.len = newsize; |
| 1491 | } |
| 1492 | ; |
| 1493 | |
| 1494 | BasicTypeId: |
| 1495 | TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; } |
| 1496 | | TOK_NULL { $$ = ASN_BASIC_NULL; } |
| 1497 | | TOK_REAL { $$ = ASN_BASIC_REAL; } |
| 1498 | | BasicTypeId_UniverationCompatible { $$ = $1; } |
| 1499 | | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; } |
| 1500 | | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; } |
| 1501 | | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; } |
| 1502 | | TOK_EXTERNAL { $$ = ASN_BASIC_EXTERNAL; } |
| 1503 | | TOK_EMBEDDED TOK_PDV { $$ = ASN_BASIC_EMBEDDED_PDV; } |
| 1504 | | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; } |
| 1505 | | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; } |
| 1506 | | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; } |
Lev Walkin | c7d939d | 2005-03-20 11:12:40 +0000 | [diff] [blame] | 1507 | | BasicString { $$ = $1; } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1508 | ; |
| 1509 | |
| 1510 | /* |
| 1511 | * A type identifier which may be used with "{ a(1), b(2) }" clause. |
| 1512 | */ |
| 1513 | BasicTypeId_UniverationCompatible: |
| 1514 | TOK_INTEGER { $$ = ASN_BASIC_INTEGER; } |
| 1515 | | TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; } |
| 1516 | | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; } |
| 1517 | ; |
| 1518 | |
| 1519 | BasicType: |
| 1520 | BasicTypeId { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1521 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1522 | checkmem($$); |
| 1523 | $$->expr_type = $1; |
| 1524 | $$->meta_type = AMT_TYPE; |
| 1525 | } |
| 1526 | | BasicTypeId_UniverationCompatible UniverationDefinition { |
| 1527 | if($2) { |
| 1528 | $$ = $2; |
| 1529 | } else { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1530 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1531 | checkmem($$); |
| 1532 | } |
| 1533 | $$->expr_type = $1; |
| 1534 | $$->meta_type = AMT_TYPE; |
| 1535 | } |
| 1536 | ; |
| 1537 | |
| 1538 | BasicString: |
| 1539 | TOK_BMPString { $$ = ASN_STRING_BMPString; } |
| 1540 | | TOK_GeneralString { |
| 1541 | $$ = ASN_STRING_GeneralString; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1542 | fprintf(stderr, "WARNING: GeneralString is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1543 | } |
| 1544 | | TOK_GraphicString { |
| 1545 | $$ = ASN_STRING_GraphicString; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1546 | fprintf(stderr, "WARNING: GraphicString is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1547 | } |
| 1548 | | TOK_IA5String { $$ = ASN_STRING_IA5String; } |
| 1549 | | TOK_ISO646String { $$ = ASN_STRING_ISO646String; } |
| 1550 | | TOK_NumericString { $$ = ASN_STRING_NumericString; } |
| 1551 | | TOK_PrintableString { $$ = ASN_STRING_PrintableString; } |
| 1552 | | TOK_T61String { |
| 1553 | $$ = ASN_STRING_T61String; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1554 | fprintf(stderr, "WARNING: T61String is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1555 | } |
| 1556 | | TOK_TeletexString { $$ = ASN_STRING_TeletexString; } |
| 1557 | | TOK_UniversalString { $$ = ASN_STRING_UniversalString; } |
| 1558 | | TOK_UTF8String { $$ = ASN_STRING_UTF8String; } |
| 1559 | | TOK_VideotexString { |
| 1560 | $$ = ASN_STRING_VideotexString; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1561 | fprintf(stderr, "WARNING: VideotexString is not fully supported\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1562 | } |
| 1563 | | TOK_VisibleString { $$ = ASN_STRING_VisibleString; } |
| 1564 | | TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; } |
| 1565 | ; |
| 1566 | |
Lev Walkin | d2ea1de | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1567 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1568 | /* |
| 1569 | * Data type constraints. |
| 1570 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1571 | Union: '|' | TOK_UNION; |
| 1572 | Intersection: '^' | TOK_INTERSECTION; |
| 1573 | Except: TOK_EXCEPT; |
| 1574 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1575 | optConstraints: |
| 1576 | { $$ = 0; } |
Lev Walkin | d2ea1de | 2004-08-20 13:25:29 +0000 | [diff] [blame] | 1577 | | Constraints { |
| 1578 | $$ = $1; |
| 1579 | } |
| 1580 | ; |
| 1581 | |
| 1582 | Constraints: |
| 1583 | SetOfConstraints { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1584 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1585 | } |
| 1586 | | TOK_SIZE '(' ElementSetSpecs ')' { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1587 | /* |
| 1588 | * This is a special case, for compatibility purposes. |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1589 | * It goes without parentheses. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1590 | */ |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1591 | CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1592 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1593 | ; |
| 1594 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1595 | SetOfConstraints: |
| 1596 | '(' ElementSetSpecs ')' { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1597 | $$ = $2; |
| 1598 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1599 | | SetOfConstraints '(' ElementSetSpecs ')' { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1600 | CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1601 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1602 | ; |
| 1603 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1604 | ElementSetSpecs: |
| 1605 | ElementSetSpec { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1606 | $$ = $1; |
| 1607 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1608 | | ElementSetSpec ',' TOK_ThreeDots { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1609 | asn1p_constraint_t *ct; |
| 1610 | ct = asn1p_constraint_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1611 | ct->type = ACT_EL_EXT; |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1612 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1613 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1614 | | ElementSetSpec ',' TOK_ThreeDots ',' ElementSetSpec { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1615 | asn1p_constraint_t *ct; |
| 1616 | ct = asn1p_constraint_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1617 | ct->type = ACT_EL_EXT; |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1618 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
Lev Walkin | b4fcdd2 | 2004-08-13 12:35:09 +0000 | [diff] [blame] | 1619 | ct = $$; |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1620 | CONSTRAINT_INSERT($$, ACT_CA_CSV, ct, $5); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1621 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1622 | ; |
| 1623 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1624 | ElementSetSpec: |
| 1625 | ConstraintSubtypeElement { |
| 1626 | $$ = $1; |
| 1627 | } |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1628 | | TOK_ALL TOK_EXCEPT ConstraintSubtypeElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1629 | CONSTRAINT_INSERT($$, ACT_CA_AEX, $3, 0); |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1630 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1631 | | ElementSetSpec Union ConstraintSubtypeElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1632 | CONSTRAINT_INSERT($$, ACT_CA_UNI, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1633 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1634 | | ElementSetSpec Intersection ConstraintSubtypeElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1635 | CONSTRAINT_INSERT($$, ACT_CA_INT, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1636 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1637 | | ConstraintSubtypeElement Except ConstraintSubtypeElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1638 | CONSTRAINT_INSERT($$, ACT_CA_EXC, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1639 | } |
| 1640 | ; |
| 1641 | |
| 1642 | ConstraintSubtypeElement: |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1643 | ConstraintSpec '(' ElementSetSpecs ')' { |
| 1644 | int ret; |
| 1645 | $$ = asn1p_constraint_new(yylineno); |
| 1646 | checkmem($$); |
| 1647 | $$->type = $1; |
| 1648 | ret = asn1p_constraint_insert($$, $3); |
| 1649 | checkmem(ret == 0); |
| 1650 | } |
| 1651 | | '(' ElementSetSpecs ')' { |
| 1652 | int ret; |
| 1653 | $$ = asn1p_constraint_new(yylineno); |
| 1654 | checkmem($$); |
| 1655 | $$->type = ACT_CA_SET; |
| 1656 | ret = asn1p_constraint_insert($$, $2); |
| 1657 | checkmem(ret == 0); |
| 1658 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1659 | | SingleValue { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1660 | $$ = asn1p_constraint_new(yylineno); |
| 1661 | checkmem($$); |
| 1662 | $$->type = ACT_EL_VALUE; |
| 1663 | $$->value = $1; |
| 1664 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1665 | | ContainedSubtype { |
| 1666 | $$ = asn1p_constraint_new(yylineno); |
| 1667 | checkmem($$); |
| 1668 | $$->type = ACT_EL_TYPE; |
| 1669 | $$->containedSubtype = $1; |
| 1670 | } |
| 1671 | | SingleValue ConstraintRangeSpec SingleValue { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1672 | $$ = asn1p_constraint_new(yylineno); |
| 1673 | checkmem($$); |
| 1674 | $$->type = $2; |
| 1675 | $$->range_start = $1; |
| 1676 | $$->range_stop = $3; |
| 1677 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1678 | | TOK_MIN ConstraintRangeSpec SingleValue { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1679 | $$ = asn1p_constraint_new(yylineno); |
| 1680 | checkmem($$); |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1681 | $$->type = $2; |
| 1682 | $$->range_start = asn1p_value_fromint(-123); |
| 1683 | $$->range_stop = $3; |
| 1684 | $$->range_start->type = ATV_MIN; |
| 1685 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1686 | | SingleValue ConstraintRangeSpec TOK_MAX { |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 1687 | $$ = asn1p_constraint_new(yylineno); |
| 1688 | checkmem($$); |
| 1689 | $$->type = $2; |
| 1690 | $$->range_start = $1; |
| 1691 | $$->range_stop = asn1p_value_fromint(321); |
| 1692 | $$->range_stop->type = ATV_MAX; |
| 1693 | } |
| 1694 | | TOK_MIN ConstraintRangeSpec TOK_MAX { |
| 1695 | $$ = asn1p_constraint_new(yylineno); |
| 1696 | checkmem($$); |
| 1697 | $$->type = $2; |
| 1698 | $$->range_start = asn1p_value_fromint(-123); |
| 1699 | $$->range_stop = asn1p_value_fromint(321); |
| 1700 | $$->range_start->type = ATV_MIN; |
| 1701 | $$->range_stop->type = ATV_MAX; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1702 | } |
| 1703 | | TableConstraint { |
| 1704 | $$ = $1; |
| 1705 | } |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1706 | | InnerTypeConstraint { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1707 | $$ = $1; |
| 1708 | } |
Lev Walkin | 1893ddf | 2005-03-20 14:28:32 +0000 | [diff] [blame] | 1709 | | TOK_CONSTRAINED TOK_BY '{' |
| 1710 | { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { |
| 1711 | $$ = asn1p_constraint_new(yylineno); |
| 1712 | checkmem($$); |
| 1713 | $$->type = ACT_CT_CTDBY; |
| 1714 | $$->value = asn1p_value_frombuf($5.buf, $5.len, 0); |
| 1715 | checkmem($$->value); |
| 1716 | $$->value->type = ATV_UNPARSED; |
| 1717 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1718 | ; |
| 1719 | |
| 1720 | ConstraintRangeSpec: |
| 1721 | TOK_TwoDots { $$ = ACT_EL_RANGE; } |
| 1722 | | TOK_TwoDots '<' { $$ = ACT_EL_RLRANGE; } |
| 1723 | | '<' TOK_TwoDots { $$ = ACT_EL_LLRANGE; } |
| 1724 | | '<' TOK_TwoDots '<' { $$ = ACT_EL_ULRANGE; } |
| 1725 | ; |
| 1726 | |
| 1727 | ConstraintSpec: |
| 1728 | TOK_SIZE { |
| 1729 | $$ = ACT_CT_SIZE; |
| 1730 | } |
| 1731 | | TOK_FROM { |
| 1732 | $$ = ACT_CT_FROM; |
| 1733 | } |
| 1734 | ; |
| 1735 | |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1736 | SingleValue: |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1737 | TOK_FALSE { |
| 1738 | $$ = asn1p_value_fromint(0); |
| 1739 | checkmem($$); |
| 1740 | $$->type = ATV_FALSE; |
| 1741 | } |
| 1742 | | TOK_TRUE { |
| 1743 | $$ = asn1p_value_fromint(1); |
| 1744 | checkmem($$); |
| 1745 | $$->type = ATV_TRUE; |
| 1746 | } |
| 1747 | | SignedNumber { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1748 | $$ = $1; |
| 1749 | } |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 1750 | | RestrictedCharacterStringValue { |
| 1751 | $$ = $1; |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1752 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1753 | | Identifier { |
| 1754 | asn1p_ref_t *ref; |
| 1755 | int ret; |
| 1756 | ref = asn1p_ref_new(yylineno); |
| 1757 | checkmem(ref); |
| 1758 | ret = asn1p_ref_add_component(ref, $1, RLT_lowercase); |
| 1759 | checkmem(ret == 0); |
| 1760 | $$ = asn1p_value_fromref(ref, 0); |
| 1761 | checkmem($$); |
| 1762 | free($1); |
| 1763 | } |
Lev Walkin | ff7dd14 | 2005-03-20 12:58:00 +0000 | [diff] [blame] | 1764 | ; |
| 1765 | |
| 1766 | ContainedSubtype: |
| 1767 | TypeRefName { |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1768 | asn1p_ref_t *ref; |
| 1769 | int ret; |
| 1770 | ref = asn1p_ref_new(yylineno); |
| 1771 | checkmem(ref); |
| 1772 | ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN); |
| 1773 | checkmem(ret == 0); |
| 1774 | $$ = asn1p_value_fromref(ref, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1775 | checkmem($$); |
Lev Walkin | c8092cb | 2005-02-18 16:34:21 +0000 | [diff] [blame] | 1776 | free($1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1777 | } |
| 1778 | ; |
| 1779 | |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1780 | InnerTypeConstraint: |
| 1781 | TOK_WITH TOK_COMPONENT SetOfConstraints { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1782 | CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0); |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1783 | } |
| 1784 | | TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1785 | CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1786 | } |
| 1787 | ; |
| 1788 | |
| 1789 | WithComponentsList: |
| 1790 | WithComponentsElement { |
| 1791 | $$ = $1; |
| 1792 | } |
| 1793 | | WithComponentsList ',' WithComponentsElement { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1794 | CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1795 | } |
| 1796 | ; |
| 1797 | |
| 1798 | WithComponentsElement: |
| 1799 | TOK_ThreeDots { |
| 1800 | $$ = asn1p_constraint_new(yylineno); |
| 1801 | checkmem($$); |
| 1802 | $$->type = ACT_EL_EXT; |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1803 | $$->value = asn1p_value_frombuf("...", 3, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1804 | } |
| 1805 | | Identifier optConstraints optPresenceConstraint { |
| 1806 | $$ = asn1p_constraint_new(yylineno); |
| 1807 | checkmem($$); |
| 1808 | $$->type = ACT_EL_VALUE; |
| 1809 | $$->value = asn1p_value_frombuf($1, strlen($1), 0); |
| 1810 | $$->presence = $3; |
Lev Walkin | e596bf0 | 2005-03-28 15:01:27 +0000 | [diff] [blame] | 1811 | if($2) asn1p_constraint_insert($$, $2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1812 | } |
| 1813 | ; |
| 1814 | |
| 1815 | /* |
| 1816 | * presence constraint for WithComponents |
| 1817 | */ |
| 1818 | optPresenceConstraint: |
| 1819 | { $$ = ACPRES_DEFAULT; } |
| 1820 | | PresenceConstraint { $$ = $1; } |
| 1821 | ; |
| 1822 | |
| 1823 | PresenceConstraint: |
| 1824 | TOK_PRESENT { |
| 1825 | $$ = ACPRES_PRESENT; |
| 1826 | } |
| 1827 | | TOK_ABSENT { |
| 1828 | $$ = ACPRES_ABSENT; |
| 1829 | } |
| 1830 | | TOK_OPTIONAL { |
| 1831 | $$ = ACPRES_OPTIONAL; |
| 1832 | } |
| 1833 | ; |
| 1834 | |
| 1835 | TableConstraint: |
| 1836 | SimpleTableConstraint { |
| 1837 | $$ = $1; |
| 1838 | } |
| 1839 | | ComponentRelationConstraint { |
| 1840 | $$ = $1; |
| 1841 | } |
| 1842 | ; |
| 1843 | |
| 1844 | /* |
| 1845 | * "{ExtensionSet}" |
| 1846 | */ |
| 1847 | SimpleTableConstraint: |
| 1848 | '{' TypeRefName '}' { |
| 1849 | asn1p_ref_t *ref = asn1p_ref_new(yylineno); |
| 1850 | asn1p_constraint_t *ct; |
| 1851 | int ret; |
| 1852 | ret = asn1p_ref_add_component(ref, $2, 0); |
| 1853 | checkmem(ret == 0); |
| 1854 | ct = asn1p_constraint_new(yylineno); |
| 1855 | checkmem($$); |
| 1856 | ct->type = ACT_EL_VALUE; |
| 1857 | ct->value = asn1p_value_fromref(ref, 0); |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1858 | CONSTRAINT_INSERT($$, ACT_CA_CRC, ct, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1859 | } |
| 1860 | ; |
| 1861 | |
| 1862 | ComponentRelationConstraint: |
| 1863 | SimpleTableConstraint '{' AtNotationList '}' { |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1864 | CONSTRAINT_INSERT($$, ACT_CA_CRC, $1, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1865 | } |
| 1866 | ; |
| 1867 | |
| 1868 | AtNotationList: |
| 1869 | AtNotationElement { |
| 1870 | $$ = asn1p_constraint_new(yylineno); |
| 1871 | checkmem($$); |
| 1872 | $$->type = ACT_EL_VALUE; |
| 1873 | $$->value = asn1p_value_fromref($1, 0); |
| 1874 | } |
| 1875 | | AtNotationList ',' AtNotationElement { |
| 1876 | asn1p_constraint_t *ct; |
| 1877 | ct = asn1p_constraint_new(yylineno); |
| 1878 | checkmem(ct); |
| 1879 | ct->type = ACT_EL_VALUE; |
| 1880 | ct->value = asn1p_value_fromref($3, 0); |
Lev Walkin | 2c14a69 | 2005-08-12 10:08:45 +0000 | [diff] [blame] | 1881 | CONSTRAINT_INSERT($$, ACT_CA_CSV, $1, ct); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1882 | } |
| 1883 | ; |
| 1884 | |
| 1885 | /* |
| 1886 | * @blah |
| 1887 | */ |
| 1888 | AtNotationElement: |
| 1889 | '@' ComponentIdList { |
| 1890 | char *p = malloc(strlen($2) + 2); |
| 1891 | int ret; |
| 1892 | *p = '@'; |
| 1893 | strcpy(p + 1, $2); |
| 1894 | $$ = asn1p_ref_new(yylineno); |
| 1895 | ret = asn1p_ref_add_component($$, p, 0); |
| 1896 | checkmem(ret == 0); |
| 1897 | free(p); |
| 1898 | free($2); |
| 1899 | } |
| 1900 | | '@' '.' ComponentIdList { |
| 1901 | char *p = malloc(strlen($3) + 3); |
| 1902 | int ret; |
| 1903 | p[0] = '@'; |
| 1904 | p[1] = '.'; |
| 1905 | strcpy(p + 2, $3); |
| 1906 | $$ = asn1p_ref_new(yylineno); |
| 1907 | ret = asn1p_ref_add_component($$, p, 0); |
| 1908 | checkmem(ret == 0); |
| 1909 | free(p); |
| 1910 | free($3); |
| 1911 | } |
| 1912 | ; |
| 1913 | |
| 1914 | /* identifier "." ... */ |
| 1915 | ComponentIdList: |
| 1916 | Identifier { |
| 1917 | $$ = $1; |
| 1918 | } |
| 1919 | | ComponentIdList '.' Identifier { |
| 1920 | int l1 = strlen($1); |
| 1921 | int l3 = strlen($3); |
| 1922 | $$ = malloc(l1 + 1 + l3 + 1); |
| 1923 | memcpy($$, $1, l1); |
| 1924 | $$[l1] = '.'; |
| 1925 | memcpy($$ + l1 + 1, $3, l3); |
| 1926 | $$[l1 + 1 + l3] = '\0'; |
| 1927 | } |
| 1928 | ; |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | /* |
| 1933 | * MARKERS |
| 1934 | */ |
| 1935 | |
| 1936 | optMarker: |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1937 | { |
| 1938 | $$.flags = EM_NOMARK; |
| 1939 | $$.default_value = 0; |
| 1940 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1941 | | Marker { $$ = $1; } |
| 1942 | ; |
| 1943 | |
| 1944 | Marker: |
| 1945 | TOK_OPTIONAL { |
Lev Walkin | 7085305 | 2005-11-26 11:21:55 +0000 | [diff] [blame] | 1946 | $$.flags = EM_OPTIONAL | EM_INDIRECT; |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1947 | $$.default_value = 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1948 | } |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 1949 | | TOK_DEFAULT Value { |
| 1950 | $$.flags = EM_DEFAULT; |
| 1951 | $$.default_value = $2; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1952 | } |
| 1953 | ; |
| 1954 | |
| 1955 | /* |
| 1956 | * Universal enumeration definition to use in INTEGER and ENUMERATED. |
| 1957 | * === EXAMPLE === |
| 1958 | * Gender ::= ENUMERATED { unknown(0), male(1), female(2) } |
| 1959 | * Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) } |
| 1960 | * === EOF === |
| 1961 | */ |
| 1962 | /* |
| 1963 | optUniverationDefinition: |
| 1964 | { $$ = 0; } |
| 1965 | | UniverationDefinition { |
| 1966 | $$ = $1; |
| 1967 | } |
| 1968 | ; |
| 1969 | */ |
| 1970 | |
| 1971 | UniverationDefinition: |
| 1972 | '{' '}' { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1973 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1974 | checkmem($$); |
| 1975 | } |
| 1976 | | '{' UniverationList '}' { |
| 1977 | $$ = $2; |
| 1978 | } |
| 1979 | ; |
| 1980 | |
| 1981 | UniverationList: |
| 1982 | UniverationElement { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1983 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1984 | checkmem($$); |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1985 | asn1p_expr_add($$, $1); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1986 | } |
| 1987 | | UniverationList ',' UniverationElement { |
| 1988 | $$ = $1; |
Lev Walkin | 1004aa9 | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 1989 | asn1p_expr_add($$, $3); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1990 | } |
| 1991 | ; |
| 1992 | |
| 1993 | UniverationElement: |
| 1994 | Identifier { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 1995 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1996 | checkmem($$); |
| 1997 | $$->expr_type = A1TC_UNIVERVAL; |
| 1998 | $$->meta_type = AMT_VALUE; |
| 1999 | $$->Identifier = $1; |
| 2000 | } |
| 2001 | | Identifier '(' SignedNumber ')' { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 2002 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2003 | checkmem($$); |
| 2004 | $$->expr_type = A1TC_UNIVERVAL; |
| 2005 | $$->meta_type = AMT_VALUE; |
| 2006 | $$->Identifier = $1; |
| 2007 | $$->value = $3; |
| 2008 | } |
| 2009 | | Identifier '(' DefinedValue ')' { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 2010 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2011 | checkmem($$); |
| 2012 | $$->expr_type = A1TC_UNIVERVAL; |
| 2013 | $$->meta_type = AMT_VALUE; |
| 2014 | $$->Identifier = $1; |
| 2015 | $$->value = $3; |
| 2016 | } |
| 2017 | | SignedNumber { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 2018 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2019 | checkmem($$); |
| 2020 | $$->expr_type = A1TC_UNIVERVAL; |
| 2021 | $$->meta_type = AMT_VALUE; |
| 2022 | $$->value = $1; |
| 2023 | } |
| 2024 | | TOK_ThreeDots { |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 2025 | $$ = asn1p_expr_new(yylineno); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2026 | checkmem($$); |
| 2027 | $$->Identifier = strdup("..."); |
| 2028 | checkmem($$->Identifier); |
| 2029 | $$->expr_type = A1TC_EXTENSIBLE; |
| 2030 | $$->meta_type = AMT_VALUE; |
| 2031 | } |
| 2032 | ; |
| 2033 | |
| 2034 | SignedNumber: |
| 2035 | TOK_number { |
| 2036 | $$ = asn1p_value_fromint($1); |
| 2037 | checkmem($$); |
| 2038 | } |
| 2039 | | TOK_number_negative { |
| 2040 | $$ = asn1p_value_fromint($1); |
| 2041 | checkmem($$); |
| 2042 | } |
| 2043 | ; |
| 2044 | |
| 2045 | /* |
| 2046 | * SEQUENCE definition. |
| 2047 | * === EXAMPLE === |
| 2048 | * Struct1 ::= SEQUENCE { |
| 2049 | * memb1 Struct2, |
| 2050 | * memb2 SEQUENCE OF { |
| 2051 | * memb2-1 Struct 3 |
| 2052 | * } |
| 2053 | * } |
| 2054 | * === EOF === |
| 2055 | */ |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | /* |
| 2060 | * SET definition. |
| 2061 | * === EXAMPLE === |
| 2062 | * Person ::= SET { |
| 2063 | * name [0] PrintableString (SIZE(1..20)), |
| 2064 | * country [1] PrintableString (SIZE(1..20)) DEFAULT default-country, |
| 2065 | * } |
| 2066 | * === EOF === |
| 2067 | */ |
| 2068 | |
| 2069 | optTag: |
| 2070 | { memset(&$$, 0, sizeof($$)); } |
| 2071 | | Tag { $$ = $1; } |
| 2072 | ; |
| 2073 | |
| 2074 | Tag: |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 2075 | TagTypeValue TagPlicit { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2076 | $$ = $1; |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 2077 | $$.tag_mode = $2.tag_mode; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2078 | } |
Lev Walkin | c603f10 | 2005-01-23 09:51:44 +0000 | [diff] [blame] | 2079 | ; |
| 2080 | |
| 2081 | TagTypeValue: |
| 2082 | '[' TagClass TOK_number ']' { |
| 2083 | $$ = $2; |
| 2084 | $$.tag_value = $3; |
| 2085 | }; |
| 2086 | |
| 2087 | TagClass: |
| 2088 | { $$.tag_class = TC_CONTEXT_SPECIFIC; } |
| 2089 | | TOK_UNIVERSAL { $$.tag_class = TC_UNIVERSAL; } |
| 2090 | | TOK_APPLICATION { $$.tag_class = TC_APPLICATION; } |
| 2091 | | TOK_PRIVATE { $$.tag_class = TC_PRIVATE; } |
| 2092 | ; |
| 2093 | |
| 2094 | TagPlicit: |
| 2095 | { $$.tag_mode = TM_DEFAULT; } |
| 2096 | | TOK_IMPLICIT { $$.tag_mode = TM_IMPLICIT; } |
| 2097 | | TOK_EXPLICIT { $$.tag_mode = TM_EXPLICIT; } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2098 | ; |
| 2099 | |
| 2100 | TypeRefName: |
| 2101 | TOK_typereference { |
| 2102 | checkmem($1); |
| 2103 | $$ = $1; |
| 2104 | } |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2105 | | TOK_capitalreference { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2106 | checkmem($1); |
| 2107 | $$ = $1; |
| 2108 | } |
| 2109 | ; |
| 2110 | |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2111 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2112 | ObjectClassReference: |
Lev Walkin | f59d075 | 2004-08-18 04:59:12 +0000 | [diff] [blame] | 2113 | TOK_capitalreference { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2114 | checkmem($1); |
| 2115 | $$ = $1; |
| 2116 | } |
| 2117 | ; |
| 2118 | |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 2119 | optIdentifier: |
| 2120 | { $$ = 0; } |
| 2121 | | Identifier { |
| 2122 | $$ = $1; |
| 2123 | } |
Lev Walkin | 8f294e0 | 2005-06-06 08:28:58 +0000 | [diff] [blame] | 2124 | ; |
Lev Walkin | 83cac2f | 2004-09-22 16:03:36 +0000 | [diff] [blame] | 2125 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2126 | Identifier: |
| 2127 | TOK_identifier { |
| 2128 | checkmem($1); |
| 2129 | $$ = $1; |
| 2130 | } |
| 2131 | ; |
| 2132 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2133 | %% |
| 2134 | |
| 2135 | |
| 2136 | /* |
| 2137 | * Convert Xstring ('0101'B or '5'H) to the binary vector. |
| 2138 | */ |
| 2139 | static asn1p_value_t * |
| 2140 | _convert_bitstring2binary(char *str, int base) { |
| 2141 | asn1p_value_t *val; |
| 2142 | int slen; |
| 2143 | int memlen; |
| 2144 | int baselen; |
| 2145 | int bits; |
| 2146 | uint8_t *binary_vector; |
| 2147 | uint8_t *bv_ptr; |
| 2148 | uint8_t cur_val; |
| 2149 | |
| 2150 | assert(str); |
| 2151 | assert(str[0] == '\''); |
| 2152 | |
| 2153 | switch(base) { |
| 2154 | case 'B': |
| 2155 | baselen = 1; |
| 2156 | break; |
| 2157 | case 'H': |
| 2158 | baselen = 4; |
| 2159 | break; |
| 2160 | default: |
| 2161 | assert(base == 'B' || base == 'H'); |
| 2162 | errno = EINVAL; |
| 2163 | return NULL; |
| 2164 | } |
| 2165 | |
| 2166 | slen = strlen(str); |
| 2167 | assert(str[slen - 1] == base); |
| 2168 | assert(str[slen - 2] == '\''); |
| 2169 | |
| 2170 | memlen = slen / (8 / baselen); /* Conservative estimate */ |
| 2171 | |
| 2172 | bv_ptr = binary_vector = malloc(memlen + 1); |
| 2173 | if(bv_ptr == NULL) |
| 2174 | /* ENOMEM */ |
| 2175 | return NULL; |
| 2176 | |
| 2177 | cur_val = 0; |
| 2178 | bits = 0; |
| 2179 | while(*(++str) != '\'') { |
| 2180 | switch(baselen) { |
| 2181 | case 1: |
| 2182 | switch(*str) { |
| 2183 | case '1': |
| 2184 | cur_val |= 1 << (7 - (bits % 8)); |
| 2185 | case '0': |
| 2186 | break; |
| 2187 | default: |
| 2188 | assert(!"_y UNREACH1"); |
| 2189 | case ' ': case '\r': case '\n': |
| 2190 | continue; |
| 2191 | } |
| 2192 | break; |
| 2193 | case 4: |
| 2194 | switch(*str) { |
| 2195 | case '0': case '1': case '2': case '3': case '4': |
| 2196 | case '5': case '6': case '7': case '8': case '9': |
| 2197 | cur_val |= (*str - '0') << (4 - (bits % 8)); |
| 2198 | break; |
| 2199 | case 'A': case 'B': case 'C': |
| 2200 | case 'D': case 'E': case 'F': |
| 2201 | cur_val |= ((*str - 'A') + 10) |
| 2202 | << (4 - (bits % 8)); |
| 2203 | break; |
| 2204 | default: |
| 2205 | assert(!"_y UNREACH2"); |
| 2206 | case ' ': case '\r': case '\n': |
| 2207 | continue; |
| 2208 | } |
| 2209 | break; |
| 2210 | } |
| 2211 | |
| 2212 | bits += baselen; |
| 2213 | if((bits % 8) == 0) { |
| 2214 | *bv_ptr++ = cur_val; |
| 2215 | cur_val = 0; |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | *bv_ptr = cur_val; |
| 2220 | assert((bv_ptr - binary_vector) <= memlen); |
| 2221 | |
| 2222 | val = asn1p_value_frombits(binary_vector, bits, 0); |
| 2223 | if(val == NULL) { |
| 2224 | free(binary_vector); |
| 2225 | } |
| 2226 | |
| 2227 | return val; |
| 2228 | } |
| 2229 | |
Lev Walkin | 2e9bd5c | 2005-08-13 09:07:11 +0000 | [diff] [blame] | 2230 | /* |
| 2231 | * For unnamed types (used in old X.208 compliant modules) |
| 2232 | * generate some sort of interim names, to not to force human being to fix |
| 2233 | * the specification's compliance to modern ASN.1 standards. |
| 2234 | */ |
| 2235 | static void |
| 2236 | _fixup_anonymous_identifier(asn1p_expr_t *expr) { |
| 2237 | char *p; |
| 2238 | assert(expr->Identifier == 0); |
| 2239 | |
| 2240 | /* |
| 2241 | * Try to figure out the type name |
| 2242 | * without going too much into details |
| 2243 | */ |
| 2244 | expr->Identifier = ASN_EXPR_TYPE2STR(expr->expr_type); |
| 2245 | if(expr->reference && expr->reference->comp_count > 0) |
| 2246 | expr->Identifier = expr->reference->components[0].name; |
| 2247 | |
| 2248 | fprintf(stderr, |
| 2249 | "WARNING: Line %d: expected lower-case member identifier, " |
| 2250 | "found an unnamed %s.\n" |
| 2251 | "WARNING: Obsolete X.208 syntax detected, " |
| 2252 | "please give the member a name.\n", |
| 2253 | yylineno, expr->Identifier ? expr->Identifier : "type"); |
| 2254 | |
| 2255 | if(!expr->Identifier) |
| 2256 | expr->Identifier = "unnamed"; |
| 2257 | expr->Identifier = strdup(expr->Identifier); |
| 2258 | assert(expr->Identifier); |
| 2259 | /* Make a lowercase identifier from the type name */ |
| 2260 | for(p = expr->Identifier; *p; p++) { |
| 2261 | switch(*p) { |
| 2262 | case 'A' ... 'Z': *p += 32; break; |
| 2263 | case ' ': *p = '_'; break; |
| 2264 | case '-': *p = '_'; break; |
| 2265 | } |
| 2266 | } |
| 2267 | fprintf(stderr, "NOTE: Assigning temporary identifier \"%s\". " |
| 2268 | "Name clash may occur later.\n", |
| 2269 | expr->Identifier); |
| 2270 | } |
| 2271 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2272 | extern char *asn1p_text; |
| 2273 | |
| 2274 | int |
| 2275 | yyerror(const char *msg) { |
| 2276 | fprintf(stderr, |
| 2277 | "ASN.1 grammar parse error " |
| 2278 | "near line %d (token \"%s\"): %s\n", |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 2279 | yylineno, asn1p_text, msg); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 2280 | return -1; |
| 2281 | } |
| 2282 | |
| 2283 | |