Skip to content

Commit 8663b74

Browse files
committed
Use comprehensible names for instances of parameterized types
With previous commit, the following data types are generated in ProtocolIE-Field.h for S1AP's ASN.1 : ``` typedef enum ProtocolIE_Field_6564P0__value_PR { ProtocolIE_Field_6564P0__value_PR_NOTHING, /* No components present */ ProtocolIE_Field_6564P0__value_PR_E_RABToBeSetupItemBearerSUReq } ProtocolIE_Field_6564P0__value_PR; typedef struct ProtocolIE_Field_6564P0 { ProtocolIE_ID_t id; Criticality_t criticality; struct ProtocolIE_Field_6564P0__value { ProtocolIE_Field_6564P0__value_PR present; union ProtocolIE_Field_6564P0__value_u { E_RABToBeSetupItemBearerSUReq_t E_RABToBeSetupItemBearerSUReq; } 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_6564P0_t; ``` It's difficult for developer to recognize to which ASN.1 type they are linked. They all start with 'ProtocolIE_Field_'. It will be error-prone. With this commit, more human comprehensible data types are generated : ``` typedef enum E_RABToBeSetupItemBearerSUReqIEs_6564P0__value_PR { E_RABToBeSetupItemBearerSUReqIEs_6564P0__value_PR_NOTHING, /* No components present */ E_RABToBeSetupItemBearerSUReqIEs_6564P0__value_PR_E_RABToBeSetupItemBearerSUReq } E_RABToBeSetupItemBearerSUReqIEs_6564P0__value_PR; typedef struct E_RABToBeSetupItemBearerSUReqIEs_6564P0 { ProtocolIE_ID_t id; Criticality_t criticality; struct E_RABToBeSetupItemBearerSUReqIEs_6564P0__value { E_RABToBeSetupItemBearerSUReqIEs_6564P0__value_PR present; union E_RABToBeSetupItemBearerSUReqIEs_6564P0__value_u { E_RABToBeSetupItemBearerSUReq_t E_RABToBeSetupItemBearerSUReq; } 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; } E_RABToBeSetupItemBearerSUReqIEs_6564P0_t; ``` Developers can understand they are generated from : ``` E-RABToBeSetupItemBearerSUReqIEs S1AP-PROTOCOL-IES ::= { { ID id-E-RABToBeSetupItemBearerSUReq CRITICALITY reject TYPE E-RABToBeSetupItemBearerSUReq PRESENCE mandatory }, ... } ```
1 parent ae11d5c commit 8663b74

8 files changed

+178
-146
lines changed

libasn1compiler/asn1c_C.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ asn1c_lang_C_type_SIMPLE_TYPE(arg_t *arg) {
13041304
}
13051305

