Commit 070a52d8 authored by Lev Walkin's avatar Lev Walkin

COMPONENTS OF support and other enhancements

parent a09e5da5
...@@ -23,9 +23,10 @@ asn1p_expr_new(int _lineno) { ...@@ -23,9 +23,10 @@ asn1p_expr_new(int _lineno) {
} }
asn1p_expr_t * asn1p_expr_t *
asn1p_expr_clone(asn1p_expr_t *expr) { asn1p_expr_clone(asn1p_expr_t *expr, int skip_extensions) {
asn1p_expr_t *clone; asn1p_expr_t *clone;
asn1p_expr_t *tcmemb; /* Child of tc */ asn1p_expr_t *tcmemb; /* Child of tc */
int hit_ext = 0;
clone = asn1p_expr_new(expr->_lineno); clone = asn1p_expr_new(expr->_lineno);
if(clone == NULL) return NULL; if(clone == NULL) return NULL;
...@@ -45,7 +46,8 @@ asn1p_expr_clone(asn1p_expr_t *expr) { ...@@ -45,7 +46,8 @@ asn1p_expr_clone(asn1p_expr_t *expr) {
CLCOPY(meta_type); CLCOPY(meta_type);
CLCOPY(expr_type); CLCOPY(expr_type);
CLCOPY(tag); CLCOPY(tag);
CLCOPY(marker); CLCOPY(marker); /* OPTIONAL/DEFAULT */
CLCOPY(module);
CLCOPY(_mark); CLCOPY(_mark);
clone->data = 0; /* Do not clone this */ clone->data = 0; /* Do not clone this */
...@@ -66,7 +68,16 @@ asn1p_expr_clone(asn1p_expr_t *expr) { ...@@ -66,7 +68,16 @@ asn1p_expr_clone(asn1p_expr_t *expr) {
* Copy all the children of this expr. * Copy all the children of this expr.
*/ */
TQ_FOR(tcmemb, &(expr->members), next) { TQ_FOR(tcmemb, &(expr->members), next) {
asn1p_expr_t *cmemb = asn1p_expr_clone(tcmemb); asn1p_expr_t *cmemb;
if(skip_extensions
&& tcmemb->expr_type == A1TC_EXTENSIBLE) {
hit_ext++; /* Even if hit_ext wraps around, we're OK. */
continue;
}
if(hit_ext == 1) continue; /* Skip between ...'s */
cmemb = asn1p_expr_clone(tcmemb, skip_extensions);
if(cmemb == NULL) { if(cmemb == NULL) {
asn1p_expr_free(clone); asn1p_expr_free(clone);
return NULL; return NULL;
......
...@@ -35,12 +35,14 @@ typedef enum asn1p_expr_type { ...@@ -35,12 +35,14 @@ typedef enum asn1p_expr_type {
A1TC_BITVECTOR, /* A plain collection of bits */ A1TC_BITVECTOR, /* A plain collection of bits */
A1TC_OPAQUE, /* Opaque data encoded as a bitvector */ A1TC_OPAQUE, /* Opaque data encoded as a bitvector */
A1TC_EXTENSIBLE, /* An extension marker "..." */ A1TC_EXTENSIBLE, /* An extension marker "..." */
A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
A1TC_PARAMETRIZED, /* A parametrized type declaration */ A1TC_PARAMETRIZED, /* A parametrized type declaration */
A1TC_VALUESET, /* Value set definition */ A1TC_VALUESET, /* Value set definition */
A1TC_CLASSDEF, /* Information Object Class */ A1TC_CLASSDEF, /* Information Object Class */
A1TC_CLASSFIELD, /* Information Object Class field */ A1TC_CLASSFIELD, /* Information Object Class field */
A1TC_INSTANCE, /* Instance of Object Class */ A1TC_INSTANCE, /* Instance of Object Class */
A1TC_TYPEID, /* Type identifier */ A1TC_TYPEID, /* Type identifier */
/* /*
* ASN.1 Constructed types * ASN.1 Constructed types
*/ */
...@@ -69,6 +71,7 @@ typedef enum asn1p_expr_type { ...@@ -69,6 +71,7 @@ typedef enum asn1p_expr_type {
ASN_BASIC_CHARACTER_STRING, ASN_BASIC_CHARACTER_STRING,
ASN_BASIC_UTCTime, ASN_BASIC_UTCTime,
ASN_BASIC_GeneralizedTime, ASN_BASIC_GeneralizedTime,
/* /*
* ASN.1 String types * ASN.1 String types
*/ */
...@@ -93,6 +96,8 @@ typedef enum asn1p_expr_type { ...@@ -93,6 +96,8 @@ typedef enum asn1p_expr_type {
#include "asn1p_expr_str.h" #include "asn1p_expr_str.h"
#include "asn1p_expr2uclass.h" #include "asn1p_expr2uclass.h"
struct asn1p_module_s; /* Forward declaration */
/* /*
* A named collection of types. * A named collection of types.
*/ */
...@@ -192,6 +197,9 @@ typedef struct asn1p_expr_s { ...@@ -192,6 +197,9 @@ typedef struct asn1p_expr_s {
* grammar source. * grammar source.
*/ */
int _lineno; int _lineno;
struct asn1p_module_s *module; /* Defined in module */
/* /*
* Marks are used for various purposes. * Marks are used for various purposes.
* Here are some predefined ones. * Here are some predefined ones.
...@@ -201,6 +209,8 @@ typedef struct asn1p_expr_s { ...@@ -201,6 +209,8 @@ typedef struct asn1p_expr_s {
TM_RECURSION, /* Used to break recursion */ TM_RECURSION, /* Used to break recursion */
} _mark; } _mark;
int _anonymous_type; /* Used by the compiler */
/* /*
* Opaque data may be attached to this structure, * Opaque data may be attached to this structure,
* probably by compiler. * probably by compiler.
...@@ -214,7 +224,7 @@ typedef struct asn1p_expr_s { ...@@ -214,7 +224,7 @@ typedef struct asn1p_expr_s {
* Constructor and destructor. * Constructor and destructor.
*/ */
asn1p_expr_t *asn1p_expr_new(int _lineno); asn1p_expr_t *asn1p_expr_new(int _lineno);
asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *); asn1p_expr_t *asn1p_expr_clone(asn1p_expr_t *, int skip_extensions);
void asn1p_expr_free(asn1p_expr_t *expr); void asn1p_expr_free(asn1p_expr_t *expr);
#endif /* ASN1_PARSER_EXPR_H */ #endif /* ASN1_PARSER_EXPR_H */
This diff is collapsed.
...@@ -218,9 +218,8 @@ static asn1p_value_t * ...@@ -218,9 +218,8 @@ static asn1p_value_t *
%type <a_xports> ExportsBody %type <a_xports> ExportsBody
%type <a_expr> ImportsElement %type <a_expr> ImportsElement
%type <a_expr> ExportsElement %type <a_expr> ExportsElement
%type <a_expr> DataTypeMember
%type <a_expr> ExtensionAndException %type <a_expr> ExtensionAndException
%type <a_expr> UnconstrainedTypeDeclaration %type <a_expr> TypeDeclaration
%type <a_ref> ComplexTypeReference %type <a_ref> ComplexTypeReference
%type <a_ref> ComplexTypeReferenceAmpList %type <a_ref> ComplexTypeReferenceAmpList
%type <a_refcomp> ComplexTypeReferenceElement %type <a_refcomp> ComplexTypeReferenceElement
...@@ -229,7 +228,7 @@ static asn1p_value_t * ...@@ -229,7 +228,7 @@ static asn1p_value_t *
%type <a_expr> ClassFieldList %type <a_expr> ClassFieldList
%type <a_expr> ClassField %type <a_expr> ClassField
%type <a_expr> ClassDeclaration %type <a_expr> ClassDeclaration
%type <a_expr> ConstrainedTypeDeclaration %type <a_expr> Type
%type <a_expr> DataTypeReference /* Type1 ::= Type2 */ %type <a_expr> DataTypeReference /* Type1 ::= Type2 */
%type <a_expr> DefinedTypeRef %type <a_expr> DefinedTypeRef
%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */ %type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
...@@ -238,9 +237,10 @@ static asn1p_value_t * ...@@ -238,9 +237,10 @@ static asn1p_value_t *
%type <a_value> InlineOrDefinedValue %type <a_value> InlineOrDefinedValue
%type <a_value> DefinedValue %type <a_value> DefinedValue
%type <a_value> SignedNumber %type <a_value> SignedNumber
%type <a_expr> ConstructedType %type <a_expr> ComponentTypeLists
%type <a_expr> ConstructedTypeConstrained %type <a_expr> ComponentType
%type <a_expr> ConstructedDataTypeDefinition %type <a_expr> AlternativeTypeLists
%type <a_expr> AlternativeType
//%type <a_expr> optUniverationDefinition //%type <a_expr> optUniverationDefinition
%type <a_expr> UniverationDefinition %type <a_expr> UniverationDefinition
%type <a_expr> UniverationList %type <a_expr> UniverationList
...@@ -718,7 +718,7 @@ DataTypeReference: ...@@ -718,7 +718,7 @@ DataTypeReference:
$$->expr_type = A1TC_TYPEID; $$->expr_type = A1TC_TYPEID;
$$->meta_type = AMT_TYPE; $$->meta_type = AMT_TYPE;
} }
| TypeRefName TOK_PPEQ optTag ConstrainedTypeDeclaration { | TypeRefName TOK_PPEQ optTag Type {
$$ = $4; $$ = $4;
$$->Identifier = $1; $$->Identifier = $1;
$$->tag = $3; $$->tag = $3;
...@@ -741,8 +741,7 @@ DataTypeReference: ...@@ -741,8 +741,7 @@ DataTypeReference:
* } * }
* === EOF === * === EOF ===
*/ */
| TypeRefName '{' ParameterArgumentList '}' | TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
TOK_PPEQ ConstrainedTypeDeclaration {
$$ = $6; $$ = $6;
assert($$->Identifier == 0); assert($$->Identifier == 0);
$$->Identifier = $1; $$->Identifier = $1;
...@@ -806,7 +805,7 @@ ActualParameterList: ...@@ -806,7 +805,7 @@ ActualParameterList:
; ;
ActualParameter: ActualParameter:
UnconstrainedTypeDeclaration { Type {
$$ = $1; $$ = $1;
} }
| Identifier { | Identifier {
...@@ -821,18 +820,62 @@ ActualParameter: ...@@ -821,18 +820,62 @@ ActualParameter:
/* /*
* A collection of constructed data type members. * A collection of constructed data type members.
*/ */
ConstructedDataTypeDefinition: ComponentTypeLists:
DataTypeMember { ComponentType {
$$ = asn1p_expr_new(yylineno); $$ = asn1p_expr_new(yylineno);
checkmem($$); checkmem($$);
TQ_ADD(&($$->members), $1, next); TQ_ADD(&($$->members), $1, next);
} }
| ConstructedDataTypeDefinition ',' DataTypeMember { | ComponentTypeLists ',' ComponentType {
$$ = $1; $$ = $1;
TQ_ADD(&($$->members), $3, next); TQ_ADD(&($$->members), $3, next);
} }
; ;
ComponentType:
TaggedIdentifier Type optMarker {
$$ = $2;
assert($$->Identifier == 0);
$$->Identifier = $1.name;
$$->tag = $1.tag;
$$->marker = $3;
}
| TOK_COMPONENTS TOK_OF Type {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
$$->meta_type = $3->meta_type;
$$->expr_type = A1TC_COMPONENTS_OF;
TQ_ADD(&($$->members), $3, next);
}
| ExtensionAndException {
$$ = $1;
}
;
AlternativeTypeLists:
AlternativeType {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
TQ_ADD(&($$->members), $1, next);
}
| AlternativeTypeLists ',' AlternativeType {
$$ = $1;
TQ_ADD(&($$->members), $3, next);
}
;
AlternativeType:
TaggedIdentifier Type {
$$ = $2;
assert($$->Identifier == 0);
$$->Identifier = $1.name;
$$->tag = $1.tag;
}
| ExtensionAndException {
$$ = $1;
}
;
ClassDeclaration: ClassDeclaration:
TOK_CLASS '{' ClassFieldList '}' optWithSyntax { TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
$$ = $3; $$ = $3;
...@@ -871,10 +914,11 @@ ClassField: ...@@ -871,10 +914,11 @@ ClassField:
$$->meta_type = AMT_OBJECTFIELD; $$->meta_type = AMT_OBJECTFIELD;
$$->marker = $2; $$->marker = $2;
} }
| ClassFieldIdentifier ConstrainedTypeDeclaration optUnique { | ClassFieldIdentifier Type optMarker optUnique {
$$ = $2; $$ = $2;
$$->Identifier = $1.name; $$->Identifier = $1.name;
$$->unique = $3; $$->marker = $3;
$$->unique = $4;
} }
| ClassFieldIdentifier ClassFieldIdentifier optMarker optUnique { | ClassFieldIdentifier ClassFieldIdentifier optMarker optUnique {
int ret; int ret;
...@@ -935,50 +979,6 @@ WithSyntaxFormatToken: ...@@ -935,50 +979,6 @@ WithSyntaxFormatToken:
} }
; ;
/*
* A data type member goes like this
* ===
* memb1 [0] Type1 { a(1), b(2) } (2)
* ===
* Therefore, we propose a split.
* ^^^^^^^^^ ^^^^^^^^^^
* ^TaggedIdentifier ^TypeDeclaration
* ^ConstrainedTypeDeclaration
*/
/*
* A member of a constructed data type ("a" or "b" in above example).
*/
DataTypeMember:
TaggedIdentifier ConstrainedTypeDeclaration {
$$ = $2;
assert($$->Identifier == 0);
$$->Identifier = $1.name;
$$->tag = $1.tag;
}
| ExtensionAndException {
$$ = $1;
}
;
ConstrainedTypeDeclaration:
UnconstrainedTypeDeclaration optConstraints optMarker {
$$ = $1;
if($$->constraints) {
assert(!$2);
} else {
$$->constraints = $2;
}
$$->marker = $3;
}
| ConstructedTypeConstrained {
/* This type includes constraints on its own */
$$ = $1;
checkmem($$);
assert($$->meta_type);
}
;
ExtensionAndException: ExtensionAndException:
TOK_ThreeDots { TOK_ThreeDots {
$$ = asn1p_expr_new(asn1p_lineno); $$ = asn1p_expr_new(asn1p_lineno);
...@@ -1008,7 +1008,28 @@ ExtensionAndException: ...@@ -1008,7 +1008,28 @@ ExtensionAndException:
} }
; ;
UnconstrainedTypeDeclaration: Type:
TypeDeclaration optConstraints {
$$ = $1;
/*
* Outer constraint for SEQUENCE OF and SET OF applies
* to the inner type.
*/
if($$->expr_type == ASN_CONSTR_SEQUENCE_OF
|| $$->expr_type == ASN_CONSTR_SET_OF) {
assert(!TQ_FIRST(&($$->members))->constraints);
TQ_FIRST(&($$->members))->constraints = $2;
} else {
if($$->constraints) {
assert(!$2);
} else {
$$->constraints = $2;
}
}
}
;
TypeDeclaration:
BasicType { BasicType {
$$ = $1; $$ = $1;
} }
...@@ -1018,11 +1039,58 @@ UnconstrainedTypeDeclaration: ...@@ -1018,11 +1039,58 @@ UnconstrainedTypeDeclaration:
$$->expr_type = $1; $$->expr_type = $1;
$$->meta_type = AMT_TYPE; $$->meta_type = AMT_TYPE;
} }
| ConstructedType { | TOK_CHOICE '{' AlternativeTypeLists '}' {
$$ = $1; $$ = $3;
assert($$->expr_type == A1TC_INVALID);
$$->expr_type = ASN_CONSTR_CHOICE;
$$->meta_type = AMT_TYPE;
}
| TOK_SEQUENCE '{' ComponentTypeLists '}' {
$$ = $3;
assert($$->expr_type == A1TC_INVALID);
$$->expr_type = ASN_CONSTR_SEQUENCE;
$$->meta_type = AMT_TYPE;
}
| TOK_SET '{' ComponentTypeLists '}' {
$$ = $3;
assert($$->expr_type == A1TC_INVALID);
$$->expr_type = ASN_CONSTR_SET;
$$->meta_type = AMT_TYPE;
}
| TOK_SEQUENCE optConstraints TOK_OF TypeDeclaration {
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$); checkmem($$);
assert($$->meta_type); $$->constraints = $2;
$$->expr_type = ASN_CONSTR_SEQUENCE_OF;
$$->meta_type = AMT_TYPE;
TQ_ADD(&($$->members), $4, next);
} }
| TOK_SET optConstraints TOK_OF TypeDeclaration {
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->constraints = $2;
$$->expr_type = ASN_CONSTR_SET_OF;
$$->meta_type = AMT_TYPE;
TQ_ADD(&($$->members), $4, next);
}
| TOK_ANY {
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->expr_type = ASN_CONSTR_ANY;
$$->meta_type = AMT_TYPE;
}
| TOK_ANY TOK_DEFINED TOK_BY Identifier {
int ret;
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->reference = asn1p_ref_new(yylineno);
ret = asn1p_ref_add_component($$->reference,
$4, RLT_lowercase);
checkmem(ret == 0);
$$->expr_type = ASN_CONSTR_ANY;
$$->meta_type = AMT_TYPE;
}
;
/* /*
* A parametrized assignment. * A parametrized assignment.
*/ */
...@@ -1332,63 +1400,6 @@ BasicString: ...@@ -1332,63 +1400,6 @@ BasicString:
; ;
ConstructedTypeConstrained:
TOK_SEQUENCE optConstraints TOK_OF ConstrainedTypeDeclaration {
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->constraints = $2;
$$->expr_type = ASN_CONSTR_SEQUENCE_OF;
$$->meta_type = AMT_TYPE;
TQ_ADD(&($$->members), $4, next);
}
| TOK_SET optConstraints TOK_OF ConstrainedTypeDeclaration {
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->constraints = $2;
$$->expr_type = ASN_CONSTR_SET_OF;
$$->meta_type = AMT_TYPE;
TQ_ADD(&($$->members), $4, next);
}
;
ConstructedType:
TOK_CHOICE '{' ConstructedDataTypeDefinition '}' {
$$ = $3;
assert($$->expr_type == A1TC_INVALID);
$$->expr_type = ASN_CONSTR_CHOICE;
$$->meta_type = AMT_TYPE;
}
| TOK_SEQUENCE '{' ConstructedDataTypeDefinition '}' {
$$ = $3;
assert($$->expr_type == A1TC_INVALID);
$$->expr_type = ASN_CONSTR_SEQUENCE;
$$->meta_type = AMT_TYPE;
}
| TOK_SET '{' ConstructedDataTypeDefinition '}' {
$$ = $3;
assert($$->expr_type == A1TC_INVALID);
$$->expr_type = ASN_CONSTR_SET;
$$->meta_type = AMT_TYPE;
}
| TOK_ANY {
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->expr_type = ASN_CONSTR_ANY;
$$->meta_type = AMT_TYPE;
}
| TOK_ANY TOK_DEFINED TOK_BY Identifier {
int ret;
$$ = asn1p_expr_new(asn1p_lineno);
checkmem($$);
$$->reference = asn1p_ref_new(yylineno);
ret = asn1p_ref_add_component($$->reference,
$4, RLT_lowercase);
checkmem(ret == 0);
$$->expr_type = ASN_CONSTR_ANY;
$$->meta_type = AMT_TYPE;
}
;
/* /*
* Data type constraints. * Data type constraints.
*/ */
......
...@@ -17,7 +17,7 @@ void *asn1p_restart(FILE *); ...@@ -17,7 +17,7 @@ void *asn1p_restart(FILE *);
extern int asn1p_lineno; extern int asn1p_lineno;
static int _asn1p_set_flags(enum asn1p_flags flags); static int _asn1p_set_flags(enum asn1p_flags flags);
static int _asn1p_assign_filename(asn1p_t *a, const char *fname); static int _asn1p_fix_modules(asn1p_t *a, const char *fname);
/* /*
* Parse the given buffer. * Parse the given buffer.
...@@ -52,7 +52,7 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla ...@@ -52,7 +52,7 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla
if(ret == 0) { if(ret == 0) {
assert(a); assert(a);
if(_asn1p_assign_filename(a, "-")) if(_asn1p_fix_modules(a, "-"))
return NULL; /* FIXME: destroy (a) */ return NULL; /* FIXME: destroy (a) */
} else { } else {
assert(a == NULL); assert(a == NULL);
...@@ -104,7 +104,7 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) { ...@@ -104,7 +104,7 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) {
if(ret == 0) { if(ret == 0) {
assert(a); assert(a);
if(_asn1p_assign_filename(a, filename)) if(_asn1p_fix_modules(a, filename))
return NULL; /* FIXME: destroy (a) */ return NULL; /* FIXME: destroy (a) */
} else { } else {
assert(a == NULL); assert(a == NULL);
...@@ -159,13 +159,38 @@ _asn1p_set_flags(enum asn1p_flags flags) { ...@@ -159,13 +159,38 @@ _asn1p_set_flags(enum asn1p_flags flags) {
return 0; return 0;
} }
/*
* Perform last touches.
*/
static void
_asn1p_apply_module2expr(asn1p_expr_t *expr, asn1p_module_t *mod) {
asn1p_expr_t *e;
expr->module = mod; /* This is a useful thing */
/*
* Do it to children also.
*/
TQ_FOR(e, &(expr->members), next) {
_asn1p_apply_module2expr(e, mod);
}
}
static int static int
_asn1p_assign_filename(asn1p_t *a, const char *fname) { _asn1p_fix_modules(asn1p_t *a, const char *fname) {
asn1p_module_t *mod; asn1p_module_t *mod;
TQ_FOR(mod, &(a->modules), mod_next) { TQ_FOR(mod, &(a->modules), mod_next) {
asn1p_expr_t *expr;
mod->source_file_name = strdup(fname); mod->source_file_name = strdup(fname);
if(mod->source_file_name == NULL) if(mod->source_file_name == NULL)
return -1; return -1;
TQ_FOR(expr, &(mod->members), next) {
_asn1p_apply_module2expr(expr, mod);
}
} }
return 0; return 0;
} }
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