Commit 0a752418 authored by Bi-Ruei, Chiu's avatar Bi-Ruei, Chiu

Fix the problem that duplicate type names exist in OPEN TYPE

This is a side-effect of commit :

  939573d7 and
  dcc822a0

Which intends to solve the problem result from, e.g. for the following ASN.1 :

  HandoverRequestAcknowledge-IEs X2AP-PROTOCOL-IES ::= {
    { ID id-Old-eNB-UE-X2AP-ID  CRITICALITY ignore  TYPE UE-X2AP-ID  PRESENCE mandatory}|
    { ID id-New-eNB-UE-X2AP-ID  CRITICALITY ignore  TYPE UE-X2AP-ID  PRESENCE mandatory}|
    ...
  }

Items with id-Old-eNB-UE-X2AP-ID and id-New-eNB-UE-X2AP-ID are both of
type UE-X2AP-ID, so the generated enum type HandoverRequestAcknowledge_IEs__value_PR
will have two identical members :

  typedef enum HandoverRequestAcknowledge_IEs__value_PR {
      HandoverRequestAcknowledge_IEs__value_PR_NOTHING,    /* No components present */
      HandoverRequestAcknowledge_IEs__value_PR_UE_X2AP_ID,
      HandoverRequestAcknowledge_IEs__value_PR_UE_X2AP_ID,
      ...
  } HandoverRequestAcknowledge_IEs__value_PR

