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) {
}
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 *tcmemb; /* Child of tc */
int hit_ext = 0;
clone = asn1p_expr_new(expr->_lineno);
if(clone == NULL) return NULL;
......@@ -45,7 +46,8 @@ asn1p_expr_clone(asn1p_expr_t *expr) {
CLCOPY(meta_type);
CLCOPY(expr_type);
CLCOPY(tag);
CLCOPY(marker);
CLCOPY(marker); /* OPTIONAL/DEFAULT */
CLCOPY(module);
CLCOPY(_mark);
clone->data = 0; /* Do not clone this */
......@@ -66,7 +68,16 @@ asn1p_expr_clone(asn1p_expr_t *expr) {
* Copy all the children of this expr.
*/
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) {
asn1p_expr_free(clone);
return NULL;
......
......@@ -35,12 +35,14 @@ typedef enum asn1p_expr_type {
A1TC_BITVECTOR, /* A plain collection of bits */
A1TC_OPAQUE, /* Opaque data encoded as a bitvector */
A1TC_EXTENSIBLE, /* An extension marker "..." */
A1TC_COMPONENTS_OF, /* COMPONENTS OF clause */
A1TC_PARAMETRIZED, /* A parametrized type declaration */
A1TC_VALUESET, /* Value set definition */
A1TC_CLASSDEF, /* Information Object Class */
A1TC_CLASSFIELD, /* Information Object Class field */
A1TC_INSTANCE, /* Instance of Object Class */
A1TC_TYPEID, /* Type identifier */
/*
* ASN.1 Constructed types
*/
......@@ -69,6 +71,7 @@ typedef enum asn1p_expr_type {
ASN_BASIC_CHARACTER_STRING,
ASN_BASIC_UTCTime,
ASN_BASIC_GeneralizedTime,
/*
* ASN.1 String types
*/
......@@ -93,6 +96,8 @@ typedef enum asn1p_expr_type {
#include "asn1p_expr_str.h"
#include "asn1p_expr2uclass.h"
struct asn1p_module_s; /* Forward declaration */
/*
* A named collection of types.
*/
......@@ -192,6 +197,9 @@ typedef struct asn1p_expr_s {
* grammar source.
*/
int _lineno;
struct asn1p_module_s *module; /* Defined in module */
/*
* Marks are used for various purposes.
* Here are some predefined ones.
......@@ -201,6 +209,8 @@ typedef struct asn1p_expr_s {
TM_RECURSION, /* Used to break recursion */
} _mark;
int _anonymous_type; /* Used by the compiler */
/*
* Opaque data may be attached to this structure,
* probably by compiler.
......@@ -214,7 +224,7 @@ typedef struct asn1p_expr_s {
* Constructor and destructor.
*/
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);
#endif /* ASN1_PARSER_EXPR_H */
This diff is collapsed.
......@@ -218,9 +218,8 @@ static asn1p_value_t *
%type <a_xports> ExportsBody
%type <a_expr> ImportsElement
%type <a_expr> ExportsElement
%type <a_expr> DataTypeMember
%type <a_expr> ExtensionAndException
%type <a_expr> UnconstrainedTypeDeclaration
%type <a_expr> TypeDeclaration
%type <a_ref> ComplexTypeReference
%type <a_ref> ComplexTypeReferenceAmpList
%type <a_refcomp> ComplexTypeReferenceElement
......@@ -229,7 +228,7 @@ static asn1p_value_t *
%type <a_expr> ClassFieldList
%type <a_expr> ClassField
%type <a_expr> ClassDeclaration
%type <a_expr> ConstrainedTypeDeclaration
%type <a_expr> Type
%type <a_expr> DataTypeReference /* Type1 ::= Type2 */
%type <a_expr> DefinedTypeRef
%type <a_expr> ValueSetDefinition /* Val INTEGER ::= {1|2} */
......@@ -238,9 +237,10 @@ static asn1p_value_t *
%type <a_value> InlineOrDefinedValue
%type <a_value> DefinedValue
%type <a_value> SignedNumber
%type <a_expr> ConstructedType
%type <a_expr> ConstructedTypeConstrained
%type <a_expr> ConstructedDataTypeDefinition
%type <a_expr> ComponentTypeLists
%type <a_expr> ComponentType
%type <a_expr> AlternativeTypeLists
%type <a_expr> AlternativeType
//%type <a_expr> optUniverationDefinition
%type <a_expr> UniverationDefinition
%type <a_expr> UniverationList
......@@ -718,7 +718,7 @@ DataTypeReference:
$$->expr_type = A1TC_TYPEID;
$$->meta_type = AMT_TYPE;
}
| TypeRefName TOK_PPEQ optTag ConstrainedTypeDeclaration {
| TypeRefName TOK_PPEQ optTag Type {
$$ = $4;
$$->Identifier = $1;
$$->tag = $3;
......@@ -741,8 +741,7 @@ DataTypeReference:
* }
* === EOF ===
*/
| TypeRefName '{' ParameterArgumentList '}'
TOK_PPEQ ConstrainedTypeDeclaration {
| TypeRefName '{' ParameterArgumentList '}' TOK_PPEQ Type {
$$ = $6;
assert($$->Identifier == 0);
$$->Identifier = $1;
......@@ -806,7 +805,7 @@ ActualParameterList:
;
ActualParameter:
UnconstrainedTypeDeclaration {
Type {
$$ = $1;
}
| Identifier {
......@@ -821,18 +820,62 @@ ActualParameter:
/*
* A collection of constructed data type members.
*/
ConstructedDataTypeDefinition:
DataTypeMember {
ComponentTypeLists:
ComponentType {
$$ = asn1p_expr_new(yylineno);
checkmem($$);
TQ_ADD(&($$->members), $1, next);
}
| ConstructedDataTypeDefinition ',' DataTypeMember {
| ComponentTypeLists ',' ComponentType {
$$ = $1;
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:
TOK_CLASS '{' ClassFieldList '}' optWithSyntax {
$$ = $3;
......@@ -871,10 +914,11 @@ ClassField:
$$->meta_type = AMT_OBJECTFIELD;
$$->marker = $2;
}
| ClassFieldIdentifier ConstrainedTypeDeclaration optUnique {
| ClassFieldIdentifier Type optMarker optUnique {
$$ = $2;
$$->Identifier = $1.name;
$$->unique = $3;
$$->marker = $3;
$$->unique = $4;
}
| ClassFieldIdentifier ClassFieldIdentifier optMarker optUnique {
int ret;
......@@ -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:
TOK_ThreeDots {
$$ = asn1p_expr_new(asn1p_lineno);
......@@ -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 {
$$ = $1;
}
......@@ -1018,11 +1039,58 @@ UnconstrainedTypeDeclaration:
$$->expr_type = $1;
$$->meta_type = AMT_TYPE;
}
| ConstructedType {
$$ = $1;
| TOK_CHOICE '{' AlternativeTypeLists '}' {
$$ = $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($$);
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.
*/
......@@ -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.
*/
......
......@@ -17,7 +17,7 @@ void *asn1p_restart(FILE *);
extern int asn1p_lineno;
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.
......@@ -52,7 +52,7 @@ asn1p_parse_buffer(const char *buffer, int size /* = -1 */, enum asn1p_flags fla
if(ret == 0) {
assert(a);
if(_asn1p_assign_filename(a, "-"))
if(_asn1p_fix_modules(a, "-"))
return NULL; /* FIXME: destroy (a) */
} else {
assert(a == NULL);
......@@ -104,7 +104,7 @@ asn1p_parse_file(const char *filename, enum asn1p_flags flags) {
if(ret == 0) {
assert(a);
if(_asn1p_assign_filename(a, filename))
if(_asn1p_fix_modules(a, filename))
return NULL; /* FIXME: destroy (a) */
} else {
assert(a == NULL);
......@@ -159,13 +159,38 @@ _asn1p_set_flags(enum asn1p_flags flags) {
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
_asn1p_assign_filename(asn1p_t *a, const char *fname) {
_asn1p_fix_modules(asn1p_t *a, const char *fname) {
asn1p_module_t *mod;
TQ_FOR(mod, &(a->modules), mod_next) {
asn1p_expr_t *expr;
mod->source_file_name = strdup(fname);
if(mod->source_file_name == NULL)
return -1;
TQ_FOR(expr, &(mod->members), next) {
_asn1p_apply_module2expr(expr, mod);
}
}
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