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