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