From 09beb7af3340e53cda26e83598e24ccc62b1ce77 Mon Sep 17 00:00:00 2001 From: "Bi-Ruei, Chiu" Date: Wed, 18 Apr 2018 19:04:21 +0800 Subject: [PATCH 1/2] Fix item 2 of issue 254 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Record the de-referenced expression to newly added field ref_expr of strcut asn1p_ref_t. 2. In function asn1c_make_identifier(), not only check whehter there is name clash occurred for this asn1p_expr_t but also the referenced expression to determine whether an additional module name to be added. 3. Change signature of some functions and variables to eliminate warning messages when const type pointer, i.e. const asn1p_ref_t *, variables versus, non-const * type pointer, i.e. asn1p_ref_t *, varibles are used. E.g.: warning: assignment discards ‘const’ qualifier from pointer target type --- libasn1common/asn1_ref.h | 2 ++ libasn1compiler/asn1c_ioc.c | 6 +++--- libasn1compiler/asn1c_ioc.h | 2 +- libasn1compiler/asn1c_misc.c | 6 ++++++ libasn1fix/asn1fix_export.c | 2 +- libasn1fix/asn1fix_export.h | 2 +- libasn1fix/asn1fix_retrieve.c | 6 ++++-- libasn1fix/asn1fix_retrieve.h | 2 +- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libasn1common/asn1_ref.h b/libasn1common/asn1_ref.h index dbc8f878b..ad31e55a0 100644 --- a/libasn1common/asn1_ref.h +++ b/libasn1common/asn1_ref.h @@ -5,6 +5,7 @@ #define ASN1_REFERENCE_H struct asn1p_module_s; +struct asn1p_expr_s; typedef struct asn1p_ref_s { @@ -39,6 +40,7 @@ typedef struct asn1p_ref_s { size_t comp_count; /* Number of the components in the reference name. */ size_t comp_size; /* Number of allocated structures */ + struct asn1p_expr_s *ref_expr; /* De-referenced expression */ struct asn1p_module_s *module; /* Defined in module */ int _lineno; /* Number of line in the file */ } asn1p_ref_t; diff --git a/libasn1compiler/asn1c_ioc.c b/libasn1compiler/asn1c_ioc.c index 9a5e25316..bcc526cda 100644 --- a/libasn1compiler/asn1c_ioc.c +++ b/libasn1compiler/asn1c_ioc.c @@ -11,7 +11,7 @@ * Given the table constraint or component relation constraint * ({ObjectSetName}{...}) returns "ObjectSetName" as a reference. */ -const asn1p_ref_t * +asn1p_ref_t * asn1c_get_information_object_set_reference_from_constraint(arg_t *arg, const asn1p_constraint_t *ct) { @@ -68,14 +68,14 @@ asn1c_get_ioc_table(arg_t *arg) { asn1p_expr_t *expr = arg->expr; asn1p_expr_t *memb; asn1p_expr_t *objset = 0; - const asn1p_ref_t *objset_ref = NULL; + asn1p_ref_t *objset_ref = NULL; asn1c_ioc_table_and_objset_t safe_ioc_tao = {0, 0, 0}; asn1c_ioc_table_and_objset_t failed_ioc_tao = { 0, 0, 1 }; TQ_FOR(memb, &(expr->members), next) { const asn1p_constraint_t *cr_ct = asn1p_get_component_relation_constraint(memb->constraints); - const asn1p_ref_t *tmpref = + asn1p_ref_t *tmpref = asn1c_get_information_object_set_reference_from_constraint(arg, cr_ct); if(tmpref) { diff --git a/libasn1compiler/asn1c_ioc.h b/libasn1compiler/asn1c_ioc.h index d1a4b4ceb..20bec6244 100644 --- a/libasn1compiler/asn1c_ioc.h +++ b/libasn1compiler/asn1c_ioc.h @@ -15,7 +15,7 @@ asn1c_ioc_table_and_objset_t asn1c_get_ioc_table(arg_t *arg); int emit_ioc_table(arg_t *arg, asn1p_expr_t *context, asn1c_ioc_table_and_objset_t); -const asn1p_ref_t *asn1c_get_information_object_set_reference_from_constraint( +asn1p_ref_t *asn1c_get_information_object_set_reference_from_constraint( arg_t *arg, const asn1p_constraint_t *ct); diff --git a/libasn1compiler/asn1c_misc.c b/libasn1compiler/asn1c_misc.c index 8cfafc0e0..7e7d8db04 100644 --- a/libasn1compiler/asn1c_misc.c +++ b/libasn1compiler/asn1c_misc.c @@ -69,7 +69,13 @@ asn1c_make_identifier(enum ami_flags_e flags, asn1p_expr_t *expr, ...) { if(expr->_mark & TM_NAMECLASH) { size += strlen(expr->module->ModuleName) + 2; sptr[sptr_cnt++] = expr->module->ModuleName; + } else if (expr->reference && expr->reference->ref_expr && + (expr->reference->ref_expr->_mark & TM_NAMECLASH) && + (strcmp(expr->Identifier, expr->reference->ref_expr->Identifier) == 0)) { + size += strlen(expr->reference->ref_expr->module->ModuleName) + 2; + sptr[sptr_cnt++] = expr->reference->ref_expr->module->ModuleName; } + sptr[sptr_cnt++] = expr->Identifier; size += strlen(expr->Identifier); diff --git a/libasn1fix/asn1fix_export.c b/libasn1fix/asn1fix_export.c index ee39afbe7..5a4e847ff 100644 --- a/libasn1fix/asn1fix_export.c +++ b/libasn1fix/asn1fix_export.c @@ -47,7 +47,7 @@ asn1f_lookup_module_ex(asn1p_t *asn, const char *module_name, asn1p_expr_t * asn1f_lookup_symbol_ex(asn1p_t *asn, asn1_namespace_t *ns, asn1p_expr_t *expr, - const asn1p_ref_t *ref) { + asn1p_ref_t *ref) { arg_t arg; memset(&arg, 0, sizeof(arg)); diff --git a/libasn1fix/asn1fix_export.h b/libasn1fix/asn1fix_export.h index bfa055b8f..3092df459 100644 --- a/libasn1fix/asn1fix_export.h +++ b/libasn1fix/asn1fix_export.h @@ -30,7 +30,7 @@ asn1p_expr_t *asn1f_lookup_symbol_ex( asn1p_t *asn, struct asn1_namespace_s *ns, asn1p_expr_t *expr, - const asn1p_ref_t *ref); + asn1p_ref_t *ref); /* * Exportable version of an asn1f_class_access(). diff --git a/libasn1fix/asn1fix_retrieve.c b/libasn1fix/asn1fix_retrieve.c index 16f5c1c3e..d1aad18c4 100644 --- a/libasn1fix/asn1fix_retrieve.c +++ b/libasn1fix/asn1fix_retrieve.c @@ -441,8 +441,10 @@ asn1f_lookup_symbol_impl(arg_t *arg, asn1p_expr_t *rhs_pspecs, const asn1p_ref_t asn1p_expr_t * asn1f_lookup_symbol(arg_t *arg, asn1p_expr_t *rhs_pspecs, - const asn1p_ref_t *ref) { - return asn1f_lookup_symbol_impl(arg, rhs_pspecs, ref, 0); + asn1p_ref_t *ref) { + asn1p_expr_t *expr = asn1f_lookup_symbol_impl(arg, rhs_pspecs, ref, 0); + if (ref) ref->ref_expr = expr; + return expr; } asn1p_expr_t * diff --git a/libasn1fix/asn1fix_retrieve.h b/libasn1fix/asn1fix_retrieve.h index 814393724..c29f82fc4 100644 --- a/libasn1fix/asn1fix_retrieve.h +++ b/libasn1fix/asn1fix_retrieve.h @@ -38,7 +38,7 @@ asn1p_module_t *asn1f_lookup_module(arg_t *arg, * symbol lookup. Not a recursive function. */ asn1p_expr_t *asn1f_lookup_symbol(arg_t *arg, asn1p_expr_t *rhs_pspecs, - const asn1p_ref_t *ref); + asn1p_ref_t *ref); /* * Recursively find the original type for the given expression. From f97fac41f9110ea64a6e4005c3298a4648a719f4 Mon Sep 17 00:00:00 2001 From: "Bi-Ruei, Chiu" Date: Wed, 18 Apr 2018 19:18:41 +0800 Subject: [PATCH 2/2] Add test case --- ...-add-module-name-to-ios-when-clash-OK.asn1 | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/tests-asn1c-compiler/159-add-module-name-to-ios-when-clash-OK.asn1 diff --git a/tests/tests-asn1c-compiler/159-add-module-name-to-ios-when-clash-OK.asn1 b/tests/tests-asn1c-compiler/159-add-module-name-to-ios-when-clash-OK.asn1 new file mode 100644 index 000000000..c3fed2139 --- /dev/null +++ b/tests/tests-asn1c-compiler/159-add-module-name-to-ios-when-clash-OK.asn1 @@ -0,0 +1,45 @@ +-- OK: Everything is fine + +-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1) +-- .spelio.software.asn1c.test (9363.1.5.1) +-- .159 + +ModuleA + { iso org(3) dod(6) internet(1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 159 } +DEFINITIONS IMPLICIT TAGS ::= +BEGIN + +Rate ::= INTEGER(0..65535) +c-Rate INTEGER ::= 2 +EXT-TYPE ::= CLASS { + &extRef RefExt UNIQUE, + &ExtValue + } + WITH SYNTAX {&ExtValue IDENTIFIED BY &extRef} +RefExt::=INTEGER (0..255) + +END + +ModuleB +DEFINITIONS IMPLICIT TAGS ::= +BEGIN + +Rate ::= INTEGER(0..255) +c-Rate INTEGER ::= 1 + +END + +ModuleC +DEFINITIONS IMPLICIT TAGS ::= +BEGIN +IMPORTS + Rate, EXT-TYPE FROM ModuleA + c-Repeat FROM ModuleB; + +ExtTypes EXT-TYPE ::= { + { Rate IDENTIFIED BY c-Rate }, + ... + } + +END