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