and the generated struc type HandoverRequestAcknowledge_IEs_t
will also have two identical members :

  typedef struct HandoverRequestAcknowledge_IEs {
      ProtocolIE_ID_t  id;
      Criticality_t    criticality;
      struct HandoverRequestAcknowledge_IEs__value {
          HandoverRequestAcknowledge_IEs__value_PR present;
          union XHandoverRequestAcknowledge_IEs__value_u {
              UE_X2AP_ID_t  UE_X2AP_ID;
              UE_X2AP_ID_t  UE_X2AP_ID;
              ...
          } 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;
  } HandoverRequestAcknowledge_IEs_t;

these code excerpts results in compilation error.

Previous commits solve it by skipping duplicate items but raise
a side-effect that asn_MBR_HandoverRequestAcknowledge_IEs only has
one item corresponding UE_X2AP_ID field.

This commit rename the second item by adding '_2' (or said '_%d'
according to number of occurrence) to their names thus solve the
conflict.
parent d3aed06b
...@@ -1100,10 +1100,14 @@ asn1c_lang_C_OpenType(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc, ...@@ -1100,10 +1100,14 @@ asn1c_lang_C_OpenType(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc,
if(!cell->value) continue; if(!cell->value) continue;
if(asn1p_lookup_child(open_type_choice, cell->value->Identifier))
continue;
asn1p_expr_t *m = asn1p_expr_clone(cell->value, 0); asn1p_expr_t *m = asn1p_expr_clone(cell->value, 0);
int n = asn1p_lookup_child_count_by_name(open_type_choice, cell->value->Identifier);
if (n) {
m->spec_index = n;
m->_lineno = -1;
}
asn1p_expr_add(open_type_choice, m); asn1p_expr_add(open_type_choice, m);
} }
......
...@@ -94,8 +94,13 @@ asn1c_make_identifier(enum ami_flags_e flags, asn1p_expr_t *expr, ...) { ...@@ -94,8 +94,13 @@ asn1c_make_identifier(enum ami_flags_e flags, asn1p_expr_t *expr, ...) {
size += strlen(expr->Identifier); size += strlen(expr->Identifier);
if(expr->spec_index != -1 && expr->_lineno) { if(expr->spec_index != -1 && expr->_lineno) {
static char buf[32]; static char buf[32];
size += 1 + snprintf(buf, sizeof buf, "%dP%d",
expr->_lineno, expr->spec_index); if(expr->_lineno > 0)
size += 1 + snprintf(buf, sizeof buf, "%dP%d",
expr->_lineno, expr->spec_index);
else if(expr->_lineno < 0)
size += 1 + snprintf(buf, sizeof buf, "%d",
expr->spec_index);
sptr[sptr_cnt++] = (char *)&buf; sptr[sptr_cnt++] = (char *)&buf;
} }
} else { } else {
......
...@@ -333,6 +333,21 @@ asn1p_lookup_child(asn1p_expr_t *tc, const char *name) { ...@@ -333,6 +333,21 @@ asn1p_lookup_child(asn1p_expr_t *tc, const char *name) {
return NULL; return NULL;
} }
int
asn1p_lookup_child_count_by_name(asn1p_expr_t *tc, const char *name) {
asn1p_expr_t *child_tc;
int count = 0;
TQ_FOR(child_tc, &(tc->members), next) {
if(child_tc->Identifier
&& strcmp(child_tc->Identifier, name) == 0) {
count++;
}
}
return count;
}
/* /*
* Destruct the types collection structure. * Destruct the types collection structure.
*/ */
......
...@@ -281,6 +281,7 @@ asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *, ...@@ -281,6 +281,7 @@ asn1p_expr_t *asn1p_expr_clone_with_resolver(asn1p_expr_t *,
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); asn1p_expr_t *asn1p_lookup_child(asn1p_expr_t *tc, const char *name);
int asn1p_lookup_child_count_by_name(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);
......
...@@ -78,7 +78,10 @@ typedef enum value_PR { ...@@ -78,7 +78,10 @@ typedef enum value_PR {
value_PR_NOTHING, /* No components present */ value_PR_NOTHING, /* No components present */
value_PR_INTEGER, value_PR_INTEGER,
value_PR_BOOLEAN, value_PR_BOOLEAN,
value_PR_OCTET_STRING value_PR_OCTET_STRING,
value_PR_INTEGER_1,
value_PR_BOOLEAN_1,
value_PR_OCTET_STRING_1
} value_PR; } value_PR;
/*** <<< TYPE-DECLS [SpecializedContent] >>> ***/ /*** <<< TYPE-DECLS [SpecializedContent] >>> ***/
...@@ -91,6 +94,9 @@ typedef struct TotalRegionExtension { ...@@ -91,6 +94,9 @@ typedef struct TotalRegionExtension {
long INTEGER; long INTEGER;
BOOLEAN_t BOOLEAN; BOOLEAN_t BOOLEAN;
OCTET_STRING_t OCTET_STRING; OCTET_STRING_t OCTET_STRING;
long INTEGER_1;
BOOLEAN_t BOOLEAN_1;
OCTET_STRING_t OCTET_STRING_1;
} choice; } choice;
/* Context for parsing across buffer boundaries */ /* Context for parsing across buffer boundaries */
...@@ -244,13 +250,43 @@ static asn_TYPE_member_t asn_MBR_value_3[] = { ...@@ -244,13 +250,43 @@ static asn_TYPE_member_t asn_MBR_value_3[] = {
0, 0, /* No default value */ 0, 0, /* No default value */
.name = "OCTET STRING" .name = "OCTET STRING"
}, },
{ ATF_NOFLAGS, 0, offsetof(struct value, choice.INTEGER_1),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
.tag_mode = 0,
.type = &asn_DEF_NativeInteger,
.type_selector = 0,
{ .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
0, 0, /* No default value */
.name = "INTEGER"
},
{ ATF_NOFLAGS, 0, offsetof(struct value, choice.BOOLEAN_1),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)),
.tag_mode = 0,
.type = &asn_DEF_BOOLEAN,
.type_selector = 0,
{ .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
0, 0, /* No default value */
.name = "BOOLEAN"
},
{ ATF_NOFLAGS, 0, offsetof(struct value, choice.OCTET_STRING_1),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)),
.tag_mode = 0,
.type = &asn_DEF_OCTET_STRING,
.type_selector = 0,
{ .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
0, 0, /* No default value */
.name = "OCTET STRING"
},
}; };
static const unsigned asn_MAP_value_to_canonical_3[] = { 1, 0, 2 }; static const unsigned asn_MAP_value_to_canonical_3[] = { 1, 4, 0, 3, 2, 5 };
static const unsigned asn_MAP_value_from_canonical_3[] = { 1, 0, 2 }; static const unsigned asn_MAP_value_from_canonical_3[] = { 2, 0, 4, 3, 1, 5 };
static const asn_TYPE_tag2member_t asn_MAP_value_tag2el_3[] = { static const asn_TYPE_tag2member_t asn_MAP_value_tag2el_3[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), 1, 0, 0 }, /* BOOLEAN */ { (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), 1, 0, 1 }, /* BOOLEAN */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* INTEGER */ { (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), 4, -1, 0 }, /* BOOLEAN */
{ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), 2, 0, 0 } /* OCTET STRING */ { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 1 }, /* INTEGER */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 3, -1, 0 }, /* INTEGER */
{ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), 2, 0, 1 }, /* OCTET STRING */
{ (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), 5, -1, 0 } /* OCTET STRING */
}; };
static asn_CHOICE_specifics_t asn_SPC_value_specs_3 = { static asn_CHOICE_specifics_t asn_SPC_value_specs_3 = {
sizeof(struct value), sizeof(struct value),
...@@ -258,7 +294,7 @@ static asn_CHOICE_specifics_t asn_SPC_value_specs_3 = { ...@@ -258,7 +294,7 @@ static asn_CHOICE_specifics_t asn_SPC_value_specs_3 = {
offsetof(struct value, present), offsetof(struct value, present),
sizeof(((struct value *)0)->present), sizeof(((struct value *)0)->present),
.tag2el = asn_MAP_value_tag2el_3, .tag2el = asn_MAP_value_tag2el_3,
.tag2el_count = 3, /* Count of tags in the map */ .tag2el_count = 6, /* Count of tags in the map */
.to_canonical_order = asn_MAP_value_to_canonical_3, .to_canonical_order = asn_MAP_value_to_canonical_3,
.from_canonical_order = asn_MAP_value_from_canonical_3, .from_canonical_order = asn_MAP_value_from_canonical_3,
.first_extension = -1 /* Extensions start */ .first_extension = -1 /* Extensions start */
...@@ -274,7 +310,7 @@ asn_TYPE_descriptor_t asn_DEF_value_3 = { ...@@ -274,7 +310,7 @@ asn_TYPE_descriptor_t asn_DEF_value_3 = {
0, /* No tags (count) */ 0, /* No tags (count) */
{ 0, 0, OPEN_TYPE_constraint }, { 0, 0, OPEN_TYPE_constraint },
asn_MBR_value_3, asn_MBR_value_3,
3, /* Elements count */ 6, /* Elements count */
&asn_SPC_value_specs_3 /* Additional specs */ &asn_SPC_value_specs_3 /* Additional specs */
}; };
......
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