refactoring
diff --git a/libasn1fix/asn1fix_bitstring.c b/libasn1fix/asn1fix_bitstring.c
index 0d3961d..c9a0976 100644
--- a/libasn1fix/asn1fix_bitstring.c
+++ b/libasn1fix/asn1fix_bitstring.c
@@ -16,7 +16,7 @@
DEBUG("%s(%s) for line %d", __func__,
expr->Identifier, expr->_lineno);
- ttype = asn1f_find_terminal_type(arg, expr, 0);
+ ttype = asn1f_find_terminal_type(arg, expr);
if(ttype && ttype->expr_type == ASN_BASIC_BIT_STRING) {
ret = asn1f_fix_bit_string_value(arg, ttype);
RET2RVAL(ret, r_value);
diff --git a/libasn1fix/asn1fix_class.c b/libasn1fix/asn1fix_class.c
index f617c31..98d47f4 100644
--- a/libasn1fix/asn1fix_class.c
+++ b/libasn1fix/asn1fix_class.c
@@ -23,15 +23,13 @@
asn1f_class_dot_lookup(arg_t *arg, asn1p_expr_t *obj, asn1p_ref_t *ref);
asn1p_expr_t *
-asn1f_class_access(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **mod_r) {
+asn1f_class_access(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) {
asn1p_expr_t *obj; /* Information Object or Object Set */
object_category_e obj_cat; /* Object category */
//field_category_e field_cat; /* Field category */
asn1p_expr_t *result;
asn1p_ref_t tmpref;
- (void)mod_r; /* Unused argument */
-
assert(ref->comp_count > 1);
DEBUG("%s(%s) for line %d", __func__,
@@ -47,7 +45,7 @@
tmpref = *ref;
tmpref.comp_count = 1;
- obj = asn1f_lookup_symbol(arg, &tmpref, 0);
+ obj = asn1f_lookup_symbol(arg, mod, &tmpref);
if(obj == NULL) {
errno = ESRCH;
return NULL;
diff --git a/libasn1fix/asn1fix_class.h b/libasn1fix/asn1fix_class.h
index c849b2b..763e48c 100644
--- a/libasn1fix/asn1fix_class.h
+++ b/libasn1fix/asn1fix_class.h
@@ -4,13 +4,12 @@
/*
* Fetch the element from the class-related stuff (thing) by its reference.
*/
-asn1p_expr_t *
-asn1f_class_access(arg_t *, asn1p_ref_t *, asn1p_module_t **mod_r);
+asn1p_expr_t *asn1f_class_access(arg_t *, asn1p_module_t *mod, asn1p_ref_t *);
/*
* Externally accessible version of above function.
*/
asn1p_expr_t *asn1f_class_access2(asn1p_t *asn, asn1p_module_t *mod,
- asn1p_expr_t *expr, asn1p_ref_t *, asn1p_module_t **mod_r);
+ asn1p_expr_t *expr, asn1p_ref_t *);
#endif /* _ASN1FIX_CLASS_H_ */
diff --git a/libasn1fix/asn1fix_constraint.c b/libasn1fix/asn1fix_constraint.c
index 4620ec5..4a25fae 100644
--- a/libasn1fix/asn1fix_constraint.c
+++ b/libasn1fix/asn1fix_constraint.c
@@ -3,7 +3,7 @@
#include <asn1fix_crange.h>
static void _remove_exceptions(arg_t *arg, asn1p_constraint_t *ct);
-static int _constraint_value_resolve(arg_t *arg, asn1p_value_t **value);
+static int _constraint_value_resolve(arg_t *arg, asn1p_module_t *mod, asn1p_value_t **value);
int
asn1constraint_pullup(arg_t *arg) {
@@ -25,11 +25,10 @@
if(expr->expr_type == A1TC_REFERENCE) {
asn1p_ref_t *ref = expr->reference;
- asn1p_module_t *mod_rw = arg->mod;
asn1p_expr_t *parent_expr;
assert(ref);
- parent_expr = asn1f_lookup_symbol(arg, ref, &mod_rw);
+ parent_expr = asn1f_lookup_symbol(arg, expr->module, ref);
if(!parent_expr) {
if(errno != EEXIST) {
DEBUG("\tWhile fetching parent constraints: "
@@ -120,7 +119,7 @@
}
int
-asn1constraint_resolve(arg_t *arg, asn1p_constraint_t *ct, asn1p_expr_type_e etype, enum asn1p_constraint_type_e effective_type) {
+asn1constraint_resolve(arg_t *arg, asn1p_module_t *mod, asn1p_constraint_t *ct, asn1p_expr_type_e etype, enum asn1p_constraint_type_e effective_type) {
int rvalue = 0;
int ret;
int el;
@@ -183,15 +182,15 @@
* Resolve all possible references, wherever they occur.
*/
if(ct->value && ct->value->type == ATV_REFERENCED) {
- ret = _constraint_value_resolve(arg, &ct->value);
+ ret = _constraint_value_resolve(arg, mod, &ct->value);
RET2RVAL(ret, rvalue);
}
if(ct->range_start && ct->range_start->type == ATV_REFERENCED) {
- ret = _constraint_value_resolve(arg, &ct->range_start);
+ ret = _constraint_value_resolve(arg, mod, &ct->range_start);
RET2RVAL(ret, rvalue);
}
if(ct->range_stop && ct->range_stop->type == ATV_REFERENCED) {
- ret = _constraint_value_resolve(arg, &ct->range_stop);
+ ret = _constraint_value_resolve(arg, mod, &ct->range_stop);
RET2RVAL(ret, rvalue);
}
@@ -199,7 +198,7 @@
* Proceed recursively.
*/
for(el = 0; el < ct->el_count; el++) {
- ret = asn1constraint_resolve(arg, ct->elements[el],
+ ret = asn1constraint_resolve(arg, mod, ct->elements[el],
etype, effective_type);
RET2RVAL(ret, rvalue);
}
@@ -230,15 +229,14 @@
static int
-_constraint_value_resolve(arg_t *arg, asn1p_value_t **value) {
+_constraint_value_resolve(arg_t *arg, asn1p_module_t *mod, asn1p_value_t **value) {
asn1p_expr_t static_expr;
asn1p_expr_t *tmp_expr;
- asn1p_module_t *mod_rw = arg->mod;
arg_t tmp_arg;
int rvalue = 0;
int ret;
- tmp_expr = asn1f_lookup_symbol(arg, (*value)->value.reference, &mod_rw);
+ tmp_expr = asn1f_lookup_symbol(arg, mod, (*value)->value.reference);
if(tmp_expr == NULL) {
FATAL("Cannot find symbol %s "
"used in %s subtype constraint at line %d",
@@ -251,7 +249,7 @@
static_expr = *tmp_expr;
static_expr.value = *value;
tmp_arg = *arg;
- tmp_arg.mod = mod_rw;
+ tmp_arg.mod = tmp_expr->module;
tmp_arg.expr = &static_expr;
ret = asn1f_fix_dereference_values(&tmp_arg);
RET2RVAL(ret, rvalue);
diff --git a/libasn1fix/asn1fix_constraint.h b/libasn1fix/asn1fix_constraint.h
index 9e692ef..cc6621f 100644
--- a/libasn1fix/asn1fix_constraint.h
+++ b/libasn1fix/asn1fix_constraint.h
@@ -4,7 +4,8 @@
/*
* Resolve referenced values inside constraints.
*/
-int asn1constraint_resolve(arg_t *arg, asn1p_constraint_t *ct,
+int asn1constraint_resolve(arg_t *arg, asn1p_module_t *module,
+ asn1p_constraint_t *ct,
asn1p_expr_type_e topmost_parent_expression_type,
enum asn1p_constraint_type_e effective_constraint_type);
diff --git a/libasn1fix/asn1fix_dereft.c b/libasn1fix/asn1fix_dereft.c
index 1f9b5bf..352df7b 100644
--- a/libasn1fix/asn1fix_dereft.c
+++ b/libasn1fix/asn1fix_dereft.c
@@ -26,7 +26,7 @@
/*
* Follow the reference.
*/
- type_expr = asn1f_find_terminal_type(arg, expr, 0);
+ type_expr = asn1f_find_terminal_type(arg, expr);
if(type_expr == NULL) {
const char *type_name;
@@ -44,35 +44,6 @@
return -1;
}
- /*
- * Copying members of the source expression
- * into the current expression.
- */
- if(0) {
- asn1p_expr_t *tmp_clone;
-
- tmp_clone = asn1p_expr_clone(type_expr);
- if(tmp_clone == NULL) {
- FATAL("Could not clone \"%s\" at line %d",
- type_expr->Identifier, type_expr->_lineno);
- return -1;
- }
-
- /*
- * Replace the referenced type with its definition.
- */
- DEBUG("\tChanging type of \"%s\":%x to %x for line %d",
- expr->Identifier,
- expr->expr_type,
- type_expr->expr_type,
- expr->_lineno
- );
- expr->expr_type = type_expr->expr_type;
- expr->members = tmp_clone->members;
- memset(&tmp_clone->members, 0, sizeof(tmp_clone->members));
- asn1p_expr_free(tmp_clone);
- }
-
return r_value;
}
diff --git a/libasn1fix/asn1fix_export.c b/libasn1fix/asn1fix_export.c
index cdae650..3a18ece 100644
--- a/libasn1fix/asn1fix_export.c
+++ b/libasn1fix/asn1fix_export.c
@@ -7,7 +7,7 @@
asn1p_expr_t *
asn1f_lookup_symbol_ex(
asn1p_t *asn,
- asn1p_module_t **module_rw,
+ asn1p_module_t *mod,
asn1p_expr_t *expr,
asn1p_ref_t *ref) {
arg_t arg;
@@ -15,21 +15,20 @@
memset(&arg, 0, sizeof(arg));
arg.asn = asn;
- arg.mod = *module_rw;
+ arg.mod = mod;
arg.expr = expr;
arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug;
- return asn1f_lookup_symbol(&arg, ref, module_rw);
+ return asn1f_lookup_symbol(&arg, mod, ref);
}
asn1p_expr_t *
asn1f_class_access_ex(asn1p_t *asn,
asn1p_module_t *mod,
asn1p_expr_t *expr,
- asn1p_ref_t *ref,
- asn1p_module_t **mod_r) {
+ asn1p_ref_t *ref) {
arg_t arg;
memset(&arg, 0, sizeof(arg));
@@ -40,14 +39,13 @@
arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug;
- return asn1f_class_access(&arg, ref, mod_r);
+ return asn1f_class_access(&arg, mod, ref);
}
asn1p_expr_t *
asn1f_find_terminal_type_ex(asn1p_t *asn,
asn1p_module_t *mod,
- asn1p_expr_t *expr,
- asn1p_module_t **mod_r) {
+ asn1p_expr_t *expr) {
arg_t arg;
memset(&arg, 0, sizeof(arg));
@@ -58,7 +56,7 @@
arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug;
- return asn1f_find_terminal_type(&arg, expr, mod_r);
+ return asn1f_find_terminal_type(&arg, expr);
}
int
diff --git a/libasn1fix/asn1fix_export.h b/libasn1fix/asn1fix_export.h
index 7fd9ce1..8ebe448 100644
--- a/libasn1fix/asn1fix_export.h
+++ b/libasn1fix/asn1fix_export.h
@@ -18,7 +18,7 @@
*/
asn1p_expr_t *asn1f_lookup_symbol_ex(
asn1p_t *asn,
- asn1p_module_t **module_rw,
+ asn1p_module_t *mod,
asn1p_expr_t *expr,
asn1p_ref_t *ref);
@@ -26,13 +26,13 @@
* Exportable version of an asn1f_class_access().
*/
asn1p_expr_t *asn1f_class_access_ex(asn1p_t *asn, asn1p_module_t *mod,
- asn1p_expr_t *expr, asn1p_ref_t *, asn1p_module_t **mod_r);
+ asn1p_expr_t *expr, asn1p_ref_t *);
/*
* Exportable version of asn1f_find_terminal_type().
*/
asn1p_expr_t *asn1f_find_terminal_type_ex(asn1p_t *asn, asn1p_module_t *mod,
- asn1p_expr_t *tc, asn1p_module_t **opt_module_r);
+ asn1p_expr_t *tc);
/*
* Exportable version of asn1f_fix_dereference_values();
diff --git a/libasn1fix/asn1fix_integer.c b/libasn1fix/asn1fix_integer.c
index c3a2a7b..729d1e3 100644
--- a/libasn1fix/asn1fix_integer.c
+++ b/libasn1fix/asn1fix_integer.c
@@ -112,7 +112,6 @@
static int
_asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type) {
- asn1p_module_t *mod = NULL;
asn1p_expr_t *next_expr;
asn1p_expr_type_e expr_type;
int ret;
@@ -144,7 +143,7 @@
* Then, it is a reference. For a reference, try to resolve type
* and try again.
*/
- next_expr = asn1f_lookup_symbol(arg, expr->reference, &mod);
+ next_expr = asn1f_lookup_symbol(arg, expr->module, expr->reference);
if(next_expr == NULL) {
errno = ESRCH;
return -1;
@@ -153,7 +152,8 @@
/*
* If symbol is here, recursively check that it conforms to the type.
*/
- WITH_MODULE(mod, ret = _asn1f_make_sure_type_is(arg, next_expr, type));
+ WITH_MODULE(next_expr->module,
+ ret = _asn1f_make_sure_type_is(arg, next_expr, type));
return ret;
}
diff --git a/libasn1fix/asn1fix_param.c b/libasn1fix/asn1fix_param.c
index 0c838cc..c399ae4 100644
--- a/libasn1fix/asn1fix_param.c
+++ b/libasn1fix/asn1fix_param.c
@@ -23,7 +23,7 @@
*/
DEBUG("Looking for parametrized type definition \"%s\"",
asn1f_printable_reference(expr->reference));
- ptype = asn1f_lookup_symbol(arg, expr->reference, 0);
+ ptype = asn1f_lookup_symbol(arg, expr->module, expr->reference);
if(ptype == NULL) {
DEBUG("%s: missing parametrized type declaration",
asn1f_printable_reference(expr->reference));
@@ -81,7 +81,7 @@
* with the actual values.
*/
- nex = asn1p_expr_clone(ptype);
+ nex = asn1p_expr_clone(ptype, 0);
if(nex == NULL) return -1;
/*
@@ -131,7 +131,7 @@
assert(child->meta_type == AMT_TYPEREF);
assert(child->expr_type == A1TC_REFERENCE);
- ne = asn1p_expr_clone(ra);
+ ne = asn1p_expr_clone(ra, 0);
if(ne == NULL) return -1;
assert(ne->Identifier == 0);
ne->Identifier = strdup(child->Identifier);
diff --git a/libasn1fix/asn1fix_retrieve.c b/libasn1fix/asn1fix_retrieve.c
index f2f91d5..97e77fe 100644
--- a/libasn1fix/asn1fix_retrieve.c
+++ b/libasn1fix/asn1fix_retrieve.c
@@ -1,6 +1,6 @@
#include "asn1fix_internal.h"
-static asn1p_expr_t *asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, asn1p_module_t **optm, int type_or_value);
+static asn1p_expr_t *asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, int type_or_value);
static int asn1f_compatible_with_exports(arg_t *arg, asn1p_module_t *mod, const char *name);
@@ -135,7 +135,7 @@
asn1p_expr_t *
-asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) {
+asn1f_lookup_symbol(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) {
asn1p_expr_t *ref_tc; /* Referenced tc */
asn1p_module_t *src_mod;
char *modulename;
@@ -155,7 +155,7 @@
DEBUG("%s(%s) in %s for line %d", __func__,
asn1f_printable_reference(ref),
- arg->mod->Identifier,
+ mod->Identifier,
ref->_lineno);
if(ref->comp_count == 1) {
@@ -173,7 +173,7 @@
* This is a reference to a CLASS-related stuff.
* Employ a separate function for that.
*/
- extract = asn1f_class_access(arg, ref, module_r);
+ extract = asn1f_class_access(arg, mod, ref);
return extract;
} else {
@@ -216,7 +216,7 @@
}
}
- if(src_mod == 0) src_mod = arg->mod;
+ if(src_mod == 0) src_mod = mod;
/*
* Now we know where to search for a value.
@@ -242,29 +242,22 @@
return NULL;
}
- if(module_r)
- *module_r = src_mod;
-
return ref_tc;
}
asn1p_expr_t *
-asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *expr,
- asn1p_module_t **optm) {
- return asn1f_find_terminal_thing(arg, expr, optm, 0);
+asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *expr) {
+ return asn1f_find_terminal_thing(arg, expr, 0);
}
asn1p_expr_t *
-asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *expr,
- asn1p_module_t **optm) {
- return asn1f_find_terminal_thing(arg, expr, optm, 1);
+asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *expr) {
+ return asn1f_find_terminal_thing(arg, expr, 1);
}
static asn1p_expr_t *
-asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr,
- asn1p_module_t **optm, int type_or_value) {
- asn1p_module_t *mod;
+asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, int type_or_value) {
asn1p_ref_t *ref;
asn1p_expr_t *tc;
@@ -272,19 +265,15 @@
/* VALUE */
assert(expr->meta_type == AMT_VALUE);
assert(expr->value);
- if(expr->value->type != ATV_REFERENCED) {
- /* Expression is a terminal value itself */
- if(optm) *optm = arg->mod;
+ /* Expression may be a terminal type itself */
+ if(expr->value->type != ATV_REFERENCED)
return expr;
- }
ref = expr->value->value.reference;
} else {
/* TYPE */
- if(expr->expr_type != A1TC_REFERENCE) {
- /* Expression is a terminal type itself */
- if(optm) *optm = arg->mod;
+ /* Expression may be a terminal type itself */
+ if(expr->expr_type != A1TC_REFERENCE)
return expr;
- }
ref = expr->reference;
}
@@ -300,12 +289,11 @@
*/
if(type_or_value) {
asn1p_expr_t *val_type_tc;
- val_type_tc = asn1f_find_terminal_type(arg, expr, 0);
+ val_type_tc = asn1f_find_terminal_type(arg, expr);
if(val_type_tc
&& asn1f_look_value_in_type(arg, val_type_tc, expr))
return NULL;
if(expr->value->type != ATV_REFERENCED) {
- if(optm) *optm = arg->mod;
return expr;
}
assert(ref == expr->value->value.reference);
@@ -315,7 +303,7 @@
/*
* Lookup inside the default module.
*/
- tc = asn1f_lookup_symbol(arg, ref, &mod);
+ tc = asn1f_lookup_symbol(arg, expr->module, ref);
if(tc == NULL) {
DEBUG("\tSymbol \"%s\" not found: %s",
asn1f_printable_reference(ref),
@@ -334,8 +322,8 @@
}
tc->_mark |= TM_RECURSION;
- WITH_MODULE(mod,
- expr = asn1f_find_terminal_thing(arg, tc, optm, type_or_value));
+ WITH_MODULE(tc->module,
+ expr = asn1f_find_terminal_thing(arg, tc, type_or_value));
tc->_mark &= ~TM_RECURSION;
return expr;
diff --git a/libasn1fix/asn1fix_retrieve.h b/libasn1fix/asn1fix_retrieve.h
index 47aa0a5..7088b49 100644
--- a/libasn1fix/asn1fix_retrieve.h
+++ b/libasn1fix/asn1fix_retrieve.h
@@ -36,11 +36,10 @@
/*
* Return the reference to a destination of the given reference,
* symbol lookup. Not a recursive function.
- * Optional module reference may be assigned a module in which the
- * particular expr was found.
*/
-asn1p_expr_t *asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref,
- asn1p_module_t **opt_module_r);
+asn1p_expr_t *asn1f_lookup_symbol(arg_t *arg,
+ asn1p_module_t *mod,
+ asn1p_ref_t *ref);
/*
* Recursively find the original type for the given expression.
@@ -54,8 +53,7 @@
* would return an expression for Type4.
* WARNING: No attempts are made to honor constraints at this moment.
*/
-asn1p_expr_t *asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *tc,
- asn1p_module_t **opt_module_r);
+asn1p_expr_t *asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *tc);
/*
* Recursively find the original value for the given expression.
@@ -67,7 +65,6 @@
* Then this function will return the expression for value2 if given
* the v as an argment.
*/
-asn1p_expr_t *asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *tc,
- asn1p_module_t **opt_module_r);
+asn1p_expr_t *asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *tc);
#endif /* _ASN1FIX_RETRIEVE_H_ */
diff --git a/libasn1fix/asn1fix_tags.c b/libasn1fix/asn1fix_tags.c
index ed8c19f..de80fad 100644
--- a/libasn1fix/asn1fix_tags.c
+++ b/libasn1fix/asn1fix_tags.c
@@ -30,14 +30,14 @@
arg.mod = mod;
arg.expr = expr;
- expr = asn1f_lookup_symbol(&arg, expr->reference, &mod);
+ expr = asn1f_lookup_symbol(&arg, expr->module, expr->reference);
if(expr == NULL) return -1;
if(expr->_mark & TM_RECURSION)
return -1;
expr->_mark |= TM_RECURSION;
- ret = asn1f_fetch_tag(asn, mod, expr, tag);
+ ret = asn1f_fetch_tag(asn, expr->module, expr, tag);
expr->_mark &= ~TM_RECURSION;
return ret;
}
diff --git a/libasn1fix/asn1fix_value.c b/libasn1fix/asn1fix_value.c
index a0560ed..33da366 100644
--- a/libasn1fix/asn1fix_value.c
+++ b/libasn1fix/asn1fix_value.c
@@ -4,7 +4,6 @@
int
asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) {
- asn1p_module_t *val_mod;
asn1p_expr_t *val_type_expr;
asn1p_expr_t *value_expr;
asn1p_expr_t *type_expr;
@@ -20,7 +19,7 @@
/*
* 1. Find the terminal type for this assignment.
*/
- type_expr = asn1f_find_terminal_type(arg, expr, 0);
+ type_expr = asn1f_find_terminal_type(arg, expr);
DEBUG("%s(): terminal type %p", __func__, type_expr);
if(type_expr == 0) {
DEBUG("\tTerminal type for %s not found", expr->Identifier);
@@ -33,7 +32,7 @@
/*
* 2. Find the terminal value also.
*/
- value_expr = asn1f_find_terminal_value(arg, expr, &val_mod);
+ value_expr = asn1f_find_terminal_value(arg, expr);
if(value_expr) {
DEBUG("\tTerminal value for %s->%s is %s at line %d",
expr->Identifier, asn1f_printable_value(expr->value),
@@ -47,8 +46,8 @@
/*
* 3. Find the _type_ of a _terminal value_.
*/
- WITH_MODULE(val_mod,
- val_type_expr = asn1f_find_terminal_type(arg, value_expr, 0));
+ WITH_MODULE(value_expr->module,
+ val_type_expr = asn1f_find_terminal_type(arg, value_expr));
if(val_type_expr) {
DEBUG("\tTerminal type of value %s->%s is %s at line %d",
expr->Identifier, asn1f_printable_value(expr->value),