Commit dcc822a0 authored by Bi-Ruei, Chiu's avatar Bi-Ruei, Chiu Committed by Lev Walkin

Fix duplicate type names generated in headers file

For example, there are many 'enum value_PR' and 'struct value' generated if
a class is instantiated as many instances.

typedef enum value_PR {
    value_PR_NOTHING,    /* No components present */
    .....
} value_PR;

typedef struct ProtocolIE_Field_6563P5 {
    ....
    struct value {
        value_PR present;
        union value_u {
        } choice;

        /* Context for parsing across buffer boundaries */
        asn_struct_ctx_t _asn_ctx;
    } value;

    /* Context for parsing across buffer boundaries */
    asn_struct_ctx_t _asn_ctx;
} ProtocolIE_Field_6563P5_t;
parent 3e2de696
...@@ -1065,6 +1065,7 @@ asn1c_lang_C_OpenType(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc, ...@@ -1065,6 +1065,7 @@ asn1c_lang_C_OpenType(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc,
open_type_choice->meta_type = AMT_TYPE; open_type_choice->meta_type = AMT_TYPE;
open_type_choice->expr_type = ASN_CONSTR_OPEN_TYPE; open_type_choice->expr_type = ASN_CONSTR_OPEN_TYPE;
open_type_choice->_type_unique_index = arg->expr->_type_unique_index; open_type_choice->_type_unique_index = arg->expr->_type_unique_index;
open_type_choice->parent_expr = arg->expr->parent_expr;
for(size_t row = 0; row < opt_ioc->ioct->rows; row++) { for(size_t row = 0; row < opt_ioc->ioct->rows; row++) {
struct asn1p_ioc_cell_s *cell = struct asn1p_ioc_cell_s *cell =
...@@ -1073,6 +1074,8 @@ asn1c_lang_C_OpenType(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc, ...@@ -1073,6 +1074,8 @@ asn1c_lang_C_OpenType(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc,
if(!cell->value) continue; if(!cell->value) continue;
asn1p_expr_t *m = asn1p_expr_clone(cell->value, 0); asn1p_expr_t *m = asn1p_expr_clone(cell->value, 0);
if (asn1p_lookup_child(open_type_choice, m->Identifier))
m->_mark |= TM_SKIPinUNION;
asn1p_expr_add(open_type_choice, m); asn1p_expr_add(open_type_choice, m);
} }
...@@ -1285,11 +1288,14 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) { ...@@ -1285,11 +1288,14 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
} }
} }
if(!(expr->_mark & TM_SKIPinUNION))
OUT("%s", asn1c_type_name(arg, arg->expr, tnfmt)); OUT("%s", asn1c_type_name(arg, arg->expr, tnfmt));
if(!expr->_anonymous_type) { if(!expr->_anonymous_type) {
if(!(expr->_mark & TM_SKIPinUNION)) {
OUT("%s", (expr->marker.flags&EM_INDIRECT)?"\t*":"\t "); OUT("%s", (expr->marker.flags&EM_INDIRECT)?"\t*":"\t ");
OUT("%s", MKID_safe(expr)); OUT("%s", MKID_safe(expr));
}
if((expr->marker.flags & (EM_DEFAULT & ~EM_INDIRECT)) if((expr->marker.flags & (EM_DEFAULT & ~EM_INDIRECT))
== (EM_DEFAULT & ~EM_INDIRECT)) == (EM_DEFAULT & ~EM_INDIRECT))
OUT("\t/* DEFAULT %s */", OUT("\t/* DEFAULT %s */",
...@@ -2659,7 +2665,7 @@ emit_member_type_selector(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_ob ...@@ -2659,7 +2665,7 @@ emit_member_type_selector(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_ob
REDIR(OT_CODE); REDIR(OT_CODE);
OUT("static asn_type_selector_result_t\n"); OUT("static asn_type_selector_result_t\n");
OUT("select_%s_type(const asn_TYPE_descriptor_t *parent_type, const void *parent_sptr) {\n", MKID_safe(expr)); OUT("select_%s_type(const asn_TYPE_descriptor_t *parent_type, const void *parent_sptr) {\n", c_name(arg).compound_name);
INDENT(+1); INDENT(+1);
OUT("asn_type_selector_result_t result = {0, 0};\n"); OUT("asn_type_selector_result_t result = {0, 0};\n");
...@@ -2717,7 +2723,7 @@ emit_member_type_selector(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_ob ...@@ -2717,7 +2723,7 @@ emit_member_type_selector(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_ob
OUT("\n"); OUT("\n");
REDIR(save_target); REDIR(save_target);
OUT("select_%s_type", MKID_safe(expr)); OUT("select_%s_type", c_name(arg).compound_name);
return 0; return 0;
} }
......
...@@ -173,8 +173,11 @@ c_name_impl(arg_t *arg, asn1p_expr_t *expr, int avoid_keywords) { ...@@ -173,8 +173,11 @@ c_name_impl(arg_t *arg, asn1p_expr_t *expr, int avoid_keywords) {
construct_base_name(&b_as_member, expr, 0, 1); construct_base_name(&b_as_member, expr, 0, 1);
static abuf tmp_compoundable_part_name; static abuf tmp_compoundable_part_name;
static abuf compound_part_name;
abuf_clear(&tmp_compoundable_part_name); abuf_clear(&tmp_compoundable_part_name);
abuf_clear(&compound_part_name);
construct_base_name(&tmp_compoundable_part_name, expr, compound_names, 0); construct_base_name(&tmp_compoundable_part_name, expr, compound_names, 0);
construct_base_name(&compound_part_name, expr, 1, 0);
if(!expr->_anonymous_type) { if(!expr->_anonymous_type) {
if(arg->embed) { if(arg->embed) {
...@@ -204,6 +207,7 @@ c_name_impl(arg_t *arg, asn1p_expr_t *expr, int avoid_keywords) { ...@@ -204,6 +207,7 @@ c_name_impl(arg_t *arg, asn1p_expr_t *expr, int avoid_keywords) {
names.presence_name = b_presence_name.buffer; names.presence_name = b_presence_name.buffer;
names.members_enum = b_members_enum.buffer; names.members_enum = b_members_enum.buffer;
names.members_name = b_members_name.buffer; names.members_name = b_members_name.buffer;
names.compound_name = compound_part_name.buffer;
/* A _subset_ of names is checked against being globally unique */ /* A _subset_ of names is checked against being globally unique */
register_global_name(expr, names.base_name); register_global_name(expr, names.base_name);
......
...@@ -23,6 +23,7 @@ struct c_names { ...@@ -23,6 +23,7 @@ struct c_names {
const char *presence_name; /* "foo_PR" */ const char *presence_name; /* "foo_PR" */
const char *members_enum; /* "enum foo" */ const char *members_enum; /* "enum foo" */
const char *members_name; /* "e_foo" */ const char *members_name; /* "e_foo" */
const char *compound_name; /* always contain "parent_foo" */
}; };
struct c_names c_name(arg_t *); struct c_names c_name(arg_t *);
......
...@@ -30,6 +30,10 @@ asn1p_expr_set_source(asn1p_expr_t *expr, asn1p_module_t *module, int lineno) { ...@@ -30,6 +30,10 @@ asn1p_expr_set_source(asn1p_expr_t *expr, asn1p_module_t *module, int lineno) {
int int
asn1p_expr_compare(const asn1p_expr_t *a, const asn1p_expr_t *b) { asn1p_expr_compare(const asn1p_expr_t *a, const asn1p_expr_t *b) {
if((a && !b) || (!a && b)) {
return -1;
}
if(a->meta_type != b->meta_type || a->expr_type != b->expr_type) { if(a->meta_type != b->meta_type || a->expr_type != b->expr_type) {
return -1; return -1;
} }
...@@ -185,6 +189,8 @@ asn1p_expr_clone_impl(asn1p_expr_t *expr, int skip_extensions, asn1p_expr_t *(*r ...@@ -185,6 +189,8 @@ asn1p_expr_clone_impl(asn1p_expr_t *expr, int skip_extensions, asn1p_expr_t *(*r
CLCOPY(tag); CLCOPY(tag);
CLCOPY(marker.flags); /* OPTIONAL/DEFAULT */ CLCOPY(marker.flags); /* OPTIONAL/DEFAULT */
CLCOPY(_mark); CLCOPY(_mark);
CLCOPY(parent_expr);
CLCOPY(_type_unique_index);
clone->data = 0; /* Do not clone this */ clone->data = 0; /* Do not clone this */
clone->data_free = 0; /* Do not clone this */ clone->data_free = 0; /* Do not clone this */
...@@ -303,6 +309,23 @@ asn1p_expr_add_many(asn1p_expr_t *to, asn1p_expr_t *from_what) { ...@@ -303,6 +309,23 @@ asn1p_expr_add_many(asn1p_expr_t *to, asn1p_expr_t *from_what) {
TQ_CONCAT(&(to->members), &(from_what->members), next); TQ_CONCAT(&(to->members), &(from_what->members), next);
} }
/*
* Lookup a child by its name.
*/
asn1p_expr_t *
asn1p_lookup_child(asn1p_expr_t *tc, const char *name) {
asn1p_expr_t *child_tc;
TQ_FOR(child_tc, &(tc->members), next) {
if(child_tc->Identifier
&& strcmp(child_tc->Identifier, name) == 0) {
return child_tc;
}
}
errno = ESRCH;
return NULL;
}
/* /*
* Destruct the types collection structure. * Destruct the types collection structure.
......
...@@ -251,7 +251,9 @@ typedef struct asn1p_expr_s { ...@@ -251,7 +251,9 @@ typedef struct asn1p_expr_s {
TM_BROKEN = (1<<1), /* A warning was already issued */ TM_BROKEN = (1<<1), /* A warning was already issued */
TM_PERFROMCT = (1<<2), /* PER FROM() constraint tables emitted */ TM_PERFROMCT = (1<<2), /* PER FROM() constraint tables emitted */
TM_NAMECLASH = (1<<3), /* Name clash found, need to add module name to resolve */ TM_NAMECLASH = (1<<3), /* Name clash found, need to add module name to resolve */
TM_NAMEGIVEN = (1<<4) /* The expression has already yielded a name */ TM_NAMEGIVEN = (1<<4), /* The expression has already yielded a name */
TM_SKIPinUNION = (1<<5) /* Do not include this identifier in union again due to name duplication,
especially for OPENTYPE. */
} _mark; } _mark;
/* /*
...@@ -280,6 +282,7 @@ asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *, ...@@ -280,6 +282,7 @@ asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *,
void *resolver_arg); void *resolver_arg);
void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what); void asn1p_expr_add(asn1p_expr_t *to, asn1p_expr_t *what);
void asn1p_expr_add_many(asn1p_expr_t *to, asn1p_expr_t *from_what); void asn1p_expr_add_many(asn1p_expr_t *to, asn1p_expr_t *from_what);
asn1p_expr_t *asn1p_lookup_child(asn1p_expr_t *tc, const char *name);
int asn1p_expr_compare(const asn1p_expr_t *, const asn1p_expr_t *); int asn1p_expr_compare(const asn1p_expr_t *, const asn1p_expr_t *);
void asn1p_expr_free(asn1p_expr_t *expr); void asn1p_expr_free(asn1p_expr_t *expr);
void asn1p_expr_set_source(asn1p_expr_t *, asn1p_module_t *, int lineno); void asn1p_expr_set_source(asn1p_expr_t *, asn1p_module_t *, int lineno);
......
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