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