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