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