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