Commit d523ea45 authored by Lev Walkin's avatar Lev Walkin

parse advanced WITH COMPONENTS

parent 8460940d
...@@ -24,8 +24,18 @@ asn1c_get_information_object_set_reference_from_constraint(arg_t *arg, ...@@ -24,8 +24,18 @@ asn1c_get_information_object_set_reference_from_constraint(arg_t *arg,
assert(ct->elements[0]->type == ACT_EL_VALUE); assert(ct->elements[0]->type == ACT_EL_VALUE);
asn1p_value_t *val = ct->elements[0]->value; asn1p_value_t *val = ct->elements[0]->value;
if(val->type == ATV_VALUESET && val->value.constraint->type == ACT_EL_TYPE && val->value.constraint->containedSubtype && val->value.constraint->containedSubtype->type == ATV_REFERENCED) { if(val->type == ATV_VALUESET && val->value.constraint->type == ACT_EL_TYPE) {
return val->value.constraint->containedSubtype->value.reference; asn1p_value_t *csub = val->value.constraint->containedSubtype;
if(!csub) {
/* Ignore */
} else if(csub->type == ATV_REFERENCED) {
return csub->value.reference;
} else if(csub->type == ATV_TYPE) {
if(csub->value.v_type->expr_type == A1TC_REFERENCE) {
assert(csub->value.v_type->reference);
return csub->value.v_type->reference;
}
}
} }
if(val->type != ATV_REFERENCED) { if(val->type != ATV_REFERENCED) {
FATAL("Set reference: %s", asn1f_printable_value(val)); FATAL("Set reference: %s", asn1f_printable_value(val));
......
...@@ -257,70 +257,83 @@ _remove_extensions(arg_t *arg, asn1p_constraint_t *ct, int forgive_last) { ...@@ -257,70 +257,83 @@ _remove_extensions(arg_t *arg, asn1p_constraint_t *ct, int forgive_last) {
ct->elements[i] = 0; ct->elements[i] = 0;
} }
static asn1p_ref_t *
get_reference_from(asn1p_constraint_t *ct) {
if(ct->containedSubtype->type == ATV_REFERENCED) {
return ct->containedSubtype->value.reference;
} else if(ct->containedSubtype->type == ATV_TYPE) {
if(ct->containedSubtype->value.v_type->expr_type == A1TC_REFERENCE) {
return ct->containedSubtype->value.v_type->reference;
}
}
return NULL;
}
static int static int
constraint_type_resolve(arg_t *arg, asn1p_constraint_t *ct) { constraint_type_resolve(arg_t *arg, asn1p_constraint_t *ct) {
asn1p_constraint_t *ct_expr; asn1p_constraint_t *ct_expr;
int ret; int ret;
DEBUG("(\"%s\")", asn1f_printable_value(ct->containedSubtype)); DEBUG("(\"%s\")", asn1f_printable_value(ct->containedSubtype));
if(ct->containedSubtype->type == ATV_VALUESET) { if(ct->containedSubtype->type == ATV_VALUESET) {
ct_expr = ct->containedSubtype->value.constraint; ct_expr = ct->containedSubtype->value.constraint;
DEBUG("Found %s in constraints", "ValueSet"); DEBUG("Found %s in constraints", "ValueSet");
} else if(ct->containedSubtype->type == ATV_REFERENCED) { } else if(get_reference_from(ct)) {
asn1p_expr_t *rtype; asn1p_expr_t *rtype;
arg_t tmparg; arg_t tmparg;
rtype = asn1f_lookup_symbol(arg, arg->expr->rhs_pspecs, rtype = asn1f_lookup_symbol(arg, arg->expr->rhs_pspecs,
ct->containedSubtype->value.reference); get_reference_from(ct));
if(!rtype) { if(!rtype) {
FATAL("Cannot find type \"%s\" in constraints " FATAL(
"at line %d", "Cannot find type \"%s\" in constraints "
asn1f_printable_value(ct->containedSubtype), "at line %d",
ct->_lineno); asn1f_printable_value(ct->containedSubtype), ct->_lineno);
return -1; return -1;
} }
tmparg = *arg; tmparg = *arg;
tmparg.expr = rtype; tmparg.expr = rtype;
tmparg.mod = rtype->module; tmparg.mod = rtype->module;
ret = asn1constraint_pullup(&tmparg); ret = asn1constraint_pullup(&tmparg);
if(ret) return ret; if(ret) return ret;
ct_expr = rtype->combined_constraints; ct_expr = rtype->combined_constraints;
if(!ct_expr) return 0; if(!ct_expr) return 0;
} else { } else {
FATAL("Unsupported feature at line %d", ct->_lineno); FATAL("Unsupported constraint kind %s at line %d",
return -1; asn1f_printable_value(ct->containedSubtype), ct->_lineno);
} return -1;
}
ct_expr = asn1p_constraint_clone(ct_expr);
assert(ct_expr);
_remove_extensions(arg, ct_expr, 0);
if(ct_expr->type == ACT_CA_SET) { ct_expr = asn1p_constraint_clone(ct_expr);
unsigned int i; assert(ct_expr);
for(i = 0; i < ct_expr->el_count; i++) {
if(asn1p_constraint_insert( _remove_extensions(arg, ct_expr, 0);
ct, ct_expr->elements[i])) {
asn1p_constraint_free(ct_expr); if(ct_expr->type == ACT_CA_SET) {
return -1; unsigned int i;
} else { for(i = 0; i < ct_expr->el_count; i++) {
ct_expr->elements[i] = 0; if(asn1p_constraint_insert(
} ct, ct_expr->elements[i])) {
} asn1p_constraint_free(ct_expr);
asn1p_constraint_free(ct_expr); return -1;
} else { } else {
ret = asn1p_constraint_insert(ct, ct_expr); ct_expr->elements[i] = 0;
assert(ret == 0); }
} }
asn1p_constraint_free(ct_expr);
} else {
ret = asn1p_constraint_insert(ct, ct_expr);
assert(ret == 0);
}
ct->type = ACT_CA_SET; ct->type = ACT_CA_SET;
asn1p_value_free(ct->containedSubtype); asn1p_value_free(ct->containedSubtype);
ct->containedSubtype = NULL; ct->containedSubtype = NULL;
return 0; return 0;
} }
static int static int
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE typedef union YYSTYPE
#line 88 "asn1p_y.y" #line 90 "asn1p_y.y"
{ {
asn1p_t *a_grammar; asn1p_t *a_grammar;
asn1p_module_flags_e a_module_flags; asn1p_module_flags_e a_module_flags;
......
...@@ -22,6 +22,8 @@ void asn1p_lexer_hack_enable_with_syntax(void); ...@@ -22,6 +22,8 @@ void asn1p_lexer_hack_enable_with_syntax(void);
void asn1p_lexer_hack_push_encoding_control(void); void asn1p_lexer_hack_push_encoding_control(void);
#define yylineno asn1p_lineno #define yylineno asn1p_lineno
extern int asn1p_lineno; extern int asn1p_lineno;
const char *asn1p_parse_debug_filename;
#define ASN_FILENAME asn1p_parse_debug_filename
/* /*
* Process directives as <ASN1C:RepresentAsPointer> * Process directives as <ASN1C:RepresentAsPointer>
...@@ -295,6 +297,8 @@ static asn1p_module_t *currentModule; ...@@ -295,6 +297,8 @@ static asn1p_module_t *currentModule;
%type <tv_str> TypeRefName %type <tv_str> TypeRefName
%type <tv_str> ObjectClassReference %type <tv_str> ObjectClassReference
%type <tv_str> Identifier %type <tv_str> Identifier
%type <a_ref> IdentifierAsReference
%type <a_value> IdentifierAsValue
%type <tv_str> optIdentifier %type <tv_str> optIdentifier
%type <a_parg> ParameterArgumentName %type <a_parg> ParameterArgumentName
%type <a_plist> ParameterArgumentList %type <a_plist> ParameterArgumentList
...@@ -314,9 +318,16 @@ static asn1p_module_t *currentModule; ...@@ -314,9 +318,16 @@ static asn1p_module_t *currentModule;
%type <a_tag> TagClass TagTypeValue TagPlicit %type <a_tag> TagClass TagTypeValue TagPlicit
%type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */ %type <a_tag> optTag /* [UNIVERSAL 0] IMPLICIT */
%type <a_constr> optConstraints %type <a_constr> optConstraints
%type <a_constr> optSizeConstraints
%type <a_constr> Constraint %type <a_constr> Constraint
%type <a_constr> SingleTypeConstraint
%type <a_constr> MultipleTypeConstraints
%type <a_constr> NamedConstraint
%type <a_constr> FullSpecification
%type <a_constr> PartialSpecification
%type <a_constr> TypeConstraints
%type <a_constr> ConstraintSpec
%type <a_constr> SubtypeConstraint %type <a_constr> SubtypeConstraint
%type <a_constr> ConstraintSpecs
%type <a_constr> GeneralConstraint %type <a_constr> GeneralConstraint
%type <a_constr> SetOfConstraints %type <a_constr> SetOfConstraints
%type <a_constr> ElementSetSpecs /* 1..2,...,3 */ %type <a_constr> ElementSetSpecs /* 1..2,...,3 */
...@@ -331,14 +342,12 @@ static asn1p_module_t *currentModule; ...@@ -331,14 +342,12 @@ static asn1p_module_t *currentModule;
%type <a_constr> ContentsConstraint %type <a_constr> ContentsConstraint
%type <a_constr> PatternConstraint %type <a_constr> PatternConstraint
%type <a_constr> InnerTypeConstraint %type <a_constr> InnerTypeConstraint
%type <a_constr> WithComponentsList
%type <a_constr> WithComponentsElement
%type <a_constr> ComponentRelationConstraint %type <a_constr> ComponentRelationConstraint
%type <a_constr> AtNotationList %type <a_constr> AtNotationList
%type <a_ref> AtNotationElement %type <a_ref> AtNotationElement
%type <a_value> SingleValue %type <a_value> SingleValue
%type <a_value> ContainedSubtype %type <a_value> ContainedSubtype
%type <a_ctype> ConstraintSpec %type <a_ctype> ConstraintType
%type <a_ctype> ConstraintRangeSpec %type <a_ctype> ConstraintRangeSpec
%type <a_value> RestrictedCharacterStringValue %type <a_value> RestrictedCharacterStringValue
%type <a_wsynt> optWithSyntax %type <a_wsynt> optWithSyntax
...@@ -505,9 +514,9 @@ ModuleDefinitionFlag: ...@@ -505,9 +514,9 @@ ModuleDefinitionFlag:
$$ = MSF_XER_INSTRUCTIONS; $$ = MSF_XER_INSTRUCTIONS;
} else { } else {
fprintf(stderr, fprintf(stderr,
"WARNING: %s INSTRUCTIONS at line %d: " "WARNING: %s INSTRUCTIONS at %s:%d: "
"Unrecognized encoding reference\n", "Unrecognized encoding reference\n",
$1, yylineno); $1, ASN_FILENAME, yylineno);
$$ = MSF_unk_INSTRUCTIONS; $$ = MSF_unk_INSTRUCTIONS;
} }
free($1); free($1);
...@@ -594,8 +603,8 @@ Assignment: ...@@ -594,8 +603,8 @@ Assignment:
{ {
fprintf(stderr, fprintf(stderr,
"WARNING: ENCODING-CONTROL %s " "WARNING: ENCODING-CONTROL %s "
"specification at line %d ignored\n", "specification at %s:%d ignored\n",
$2, yylineno); $2, ASN_FILENAME, yylineno);
free($2); free($2);
$$ = 0; $$ = 0;
} }
...@@ -1263,11 +1272,11 @@ TypeDeclaration: ...@@ -1263,11 +1272,11 @@ TypeDeclaration:
&& ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) { && ($$->marker.flags & EM_OPTIONAL) != EM_OPTIONAL) {
fprintf(stderr, fprintf(stderr,
"INFO: Directive <ASN1C:RepresentAsPointer> " "INFO: Directive <ASN1C:RepresentAsPointer> "
"applied to %s at line %d\n", "applied to %s at %s:%d\n",
ASN_EXPR_TYPE2STR($$->expr_type) ASN_EXPR_TYPE2STR($$->expr_type)
? ASN_EXPR_TYPE2STR($$->expr_type) ? ASN_EXPR_TYPE2STR($$->expr_type)
: "member", : "member",
$$->_lineno ASN_FILENAME, $$->_lineno
); );
} }
} }
...@@ -1295,7 +1304,7 @@ TypeDeclarationSet: ...@@ -1295,7 +1304,7 @@ TypeDeclarationSet:
$$->expr_type = ASN_CONSTR_SET; $$->expr_type = ASN_CONSTR_SET;
$$->meta_type = AMT_TYPE; $$->meta_type = AMT_TYPE;
} }
| TOK_SEQUENCE optConstraints TOK_OF optIdentifier optTag TypeDeclaration { | TOK_SEQUENCE optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration {
$$ = NEW_EXPR(); $$ = NEW_EXPR();
checkmem($$); checkmem($$);
$$->constraints = $2; $$->constraints = $2;
...@@ -1305,7 +1314,7 @@ TypeDeclarationSet: ...@@ -1305,7 +1314,7 @@ TypeDeclarationSet:
$6->tag = $5; $6->tag = $5;
asn1p_expr_add($$, $6); asn1p_expr_add($$, $6);
} }
| TOK_SET optConstraints TOK_OF optIdentifier optTag TypeDeclaration { | TOK_SET optSizeConstraints TOK_OF optIdentifier optTag TypeDeclaration {
$$ = NEW_EXPR(); $$ = NEW_EXPR();
checkmem($$); checkmem($$);
$$->constraints = $2; $$->constraints = $2;
...@@ -1705,56 +1714,45 @@ BasicString: ...@@ -1705,56 +1714,45 @@ BasicString:
UnionMark: '|' | TOK_UNION; UnionMark: '|' | TOK_UNION;
IntersectionMark: '^' | TOK_INTERSECTION; IntersectionMark: '^' | TOK_INTERSECTION;
/* empty | Constraint */
optConstraints: optConstraints:
{ $$ = 0; } { $$ = 0; }
| Constraint { | Constraint;
$$ = $1;
/* empty | Constraint | SIZE(...) */
optSizeConstraints:
{ $$ = 0; }
| Constraint
| TOK_SIZE '(' ConstraintSpec ')' {
CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
} }
; ;
Constraint: Constraint:
SubtypeConstraint SetOfConstraints {
;
SubtypeConstraint:
SetOfConstraints {
CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0); CONSTRAINT_INSERT($$, ACT_CA_SET, $1, 0);
} }
| TOK_SIZE '(' ConstraintSpecs ')' { ;
/*
* This is a special case, for compatibility purposes.
* It goes without parentheses.
*/
CONSTRAINT_INSERT($$, ACT_CT_SIZE, $3, 0);
}
;
SetOfConstraints: SetOfConstraints:
'(' ConstraintSpecs ')' { '(' ConstraintSpec ')' {
$$ = $2; $$ = $2;
} }
| SetOfConstraints '(' ConstraintSpecs ')' { | SetOfConstraints '(' ConstraintSpec ')' {
CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3); CONSTRAINT_INSERT($$, ACT_CA_SET, $1, $3);
} }
; ;
ConstraintSpecs: ConstraintSpec: SubtypeConstraint | GeneralConstraint;
ElementSetSpecs {
$$ = $1; SubtypeConstraint: ElementSetSpecs;
}
| GeneralConstraint {
$$ = $1;
}
;
ElementSetSpecs: ElementSetSpecs:
TOK_ThreeDots { TOK_ThreeDots {
$$ = asn1p_constraint_new(yylineno, currentModule); $$ = asn1p_constraint_new(yylineno, currentModule);
$$->type = ACT_EL_EXT; $$->type = ACT_EL_EXT;
} }
| ElementSetSpec { | ElementSetSpec
$$ = $1;
}
| ElementSetSpec ',' TOK_ThreeDots { | ElementSetSpec ',' TOK_ThreeDots {
asn1p_constraint_t *ct; asn1p_constraint_t *ct;
ct = asn1p_constraint_new(yylineno, currentModule); ct = asn1p_constraint_new(yylineno, currentModule);
...@@ -1801,7 +1799,7 @@ IntersectionElements: ...@@ -1801,7 +1799,7 @@ IntersectionElements:
; ;
ConstraintSubtypeElement: ConstraintSubtypeElement:
ConstraintSpec '(' ElementSetSpecs ')' { ConstraintType '(' ElementSetSpecs ')' {
int ret; int ret;
$$ = asn1p_constraint_new(yylineno, currentModule); $$ = asn1p_constraint_new(yylineno, currentModule);
checkmem($$); checkmem($$);
...@@ -1861,12 +1859,8 @@ ConstraintSubtypeElement: ...@@ -1861,12 +1859,8 @@ ConstraintSubtypeElement:
$$->range_start->type = ATV_MIN; $$->range_start->type = ATV_MIN;
$$->range_stop->type = ATV_MAX; $$->range_stop->type = ATV_MAX;
} }
| InnerTypeConstraint { | InnerTypeConstraint
$$ = $1; | PatternConstraint
}
| PatternConstraint {
$$ = $1;
}
| '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ { | '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
$$ = asn1p_constraint_new(yylineno, currentModule); $$ = asn1p_constraint_new(yylineno, currentModule);
checkmem($$); checkmem($$);
...@@ -1893,7 +1887,7 @@ PatternConstraint: ...@@ -1893,7 +1887,7 @@ PatternConstraint:
} }
; ;
ConstraintSpec: ConstraintType:
TOK_SIZE { TOK_SIZE {
$$ = ACT_CT_SIZE; $$ = ACT_CT_SIZE;
} }
...@@ -1943,62 +1937,66 @@ BitStringValue: ...@@ -1943,62 +1937,66 @@ BitStringValue:
; ;
ContainedSubtype: ContainedSubtype:
ComplexTypeReference { Type {
$$ = asn1p_value_fromref($1, 0); $$ = asn1p_value_fromtype($1);
checkmem($$);
}
/*
TypeRefName {
asn1p_ref_t *ref;
int ret;
ref = asn1p_ref_new(yylineno, currentModule);
checkmem(ref);
ret = asn1p_ref_add_component(ref, $1, RLT_UNKNOWN);
checkmem(ret == 0);
$$ = asn1p_value_fromref(ref, 0);
checkmem($$); checkmem($$);
free($1); }
}
*/
; ;
/*
* X.680 08/2015
* #51.8.5
*/
InnerTypeConstraint: InnerTypeConstraint:
TOK_WITH TOK_COMPONENT SetOfConstraints { TOK_WITH TOK_COMPONENT SingleTypeConstraint {
CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0); CONSTRAINT_INSERT($$, ACT_CT_WCOMP, $3, 0);
} }
| TOK_WITH TOK_COMPONENTS '{' WithComponentsList '}' { | TOK_WITH TOK_COMPONENTS MultipleTypeConstraints {
CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $4, 0); assert($3->type == ACT_CA_CSV);
} $3->type = ACT_CT_WCOMPS;
; $$ = $3;
WithComponentsList:
WithComponentsElement {
$$ = $1;
}
| WithComponentsList ',' WithComponentsElement {
CONSTRAINT_INSERT($$, ACT_CT_WCOMPS, $1, $3);
} }
; ;
SingleTypeConstraint: Constraint;
WithComponentsElement: MultipleTypeConstraints: FullSpecification | PartialSpecification;
TOK_ThreeDots { FullSpecification: '{' TypeConstraints '}' { $$ = $2; };
$$ = asn1p_constraint_new(yylineno, currentModule); PartialSpecification:
checkmem($$); '{' TOK_ThreeDots ',' TypeConstraints '}' {
$$->type = ACT_EL_EXT; assert($4->type == ACT_CA_CSV);
$$->value = asn1p_value_frombuf("...", 3, 1);
}
| Identifier optConstraints optPresenceConstraint {
$$ = asn1p_constraint_new(yylineno, currentModule); $$ = asn1p_constraint_new(yylineno, currentModule);
$$->type = ACT_CA_CSV;
asn1p_constraint_t *ct = asn1p_constraint_new(yylineno, currentModule);
checkmem($$); checkmem($$);
$$->type = ACT_EL_VALUE; ct->type = ACT_EL_EXT;
$$->value = asn1p_value_frombuf($1, strlen($1), 0); asn1p_constraint_insert($$, ct);
$$->presence = $3; for(unsigned i = 0; i < $4->el_count; i++) {
if($2) asn1p_constraint_insert($$, $2); asn1p_constraint_insert($$, $4->elements[i]);
} }
; };
TypeConstraints:
NamedConstraint {
$$ = asn1p_constraint_new(yylineno, currentModule);
$$->type = ACT_CA_CSV;
asn1p_constraint_insert($$, $1);
}
| TypeConstraints ',' NamedConstraint {
$$ = $1;
asn1p_constraint_insert($$, $3);
}
;
NamedConstraint:
IdentifierAsValue optConstraints optPresenceConstraint {
$$ = asn1p_constraint_new(yylineno, currentModule);
checkmem($$);
$$->type = ACT_EL_VALUE;
$$->value = $1;
if($2) asn1p_constraint_insert($$, $2);
$$->presence = $3;
}
;
/* /*
* presence constraint for WithComponents * presence constraint for NamedConstraint
*/ */
optPresenceConstraint: optPresenceConstraint:
{ $$ = ACPRES_DEFAULT; } { $$ = ACPRES_DEFAULT; }
...@@ -2361,6 +2359,17 @@ Identifier: ...@@ -2361,6 +2359,17 @@ Identifier:
} }
; ;
IdentifierAsReference:
Identifier {
$$ = asn1p_ref_new(yylineno, currentModule);
asn1p_ref_add_component($$, $1, RLT_lowercase);
};
IdentifierAsValue:
IdentifierAsReference {
$$ = asn1p_value_fromref($1, 0);
};
%% %%
...@@ -2505,8 +2514,8 @@ yyerror(const char *msg) { ...@@ -2505,8 +2514,8 @@ yyerror(const char *msg) {
extern char *asn1p_text; extern char *asn1p_text;
fprintf(stderr, fprintf(stderr,
"ASN.1 grammar parse error " "ASN.1 grammar parse error "
"near line %d (token \"%s\"): %s\n", "near %s:%d (token \"%s\"): %s\n",
yylineno, asn1p_text, msg); ASN_FILENAME, yylineno, asn1p_text, msg);
return -1; return -1;
} }
...@@ -38,7 +38,9 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla ...@@ -38,7 +38,9 @@ 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;
...@@ -106,7 +108,9 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) { ...@@ -106,7 +108,9 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) {
asn1p_restart(fp); asn1p_restart(fp);
ap = (void *)&a; ap = (void *)&a;
asn1p_parse_debug_filename = filename;
ret = asn1p_parse(ap); ret = asn1p_parse(ap);
asn1p_parse_debug_filename = NULL;
fclose(fp); fclose(fp);
......
...@@ -43,6 +43,8 @@ asn1p_t *asn1p_parse_file(const char *filename, ...@@ -43,6 +43,8 @@ asn1p_t *asn1p_parse_file(const char *filename,
asn1p_t *asn1p_parse_buffer(const char *buffer, int size /* = -1 */, asn1p_t *asn1p_parse_buffer(const char *buffer, int size /* = -1 */,
enum asn1p_flags); enum asn1p_flags);
extern const char *asn1p_parse_debug_filename;
int asn1p_lex_destroy(); int asn1p_lex_destroy();
#endif /* ASN1PARSER_H */ #endif /* ASN1PARSER_H */
...@@ -337,6 +337,7 @@ asn1p_constraint_string(const asn1p_constraint_t *ct) { ...@@ -337,6 +337,7 @@ asn1p_constraint_string(const asn1p_constraint_t *ct) {
static int static int
asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) { asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
int symno = 0; int symno = 0;
int perhaps_subconstraints = 0;
if(ct == 0) return 0; if(ct == 0) return 0;
...@@ -346,9 +347,11 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) { ...@@ -346,9 +347,11 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
switch(ct->type) { switch(ct->type) {
case ACT_EL_TYPE: case ACT_EL_TYPE:
asn1print_value(ct->containedSubtype, flags); asn1print_value(ct->containedSubtype, flags);
perhaps_subconstraints = 1;
break; break;
case ACT_EL_VALUE: case ACT_EL_VALUE:
asn1print_value(ct->value, flags); asn1print_value(ct->value, flags);
perhaps_subconstraints = 1;
break; break;
case ACT_EL_RANGE: case ACT_EL_RANGE:
case ACT_EL_LLRANGE: case ACT_EL_LLRANGE:
...@@ -382,9 +385,8 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) { ...@@ -382,9 +385,8 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
case ACT_CT_WCOMP: case ACT_CT_WCOMP:
assert(ct->el_count != 0); assert(ct->el_count != 0);
assert(ct->el_count == 1); assert(ct->el_count == 1);
safe_printf("WITH COMPONENT ("); safe_printf("WITH COMPONENT");
asn1print_constraint(ct->elements[0], flags); perhaps_subconstraints = 1;
safe_printf(")");
break; break;
case ACT_CT_WCOMPS: { case ACT_CT_WCOMPS: {
unsigned int i; unsigned int i;
...@@ -392,14 +394,7 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) { ...@@ -392,14 +394,7 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
for(i = 0; i < ct->el_count; i++) { for(i = 0; i < ct->el_count; i++) {
asn1p_constraint_t *cel = ct->elements[i]; asn1p_constraint_t *cel = ct->elements[i];
if(i) safe_printf(", "); if(i) safe_printf(", ");
safe_fwrite(cel->value->value.string.buf, asn1print_constraint(cel, flags);
cel->value->value.string.size);
if(cel->el_count) {
assert(cel->el_count == 1);
safe_printf(" ");
asn1print_constraint(cel->elements[0],
flags);
}
switch(cel->presence) { switch(cel->presence) {
case ACPRES_DEFAULT: break; case ACPRES_DEFAULT: break;
case ACPRES_PRESENT: safe_printf(" PRESENT"); break; case ACPRES_PRESENT: safe_printf(" PRESENT"); break;
...@@ -441,22 +436,27 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) { ...@@ -441,22 +436,27 @@ asn1print_constraint(const asn1p_constraint_t *ct, enum asn1print_flags flags) {
if(ct->type == ACT_CA_CRC) safe_printf("{"); if(ct->type == ACT_CA_CRC) safe_printf("{");
asn1print_constraint(ct->elements[i], flags); asn1print_constraint(ct->elements[i], flags);
if(ct->type == ACT_CA_CRC) safe_printf("}"); if(ct->type == ACT_CA_CRC) safe_printf("}");
if(i+1 < ct->el_count if(ct->type == ACT_CA_SET && i+1 < ct->el_count)
&& ct->type == ACT_CA_SET) safe_printf(") ");
safe_printf(")");
} }
} }
break; break;
case ACT_CA_AEX: case ACT_CA_AEX:
assert(ct->el_count == 1); assert(ct->el_count == 1);
safe_printf("ALL EXCEPT "); safe_printf("ALL EXCEPT");
asn1print_constraint(ct->elements[0], flags); perhaps_subconstraints = 1;
break; break;
case ACT_INVALID: case ACT_INVALID:
assert(ct->type != ACT_INVALID); assert(ct->type != ACT_INVALID);
break; break;
} }
if(perhaps_subconstraints && ct->el_count) {
safe_printf(" ");
assert(ct->el_count == 1);
asn1print_constraint(ct->elements[0], flags);
}
if(ct->type == ACT_CA_SET) if(ct->type == ACT_CA_SET)
safe_printf(")"); safe_printf(")");
...@@ -591,8 +591,25 @@ asn1print_constraint_explain(const char *dbg_name, asn1p_expr_type_e expr_type, ...@@ -591,8 +591,25 @@ asn1print_constraint_explain(const char *dbg_name, asn1p_expr_type_e expr_type,
static int static int
asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level) { asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1print_flags flags, int level) {
int SEQ_OF = 0; int SEQ_OF = 0;
int has_space = 0;
if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT)) #define HAS_SPACE() \
do { \
has_space = 1; \
} while(0)
#define ENSURE_SPACE() \
do { \
if(!has_space) { \
has_space = 1; \
safe_printf(" "); \
} \
} while(0)
#define WANT_SPACE() \
do { \
has_space = 0; \
} while(0)
if(flags & APF_LINE_COMMENTS && !(flags & APF_NOINDENT))
INDENT("-- #line %d\n", tc->_lineno); INDENT("-- #line %d\n", tc->_lineno);
/* Reconstruct compiler directive information */ /* Reconstruct compiler directive information */
...@@ -606,8 +623,10 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri ...@@ -606,8 +623,10 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
if(tc->Identifier if(tc->Identifier
&& (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE) && (!(tc->meta_type == AMT_VALUE && tc->expr_type == A1TC_REFERENCE)
|| level == 0)) || level == 0)) {
INDENT("%s", tc->Identifier); INDENT("%s", tc->Identifier);
WANT_SPACE();
}
if(tc->lhs_params) { if(tc->lhs_params) {
asn1print_params(tc->lhs_params, flags); asn1print_params(tc->lhs_params, flags);
...@@ -619,14 +638,17 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri ...@@ -619,14 +638,17 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
if(level) { if(level) {
if(tc->Identifier && !(flags & APF_NOINDENT)) if(tc->Identifier && !(flags & APF_NOINDENT))
safe_printf("\t"); safe_printf("\t");
} else { } else if(tc->Identifier) {
safe_printf(" ::="); ENSURE_SPACE();
safe_printf("::=");
WANT_SPACE();
} }
} }
if(tc->tag.tag_class) { if(tc->tag.tag_class) {
safe_printf(" "); ENSURE_SPACE();
asn1print_tag(tc, flags); asn1print_tag(tc, flags);
WANT_SPACE();
} }
switch(tc->expr_type) { switch(tc->expr_type) {
...@@ -639,12 +661,14 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri ...@@ -639,12 +661,14 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
case A1TC_COMPONENTS_OF: case A1TC_COMPONENTS_OF:
SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */ SEQ_OF = 1; /* Equivalent to SET OF for printint purposes */
safe_printf(" COMPONENTS OF"); safe_printf(" COMPONENTS OF");
WANT_SPACE();
break; break;
case A1TC_REFERENCE: case A1TC_REFERENCE:
case A1TC_UNIVERVAL: case A1TC_UNIVERVAL:
break; break;
case A1TC_CLASSDEF: case A1TC_CLASSDEF:
safe_printf(" CLASS"); safe_printf(" CLASS");
WANT_SPACE();
break; break;
case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS: case A1TC_CLASSFIELD_TFS ... A1TC_CLASSFIELD_OSFS:
/* Nothing to print here */ /* Nothing to print here */
...@@ -652,22 +676,26 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri ...@@ -652,22 +676,26 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
case ASN_CONSTR_SET_OF: case ASN_CONSTR_SET_OF:
case ASN_CONSTR_SEQUENCE_OF: case ASN_CONSTR_SEQUENCE_OF:
SEQ_OF = 1; SEQ_OF = 1;
ENSURE_SPACE();
if(tc->expr_type == ASN_CONSTR_SET_OF) if(tc->expr_type == ASN_CONSTR_SET_OF)
safe_printf(" SET"); safe_printf("SET");
else else
safe_printf(" SEQUENCE"); safe_printf("SEQUENCE");
if(tc->constraints) { if(tc->constraints) {
safe_printf(" "); safe_printf(" ");
asn1print_constraint(tc->constraints, flags); asn1print_constraint(tc->constraints, flags);
} }
safe_printf(" OF"); safe_printf(" OF");
WANT_SPACE();
break; break;
case A1TC_VALUESET: case A1TC_VALUESET:
break; break;
default: default:
{ {
char *p = ASN_EXPR_TYPE2STR(tc->expr_type); char *p = ASN_EXPR_TYPE2STR(tc->expr_type);
safe_printf(" %s", p?p:"<unknown type!>"); ENSURE_SPACE();
safe_printf("%s", p?p:"<unknown type!>");
WANT_SPACE();
} }
break; break;
} }
...@@ -676,12 +704,16 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri ...@@ -676,12 +704,16 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
* Put the name of the referred type. * Put the name of the referred type.
*/ */
if(tc->reference) { if(tc->reference) {
safe_printf(" "); ENSURE_SPACE();
asn1print_ref(tc->reference, flags); asn1print_ref(tc->reference, flags);
WANT_SPACE();
} }
if(tc->meta_type == AMT_VALUESET && level == 0) if(tc->meta_type == AMT_VALUESET && level == 0) {
safe_printf(" ::="); ENSURE_SPACE();
safe_printf("::=");
WANT_SPACE();
}
/* /*
* Display the descendants (children) of the current type. * Display the descendants (children) of the current type.
...@@ -775,7 +807,7 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri ...@@ -775,7 +807,7 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
safe_printf(")"); safe_printf(")");
} }
} else { } else {
if(level == 0) safe_printf(" ::= "); if(level == 0 && tc->Identifier) safe_printf(" ::= ");
asn1print_value(tc->value, flags); asn1print_value(tc->value, flags);
} }
} }
......
...@@ -14,7 +14,7 @@ BEGIN ...@@ -14,7 +14,7 @@ BEGIN
PCLASS {Type, INTEGER:value, INTEGER:ValueSet} ::= CLASS { PCLASS {Type, INTEGER:value, INTEGER:ValueSet} ::= CLASS {
&valueField1 Type, &valueField1 Type,
&valueField2 INTEGER DEFAULT value, &valueField2 INTEGER DEFAULT value,
&valueField3 INTEGER (ValueSet), &valueField3 INTEGER ({ValueSet}),
&ValueSetField INTEGER DEFAULT {ValueSet} &ValueSetField INTEGER DEFAULT {ValueSet}
} WITH SYNTAX { } WITH SYNTAX {
&valueField1, &valueField2, &valueField3, &ValueSetField } &valueField1, &valueField2, &valueField3, &ValueSetField }
......
...@@ -6,7 +6,7 @@ BEGIN ...@@ -6,7 +6,7 @@ BEGIN
PCLASS{Type, INTEGER:value, INTEGER:ValueSet} ::= CLASS { PCLASS{Type, INTEGER:value, INTEGER:ValueSet} ::= CLASS {
&valueField1 Type, &valueField1 Type,
&valueField2 INTEGER DEFAULT value, &valueField2 INTEGER DEFAULT value,
&valueField3 INTEGER (ValueSet), &valueField3 INTEGER ({ValueSet}),
&ValueSetField INTEGER DEFAULT {ValueSet} &ValueSetField INTEGER DEFAULT {ValueSet}
} WITH SYNTAX { } WITH SYNTAX {
&valueField1, &valueField2, &valueField3, &ValueSetField } &valueField1, &valueField2, &valueField3, &ValueSetField }
......
...@@ -3,6 +3,6 @@ ModuleMultiConstraint { iso org(3) dod(6) internet(1) private(4) enterprise(1) ...@@ -3,6 +3,6 @@ ModuleMultiConstraint { iso org(3) dod(6) internet(1) private(4) enterprise(1)
DEFINITIONS AUTOMATIC TAGS ::= DEFINITIONS AUTOMATIC TAGS ::=
BEGIN BEGIN
T ::= VisibleString (PATTERN "^[a-z]+$")(CONSTRAINED BY { ... }) T ::= VisibleString (PATTERN "^[a-z]+$") (CONSTRAINED BY { ... })
END END
-- SE: Semantic error
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .149
ModuleComplexWithComponents
{ iso org(3) dod(6) internet(1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 149 }
DEFINITIONS ::= BEGIN
Certificate ::= ExplicitCertificate (WITH COMPONENTS { ...,
issuer (WITH COMPONENTS {sha256AndDigest}),
toBeSigned (WITH COMPONENTS { ...,
id (WITH COMPONENTS {
name ("foo" | "bar") -- Some comment
}),
crlSeries(ScmsSpclComponentCrlSeries),
validityPeriod (WITH COMPONENTS { ...,
duration (CrlgCertExpiration)
}),
region (WITH COMPONENTS {
identifiedRegion (SequenceOfIdentifiedRegion (SIZE(3)) (CONSTRAINED BY {
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Canada) }),
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Mexico) }),
IdentifiedRegion ( WITH COMPONENTS { countryOnly(USA) })
}))
}),
canRequestRollover (NULL),
encryptionKey ABSENT,
verifyKeyIndicator (WITH COMPONENTS {
verificationKey (WITH COMPONENTS {
ecdsaNistP256 (WITH COMPONENTS {
compressed-y-0, compressed-y-1
})
})
})
})
})
END
ModuleComplexWithComponents { iso org(3) dod(6) internet(1) private(4)
enterprise(1) spelio(9363) software(1) asn1c(5) test(1) 149 }
DEFINITIONS ::=
BEGIN
Certificate ::= ExplicitCertificate (WITH COMPONENTS { ..., issuer (WITH COMPONENTS { sha256AndDigest }), toBeSigned (WITH COMPONENTS { ..., id (WITH COMPONENTS { name ("foo" | "bar") }), crlSeries ( ScmsSpclComponentCrlSeries), validityPeriod (WITH COMPONENTS { ..., duration ( CrlgCertExpiration) }), region (WITH COMPONENTS { identifiedRegion ( SequenceOfIdentifiedRegion (SIZE(3)) (CONSTRAINED BY {
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Canada) }),
IdentifiedRegion ( WITH COMPONENTS { countryOnly(Mexico) }),
IdentifiedRegion ( WITH COMPONENTS { countryOnly(USA) })
})) }), canRequestRollover ( NULL), encryptionKey ABSENT, verifyKeyIndicator (WITH COMPONENTS { verificationKey (WITH COMPONENTS { ecdsaNistP256 (WITH COMPONENTS { compressed-y-0, compressed-y-1 }) }) }) }) })
END
...@@ -3,9 +3,9 @@ ModuleTestConstraint1 { iso org(3) dod(6) internet(1) private(4) enterprise(1) ...@@ -3,9 +3,9 @@ ModuleTestConstraint1 { iso org(3) dod(6) internet(1) private(4) enterprise(1)
DEFINITIONS ::= DEFINITIONS ::=
BEGIN BEGIN
Type0 ::= IA5String (((SIZE(1..10))(FROM("a".."z" | "#")))) Type0 ::= IA5String (((SIZE(1..10)) (FROM("a".."z" | "#"))))
Type6 ::= IA5String ((SIZE(1..10))(FROM("a".."z" | "#"))) Type6 ::= IA5String ((SIZE(1..10)) (FROM("a".."z" | "#")))
END END
...@@ -14,7 +14,7 @@ ModuleTestConstraint2 { iso org(3) dod(6) internet(1) private(4) enterprise(1) ...@@ -14,7 +14,7 @@ ModuleTestConstraint2 { iso org(3) dod(6) internet(1) private(4) enterprise(1)
DEFINITIONS ::= DEFINITIONS ::=
BEGIN BEGIN
Type1 ::= IA5String (SIZE(1..10,...))(FROM("a".."z" | "#",...)) Type1 ::= IA5String (SIZE(1..10,...)) (FROM("a".."z" | "#",...))
Type2 ::= IA5String (SIZE(MIN..4) | FROM("abc")) Type2 ::= IA5String (SIZE(MIN..4) | FROM("abc"))
......
...@@ -14,7 +14,7 @@ BEGIN ...@@ -14,7 +14,7 @@ BEGIN
SIGNED { ToBeSigned } ::= SEQUENCE { SIGNED { ToBeSigned } ::= SEQUENCE {
toBeSigned ToBeSigned, toBeSigned ToBeSigned,
algorithm OBJECT IDENTIFIER, algorithm OBJECT IDENTIFIER,
signature BIT STRING SIZE(0..256) signature BIT STRING (SIZE(0..256))
} }
Certificate ::= SIGNED { SEQUENCE { Certificate ::= SIGNED { SEQUENCE {
......
...@@ -6,7 +6,7 @@ BEGIN ...@@ -6,7 +6,7 @@ BEGIN
SIGNED{ToBeSigned} ::= SEQUENCE { SIGNED{ToBeSigned} ::= SEQUENCE {
toBeSigned ToBeSigned, toBeSigned ToBeSigned,
algorithm OBJECT IDENTIFIER, algorithm OBJECT IDENTIFIER,
signature BIT STRING SIZE(0..256) signature BIT STRING (SIZE(0..256))
} }
Certificate ::= SIGNED{ SEQUENCE { Certificate ::= SIGNED{ SEQUENCE {
......
...@@ -31,13 +31,13 @@ BEGIN ...@@ -31,13 +31,13 @@ BEGIN
Type2 ::= CHOICE { Type2 ::= CHOICE {
one-name SEQUENCE { one-name SEQUENCE {
another-name SEQUENCE { another-name SEQUENCE {
a BIT STRING { one(0) } SIZE(2), a BIT STRING { one(0) } (SIZE(2)),
b INTEGER b INTEGER
} }
}, },
two-name SET { two-name SET {
another-name SEQUENCE { another-name SEQUENCE {
a BIT STRING { one(0) } SIZE(2), a BIT STRING { one(0) } (SIZE(2)),
b INTEGER b INTEGER
} }
} }
......
...@@ -34,7 +34,7 @@ Int ::= INTEGER { ...@@ -34,7 +34,7 @@ Int ::= INTEGER {
-- PER-visible constraints (Int): (123) -- PER-visible constraints (Int): (123)
EnumRef ::= Enum (1) EnumRef ::= Enum (1)
-- Combined constraints: (1 | 0)(1) -- Combined constraints: (1 | 0) (1)
-- Practical constraints (Enum): (1) -- Practical constraints (Enum): (1)
-- OER-visible constraints (Enum): (1) -- OER-visible constraints (Enum): (1)
-- PER-visible constraints (Enum): (1) -- PER-visible constraints (Enum): (1)
......
...@@ -5,7 +5,7 @@ BEGIN ...@@ -5,7 +5,7 @@ BEGIN
BunchOfStrings ::= SEQUENCE OF VisibleString BunchOfStrings ::= SEQUENCE OF VisibleString
Address ::= BunchOfStrings (SIZE(1..6))(WITH COMPONENT (SIZE(1..32))) Address ::= BunchOfStrings (SIZE(1..6)) (WITH COMPONENT (SIZE(1..32)))
Type ::= SEQUENCE { Type ::= SEQUENCE {
one INTEGER DEFAULT 1 one INTEGER DEFAULT 1
......
...@@ -11,10 +11,10 @@ ModuleTestWithComponents2 ...@@ -11,10 +11,10 @@ ModuleTestWithComponents2
DEFINITIONS ::= DEFINITIONS ::=
BEGIN BEGIN
Type1 ::= SET {} Type1 ::= SET { foo INTEGER OPTIONAL }
Type2 ::= SET { Type2 ::= SET {
COMPONENTS OF Type1 (WITH COMPONENTS { ... }) COMPONENTS OF Type1 (WITH COMPONENTS { ..., foo ABSENT })
} }
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