aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1fix/asn1fix.c
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2005-02-22 07:59:59 +0000
committerLev Walkin <vlm@lionet.info>2005-02-22 07:59:59 +0000
commitf593f107819f04164a489a3d4c6861d5c536d371 (patch)
tree4b512bc61d8e3e7baa8a592822a8207ffcf8d1e5 /libasn1fix/asn1fix.c
parent7f70fe56c31e914c36a89b228745a31be60024c6 (diff)
anti-clash
Diffstat (limited to 'libasn1fix/asn1fix.c')
-rw-r--r--libasn1fix/asn1fix.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/libasn1fix/asn1fix.c b/libasn1fix/asn1fix.c
index 7bfb9034..f120853c 100644
--- a/libasn1fix/asn1fix.c
+++ b/libasn1fix/asn1fix.c
@@ -18,6 +18,7 @@ static int asn1f_fix_simple(arg_t *arg); /* For INTEGER/ENUMERATED */
static int asn1f_fix_constructed(arg_t *arg); /* For SEQUENCE/SET/CHOICE */
static int asn1f_resolve_constraints(arg_t *arg); /* For subtype constraints */
static int asn1f_check_constraints(arg_t *arg); /* For subtype constraints */
+static int asn1f_check_duplicate(arg_t *arg);
arg_t a1f_replace_me_with_proper_interface_arg;
@@ -78,6 +79,7 @@ asn1f_process(asn1p_t *asn, enum asn1f_flags flags,
/*
* Process each module in the list.
+ * PHASE I.
*/
TQ_FOR(arg.mod, &(asn->modules), mod_next) {
int ret = asn1f_fix_module__phase_1(&arg);
@@ -88,6 +90,7 @@ asn1f_process(asn1p_t *asn, enum asn1f_flags flags,
if(ret == -1) fatals++;
if(ret == 1) warnings++;
}
+ /* PHASE II. */
TQ_FOR(arg.mod, &(asn->modules), mod_next) {
int ret = asn1f_fix_module__phase_2(&arg);
if(ret == -1) fatals++;
@@ -145,11 +148,14 @@ asn1f_fix_module__phase_1(arg_t *arg) {
/*
* Do various non-recursive transformations.
- * Order is not important.
*/
TQ_FOR(expr, &(arg->mod->members), next) {
arg->expr = expr;
+ /* Check whether this type is a duplicate */
+ ret = asn1f_check_duplicate(arg);
+ RET2RVAL(ret, rvalue);
+
if(expr->meta_type == AMT_PARAMTYPE)
/* Do not process the parametrized type just yet */
continue;
@@ -257,7 +263,7 @@ asn1f_fix_module__phase_2(arg_t *arg) {
TQ_FOR(expr, &(arg->mod->members), next) {
arg->expr = expr;
- if(arg->expr->meta_type == AMT_PARAMTYPE)
+ if(expr->meta_type == AMT_PARAMTYPE)
/* Do not process the parametrized types here */
continue;
@@ -388,6 +394,46 @@ asn1f_check_constraints(arg_t *arg) {
return rvalue;
}
+static int
+asn1f_check_duplicate(arg_t *arg) {
+ arg_t tmparg = *arg;
+
+ /*
+ * This is a linear scan in search of a similar type.
+ * The linear scan is just fine for the task, no need to over-optimize.
+ */
+ TQ_FOR(tmparg.mod, &arg->asn->modules, mod_next) {
+ TQ_FOR(tmparg.expr, &(tmparg.mod->members), next) {
+ assert(tmparg.expr->Identifier);
+ assert(arg->expr->Identifier);
+ if(tmparg.expr == arg->expr) break;
+
+ if(strcmp(tmparg.expr->Identifier,
+ arg->expr->Identifier) == 0) {
+ int diff_files = strcmp(arg->mod->source_file_name, tmparg.mod->source_file_name) ? 1 : 0;
+ FATAL("ASN.1 expression \"%s\" at line %d of module %s\n"
+ "clashes with expression \"%s\" at line %d of module %s"
+ "%s%s%s.\n"
+ "Please rename either instance to resolve the conflict",
+ arg->expr->Identifier,
+ arg->expr->_lineno,
+ arg->mod->Identifier,
+ tmparg.expr->Identifier,
+ tmparg.expr->_lineno,
+ tmparg.mod->Identifier,
+ diff_files ? " (" : "",
+ diff_files ? tmparg.mod->source_file_name : "",
+ diff_files ? ")" : ""
+ );
+ return -1;
+ }
+ }
+ if(tmparg.mod == arg->mod) break;
+ }
+
+ return 0;
+}
+
/*
* Print everything to stderr
*/