Commit 6fec44d9 authored by Lev Walkin's avatar Lev Walkin

refactoring

parent 4ec3b4c0
...@@ -69,6 +69,8 @@ int asn1c_compiled_output(arg_t *arg, const char *fmt, ...); ...@@ -69,6 +69,8 @@ int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
_tmp.default_cb(&_tmp); \ _tmp.default_cb(&_tmp); \
); \ ); \
arg->embed--; \ arg->embed--; \
if(ev->expr_type != A1TC_EXTENSIBLE) \
OUT(";\n"); \
assert(arg->target->target == OT_TYPE_DECLS); \ assert(arg->target->target == OT_TYPE_DECLS); \
REDIR(saved_target); \ REDIR(saved_target); \
} while(0) } while(0)
......
...@@ -84,6 +84,9 @@ asn1c_compile_expr(arg_t *arg) { ...@@ -84,6 +84,9 @@ asn1c_compile_expr(arg_t *arg) {
expr->_lineno); expr->_lineno);
ret = type_cb(arg); ret = type_cb(arg);
if(arg->target->destination[OT_TYPE_DECLS].indent_level == 0)
OUT(";\n");
} else { } else {
ret = -1; ret = -1;
/* /*
...@@ -112,6 +115,11 @@ asn1c_compile_expr(arg_t *arg) { ...@@ -112,6 +115,11 @@ asn1c_compile_expr(arg_t *arg) {
} }
if(ret == -1) { if(ret == -1) {
FATAL("Cannot compile \"%s\" (%x:%x) at line %d",
arg->expr->Identifier,
arg->expr->expr_type,
arg->expr->meta_type,
arg->expr->_lineno);
OUT("#error Cannot compile \"%s\" (%x/%x) at line %d\n", OUT("#error Cannot compile \"%s\" (%x/%x) at line %d\n",
arg->expr->Identifier, arg->expr->Identifier,
arg->expr->meta_type, arg->expr->meta_type,
......
...@@ -16,7 +16,7 @@ asn1f_fix_bit_string(arg_t *arg) { ...@@ -16,7 +16,7 @@ asn1f_fix_bit_string(arg_t *arg) {
DEBUG("%s(%s) for line %d", __func__, DEBUG("%s(%s) for line %d", __func__,
expr->Identifier, expr->_lineno); 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) { if(ttype && ttype->expr_type == ASN_BASIC_BIT_STRING) {
ret = asn1f_fix_bit_string_value(arg, ttype); ret = asn1f_fix_bit_string_value(arg, ttype);
RET2RVAL(ret, r_value); RET2RVAL(ret, r_value);
......
...@@ -23,15 +23,13 @@ static asn1p_expr_t * ...@@ -23,15 +23,13 @@ static asn1p_expr_t *
asn1f_class_dot_lookup(arg_t *arg, asn1p_expr_t *obj, asn1p_ref_t *ref); asn1f_class_dot_lookup(arg_t *arg, asn1p_expr_t *obj, asn1p_ref_t *ref);
asn1p_expr_t * 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 */ asn1p_expr_t *obj; /* Information Object or Object Set */
object_category_e obj_cat; /* Object category */ object_category_e obj_cat; /* Object category */
//field_category_e field_cat; /* Field category */ //field_category_e field_cat; /* Field category */
asn1p_expr_t *result; asn1p_expr_t *result;
asn1p_ref_t tmpref; asn1p_ref_t tmpref;
(void)mod_r; /* Unused argument */
assert(ref->comp_count > 1); assert(ref->comp_count > 1);
DEBUG("%s(%s) for line %d", __func__, DEBUG("%s(%s) for line %d", __func__,
...@@ -47,7 +45,7 @@ asn1f_class_access(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **mod_r) { ...@@ -47,7 +45,7 @@ asn1f_class_access(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **mod_r) {
tmpref = *ref; tmpref = *ref;
tmpref.comp_count = 1; tmpref.comp_count = 1;
obj = asn1f_lookup_symbol(arg, &tmpref, 0); obj = asn1f_lookup_symbol(arg, mod, &tmpref);
if(obj == NULL) { if(obj == NULL) {
errno = ESRCH; errno = ESRCH;
return NULL; return NULL;
......
...@@ -4,13 +4,12 @@ ...@@ -4,13 +4,12 @@
/* /*
* Fetch the element from the class-related stuff (thing) by its reference. * Fetch the element from the class-related stuff (thing) by its reference.
*/ */
asn1p_expr_t * asn1p_expr_t *asn1f_class_access(arg_t *, asn1p_module_t *mod, asn1p_ref_t *);
asn1f_class_access(arg_t *, asn1p_ref_t *, asn1p_module_t **mod_r);
/* /*
* Externally accessible version of above function. * Externally accessible version of above function.
*/ */
asn1p_expr_t *asn1f_class_access2(asn1p_t *asn, asn1p_module_t *mod, 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_ */ #endif /* _ASN1FIX_CLASS_H_ */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <asn1fix_crange.h> #include <asn1fix_crange.h>
static void _remove_exceptions(arg_t *arg, asn1p_constraint_t *ct); 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 int
asn1constraint_pullup(arg_t *arg) { asn1constraint_pullup(arg_t *arg) {
...@@ -25,11 +25,10 @@ asn1constraint_pullup(arg_t *arg) { ...@@ -25,11 +25,10 @@ asn1constraint_pullup(arg_t *arg) {
if(expr->expr_type == A1TC_REFERENCE) { if(expr->expr_type == A1TC_REFERENCE) {
asn1p_ref_t *ref = expr->reference; asn1p_ref_t *ref = expr->reference;
asn1p_module_t *mod_rw = arg->mod;
asn1p_expr_t *parent_expr; asn1p_expr_t *parent_expr;
assert(ref); assert(ref);
parent_expr = asn1f_lookup_symbol(arg, ref, &mod_rw); parent_expr = asn1f_lookup_symbol(arg, expr->module, ref);
if(!parent_expr) { if(!parent_expr) {
if(errno != EEXIST) { if(errno != EEXIST) {
DEBUG("\tWhile fetching parent constraints: " DEBUG("\tWhile fetching parent constraints: "
...@@ -120,7 +119,7 @@ asn1constraint_pullup(arg_t *arg) { ...@@ -120,7 +119,7 @@ asn1constraint_pullup(arg_t *arg) {
} }
int 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 rvalue = 0;
int ret; int ret;
int el; int el;
...@@ -183,15 +182,15 @@ asn1constraint_resolve(arg_t *arg, asn1p_constraint_t *ct, asn1p_expr_type_e ety ...@@ -183,15 +182,15 @@ asn1constraint_resolve(arg_t *arg, asn1p_constraint_t *ct, asn1p_expr_type_e ety
* Resolve all possible references, wherever they occur. * Resolve all possible references, wherever they occur.
*/ */
if(ct->value && ct->value->type == ATV_REFERENCED) { 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); RET2RVAL(ret, rvalue);
} }
if(ct->range_start && ct->range_start->type == ATV_REFERENCED) { 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); RET2RVAL(ret, rvalue);
} }
if(ct->range_stop && ct->range_stop->type == ATV_REFERENCED) { 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); RET2RVAL(ret, rvalue);
} }
...@@ -199,7 +198,7 @@ asn1constraint_resolve(arg_t *arg, asn1p_constraint_t *ct, asn1p_expr_type_e ety ...@@ -199,7 +198,7 @@ asn1constraint_resolve(arg_t *arg, asn1p_constraint_t *ct, asn1p_expr_type_e ety
* Proceed recursively. * Proceed recursively.
*/ */
for(el = 0; el < ct->el_count; el++) { 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); etype, effective_type);
RET2RVAL(ret, rvalue); RET2RVAL(ret, rvalue);
} }
...@@ -230,15 +229,14 @@ _remove_exceptions(arg_t *arg, asn1p_constraint_t *ct) { ...@@ -230,15 +229,14 @@ _remove_exceptions(arg_t *arg, asn1p_constraint_t *ct) {
static int 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 static_expr;
asn1p_expr_t *tmp_expr; asn1p_expr_t *tmp_expr;
asn1p_module_t *mod_rw = arg->mod;
arg_t tmp_arg; arg_t tmp_arg;
int rvalue = 0; int rvalue = 0;
int ret; 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) { if(tmp_expr == NULL) {
FATAL("Cannot find symbol %s " FATAL("Cannot find symbol %s "
"used in %s subtype constraint at line %d", "used in %s subtype constraint at line %d",
...@@ -251,7 +249,7 @@ _constraint_value_resolve(arg_t *arg, asn1p_value_t **value) { ...@@ -251,7 +249,7 @@ _constraint_value_resolve(arg_t *arg, asn1p_value_t **value) {
static_expr = *tmp_expr; static_expr = *tmp_expr;
static_expr.value = *value; static_expr.value = *value;
tmp_arg = *arg; tmp_arg = *arg;
tmp_arg.mod = mod_rw; tmp_arg.mod = tmp_expr->module;
tmp_arg.expr = &static_expr; tmp_arg.expr = &static_expr;
ret = asn1f_fix_dereference_values(&tmp_arg); ret = asn1f_fix_dereference_values(&tmp_arg);
RET2RVAL(ret, rvalue); RET2RVAL(ret, rvalue);
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
/* /*
* Resolve referenced values inside constraints. * 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, asn1p_expr_type_e topmost_parent_expression_type,
enum asn1p_constraint_type_e effective_constraint_type); enum asn1p_constraint_type_e effective_constraint_type);
......
...@@ -26,7 +26,7 @@ asn1f_fix_dereference_types(arg_t *arg) { ...@@ -26,7 +26,7 @@ asn1f_fix_dereference_types(arg_t *arg) {
/* /*
* Follow the reference. * Follow the reference.
*/ */
type_expr = asn1f_find_terminal_type(arg, expr, 0); type_expr = asn1f_find_terminal_type(arg, expr);
if(type_expr == NULL) { if(type_expr == NULL) {
const char *type_name; const char *type_name;
...@@ -44,35 +44,6 @@ asn1f_fix_dereference_types(arg_t *arg) { ...@@ -44,35 +44,6 @@ asn1f_fix_dereference_types(arg_t *arg) {
return -1; 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; return r_value;
} }
...@@ -7,7 +7,7 @@ extern arg_t a1f_replace_me_with_proper_interface_arg; ...@@ -7,7 +7,7 @@ extern arg_t a1f_replace_me_with_proper_interface_arg;
asn1p_expr_t * asn1p_expr_t *
asn1f_lookup_symbol_ex( asn1f_lookup_symbol_ex(
asn1p_t *asn, asn1p_t *asn,
asn1p_module_t **module_rw, asn1p_module_t *mod,
asn1p_expr_t *expr, asn1p_expr_t *expr,
asn1p_ref_t *ref) { asn1p_ref_t *ref) {
arg_t arg; arg_t arg;
...@@ -15,21 +15,20 @@ asn1f_lookup_symbol_ex( ...@@ -15,21 +15,20 @@ asn1f_lookup_symbol_ex(
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.asn = asn; arg.asn = asn;
arg.mod = *module_rw; arg.mod = mod;
arg.expr = expr; arg.expr = expr;
arg.eh = a1f_replace_me_with_proper_interface_arg.eh; arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug; 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 * asn1p_expr_t *
asn1f_class_access_ex(asn1p_t *asn, asn1f_class_access_ex(asn1p_t *asn,
asn1p_module_t *mod, asn1p_module_t *mod,
asn1p_expr_t *expr, asn1p_expr_t *expr,
asn1p_ref_t *ref, asn1p_ref_t *ref) {
asn1p_module_t **mod_r) {
arg_t arg; arg_t arg;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
...@@ -40,14 +39,13 @@ asn1f_class_access_ex(asn1p_t *asn, ...@@ -40,14 +39,13 @@ asn1f_class_access_ex(asn1p_t *asn,
arg.eh = a1f_replace_me_with_proper_interface_arg.eh; arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug; 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 * asn1p_expr_t *
asn1f_find_terminal_type_ex(asn1p_t *asn, asn1f_find_terminal_type_ex(asn1p_t *asn,
asn1p_module_t *mod, asn1p_module_t *mod,
asn1p_expr_t *expr, asn1p_expr_t *expr) {
asn1p_module_t **mod_r) {
arg_t arg; arg_t arg;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
...@@ -58,7 +56,7 @@ asn1f_find_terminal_type_ex(asn1p_t *asn, ...@@ -58,7 +56,7 @@ asn1f_find_terminal_type_ex(asn1p_t *asn,
arg.eh = a1f_replace_me_with_proper_interface_arg.eh; arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
arg.debug = a1f_replace_me_with_proper_interface_arg.debug; 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 int
......
...@@ -18,7 +18,7 @@ char const *asn1f_printable_value(asn1p_value_t *value); ...@@ -18,7 +18,7 @@ char const *asn1f_printable_value(asn1p_value_t *value);
*/ */
asn1p_expr_t *asn1f_lookup_symbol_ex( asn1p_expr_t *asn1f_lookup_symbol_ex(
asn1p_t *asn, asn1p_t *asn,
asn1p_module_t **module_rw, asn1p_module_t *mod,
asn1p_expr_t *expr, asn1p_expr_t *expr,
asn1p_ref_t *ref); asn1p_ref_t *ref);
...@@ -26,13 +26,13 @@ asn1p_expr_t *asn1f_lookup_symbol_ex( ...@@ -26,13 +26,13 @@ asn1p_expr_t *asn1f_lookup_symbol_ex(
* Exportable version of an asn1f_class_access(). * Exportable version of an asn1f_class_access().
*/ */
asn1p_expr_t *asn1f_class_access_ex(asn1p_t *asn, asn1p_module_t *mod, 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(). * 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 *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(); * Exportable version of asn1f_fix_dereference_values();
......
...@@ -112,7 +112,6 @@ asn1f_fix_integer(arg_t *arg) { ...@@ -112,7 +112,6 @@ asn1f_fix_integer(arg_t *arg) {
static int static int
_asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type) { _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_t *next_expr;
asn1p_expr_type_e expr_type; asn1p_expr_type_e expr_type;
int ret; int ret;
...@@ -144,7 +143,7 @@ _asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type) ...@@ -144,7 +143,7 @@ _asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type)
* Then, it is a reference. For a reference, try to resolve type * Then, it is a reference. For a reference, try to resolve type
* and try again. * 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) { if(next_expr == NULL) {
errno = ESRCH; errno = ESRCH;
return -1; return -1;
...@@ -153,7 +152,8 @@ _asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type) ...@@ -153,7 +152,8 @@ _asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type)
/* /*
* If symbol is here, recursively check that it conforms to the type. * 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; return ret;
} }
......
...@@ -23,7 +23,7 @@ asn1f_fix_parametrized_assignment(arg_t *arg) { ...@@ -23,7 +23,7 @@ asn1f_fix_parametrized_assignment(arg_t *arg) {
*/ */
DEBUG("Looking for parametrized type definition \"%s\"", DEBUG("Looking for parametrized type definition \"%s\"",
asn1f_printable_reference(expr->reference)); 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) { if(ptype == NULL) {
DEBUG("%s: missing parametrized type declaration", DEBUG("%s: missing parametrized type declaration",
asn1f_printable_reference(expr->reference)); asn1f_printable_reference(expr->reference));
...@@ -81,7 +81,7 @@ asn1f_parametrize(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *ptype) { ...@@ -81,7 +81,7 @@ asn1f_parametrize(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *ptype) {
* with the actual values. * with the actual values.
*/ */
nex = asn1p_expr_clone(ptype); nex = asn1p_expr_clone(ptype, 0);
if(nex == NULL) return -1; if(nex == NULL) return -1;
/* /*
...@@ -131,7 +131,7 @@ asn1f_param_process_recursive(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *ptyp ...@@ -131,7 +131,7 @@ asn1f_param_process_recursive(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *ptyp
assert(child->meta_type == AMT_TYPEREF); assert(child->meta_type == AMT_TYPEREF);
assert(child->expr_type == A1TC_REFERENCE); assert(child->expr_type == A1TC_REFERENCE);
ne = asn1p_expr_clone(ra); ne = asn1p_expr_clone(ra, 0);
if(ne == NULL) return -1; if(ne == NULL) return -1;
assert(ne->Identifier == 0); assert(ne->Identifier == 0);
ne->Identifier = strdup(child->Identifier); ne->Identifier = strdup(child->Identifier);
......
#include "asn1fix_internal.h" #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); static int asn1f_compatible_with_exports(arg_t *arg, asn1p_module_t *mod, const char *name);
...@@ -135,7 +135,7 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, asn1p_oid_t *oid) { ...@@ -135,7 +135,7 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, asn1p_oid_t *oid) {
asn1p_expr_t * 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_expr_t *ref_tc; /* Referenced tc */
asn1p_module_t *src_mod; asn1p_module_t *src_mod;
char *modulename; char *modulename;
...@@ -155,7 +155,7 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) { ...@@ -155,7 +155,7 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) {
DEBUG("%s(%s) in %s for line %d", __func__, DEBUG("%s(%s) in %s for line %d", __func__,
asn1f_printable_reference(ref), asn1f_printable_reference(ref),
arg->mod->Identifier, mod->Identifier,
ref->_lineno); ref->_lineno);
if(ref->comp_count == 1) { if(ref->comp_count == 1) {
...@@ -173,7 +173,7 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) { ...@@ -173,7 +173,7 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) {
* This is a reference to a CLASS-related stuff. * This is a reference to a CLASS-related stuff.
* Employ a separate function for that. * Employ a separate function for that.
*/ */
extract = asn1f_class_access(arg, ref, module_r); extract = asn1f_class_access(arg, mod, ref);
return extract; return extract;
} else { } else {
...@@ -216,7 +216,7 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) { ...@@ -216,7 +216,7 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) {
} }
} }
if(src_mod == 0) src_mod = arg->mod; if(src_mod == 0) src_mod = mod;
/* /*
* Now we know where to search for a value. * Now we know where to search for a value.
...@@ -242,29 +242,22 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) { ...@@ -242,29 +242,22 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, asn1p_module_t **module_r) {
return NULL; return NULL;
} }
if(module_r)
*module_r = src_mod;
return ref_tc; return ref_tc;
} }
asn1p_expr_t * asn1p_expr_t *
asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *expr, asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *expr) {
asn1p_module_t **optm) { return asn1f_find_terminal_thing(arg, expr, 0);
return asn1f_find_terminal_thing(arg, expr, optm, 0);
} }
asn1p_expr_t * asn1p_expr_t *
asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *expr, asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *expr) {
asn1p_module_t **optm) { return asn1f_find_terminal_thing(arg, expr, 1);
return asn1f_find_terminal_thing(arg, expr, optm, 1);
} }
static asn1p_expr_t * static asn1p_expr_t *
asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, int type_or_value) {
asn1p_module_t **optm, int type_or_value) {
asn1p_module_t *mod;
asn1p_ref_t *ref; asn1p_ref_t *ref;
asn1p_expr_t *tc; asn1p_expr_t *tc;
...@@ -272,19 +265,15 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, ...@@ -272,19 +265,15 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr,
/* VALUE */ /* VALUE */
assert(expr->meta_type == AMT_VALUE); assert(expr->meta_type == AMT_VALUE);
assert(expr->value); assert(expr->value);
if(expr->value->type != ATV_REFERENCED) { /* Expression may be a terminal type itself */
/* Expression is a terminal value itself */ if(expr->value->type != ATV_REFERENCED)
if(optm) *optm = arg->mod;
return expr; return expr;
}
ref = expr->value->value.reference; ref = expr->value->value.reference;
} else { } else {
/* TYPE */ /* TYPE */
if(expr->expr_type != A1TC_REFERENCE) { /* Expression may be a terminal type itself */
/* Expression is a terminal type itself */ if(expr->expr_type != A1TC_REFERENCE)
if(optm) *optm = arg->mod;
return expr; return expr;
}
ref = expr->reference; ref = expr->reference;
} }
...@@ -300,12 +289,11 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, ...@@ -300,12 +289,11 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr,
*/ */
if(type_or_value) { if(type_or_value) {
asn1p_expr_t *val_type_tc; 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 if(val_type_tc
&& asn1f_look_value_in_type(arg, val_type_tc, expr)) && asn1f_look_value_in_type(arg, val_type_tc, expr))
return NULL; return NULL;
if(expr->value->type != ATV_REFERENCED) { if(expr->value->type != ATV_REFERENCED) {
if(optm) *optm = arg->mod;
return expr; return expr;
} }
assert(ref == expr->value->value.reference); assert(ref == expr->value->value.reference);
...@@ -315,7 +303,7 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, ...@@ -315,7 +303,7 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr,
/* /*
* Lookup inside the default module. * Lookup inside the default module.
*/ */
tc = asn1f_lookup_symbol(arg, ref, &mod); tc = asn1f_lookup_symbol(arg, expr->module, ref);
if(tc == NULL) { if(tc == NULL) {
DEBUG("\tSymbol \"%s\" not found: %s", DEBUG("\tSymbol \"%s\" not found: %s",
asn1f_printable_reference(ref), asn1f_printable_reference(ref),
...@@ -334,8 +322,8 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, ...@@ -334,8 +322,8 @@ asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr,
} }
tc->_mark |= TM_RECURSION; tc->_mark |= TM_RECURSION;
WITH_MODULE(mod, WITH_MODULE(tc->module,
expr = asn1f_find_terminal_thing(arg, tc, optm, type_or_value)); expr = asn1f_find_terminal_thing(arg, tc, type_or_value));
tc->_mark &= ~TM_RECURSION; tc->_mark &= ~TM_RECURSION;
return expr; return expr;
......
...@@ -36,11 +36,10 @@ asn1p_module_t *asn1f_lookup_module(arg_t *arg, ...@@ -36,11 +36,10 @@ asn1p_module_t *asn1f_lookup_module(arg_t *arg,
/* /*
* Return the reference to a destination of the given reference, * Return the reference to a destination of the given reference,
* symbol lookup. Not a recursive function. * 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_expr_t *asn1f_lookup_symbol(arg_t *arg,
asn1p_module_t **opt_module_r); asn1p_module_t *mod,
asn1p_ref_t *ref);
/* /*
* Recursively find the original type for the given expression. * Recursively find the original type for the given expression.
...@@ -54,8 +53,7 @@ asn1p_expr_t *asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref, ...@@ -54,8 +53,7 @@ asn1p_expr_t *asn1f_lookup_symbol(arg_t *arg, asn1p_ref_t *ref,
* would return an expression for Type4. * would return an expression for Type4.
* WARNING: No attempts are made to honor constraints at this moment. * 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_expr_t *asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *tc);
asn1p_module_t **opt_module_r);
/* /*
* Recursively find the original value for the given expression. * Recursively find the original value for the given expression.
...@@ -67,7 +65,6 @@ asn1p_expr_t *asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *tc, ...@@ -67,7 +65,6 @@ asn1p_expr_t *asn1f_find_terminal_type(arg_t *arg, asn1p_expr_t *tc,
* Then this function will return the expression for value2 if given * Then this function will return the expression for value2 if given
* the v as an argment. * the v as an argment.
*/ */
asn1p_expr_t *asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *tc, asn1p_expr_t *asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *tc);
asn1p_module_t **opt_module_r);
#endif /* _ASN1FIX_RETRIEVE_H_ */ #endif /* _ASN1FIX_RETRIEVE_H_ */
...@@ -30,14 +30,14 @@ asn1f_fetch_tag(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, struct as ...@@ -30,14 +30,14 @@ asn1f_fetch_tag(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *expr, struct as
arg.mod = mod; arg.mod = mod;
arg.expr = expr; 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 == NULL) return -1;
if(expr->_mark & TM_RECURSION) if(expr->_mark & TM_RECURSION)
return -1; return -1;
expr->_mark |= TM_RECURSION; 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; expr->_mark &= ~TM_RECURSION;
return ret; return ret;
} }
......
...@@ -4,7 +4,6 @@ static int _asn1f_copy_value(arg_t *arg, asn1p_expr_t *to,asn1p_expr_t *from); ...@@ -4,7 +4,6 @@ static int _asn1f_copy_value(arg_t *arg, asn1p_expr_t *to,asn1p_expr_t *from);
int int
asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) { asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) {
asn1p_module_t *val_mod;
asn1p_expr_t *val_type_expr; asn1p_expr_t *val_type_expr;
asn1p_expr_t *value_expr; asn1p_expr_t *value_expr;
asn1p_expr_t *type_expr; asn1p_expr_t *type_expr;
...@@ -20,7 +19,7 @@ asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) { ...@@ -20,7 +19,7 @@ asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) {
/* /*
* 1. Find the terminal type for this assignment. * 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); DEBUG("%s(): terminal type %p", __func__, type_expr);
if(type_expr == 0) { if(type_expr == 0) {
DEBUG("\tTerminal type for %s not found", expr->Identifier); DEBUG("\tTerminal type for %s not found", expr->Identifier);
...@@ -33,7 +32,7 @@ asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) { ...@@ -33,7 +32,7 @@ asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) {
/* /*
* 2. Find the terminal value also. * 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) { if(value_expr) {
DEBUG("\tTerminal value for %s->%s is %s at line %d", DEBUG("\tTerminal value for %s->%s is %s at line %d",
expr->Identifier, asn1f_printable_value(expr->value), expr->Identifier, asn1f_printable_value(expr->value),
...@@ -47,8 +46,8 @@ asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) { ...@@ -47,8 +46,8 @@ asn1f_value_resolve(arg_t *arg, asn1p_expr_t *expr) {
/* /*
* 3. Find the _type_ of a _terminal value_. * 3. Find the _type_ of a _terminal value_.
*/ */
WITH_MODULE(val_mod, WITH_MODULE(value_expr->module,
val_type_expr = asn1f_find_terminal_type(arg, value_expr, 0)); val_type_expr = asn1f_find_terminal_type(arg, value_expr));
if(val_type_expr) { if(val_type_expr) {
DEBUG("\tTerminal type of value %s->%s is %s at line %d", DEBUG("\tTerminal type of value %s->%s is %s at line %d",
expr->Identifier, asn1f_printable_value(expr->value), expr->Identifier, asn1f_printable_value(expr->value),
......
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