13061306
} else {
1307-
GEN_INCLUDE(asn1c_type_name(arg, expr, TNF_INCLUDE));
1307+
GEN_POS_INCLUDE_BASE(OT_INCLUDES, expr);
13081308

13091309
REDIR(OT_TYPE_DECLS);
13101310

@@ -3236,13 +3236,8 @@ emit_include_dependencies(arg_t *arg) {
32363236
if((!(memb->expr_type & ASN_CONSTR_MASK)
32373237
&& memb->expr_type > ASN_CONSTR_MASK)
32383238
|| memb->meta_type == AMT_TYPEREF) {
3239-
if(memb->marker.flags & EM_UNRECURSE) {
3240-
GEN_POSTINCLUDE(asn1c_type_name(arg,
3241-
memb, TNF_INCLUDE));
3242-
} else {
3243-
GEN_INCLUDE(asn1c_type_name(arg,
3244-
memb, TNF_INCLUDE));
3245-
}
3239+
GEN_POS_INCLUDE_BASE((memb->marker.flags & EM_UNRECURSE) ?
3240+
OT_POST_INCLUDE : OT_INCLUDES, memb);
32463241
}
32473242
}
32483243

libasn1compiler/asn1c_misc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,20 @@ asn1c_type_name(arg_t *arg, asn1p_expr_t *expr, enum tnfmt _format) {
297297
_format = TNF_CTYPE;
298298
stdname = 1;
299299
typename = ASN_EXPR_TYPE2STR(expr->expr_type);
300+
if(_format == TNF_INCLUDE) {
301+
if(expr->expr_type == ASN_CONSTR_SEQUENCE)
302+
typename = "constr_SEQUENCE";
303+
else if(expr->expr_type == ASN_CONSTR_CHOICE)
304+
typename = "constr_CHOICE";
305+
else if(expr->expr_type == ASN_CONSTR_SET)
306+
typename = "constr_SET";
307+
else if(expr->expr_type == ASN_CONSTR_SEQUENCE_OF)
308+
typename = "constr_SEQUENCE_OF";
309+
else if(expr->expr_type == ASN_CONSTR_SET_OF)
310+
typename = "constr_SET_OF";
311+
else if(expr->expr_type == ASN_CONSTR_OPEN_TYPE)
312+
typename = "OPEN_TYPE";
313+
}
300314
} else {
301315
_format = TNF_RSAFE;
302316
typename = expr->Identifier;

libasn1compiler/asn1c_out.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,31 @@ int asn1c_compiled_output(arg_t *arg, const char *fmt, ...);
9090
} while(0)
9191

9292
/* Generate #include line */
93-
#define GEN_INCLUDE_STD(typename) do { \
94-
if((arg->flags & A1C_INCLUDES_QUOTED)) { \
93+
#define GEN_INCLUDE_STD(typename) do { \
94+
if((arg->flags & A1C_INCLUDES_QUOTED)) { \
9595
GEN_INCLUDE("\"" typename ".h\""); \
9696
} else { \
9797
GEN_INCLUDE("<" typename ".h>"); \
9898
} } while(0)
99-
#define GEN_INCLUDE(filename) do { \
99+
#define GEN_INCLUDE(filename) \
100+
GEN_POS_INCLUDE(OT_INCLUDES, filename)
101+
#define GEN_POSTINCLUDE(filename) \
102+
GEN_POS_INCLUDE(OT_POST_INCLUDE, filename)
103+
#define GEN_POS_INCLUDE(pos, filename) do { \
100104
int saved_target = arg->target->target; \
101105
if(!filename) break; \
102-
REDIR(OT_INCLUDES); \
106+
REDIR(pos); \
103107
OUT_NOINDENT("#include %s\n", filename); \
104108
REDIR(saved_target); \
105109
} while(0)
106-
#define GEN_POSTINCLUDE(filename) do { \
110+
#define GEN_POS_INCLUDE_BASE(pos, expr) do { \
111+
asn1p_expr_t *rhs_pspecs = expr->rhs_pspecs; \
112+
expr->rhs_pspecs = (asn1p_expr_t *)0; \
107113
int saved_target = arg->target->target; \
108-
if(!filename) break; \
109-
REDIR(OT_POST_INCLUDE); \
110-
OUT_NOINDENT("#include %s\n", filename); \
114+
REDIR(pos); \
115+
OUT_NOINDENT("#include %s\n", \
116+
asn1c_type_name(arg, expr, TNF_INCLUDE)); \
117+
expr->rhs_pspecs = rhs_pspecs; \
111118
REDIR(saved_target); \
112119
} while(0)
113120

libasn1fix/asn1fix_param.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ typedef struct resolver_arg {
66
asn1p_expr_t *original_expr;
77
asn1p_paramlist_t *lhs_params;
88
asn1p_expr_t *rhs_pspecs;
9+
char *resolved_name;
910
} resolver_arg_t;
1011

