DEFAULT type support

git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@349 59561ff5-6e30-0410-9f3c-9617f08c8826
This commit is contained in:
vlm 2004-09-15 11:59:51 +00:00
parent 6ac9b0dc46
commit c94e28fa0a
7 changed files with 2175 additions and 2123 deletions

File diff suppressed because it is too large Load Diff

View File

@ -285,7 +285,9 @@ WSP [\t\r\v\f\n ]
}
ABSENT return TOK_ABSENT;
/*
ABSTRACT-SYNTAX return TOK_ABSTRACT_SYNTAX;
*/
ALL return TOK_ALL;
ANY {
/* Appeared in 1990, removed in 1997 */
@ -485,9 +487,10 @@ WITH return TOK_WITH;
yylineno, yytext);
while(YYSTATE != INITIAL)
yy_pop_state();
yy_top_state(); /* Just to use this function. */
yyterminate();
yy_fatal_error("Unexpected token");
if(0) {
yy_top_state(); /* Just to use this function. */
yy_fatal_error("Parse error");
}
return -1;
}

View File

@ -110,13 +110,12 @@ asn1p_value_fromint(asn1_integer_t i) {
asn1p_value_t *
asn1p_value_clone(asn1p_value_t *v) {
asn1p_value_t *clone;
asn1p_value_t *clone = NULL;
if(v) {
switch(v->type) {
case ATV_NOVALUE:
return calloc(1, sizeof(*v));
case ATV_REFERENCED:
return asn1p_value_fromref(v->value.reference, 1);
case ATV_NULL:
return calloc(1, sizeof(*clone));
case ATV_REAL:
return asn1p_value_fromdouble(v->value.v_double);
case ATV_INTEGER:
@ -140,7 +139,24 @@ asn1p_value_clone(asn1p_value_t *v) {
case ATV_BITVECTOR:
return asn1p_value_frombuf(v->value.binary_vector.bits,
v->value.binary_vector.size_in_bits, 1);
case ATV_REFERENCED:
return asn1p_value_fromref(v->value.reference, 1);
case ATV_CHOICE_IDENTIFIER: {
char *id = v->value.choice_identifier.identifier;
clone = calloc(1, sizeof(*clone));
if(!clone) return NULL;
clone->type = v->type;
id = strdup(id);
if(!id) { asn1p_value_free(clone); return NULL; }
clone->value.choice_identifier.identifier = id;
v = asn1p_value_clone(v->value.choice_identifier.value);
if(!v) { asn1p_value_free(clone); return NULL; }
clone->value.choice_identifier.value = v;
return clone;
}
}
assert(!"UNREACHABLE");
}
return v;
}
@ -150,16 +166,14 @@ asn1p_value_free(asn1p_value_t *v) {
if(v) {
switch(v->type) {
case ATV_NOVALUE:
case ATV_NULL:
break;
case ATV_REFERENCED:
asn1p_ref_free(v->value.reference);
break;
case ATV_REAL:
case ATV_INTEGER:
case ATV_MIN:
case ATV_MAX:
case ATV_FALSE:
case ATV_TRUE:
case ATV_REAL:
/* No freeing necessary */
break;
case ATV_STRING:
@ -171,6 +185,13 @@ asn1p_value_free(asn1p_value_t *v) {
assert(v->value.binary_vector.bits);
free(v->value.binary_vector.bits);
break;
case ATV_REFERENCED:
asn1p_ref_free(v->value.reference);
break;
case ATV_CHOICE_IDENTIFIER:
free(v->value.choice_identifier.identifier);
asn1p_value_free(v->value.choice_identifier.value);
break;
}
free(v);
}

View File

@ -13,9 +13,9 @@ typedef struct asn1p_value_s {
*/
enum {
ATV_NOVALUE,
ATV_REFERENCED,
ATV_INTEGER,
ATV_REAL,
ATV_NULL, /* A "NULL" value of type NULL. */
ATV_REAL, /* A constant floating-point value */
ATV_INTEGER, /* An integer constant */
ATV_MAX,
ATV_MIN,
ATV_TRUE,
@ -23,6 +23,8 @@ typedef struct asn1p_value_s {
ATV_STRING,
ATV_UNPARSED,
ATV_BITVECTOR,
ATV_REFERENCED, /* Reference to a value defined elsewhere */
ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */
} type; /* Value type and location */
union {
@ -40,6 +42,10 @@ typedef struct asn1p_value_s {
uint8_t *bits;
int size_in_bits;
} binary_vector;
struct {
char *identifier;
struct asn1p_value_s *value;
} choice_identifier;
} value;
} asn1p_value_t;

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ typedef union {
asn1p_value_t *a_value; /* Number, DefinedValue, etc */
struct asn1p_param_s a_parg; /* A parameter argument */
asn1p_paramlist_t *a_plist; /* A pargs list */
enum asn1p_expr_marker_e a_marker; /* OPTIONAL/DEFAULT */
struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
asn1_integer_t a_int;
char *tv_str;

View File

@ -74,7 +74,7 @@ static asn1p_value_t *
asn1p_value_t *a_value; /* Number, DefinedValue, etc */
struct asn1p_param_s a_parg; /* A parameter argument */
asn1p_paramlist_t *a_plist; /* A pargs list */
enum asn1p_expr_marker_e a_marker; /* OPTIONAL/DEFAULT */
struct asn1p_expr_marker_s a_marker; /* OPTIONAL/DEFAULT */
enum asn1p_constr_pres_e a_pres; /* PRESENT/ABSENT/OPTIONAL */
asn1_integer_t a_int;
char *tv_str;
@ -236,7 +236,7 @@ static asn1p_value_t *
%type <a_expr> optValueSetBody
%type <a_expr> ValueSetBody
%type <a_expr> ValueSetElement
%type <a_value> InlineOrDefinedValue
%type <a_value> Value
%type <a_value> DefinedValue
%type <a_value> SignedNumber
%type <a_expr> ComponentTypeLists
@ -1178,6 +1178,16 @@ ComplexTypeReference:
checkmem(ret == 0);
free($1);
}
| ObjectClassReference '.' TypeRefName {
int ret;
$$ = asn1p_ref_new(yylineno);
checkmem($$);
ret = asn1p_ref_add_component($$, $1, RLT_UNKNOWN);
checkmem(ret == 0);
ret = asn1p_ref_add_component($$, $3, RLT_UNKNOWN);
checkmem(ret == 0);
free($1);
}
| TOK_typereference '.' Identifier {
int ret;
$$ = asn1p_ref_new(yylineno);
@ -1258,7 +1268,7 @@ ClassFieldName:
* === EOF ===
*/
ValueDefinition:
Identifier DefinedTypeRef TOK_PPEQ InlineOrDefinedValue {
Identifier DefinedTypeRef TOK_PPEQ Value {
$$ = $2;
assert($$->Identifier == NULL);
$$->Identifier = $1;
@ -1267,13 +1277,34 @@ ValueDefinition:
}
;
InlineOrDefinedValue:
'{' { asn1p_lexer_hack_push_opaque_state(); }
Opaque /* '}' */ {
Value:
Identifier ':' Value {
$$ = asn1p_value_fromint(0);
checkmem($$);
$$->type = ATV_CHOICE_IDENTIFIER;
$$->value.choice_identifier.identifier = $1;
$$->value.choice_identifier.value = $3;
}
| '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
$$ = asn1p_value_frombuf($3.buf, $3.len, 0);
checkmem($$);
$$->type = ATV_UNPARSED;
}
| TOK_NULL {
$$ = asn1p_value_fromint(0);
checkmem($$);
$$->type = ATV_NULL;
}
| TOK_FALSE {
$$ = asn1p_value_fromint(0);
checkmem($$);
$$->type = ATV_FALSE;
}
| TOK_TRUE {
$$ = asn1p_value_fromint(0);
checkmem($$);
$$->type = ATV_TRUE;
}
| TOK_bstring {
$$ = _convert_bitstring2binary($1, 'B');
checkmem($$);
@ -1394,11 +1425,11 @@ BasicString:
TOK_BMPString { $$ = ASN_STRING_BMPString; }
| TOK_GeneralString {
$$ = ASN_STRING_GeneralString;
fprintf(stderr, "WARNING: GeneralString is not fully supported");
fprintf(stderr, "WARNING: GeneralString is not fully supported\n");
}
| TOK_GraphicString {
$$ = ASN_STRING_GraphicString;
fprintf(stderr, "WARNING: GraphicString is not fully supported");
fprintf(stderr, "WARNING: GraphicString is not fully supported\n");
}
| TOK_IA5String { $$ = ASN_STRING_IA5String; }
| TOK_ISO646String { $$ = ASN_STRING_ISO646String; }
@ -1406,14 +1437,14 @@ BasicString:
| TOK_PrintableString { $$ = ASN_STRING_PrintableString; }
| TOK_T61String {
$$ = ASN_STRING_T61String;
fprintf(stderr, "WARNING: T61String is not fully supported");
fprintf(stderr, "WARNING: T61String is not fully supported\n");
}
| TOK_TeletexString { $$ = ASN_STRING_TeletexString; }
| TOK_UniversalString { $$ = ASN_STRING_UniversalString; }
| TOK_UTF8String { $$ = ASN_STRING_UTF8String; }
| TOK_VideotexString {
$$ = ASN_STRING_VideotexString;
fprintf(stderr, "WARNING: VideotexString is not fully supported");
fprintf(stderr, "WARNING: VideotexString is not fully supported\n");
}
| TOK_VisibleString { $$ = ASN_STRING_VisibleString; }
| TOK_ObjectDescriptor { $$ = ASN_STRING_ObjectDescriptor; }
@ -1589,7 +1620,6 @@ ConstraintValue:
$$ = asn1p_value_frombuf($1.buf, $1.len, 0);
checkmem($$);
}
| TOK_FALSE {
$$ = asn1p_value_fromint(0);
checkmem($$);
@ -1754,26 +1784,21 @@ ComponentIdList:
*/
optMarker:
{ $$ = EM_NOMARK; }
{
$$.flags = EM_NOMARK;
$$.default_value = 0;
}
| Marker { $$ = $1; }
;
Marker:
TOK_OPTIONAL {
$$ = EM_OPTIONAL;
$$.flags = EM_OPTIONAL;
$$.default_value = 0;
}
| TOK_DEFAULT DefaultValue {
$$ = EM_DEFAULT;
/* FIXME: store DefaultValue somewhere */
}
;
DefaultValue:
ConstraintValue {
}
| BasicTypeId {
}
| '{' { asn1p_lexer_hack_push_opaque_state(); } Opaque /* '}' */ {
| TOK_DEFAULT Value {
$$.flags = EM_DEFAULT;
$$.default_value = $2;
}
;