Skip to content
Snippets Groups Projects
Commit fbfc7bcb authored by Lev Walkin's avatar Lev Walkin
Browse files

declashing

parent 62e48d3d
No related branches found
No related tags found
No related merge requests found
...@@ -385,7 +385,7 @@ asn1f_fix_constructed(arg_t *arg) { ...@@ -385,7 +385,7 @@ asn1f_fix_constructed(arg_t *arg) {
} }
/* Check identifier distinctness */ /* Check identifier distinctness */
ret = asn1f_check_unique_expr(arg, NULL); ret = asn1f_check_unique_expr(arg);
RET2RVAL(ret, rvalue); RET2RVAL(ret, rvalue);
/* Fix extensibility */ /* Fix extensibility */
......
...@@ -32,6 +32,10 @@ asn1f_fix_bit_string(arg_t *arg) { ...@@ -32,6 +32,10 @@ asn1f_fix_bit_string(arg_t *arg) {
return r_value; return r_value;
} }
static int _compare_value(asn1p_expr_t *expr1, asn1p_expr_t *expr2) {
return expr2->value->value.v_integer - expr1->value->value.v_integer;
}
static int static int
asn1f_fix_bit_string_type(arg_t *arg) { asn1f_fix_bit_string_type(arg_t *arg) {
asn1p_expr_t *expr = arg->expr; asn1p_expr_t *expr = arg->expr;
...@@ -40,10 +44,6 @@ asn1f_fix_bit_string_type(arg_t *arg) { ...@@ -40,10 +44,6 @@ asn1f_fix_bit_string_type(arg_t *arg) {
int ret; int ret;
TQ_FOR(v, &(expr->members), next) { TQ_FOR(v, &(expr->members), next) {
/* Check identifier uniqueness as per 21.4 */
ret = asn1f_check_unique_expr_child(arg, v, 0);
RET2RVAL(ret, r_value);
if(v->expr_type == A1TC_EXTENSIBLE) { if(v->expr_type == A1TC_EXTENSIBLE) {
FATAL("Extension marker (...) is not allowed " FATAL("Extension marker (...) is not allowed "
"as a BIT STRING NamedBit at line %d ", "as a BIT STRING NamedBit at line %d ",
...@@ -74,6 +74,14 @@ asn1f_fix_bit_string_type(arg_t *arg) { ...@@ -74,6 +74,14 @@ asn1f_fix_bit_string_type(arg_t *arg) {
v->_lineno); v->_lineno);
return -1; return -1;
} }
/* Check value uniqueness as per 21.4 */
ret = asn1f_check_unique_expr_child(arg, v,
_compare_value, "value");
RET2RVAL(ret, r_value);
/* Check identifier uniqueness as per 21.5 */
ret = asn1f_check_unique_expr_child(arg, v, 0, "identifier");
RET2RVAL(ret, r_value);
} }
return r_value; return r_value;
......
...@@ -119,7 +119,7 @@ asn1f_fix_enum(arg_t *arg) { ...@@ -119,7 +119,7 @@ asn1f_fix_enum(arg_t *arg) {
* 1.4 Check that all identifiers before the current one * 1.4 Check that all identifiers before the current one
* differs from it. * differs from it.
*/ */
ret = asn1f_check_unique_expr_child(arg, ev, NULL); ret = asn1f_check_unique_expr_child(arg, ev, 0, "identifier");
RET2RVAL(ret, rvalue); RET2RVAL(ret, rvalue);
} }
......
...@@ -92,12 +92,13 @@ asn1f_fix_integer(arg_t *arg) { ...@@ -92,12 +92,13 @@ asn1f_fix_integer(arg_t *arg) {
/* /*
* Check that all identifiers are distinct. * Check that all identifiers are distinct.
*/ */
ret = asn1f_check_unique_expr_child(arg, iv, NULL); ret = asn1f_check_unique_expr_child(arg, iv, 0, "identifier");
RET2RVAL(ret, rvalue); RET2RVAL(ret, rvalue);
/* /*
* Check that all values are distinct. * Check that all values are distinct.
*/ */
ret = asn1f_check_unique_expr_child(arg, iv, _compare_value); ret = asn1f_check_unique_expr_child(arg, iv,
_compare_value, "value");
RET2RVAL(ret, rvalue); RET2RVAL(ret, rvalue);
} }
......
...@@ -236,15 +236,14 @@ asn1f_recurse_expr(arg_t *arg, int (*callback)(arg_t *arg)) { ...@@ -236,15 +236,14 @@ asn1f_recurse_expr(arg_t *arg, int (*callback)(arg_t *arg)) {
* Check that every child of a given expr has unique name or does not have any. * Check that every child of a given expr has unique name or does not have any.
*/ */
int int
asn1f_check_unique_expr(arg_t *arg, asn1f_check_unique_expr(arg_t *arg) {
int (*opt_compare)(asn1p_expr_t *a, asn1p_expr_t *b)) {
asn1p_expr_t *expr; asn1p_expr_t *expr;
int rvalue = 0; int rvalue = 0;
TQ_FOR(expr, &(arg->expr->members), next) { TQ_FOR(expr, &(arg->expr->members), next) {
if(expr->Identifier) { if(expr->Identifier) {
int ret = asn1f_check_unique_expr_child(arg, expr, int ret = asn1f_check_unique_expr_child(arg, expr,
opt_compare); 0, "identifier");
if(ret) rvalue = -1; if(ret) rvalue = -1;
} else { } else {
/* /*
...@@ -263,9 +262,11 @@ asn1f_check_unique_expr(arg_t *arg, ...@@ -263,9 +262,11 @@ asn1f_check_unique_expr(arg_t *arg,
*/ */
int int
asn1f_check_unique_expr_child(arg_t *arg, asn1p_expr_t *child, asn1f_check_unique_expr_child(arg_t *arg, asn1p_expr_t *child,
int (*opt_compare)(asn1p_expr_t *a, asn1p_expr_t *b)) { int (*opt_compare)(asn1p_expr_t *a, asn1p_expr_t *b),
const char *opt_property_name) {
asn1p_expr_t *expr; asn1p_expr_t *expr;
int rvalue = 0;
if(!opt_property_name) opt_property_name = "property";
assert(child); assert(child);
assert(opt_compare || child->Identifier); assert(opt_compare || child->Identifier);
...@@ -290,26 +291,20 @@ asn1f_check_unique_expr_child(arg_t *arg, asn1p_expr_t *child, ...@@ -290,26 +291,20 @@ asn1f_check_unique_expr_child(arg_t *arg, asn1p_expr_t *child,
} }
if(ret == 0) { if(ret == 0) {
char *msg; FATAL("Clash detected: "
msg = opt_compare
?"Expressions clash"
:"Identifiers name clash";
FATAL("%s: "
"\"%s\" at line %d has similar %s with " "\"%s\" at line %d has similar %s with "
"\"%s\" at line %d", "\"%s\" at line %d",
msg,
expr->Identifier, expr->Identifier,
expr->_lineno, expr->_lineno,
opt_compare?"property":"name", opt_property_name,
child->Identifier, child->Identifier,
child->_lineno child->_lineno
); );
return -1;
rvalue = -1;
} }
} }
return rvalue; return 0;
} }
int int
......
...@@ -11,12 +11,9 @@ ...@@ -11,12 +11,9 @@
int asn1f_recurse_expr(arg_t *arg, int (*f)(arg_t *arg)); int asn1f_recurse_expr(arg_t *arg, int (*f)(arg_t *arg));
/* /*
* Check that every child of a given expr has unique name or does not have any. * Check that every child of a given expr has unique identifier.
* If opt_compare == NULL, the default comparison of the argument's
* names (identifiers) will be performed.
*/ */
int asn1f_check_unique_expr(arg_t *arg, int asn1f_check_unique_expr(arg_t *arg);
int (*opt_compare)(asn1p_expr_t *a, asn1p_expr_t *b));
/* /*
* Check that every preceeding child of the given expr is not * Check that every preceeding child of the given expr is not
...@@ -25,7 +22,8 @@ int asn1f_check_unique_expr(arg_t *arg, ...@@ -25,7 +22,8 @@ int asn1f_check_unique_expr(arg_t *arg,
* names (identifiers) will be performed. * names (identifiers) will be performed.
*/ */
int asn1f_check_unique_expr_child(arg_t *arg, asn1p_expr_t *child, int asn1f_check_unique_expr_child(arg_t *arg, asn1p_expr_t *child,
int (*opt_compare)(asn1p_expr_t *a, asn1p_expr_t *b)); int (*opt_compare)(asn1p_expr_t *a, asn1p_expr_t *b),
const char *opt_property_name);
/* /*
* Return number of children. * Return number of children.
......
-- SE: Semantic error
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .116
ModuleBitStringSameValues
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 116 }
DEFINITIONS ::=
BEGIN
T ::= BIT STRING { one(1), another(1) }
END
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment