Skip to content

Commit a2a6148

Browse files
committed
Generate constant variables reference to user defined types
Currently, there is no code generated for following ASN.1 excerpt. Thus application is not aware of these values. ProtocolIE-ID ::= INTEGER (0..65535) id-MME-UE-S1AP-ID ProtocolIE-ID ::= 0 id-HandoverType ProtocolIE-ID ::= 1 id-Cause ProtocolIE-ID ::= 2 id-SourceID ProtocolIE-ID ::= 3 ... ProcedureCode ::= INTEGER (0..255) id-HandoverPreparation ProcedureCode ::= 0 id-HandoverResourceAllocation ProcedureCode ::= 1 id-HandoverNotification ProcedureCode ::= 2 id-PathSwitchRequest ProcedureCode ::= 3 ... This commit adds corresponding macro definitions in ProtocolIE-ID.h and ProcedureCode.h respectively. #define ProtocolIE_ID_id_MME_UE_S1AP_ID ((ProtocolIE_ID_t)0) #define ProtocolIE_ID_id_HandoverType ((ProtocolIE_ID_t)1) #define ProtocolIE_ID_id_Cause ((ProtocolIE_ID_t)2) #define ProtocolIE_ID_id_SourceID ((ProtocolIE_ID_t)3) ... #define ProcedureCode_id_HandoverPreparation ((ProcedureCode_t)0) #define ProcedureCode_id_HandoverResourceAllocation ((ProcedureCode_t)1) #define ProcedureCode_id_HandoverNotification ((ProcedureCode_t)2) #define ProcedureCode_id_PathSwitchRequest ((ProcedureCode_t)3) ... Only types of ASN_BASIC_INTEGER and ASN_BASIC_ENUMERATED referenced by these constant variables are handled. Other built-in types shall be added in the future.
1 parent 30c114b commit a2a6148

File tree

8 files changed

+51
-6
lines changed

8 files changed

+51
-6
lines changed

libasn1compiler/asn1c_C.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,40 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
12131213
return 0;
12141214
} /* _CHOICE_def() */
12151215

1216+
int
1217+
asn1c_lang_C_type_REFERENCE_Value(arg_t *arg) {
1218+
arg_t tmp = *arg;
1219+
asn1p_expr_t *expr, *ref_type;
1220+
int saved_target;
1221+
1222+
expr = arg->expr;
1223+
ref_type = WITH_MODULE_NAMESPACE(
1224+
tmp.expr->module, expr_ns,
1225+
asn1f_lookup_symbol_ex(tmp.asn, expr_ns, tmp.expr,
1226+
arg->expr->reference));
1227+
if(!ref_type)
1228+
return 0;
1229+
1230+
if(!ref_type->data)
1231+
asn1c_attach_streams(ref_type);
1232+
1233+
arg->target = ref_type->data;
1234+
saved_target = arg->target->target;
1235+
REDIR(OT_FUNC_DECLS);
1236+
1237+
if((ref_type->expr_type == ASN_BASIC_INTEGER) ||
1238+
(ref_type->expr_type == ASN_BASIC_ENUMERATED)) {
1239+
OUT("#define %s_", MKID(ref_type));
1240+
OUT("%s\t", MKID(expr));
1241+
OUT("((%s)", asn1c_type_name(arg, expr, TNF_CTYPE));
1242+
OUT("%s)\n", asn1p_itoa(expr->value->value.v_integer));
1243+
}
1244+
1245+
REDIR(saved_target);
1246+
arg->target = tmp.target;
1247+
return 0;
1248+
}
1249+
12161250
int
12171251
asn1c_lang_C_type_REFERENCE(arg_t *arg) {
12181252
asn1p_ref_t *ref;

libasn1compiler/asn1c_C.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ int asn1c_lang_C_type_common_INTEGER(arg_t *);
1515
int asn1c_lang_C_type_BIT_STRING(arg_t *);
1616
int asn1c_lang_C_type_REAL(arg_t *);
1717
int asn1c_lang_C_type_SIMPLE_TYPE(arg_t *);
18+
int asn1c_lang_C_type_REFERENCE_Value(arg_t *);
1819

1920
static asn1_language_map_t asn1_lang_C[] __attribute__ ((unused)) = {
21+
{ AMT_VALUE, A1TC_REFERENCE, asn1c_lang_C_type_REFERENCE_Value },
22+
2023
{ AMT_TYPE, A1TC_REFERENCE, asn1c_lang_C_type_REFERENCE },
2124
{ AMT_TYPEREF, A1TC_REFERENCE, asn1c_lang_C_type_REFERENCE },
2225
{ AMT_TYPE, A1TC_EXTENSIBLE, asn1c_lang_C_type_EXTENSIBLE },

libasn1compiler/asn1c_save.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
7070
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
7171
TQ_FOR(arg->expr, &(mod->members), next) {
7272
if(asn1_lang_map[arg->expr->meta_type]
73-
[arg->expr->expr_type].type_cb) {
73+
[arg->expr->expr_type].type_cb &&
74+
(arg->expr->meta_type != AMT_VALUE)) {
7475
safe_fprintf(mkf, "\t\\\n\t%s%s.c", destdir,
7576
asn1c_make_identifier(AMI_MASK_ONLY_SPACES, arg->expr, 0));
7677
}
@@ -80,7 +81,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
8081
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
8182
TQ_FOR(arg->expr, &(mod->members), next) {
8283
if(asn1_lang_map[arg->expr->meta_type]
83-
[arg->expr->expr_type].type_cb) {
84+
[arg->expr->expr_type].type_cb &&
85+
(arg->expr->meta_type != AMT_VALUE)) {
8486
safe_fprintf(mkf, "\t\\\n\t%s%s.h", destdir,
8587
asn1c_make_identifier(AMI_MASK_ONLY_SPACES, arg->expr, 0));
8688
}
@@ -387,7 +389,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
387389
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
388390
TQ_FOR(arg->expr, &(mod->members), next) {
389391
if(asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type]
390-
.type_cb) {
392+
.type_cb &&
393+
(arg->expr->meta_type != AMT_VALUE)) {
391394
if(asn1c_dump_streams(arg, deps, destdir, optc, argv)) break;
392395
}
393396
}
@@ -911,7 +914,8 @@ pdu_collection_has_unused_types(arg_t *arg) {
911914

912915
static enum include_type_result
913916
include_type_to_pdu_collection(arg_t *arg) {
914-
if(!asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type].type_cb)
917+
if(!asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type].type_cb ||
918+
(arg->expr->meta_type == AMT_VALUE))
915919
return 0;
916920

917921
/* Parameterized types can't serve as PDU's without instantiation. */

libasn1compiler/asn1compiler.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
static void default_logger_cb(int, const char *fmt, ...);
99
static int asn1c_compile_expr(arg_t *arg, const asn1c_ioc_table_and_objset_t *);
10-
static int asn1c_attach_streams(asn1p_expr_t *expr);
1110
static int asn1c_detach_streams(asn1p_expr_t *expr);
1211

1312
int
@@ -169,7 +168,7 @@ asn1c_compile_expr(arg_t *arg, const asn1c_ioc_table_and_objset_t *opt_ioc) {
169168
return ret;
170169
}
171170

172-
static int
171+
int
173172
asn1c_attach_streams(asn1p_expr_t *expr) {
174173
compiler_streams_t *cs;
175174
int i;

libasn1compiler/asn1compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ int asn1_compile(asn1p_t *asn, const char *datadir, const char *destdir, enum as
102102

103103
void asn1c__add_pdu_type(const char *typename);
104104

105+
int asn1c_attach_streams(asn1p_expr_t *expr);
106+
105107
#endif /* ASN1_COMPILER_H */

tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1.-Pgen-PER

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef long PacketId_t;
99

1010
/*** <<< FUNC-DECLS [PacketId] >>> ***/
1111

12+
#define PacketId_id_TYPE1 ((PacketId_t)1)
1213
extern asn_per_constraints_t asn_PER_type_PacketId_constr_1;
1314
extern asn_TYPE_descriptor_t asn_DEF_PacketId;
1415
asn_struct_free_f PacketId_free;

tests/tests-asn1c-compiler/50-constraint-OK.asn1.-Pfwide-types

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ber_type_decoder_f Int1_decode_ber;
1717
der_type_encoder_f Int1_encode_der;
1818
xer_type_decoder_f Int1_decode_xer;
1919
xer_type_encoder_f Int1_encode_xer;
20+
#define Int1_ten ((Int1_t)10)
2021

2122
/*** <<< CODE [Int1] >>> ***/
2223

tests/tests-asn1c-compiler/50-constraint-OK.asn1.-Pgen-PER

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ xer_type_decoder_f Int1_decode_xer;
1919
xer_type_encoder_f Int1_encode_xer;
2020
per_type_decoder_f Int1_decode_uper;
2121
per_type_encoder_f Int1_encode_uper;
22+
#define Int1_ten ((Int1_t)10)
2223

2324
/*** <<< CODE [Int1] >>> ***/
2425

0 commit comments

Comments
 (0)