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