1112
static asn1p_expr_t *resolve_expr(asn1p_expr_t *, void *resolver_arg);
@@ -52,8 +53,13 @@ asn1f_parameterization_fork(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *rhs_ps
5253
rarg.original_expr = expr;
5354
rarg.lhs_params = expr->lhs_params;
5455
rarg.rhs_pspecs = rhs_pspecs;
56+
rarg.resolved_name = NULL;
5557
exc = asn1p_expr_clone_with_resolver(expr, resolve_expr, &rarg);
5658
if(!exc) return NULL;
59+
if(rarg.resolved_name) {
60+
free(exc->Identifier);
61+
exc->Identifier = strdup(rarg.resolved_name);
62+
}
5763
rpc = asn1p_expr_clone(rhs_pspecs, 0);
5864
assert(rpc);
5965

@@ -138,6 +144,16 @@ resolve_expr(asn1p_expr_t *expr_to_resolve, void *resolver_arg) {
138144
free(nex->Identifier);
139145
nex->Identifier = expr_to_resolve->Identifier
140146
? strdup(expr_to_resolve->Identifier) : 0;
147+
if(expr->meta_type == AMT_TYPEREF) {
148+
asn1p_ref_t *ref = expr->reference;
149+
rarg->resolved_name = ref->components[ref->comp_count - 1].name;
150+
} else if(expr->meta_type == AMT_VALUESET) {
151+
asn1p_constraint_t *ct = expr->constraints;
152+
if(ct->type == ACT_EL_TYPE) {
153+
asn1p_ref_t *ref = ct->containedSubtype->value.v_type->reference;
154+
rarg->resolved_name = ref->components[ref->comp_count - 1].name;
155+
}
156+
}
141157
return nex;
142158
} else {
143159
FATAL("Feature not implemented for %s (%d/%x), "

tests/tests-asn1c-compiler/144-ios-parameterization-OK.asn1.-P

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/*** <<< TYPE-DECLS [Message] >>> ***/
88

99
typedef struct Message {
10-
SpecializedContent_30P0_t content;
10+
RegionalExtension_30P0_t content;
1111

1212
/* Context for parsing across buffer boundaries */
1313
asn_struct_ctx_t _asn_ctx;
@@ -23,7 +23,7 @@ static asn_TYPE_member_t asn_MBR_Message_1[] = {
2323
{ ATF_NOFLAGS, 0, offsetof(struct Message, content),
2424
.tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
2525
.tag_mode = 0,
26-
.type = &asn_DEF_SpecializedContent_30P0,
26+
.type = &asn_DEF_RegionalExtension_30P0,
2727
.type_selector = 0,
2828
{ .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 },
2929
0, 0, /* No default value */
@@ -81,11 +81,11 @@ typedef enum value_PR {
8181

8282
/*** <<< TYPE-DECLS [SpecializedContent] >>> ***/
8383

84-
typedef struct SpecializedContent_30P0 {
84+
typedef struct RegionalExtension_30P0 {
8585
long id;
8686
struct value {
8787
value_PR present;
88-
union SpecializedContent_30P0__value_u {
88+
union RegionalExtension_30P0__value_u {
8989
long INTEGER;
9090
BOOLEAN_t BOOLEAN;
9191
} choice;
@@ -96,13 +96,13 @@ typedef struct SpecializedContent_30P0 {
9696

9797
/* Context for parsing across buffer boundaries */
9898
asn_struct_ctx_t _asn_ctx;
99-
} SpecializedContent_30P0_t;
99+
} RegionalExtension_30P0_t;
100100

101101
/*** <<< FUNC-DECLS [SpecializedContent] >>> ***/
102102

103-
extern asn_TYPE_descriptor_t asn_DEF_SpecializedContent_30P0;
104-
extern asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_30P0_specs_1;
105-
extern asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[2];
103+
extern asn_TYPE_descriptor_t asn_DEF_RegionalExtension_30P0;
104+
extern asn_SEQUENCE_specifics_t asn_SPC_RegionalExtension_30P0_specs_1;
105+
extern asn_TYPE_member_t asn_MBR_RegionalExtension_30P0_1[2];
106106

107107
/*** <<< IOC-TABLES [SpecializedContent] >>> ***/
108108

@@ -140,13 +140,13 @@ memb_id_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr,
140140
}
141141

142142
static asn_type_selector_result_t
143-
select_SpecializedContent_30P0_value_type(const asn_TYPE_descriptor_t *parent_type, const void *parent_sptr) {
143+
select_RegionalExtension_30P0_value_type(const asn_TYPE_descriptor_t *parent_type, const void *parent_sptr) {
144144
asn_type_selector_result_t result = {0, 0};
145145
const asn_ioc_set_t *itable = asn_IOS_RegionalExtension_1;
146146
size_t constraining_column = 0; /* &id */
147147
size_t for_column = 1; /* &Type */
148148
size_t row;
149-
const long *constraining_value = (const long *)((const char *)parent_sptr + offsetof(struct SpecializedContent_30P0, id));
149+
const long *constraining_value = (const long *)((const char *)parent_sptr + offsetof(struct RegionalExtension_30P0, id));
150150

151151
for(row=0; row < itable->rows_count; row++) {
152152
const asn_ioc_cell_t *constraining_cell = &itable->rows[row * itable->columns_count + constraining_column];
@@ -233,8 +233,8 @@ asn_TYPE_descriptor_t asn_DEF_value_3 = {
233233
&asn_SPC_value_specs_3 /* Additional specs */
234234
};
235235

236-
asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[] = {
237-
{ ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_30P0, id),
236+
asn_TYPE_member_t asn_MBR_RegionalExtension_30P0_1[] = {
237+
{ ATF_NOFLAGS, 0, offsetof(struct RegionalExtension_30P0, id),
238238
.tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
239239
.tag_mode = 0,
240240
.type = &asn_DEF_NativeInteger,
@@ -243,43 +243,43 @@ asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[] = {
243243
0, 0, /* No default value */
244244
.name = "id"
245245
},
246-
{ ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_30P0, value),
246+
{ ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct RegionalExtension_30P0, value),
247247
.tag = -1 /* Ambiguous tag (ANY?) */,
248248
.tag_mode = 0,
249249
.type = &asn_DEF_value_3,
250-
.type_selector = select_SpecializedContent_30P0_value_type,
250+
.type_selector = select_RegionalExtension_30P0_value_type,
251251
{ .oer_constraints = 0, .per_constraints = 0, .general_constraints = memb_value_constraint_1 },
252252
0, 0, /* No default value */
253253
.name = "value"
254254
},
255255
};
256-
static const ber_tlv_tag_t asn_DEF_SpecializedContent_30P0_tags_1[] = {
256+
static const ber_tlv_tag_t asn_DEF_RegionalExtension_30P0_tags_1[] = {
257257
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
258258
};
259-
static const asn_TYPE_tag2member_t asn_MAP_SpecializedContent_30P0_tag2el_1[] = {
259+
static const asn_TYPE_tag2member_t asn_MAP_RegionalExtension_30P0_tag2el_1[] = {
260260
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* id */
261261
};
262-
asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_30P0_specs_1 = {
263-
sizeof(struct SpecializedContent_30P0),
264-
offsetof(struct SpecializedContent_30P0, _asn_ctx),
265-
.tag2el = asn_MAP_SpecializedContent_30P0_tag2el_1,
262+
asn_SEQUENCE_specifics_t asn_SPC_RegionalExtension_30P0_specs_1 = {
263+
sizeof(struct RegionalExtension_30P0),
264+
offsetof(struct RegionalExtension_30P0, _asn_ctx),
265+
.tag2el = asn_MAP_RegionalExtension_30P0_tag2el_1,
266266
.tag2el_count = 1, /* Count of tags in the map */
267267
0, 0, 0, /* Optional elements (not needed) */
268268
-1, /* First extension addition */
269269
};
270-
asn_TYPE_descriptor_t asn_DEF_SpecializedContent_30P0 = {
271-
"SpecializedContent",
272-
"SpecializedContent",
270+
asn_TYPE_descriptor_t asn_DEF_RegionalExtension_30P0 = {
271+
"RegionalExtension",
272+
"RegionalExtension",
273273
&asn_OP_SEQUENCE,
274-
asn_DEF_SpecializedContent_30P0_tags_1,
275-
sizeof(asn_DEF_SpecializedContent_30P0_tags_1)
276-
/sizeof(asn_DEF_SpecializedContent_30P0_tags_1[0]), /* 1 */
277-
asn_DEF_SpecializedContent_30P0_tags_1, /* Same as above */
278-
sizeof(asn_DEF_SpecializedContent_30P0_tags_1)
279-
/sizeof(asn_DEF_SpecializedContent_30P0_tags_1[0]), /* 1 */
274+
asn_DEF_RegionalExtension_30P0_tags_1,
275+
sizeof(asn_DEF_RegionalExtension_30P0_tags_1)
276+
/sizeof(asn_DEF_RegionalExtension_30P0_tags_1[0]), /* 1 */
277+
asn_DEF_RegionalExtension_30P0_tags_1, /* Same as above */
278+
sizeof(asn_DEF_RegionalExtension_30P0_tags_1)
279+
/sizeof(asn_DEF_RegionalExtension_30P0_tags_1[0]), /* 1 */
280280
{ 0, 0, SEQUENCE_constraint },
281-
asn_MBR_SpecializedContent_30P0_1,
281+
asn_MBR_RegionalExtension_30P0_1,
282282
2, /* Elements count */
283-
&asn_SPC_SpecializedContent_30P0_specs_1 /* Additional specs */
283+
&asn_SPC_RegionalExtension_30P0_specs_1 /* Additional specs */
284284
};
285285

0 commit comments

Comments
 (0)