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