Commit be518fac authored by Lev Walkin's avatar Lev Walkin

ENUMERATION can not be empty

parent 154519a3
...@@ -174,21 +174,22 @@ asn1f_BS_unparsed_convert(arg_t *arg, asn1p_value_t *value, asn1p_expr_t *ttype) ...@@ -174,21 +174,22 @@ asn1f_BS_unparsed_convert(arg_t *arg, asn1p_value_t *value, asn1p_expr_t *ttype)
assert(value->type == ATV_UNPARSED); assert(value->type == ATV_UNPARSED);
psize = value->value.string.size + 64; psize = value->value.string.size + sizeof("M DEFINITIONS ::= BEGIN V ::= BIT STRING END") + 32;
p = malloc(psize); p = malloc(psize);
if(p == NULL) if(p == NULL)
return -1; return -1;
ret = snprintf(p, psize, ret = snprintf(p, psize,
"M DEFINITIONS ::=\nBEGIN\n" "M DEFINITIONS ::=\nBEGIN\n"
"V ::= INTEGER %s\n" "V ::= #BIT STRING %s\n"
"END\n", "END\n",
value->value.string.buf value->value.string.buf
); );
assert(ret < psize); assert(ret < psize);
psize = ret; psize = ret;
asn = asn1p_parse_buffer(p, psize, A1P_NOFLAGS); asn = asn1p_parse_buffer(p, psize, arg->expr->module->source_file_name,
arg->expr->_lineno, A1P_EXTENDED_VALUES);
free(p); free(p);
if(asn == NULL) { if(asn == NULL) {
FATAL("Cannot parse BIT STRING value %s " FATAL("Cannot parse BIT STRING value %s "
...@@ -205,7 +206,6 @@ asn1f_BS_unparsed_convert(arg_t *arg, asn1p_value_t *value, asn1p_expr_t *ttype) ...@@ -205,7 +206,6 @@ asn1f_BS_unparsed_convert(arg_t *arg, asn1p_value_t *value, asn1p_expr_t *ttype)
V = TQ_FIRST(&(mod->members)); V = TQ_FIRST(&(mod->members));
assert(V); assert(V);
assert(strcmp(V->Identifier, "V") == 0); assert(strcmp(V->Identifier, "V") == 0);
assert(TQ_FIRST(&(V->members)));
/* /*
* Simple loop just to fetch the maximal bit position * Simple loop just to fetch the maximal bit position
...@@ -250,6 +250,7 @@ asn1f_BS_unparsed_convert(arg_t *arg, asn1p_value_t *value, asn1p_expr_t *ttype) ...@@ -250,6 +250,7 @@ asn1f_BS_unparsed_convert(arg_t *arg, asn1p_value_t *value, asn1p_expr_t *ttype)
bit->Identifier, bit->_lineno); bit->Identifier, bit->_lineno);
RET2RVAL(1, r_value); RET2RVAL(1, r_value);
} }
fprintf(stderr, "Referencing bit %s\n", bit->Identifier);
bitdef = asn1f_lookup_child(ttype, bit->Identifier); bitdef = asn1f_lookup_child(ttype, bit->Identifier);
if(bitdef == NULL) { if(bitdef == NULL) {
FATAL("Identifier \"%s\" at line %d is not defined " FATAL("Identifier \"%s\" at line %d is not defined "
......
...@@ -443,7 +443,8 @@ _asn1f_assign_cell_value(arg_t *arg, struct asn1p_ioc_cell_s *cell, ...@@ -443,7 +443,8 @@ _asn1f_assign_cell_value(arg_t *arg, struct asn1p_ioc_cell_s *cell,
assert(ret < psize); assert(ret < psize);
psize = ret; psize = ret;
asn = asn1p_parse_buffer(pp, psize, A1P_NOFLAGS); asn = asn1p_parse_buffer(pp, psize,
arg->expr->module->source_file_name, arg->expr->_lineno, A1P_NOFLAGS);
free(pp); free(pp);
if(asn == NULL) { if(asn == NULL) {
FATAL("Cannot parse Setting token %s " FATAL("Cannot parse Setting token %s "
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -23,6 +23,7 @@ void asn1p_lexer_hack_push_encoding_control(void); /* Used in .y */ ...@@ -23,6 +23,7 @@ void asn1p_lexer_hack_push_encoding_control(void); /* Used in .y */
int asn1p_lexer_pedantic_1990 = 0; int asn1p_lexer_pedantic_1990 = 0;
int asn1p_lexer_types_year = 0; int asn1p_lexer_types_year = 0;
int asn1p_lexer_constructs_year = 0; int asn1p_lexer_constructs_year = 0;
int asn1p_lexer_extended_values = 0;
int asn1p_as_pointer; int asn1p_as_pointer;
...@@ -85,6 +86,7 @@ static double _lex_atod(const char *ptr); ...@@ -85,6 +86,7 @@ static double _lex_atod(const char *ptr);
%x opaque %x opaque
%x encoding_control %x encoding_control
%x with_syntax %x with_syntax
%x extended_values
/* Newline */ /* Newline */
NL [\r\v\f\n] NL [\r\v\f\n]
...@@ -103,6 +105,13 @@ WSP [\t\r\v\f\n ] ...@@ -103,6 +105,13 @@ WSP [\t\r\v\f\n ]
--<[ \t]*ASN1C.RepresentAsPointer[ \t]*>-- asn1p_as_pointer = 1; --<[ \t]*ASN1C.RepresentAsPointer[ \t]*>-- asn1p_as_pointer = 1;
<extended_values>{
"#BIT STRING" {
yy_pop_state();
return TOK_ExtValue_BIT_STRING;
}
}
<INITIAL,with_syntax>-- yy_push_state(dash_comment); <INITIAL,with_syntax>-- yy_push_state(dash_comment);
<dash_comment,idash_comment>{ <dash_comment,idash_comment>{
...@@ -262,7 +271,12 @@ ANY { ...@@ -262,7 +271,12 @@ ANY {
} }
APPLICATION return TOK_APPLICATION; APPLICATION return TOK_APPLICATION;
AUTOMATIC return TOK_AUTOMATIC; AUTOMATIC return TOK_AUTOMATIC;
BEGIN return TOK_BEGIN; BEGIN {
if(asn1p_lexer_extended_values) {
yy_push_state(extended_values);
}
return TOK_BEGIN;
}
BIT return TOK_BIT; BIT return TOK_BIT;
BMPString { BMPString {
if(TYPE_LIFETIME(1994, 0)) if(TYPE_LIFETIME(1994, 0))
...@@ -292,7 +306,12 @@ DEFINITIONS return TOK_DEFINITIONS; ...@@ -292,7 +306,12 @@ DEFINITIONS return TOK_DEFINITIONS;
EMBEDDED return TOK_EMBEDDED; EMBEDDED return TOK_EMBEDDED;
ENCODED return TOK_ENCODED; ENCODED return TOK_ENCODED;
ENCODING-CONTROL return TOK_ENCODING_CONTROL; ENCODING-CONTROL return TOK_ENCODING_CONTROL;
END return TOK_END; END {
if(YYSTATE == extended_values) {
yy_pop_state();
}
return TOK_END;
}
ENUMERATED return TOK_ENUMERATED; ENUMERATED return TOK_ENUMERATED;
EXCEPT return TOK_EXCEPT; EXCEPT return TOK_EXCEPT;
EXPLICIT return TOK_EXPLICIT; EXPLICIT return TOK_EXPLICIT;
...@@ -380,7 +399,7 @@ WITH return TOK_WITH; ...@@ -380,7 +399,7 @@ WITH return TOK_WITH;
/* /*
* objectclassreference * objectclassreference
*/ */
[A-Z][A-Z0-9]*([-][A-Z0-9]+)* { <INITIAL,extended_values>[A-Z][A-Z0-9]*([-][A-Z0-9]+)* {
asn1p_lval.tv_str = strdup(yytext); asn1p_lval.tv_str = strdup(yytext);
return TOK_capitalreference; return TOK_capitalreference;
} }
...@@ -395,7 +414,7 @@ WITH return TOK_WITH; ...@@ -395,7 +414,7 @@ WITH return TOK_WITH;
return TOK_typereference; return TOK_typereference;
} }
"::=" return TOK_PPEQ; <INITIAL,extended_values>"::=" return TOK_PPEQ;
"..." return TOK_ThreeDots; "..." return TOK_ThreeDots;
".." return TOK_TwoDots; ".." return TOK_TwoDots;
...@@ -440,7 +459,7 @@ WITH return TOK_WITH; ...@@ -440,7 +459,7 @@ WITH return TOK_WITH;
} }
{WSP}+ /* Ignore whitespace */ <INITIAL,extended_values>{WSP}+ /* Ignore whitespace */
[{][\t\r\v\f\n ]*[0-7][,][\t\r\v\f\n ]*[0-9]+[\t\r\v\f\n ]*[}] { [{][\t\r\v\f\n ]*[0-7][,][\t\r\v\f\n ]*[0-9]+[\t\r\v\f\n ]*[}] {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -58,93 +58,94 @@ ...@@ -58,93 +58,94 @@
TOK_typefieldreference = 274, TOK_typefieldreference = 274,
TOK_valuefieldreference = 275, TOK_valuefieldreference = 275,
TOK_Literal = 276, TOK_Literal = 276,
TOK_ABSENT = 277, TOK_ExtValue_BIT_STRING = 277,
TOK_ABSTRACT_SYNTAX = 278, TOK_ABSENT = 278,
TOK_ALL = 279, TOK_ABSTRACT_SYNTAX = 279,
TOK_ANY = 280, TOK_ALL = 280,
TOK_APPLICATION = 281, TOK_ANY = 281,
TOK_AUTOMATIC = 282, TOK_APPLICATION = 282,
TOK_BEGIN = 283, TOK_AUTOMATIC = 283,
TOK_BIT = 284, TOK_BEGIN = 284,
TOK_BMPString = 285, TOK_BIT = 285,
TOK_BOOLEAN = 286, TOK_BMPString = 286,
TOK_BY = 287, TOK_BOOLEAN = 287,
TOK_CHARACTER = 288, TOK_BY = 288,
TOK_CHOICE = 289, TOK_CHARACTER = 289,
TOK_CLASS = 290, TOK_CHOICE = 290,
TOK_COMPONENT = 291, TOK_CLASS = 291,
TOK_COMPONENTS = 292, TOK_COMPONENT = 292,
TOK_CONSTRAINED = 293, TOK_COMPONENTS = 293,
TOK_CONTAINING = 294, TOK_CONSTRAINED = 294,
TOK_DEFAULT = 295, TOK_CONTAINING = 295,
TOK_DEFINITIONS = 296, TOK_DEFAULT = 296,
TOK_DEFINED = 297, TOK_DEFINITIONS = 297,
TOK_EMBEDDED = 298, TOK_DEFINED = 298,
TOK_ENCODED = 299, TOK_EMBEDDED = 299,
TOK_ENCODING_CONTROL = 300, TOK_ENCODED = 300,
TOK_END = 301, TOK_ENCODING_CONTROL = 301,
TOK_ENUMERATED = 302, TOK_END = 302,
TOK_EXPLICIT = 303, TOK_ENUMERATED = 303,
TOK_EXPORTS = 304, TOK_EXPLICIT = 304,
TOK_EXTENSIBILITY = 305, TOK_EXPORTS = 305,
TOK_EXTERNAL = 306, TOK_EXTENSIBILITY = 306,
TOK_FALSE = 307, TOK_EXTERNAL = 307,
TOK_FROM = 308, TOK_FALSE = 308,
TOK_GeneralizedTime = 309, TOK_FROM = 309,
TOK_GeneralString = 310, TOK_GeneralizedTime = 310,
TOK_GraphicString = 311, TOK_GeneralString = 311,
TOK_IA5String = 312, TOK_GraphicString = 312,
TOK_IDENTIFIER = 313, TOK_IA5String = 313,
TOK_IMPLICIT = 314, TOK_IDENTIFIER = 314,
TOK_IMPLIED = 315, TOK_IMPLICIT = 315,
TOK_IMPORTS = 316, TOK_IMPLIED = 316,
TOK_INCLUDES = 317, TOK_IMPORTS = 317,
TOK_INSTANCE = 318, TOK_INCLUDES = 318,
TOK_INSTRUCTIONS = 319, TOK_INSTANCE = 319,
TOK_INTEGER = 320, TOK_INSTRUCTIONS = 320,
TOK_ISO646String = 321, TOK_INTEGER = 321,
TOK_MAX = 322, TOK_ISO646String = 322,
TOK_MIN = 323, TOK_MAX = 323,
TOK_MINUS_INFINITY = 324, TOK_MIN = 324,
TOK_NULL = 325, TOK_MINUS_INFINITY = 325,
TOK_NumericString = 326, TOK_NULL = 326,
TOK_OBJECT = 327, TOK_NumericString = 327,
TOK_ObjectDescriptor = 328, TOK_OBJECT = 328,
TOK_OCTET = 329, TOK_ObjectDescriptor = 329,
TOK_OF = 330, TOK_OCTET = 330,
TOK_OPTIONAL = 331, TOK_OF = 331,
TOK_PATTERN = 332, TOK_OPTIONAL = 332,
TOK_PDV = 333, TOK_PATTERN = 333,
TOK_PLUS_INFINITY = 334, TOK_PDV = 334,
TOK_PRESENT = 335, TOK_PLUS_INFINITY = 335,
TOK_PrintableString = 336, TOK_PRESENT = 336,
TOK_PRIVATE = 337, TOK_PrintableString = 337,
TOK_REAL = 338, TOK_PRIVATE = 338,
TOK_RELATIVE_OID = 339, TOK_REAL = 339,
TOK_SEQUENCE = 340, TOK_RELATIVE_OID = 340,
TOK_SET = 341, TOK_SEQUENCE = 341,
TOK_SIZE = 342, TOK_SET = 342,
TOK_STRING = 343, TOK_SIZE = 343,
TOK_SYNTAX = 344, TOK_STRING = 344,
TOK_T61String = 345, TOK_SYNTAX = 345,
TOK_TAGS = 346, TOK_T61String = 346,
TOK_TeletexString = 347, TOK_TAGS = 347,
TOK_TRUE = 348, TOK_TeletexString = 348,
TOK_TYPE_IDENTIFIER = 349, TOK_TRUE = 349,
TOK_UNIQUE = 350, TOK_TYPE_IDENTIFIER = 350,
TOK_UNIVERSAL = 351, TOK_UNIQUE = 351,
TOK_UniversalString = 352, TOK_UNIVERSAL = 352,
TOK_UTCTime = 353, TOK_UniversalString = 353,
TOK_UTF8String = 354, TOK_UTCTime = 354,
TOK_VideotexString = 355, TOK_UTF8String = 355,
TOK_VisibleString = 356, TOK_VideotexString = 356,
TOK_WITH = 357, TOK_VisibleString = 357,
UTF8_BOM = 358, TOK_WITH = 358,
TOK_EXCEPT = 359, UTF8_BOM = 359,
TOK_INTERSECTION = 360, TOK_EXCEPT = 360,
TOK_UNION = 361, TOK_INTERSECTION = 361,
TOK_TwoDots = 362, TOK_UNION = 362,
TOK_ThreeDots = 363 TOK_TwoDots = 363,
TOK_ThreeDots = 364
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
...@@ -167,93 +168,94 @@ ...@@ -167,93 +168,94 @@
#define TOK_typefieldreference 274 #define TOK_typefieldreference 274
#define TOK_valuefieldreference 275 #define TOK_valuefieldreference 275
#define TOK_Literal 276 #define TOK_Literal 276
#define TOK_ABSENT 277 #define TOK_ExtValue_BIT_STRING 277
#define TOK_ABSTRACT_SYNTAX 278 #define TOK_ABSENT 278
#define TOK_ALL 279 #define TOK_ABSTRACT_SYNTAX 279
#define TOK_ANY 280 #define TOK_ALL 280
#define TOK_APPLICATION 281 #define TOK_ANY 281
#define TOK_AUTOMATIC 282 #define TOK_APPLICATION 282
#define TOK_BEGIN 283 #define TOK_AUTOMATIC 283
#define TOK_BIT 284 #define TOK_BEGIN 284
#define TOK_BMPString 285 #define TOK_BIT 285
#define TOK_BOOLEAN 286 #define TOK_BMPString 286
#define TOK_BY 287 #define TOK_BOOLEAN 287
#define TOK_CHARACTER 288 #define TOK_BY 288
#define TOK_CHOICE 289 #define TOK_CHARACTER 289
#define TOK_CLASS 290 #define TOK_CHOICE 290
#define TOK_COMPONENT 291 #define TOK_CLASS 291
#define TOK_COMPONENTS 292 #define TOK_COMPONENT 292
#define TOK_CONSTRAINED 293 #define TOK_COMPONENTS 293
#define TOK_CONTAINING 294 #define TOK_CONSTRAINED 294
#define TOK_DEFAULT 295 #define TOK_CONTAINING 295
#define TOK_DEFINITIONS 296 #define TOK_DEFAULT 296
#define TOK_DEFINED 297 #define TOK_DEFINITIONS 297
#define TOK_EMBEDDED 298 #define TOK_DEFINED 298
#define TOK_ENCODED 299 #define TOK_EMBEDDED 299
#define TOK_ENCODING_CONTROL 300 #define TOK_ENCODED 300
#define TOK_END 301 #define TOK_ENCODING_CONTROL 301
#define TOK_ENUMERATED 302 #define TOK_END 302
#define TOK_EXPLICIT 303 #define TOK_ENUMERATED 303
#define TOK_EXPORTS 304 #define TOK_EXPLICIT 304
#define TOK_EXTENSIBILITY 305 #define TOK_EXPORTS 305
#define TOK_EXTERNAL 306 #define TOK_EXTENSIBILITY 306
#define TOK_FALSE 307 #define TOK_EXTERNAL 307
#define TOK_FROM 308 #define TOK_FALSE 308
#define TOK_GeneralizedTime 309 #define TOK_FROM 309
#define TOK_GeneralString 310 #define TOK_GeneralizedTime 310
#define TOK_GraphicString 311 #define TOK_GeneralString 311
#define TOK_IA5String 312 #define TOK_GraphicString 312
#define TOK_IDENTIFIER 313 #define TOK_IA5String 313
#define TOK_IMPLICIT 314 #define TOK_IDENTIFIER 314
#define TOK_IMPLIED 315 #define TOK_IMPLICIT 315
#define TOK_IMPORTS 316 #define TOK_IMPLIED 316
#define TOK_INCLUDES 317 #define TOK_IMPORTS 317
#define TOK_INSTANCE 318 #define TOK_INCLUDES 318
#define TOK_INSTRUCTIONS 319 #define TOK_INSTANCE 319
#define TOK_INTEGER 320 #define TOK_INSTRUCTIONS 320
#define TOK_ISO646String 321 #define TOK_INTEGER 321
#define TOK_MAX 322 #define TOK_ISO646String 322
#define TOK_MIN 323 #define TOK_MAX 323
#define TOK_MINUS_INFINITY 324 #define TOK_MIN 324
#define TOK_NULL 325 #define TOK_MINUS_INFINITY 325
#define TOK_NumericString 326 #define TOK_NULL 326
#define TOK_OBJECT 327 #define TOK_NumericString 327
#define TOK_ObjectDescriptor 328 #define TOK_OBJECT 328
#define TOK_OCTET 329 #define TOK_ObjectDescriptor 329
#define TOK_OF 330 #define TOK_OCTET 330
#define TOK_OPTIONAL 331 #define TOK_OF 331
#define TOK_PATTERN 332 #define TOK_OPTIONAL 332
#define TOK_PDV 333 #define TOK_PATTERN 333
#define TOK_PLUS_INFINITY 334 #define TOK_PDV 334
#define TOK_PRESENT 335 #define TOK_PLUS_INFINITY 335
#define TOK_PrintableString 336 #define TOK_PRESENT 336
#define TOK_PRIVATE 337 #define TOK_PrintableString 337
#define TOK_REAL 338 #define TOK_PRIVATE 338
#define TOK_RELATIVE_OID 339 #define TOK_REAL 339
#define TOK_SEQUENCE 340 #define TOK_RELATIVE_OID 340
#define TOK_SET 341 #define TOK_SEQUENCE 341
#define TOK_SIZE 342 #define TOK_SET 342
#define TOK_STRING 343 #define TOK_SIZE 343
#define TOK_SYNTAX 344 #define TOK_STRING 344
#define TOK_T61String 345 #define TOK_SYNTAX 345
#define TOK_TAGS 346 #define TOK_T61String 346
#define TOK_TeletexString 347 #define TOK_TAGS 347
#define TOK_TRUE 348 #define TOK_TeletexString 348
#define TOK_TYPE_IDENTIFIER 349 #define TOK_TRUE 349
#define TOK_UNIQUE 350 #define TOK_TYPE_IDENTIFIER 350
#define TOK_UNIVERSAL 351 #define TOK_UNIQUE 351
#define TOK_UniversalString 352 #define TOK_UNIVERSAL 352
#define TOK_UTCTime 353 #define TOK_UniversalString 353
#define TOK_UTF8String 354 #define TOK_UTCTime 354
#define TOK_VideotexString 355 #define TOK_UTF8String 355
#define TOK_VisibleString 356 #define TOK_VideotexString 356
#define TOK_WITH 357 #define TOK_VisibleString 357
#define UTF8_BOM 358 #define TOK_WITH 358
#define TOK_EXCEPT 359 #define UTF8_BOM 359
#define TOK_INTERSECTION 360 #define TOK_EXCEPT 360
#define TOK_UNION 361 #define TOK_INTERSECTION 361
#define TOK_TwoDots 362 #define TOK_UNION 362
#define TOK_ThreeDots 363 #define TOK_TwoDots 363
#define TOK_ThreeDots 364
...@@ -296,7 +298,7 @@ typedef union YYSTYPE ...@@ -296,7 +298,7 @@ typedef union YYSTYPE
} tv_nametag; } tv_nametag;
} }
/* Line 1529 of yacc.c. */ /* Line 1529 of yacc.c. */
#line 300 "asn1p_y.h" #line 302 "asn1p_y.h"
YYSTYPE; YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
......
...@@ -132,9 +132,9 @@ static asn1p_module_t *currentModule; ...@@ -132,9 +132,9 @@ static asn1p_module_t *currentModule;
%token <tv_str> TOK_bstring %token <tv_str> TOK_bstring
%token <tv_opaque> TOK_cstring %token <tv_opaque> TOK_cstring
%token <tv_str> TOK_hstring %token <tv_str> TOK_hstring
%token <tv_str> TOK_identifier %token <tv_str> TOK_identifier "identifier"
%token <a_int> TOK_number %token <a_int> TOK_number "number"
%token <a_int> TOK_number_negative %token <a_int> TOK_number_negative "negative number"
%token <a_dbl> TOK_realnumber %token <a_dbl> TOK_realnumber
%token <a_int> TOK_tuple %token <a_int> TOK_tuple
%token <a_int> TOK_quadruple %token <a_int> TOK_quadruple
...@@ -144,6 +144,11 @@ static asn1p_module_t *currentModule; ...@@ -144,6 +144,11 @@ static asn1p_module_t *currentModule;
%token <tv_str> TOK_valuefieldreference /* "&id" */ %token <tv_str> TOK_valuefieldreference /* "&id" */
%token <tv_str> TOK_Literal /* "BY" */ %token <tv_str> TOK_Literal /* "BY" */
/*
* Tokens available with asn1p_lexer_hack_push_extended_values().
*/
%token TOK_ExtValue_BIT_STRING
/* /*
* Token types representing ASN.1 standard keywords. * Token types representing ASN.1 standard keywords.
*/ */
...@@ -235,8 +240,8 @@ static asn1p_module_t *currentModule; ...@@ -235,8 +240,8 @@ static asn1p_module_t *currentModule;
%left '|' TOK_UNION %left '|' TOK_UNION
/* Misc tags */ /* Misc tags */
%token TOK_TwoDots /* .. */ %token TOK_TwoDots ".."
%token TOK_ThreeDots /* ... */ %token TOK_ThreeDots "..."
/* /*
...@@ -291,8 +296,14 @@ static asn1p_module_t *currentModule; ...@@ -291,8 +296,14 @@ static asn1p_module_t *currentModule;
%type <a_expr> ComponentType %type <a_expr> ComponentType
%type <a_expr> AlternativeTypeLists %type <a_expr> AlternativeTypeLists
%type <a_expr> AlternativeType %type <a_expr> AlternativeType
%type <a_expr> UniverationDefinition
%type <a_expr> UniverationList %type <a_expr> UniverationList
%type <a_expr> Enumerations
%type <a_expr> NamedBitList
%type <a_expr> NamedBit
%type <a_expr> NamedNumberList
%type <a_expr> NamedNumber
%type <a_expr> IdentifierList
%type <a_expr> IdentifierElement
%type <a_expr> UniverationElement %type <a_expr> UniverationElement
%type <tv_str> TypeRefName %type <tv_str> TypeRefName
%type <tv_str> ObjectClassReference %type <tv_str> ObjectClassReference
...@@ -1638,7 +1649,6 @@ BasicTypeId: ...@@ -1638,7 +1649,6 @@ BasicTypeId:
TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; } TOK_BOOLEAN { $$ = ASN_BASIC_BOOLEAN; }
| TOK_NULL { $$ = ASN_BASIC_NULL; } | TOK_NULL { $$ = ASN_BASIC_NULL; }
| TOK_REAL { $$ = ASN_BASIC_REAL; } | TOK_REAL { $$ = ASN_BASIC_REAL; }
| BasicTypeId_UniverationCompatible { $$ = $1; }
| TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; } | TOK_OCTET TOK_STRING { $$ = ASN_BASIC_OCTET_STRING; }
| TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; } | TOK_OBJECT TOK_IDENTIFIER { $$ = ASN_BASIC_OBJECT_IDENTIFIER; }
| TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; } | TOK_RELATIVE_OID { $$ = ASN_BASIC_RELATIVE_OID; }
...@@ -1647,7 +1657,8 @@ BasicTypeId: ...@@ -1647,7 +1657,8 @@ BasicTypeId:
| TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; } | TOK_CHARACTER TOK_STRING { $$ = ASN_BASIC_CHARACTER_STRING; }
| TOK_UTCTime { $$ = ASN_BASIC_UTCTime; } | TOK_UTCTime { $$ = ASN_BASIC_UTCTime; }
| TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; } | TOK_GeneralizedTime { $$ = ASN_BASIC_GeneralizedTime; }
| BasicString { $$ = $1; } | BasicString
| BasicTypeId_UniverationCompatible
; ;
/* /*
...@@ -1655,7 +1666,7 @@ BasicTypeId: ...@@ -1655,7 +1666,7 @@ BasicTypeId:
*/ */
BasicTypeId_UniverationCompatible: BasicTypeId_UniverationCompatible:
TOK_INTEGER { $$ = ASN_BASIC_INTEGER; } TOK_INTEGER { $$ = ASN_BASIC_INTEGER; }
| TOK_ENUMERATED { $$ = ASN_BASIC_ENUMERATED; } | TOK_ENUMERATED { $$ = ASN_BASIC_INTEGER; }
| TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; } | TOK_BIT TOK_STRING { $$ = ASN_BASIC_BIT_STRING; }
; ;
...@@ -1666,16 +1677,32 @@ BasicType: ...@@ -1666,16 +1677,32 @@ BasicType:
$$->expr_type = $1; $$->expr_type = $1;
$$->meta_type = AMT_TYPE; $$->meta_type = AMT_TYPE;
} }
| BasicTypeId_UniverationCompatible UniverationDefinition { | TOK_INTEGER '{' NamedNumberList '}' {
if($2) { $$ = $3;
$$ = $2; $$->expr_type = ASN_BASIC_INTEGER;
} else { $$->meta_type = AMT_TYPE;
$$ = NEW_EXPR(); }
checkmem($$); | TOK_ENUMERATED '{' Enumerations '}' {
} $$ = $3;
$$->expr_type = $1; $$->expr_type = ASN_BASIC_ENUMERATED;
$$->meta_type = AMT_TYPE; $$->meta_type = AMT_TYPE;
} }
| TOK_BIT TOK_STRING '{' NamedBitList '}' {
$$ = $4;
$$->expr_type = ASN_BASIC_BIT_STRING;
$$->meta_type = AMT_TYPE;
}
| TOK_ExtValue_BIT_STRING '{' IdentifierList '}' {
$$ = $3;
$$->expr_type = ASN_BASIC_BIT_STRING;
$$->meta_type = AMT_TYPE;
}
| TOK_ExtValue_BIT_STRING '{' '}' {
$$ = NEW_EXPR();
checkmem($$);
$$->expr_type = ASN_BASIC_BIT_STRING;
$$->meta_type = AMT_TYPE;
}
; ;
BasicString: BasicString:
...@@ -2173,32 +2200,101 @@ Marker: ...@@ -2173,32 +2200,101 @@ Marker:
} }
; ;
/* IdentifierList:
* Universal enumeration definition to use in INTEGER and ENUMERATED. IdentifierElement {
* === EXAMPLE === $$ = NEW_EXPR();
* Gender ::= ENUMERATED { unknown(0), male(1), female(2) } checkmem($$);
* Temperature ::= INTEGER { absolute-zero(-273), freezing(0), boiling(100) } asn1p_expr_add($$, $1);
* === EOF === }
*/ | IdentifierList ',' IdentifierElement {
/* $$ = $1;
optUniverationDefinition: asn1p_expr_add($$, $3);
{ $$ = 0; } };
| UniverationDefinition {
IdentifierElement:
Identifier {
$$ = NEW_EXPR();
checkmem($$);
$$->expr_type = A1TC_UNIVERVAL;
$$->meta_type = AMT_VALUE;
$$->Identifier = $1;
}
NamedNumberList:
NamedNumber {
$$ = NEW_EXPR();
checkmem($$);
asn1p_expr_add($$, $1);
}
| NamedNumberList ',' NamedNumber {
$$ = $1; $$ = $1;
asn1p_expr_add($$, $3);
} }
; ;
*/
UniverationDefinition: NamedNumber:
'{' '}' { Identifier '(' SignedNumber ')' {
$$ = NEW_EXPR(); $$ = NEW_EXPR();
checkmem($$); checkmem($$);
$$->expr_type = A1TC_UNIVERVAL;
$$->meta_type = AMT_VALUE;
$$->Identifier = $1;
$$->value = $3;
} }
| '{' UniverationList '}' { | Identifier '(' DefinedValue ')' {
$$ = $2; $$ = NEW_EXPR();
checkmem($$);
$$->expr_type = A1TC_UNIVERVAL;
$$->meta_type = AMT_VALUE;
$$->Identifier = $1;
$$->value = $3;
};
NamedBitList:
NamedBit {
$$ = NEW_EXPR();
checkmem($$);
asn1p_expr_add($$, $1);
}
| NamedBitList ',' NamedBit {
$$ = $1;
asn1p_expr_add($$, $3);
} }
; ;
NamedBit:
Identifier '(' TOK_number ')' {
$$ = NEW_EXPR();
checkmem($$);
$$->expr_type = A1TC_UNIVERVAL;
$$->meta_type = AMT_VALUE;
$$->Identifier = $1;
$$->value = asn1p_value_fromint($3);
}
| Identifier '(' DefinedValue ')' {
$$ = NEW_EXPR();
checkmem($$);
$$->expr_type = A1TC_UNIVERVAL;
$$->meta_type = AMT_VALUE;
$$->Identifier = $1;
$$->value = $3;
};
Enumerations:
UniverationList {
$$ = $1;
asn1p_expr_t *first_memb = TQ_FIRST(&($$->members));
if(first_memb) {
if(first_memb->expr_type == A1TC_EXTENSIBLE) {
return yyerror(
"The ENUMERATION cannot start with extension (...).");
}
} else {
return yyerror(
"The ENUMERATION list cannot be empty.");
}
}
UniverationList: UniverationList:
UniverationElement { UniverationElement {
$$ = NEW_EXPR(); $$ = NEW_EXPR();
......
...@@ -24,7 +24,7 @@ static int _asn1p_fix_modules(asn1p_t *a, const char *fname); ...@@ -24,7 +24,7 @@ static int _asn1p_fix_modules(asn1p_t *a, const char *fname);
* Parse the given buffer. * Parse the given buffer.
*/ */
asn1p_t * asn1p_t *
asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags flags) { asn1p_parse_buffer(const char *buffer, int size /* = -1 */, const char *debug_filename, int initial_lineno, enum asn1p_flags flags) {
asn1p_t *a = 0; asn1p_t *a = 0;
void *ap; void *ap;
void *ybuf; void *ybuf;
...@@ -38,18 +38,18 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla ...@@ -38,18 +38,18 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla
if(size < 0) if(size < 0)
size = (int)strlen(buffer); size = (int)strlen(buffer);
asn1p_parse_debug_filename = "<stdin>";
ybuf = asn1p__scan_bytes(buffer, size); ybuf = asn1p__scan_bytes(buffer, size);
asn1p_parse_debug_filename = NULL;
if(!ybuf) { if(!ybuf) {
assert(ybuf); assert(ybuf);
return 0; return 0;
} }
asn1p_lineno = 1; asn1p_lineno = initial_lineno;
ap = (void *)&a; ap = (void *)&a;
asn1p_parse_debug_filename = debug_filename;
ret = asn1p_parse(ap); ret = asn1p_parse(ap);
asn1p_parse_debug_filename = NULL;
asn1p__delete_buffer(ybuf); asn1p__delete_buffer(ybuf);
...@@ -130,6 +130,7 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) { ...@@ -130,6 +130,7 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) {
extern int asn1p_lexer_types_year; extern int asn1p_lexer_types_year;
extern int asn1p_lexer_constructs_year; extern int asn1p_lexer_constructs_year;
extern int asn1p_lexer_extended_values;
extern int asn1p__flex_debug; extern int asn1p__flex_debug;
static int static int
...@@ -145,9 +146,16 @@ _asn1p_set_flags(enum asn1p_flags flags) { ...@@ -145,9 +146,16 @@ _asn1p_set_flags(enum asn1p_flags flags) {
if(flags & A1P_LEXER_DEBUG) { if(flags & A1P_LEXER_DEBUG) {
flags &= ~A1P_LEXER_DEBUG; flags &= ~A1P_LEXER_DEBUG;
asn1p__flex_debug = 1; asn1p__flex_debug = 1;
} }
/* if(flags & A1P_EXTENDED_VALUES) {
flags &= ~A1P_EXTENDED_VALUES;
asn1p_lexer_extended_values = 1;
} else {
asn1p_lexer_extended_values = 0;
}
/*
* Check that we haven't missed an unknown flag. * Check that we haven't missed an unknown flag.
*/ */
if(flags) { if(flags) {
......
...@@ -27,11 +27,15 @@ ...@@ -27,11 +27,15 @@
* Parser flags. * Parser flags.
*/ */
enum asn1p_flags { enum asn1p_flags {
A1P_NOFLAGS, A1P_NOFLAGS,
/* /*
* Enable verbose debugging output from lexer. * Enable verbose debugging output from lexer.
*/ */
A1P_LEXER_DEBUG = 0x0001 A1P_LEXER_DEBUG = 0x01,
/*
* Unlock internal helper value types.
*/
A1P_EXTENDED_VALUES = 0x02
}; };
/* /*
...@@ -41,6 +45,7 @@ enum asn1p_flags { ...@@ -41,6 +45,7 @@ enum asn1p_flags {
asn1p_t *asn1p_parse_file(const char *filename, asn1p_t *asn1p_parse_file(const char *filename,
enum asn1p_flags); enum asn1p_flags);
asn1p_t *asn1p_parse_buffer(const char *buffer, int size /* = -1 */, asn1p_t *asn1p_parse_buffer(const char *buffer, int size /* = -1 */,
const char *debug_filename, int initial_lineno,
enum asn1p_flags); enum asn1p_flags);
extern const char *asn1p_parse_debug_filename; extern const char *asn1p_parse_debug_filename;
......
-- SE: Semantic error -- NP: Non-parseable
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) -- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1) -- .spelio.software.asn1c.test (9363.1.5.1)
......
-- SE: Semantic error -- NP: Non-parseable
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) -- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1) -- .spelio.software.asn1c.test (9363.1.5.1)
......
...@@ -19,4 +19,6 @@ BEGIN ...@@ -19,4 +19,6 @@ BEGIN
one0one BS1 ::= '1010000'B -- Equivalent to '101'B one0one BS1 ::= '1010000'B -- Equivalent to '101'B
empty BS1 ::= { } -- Equivalent to ''B
END END
...@@ -15,4 +15,6 @@ one-zero-one BS1 ::= '101'B ...@@ -15,4 +15,6 @@ one-zero-one BS1 ::= '101'B
one0one BS1 ::= '101'B one0one BS1 ::= '101'B
empty BS1 ::= ''H
END END
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment