Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate constant variables reference to user defined types
Browse files Browse the repository at this point in the history
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.
brchiu committed Jan 16, 2018
1 parent 89d65af commit f38c31e
Showing 5 changed files with 48 additions and 6 deletions.
34 changes: 34 additions & 0 deletions libasn1compiler/asn1c_C.c
Original file line number Diff line number Diff line change
@@ -1213,6 +1213,40 @@ asn1c_lang_C_type_CHOICE_def(arg_t *arg) {
return 0;
} /* _CHOICE_def() */

int
asn1c_lang_C_type_REFERENCE_Value(arg_t *arg) {
arg_t tmp = *arg;
asn1p_expr_t *expr, *ref_type;
int saved_target;

expr = arg->expr;
ref_type = WITH_MODULE_NAMESPACE(
tmp.expr->module, expr_ns,
asn1f_lookup_symbol_ex(tmp.asn, expr_ns, tmp.expr,
arg->expr->reference));
if(!ref_type)
return 0;

if(!ref_type->data)
asn1c_attach_streams(ref_type);

arg->target = ref_type->data;
saved_target = arg->target->target;
REDIR(OT_FUNC_DECLS);

if((ref_type->expr_type == ASN_BASIC_INTEGER) ||
(ref_type->expr_type == ASN_BASIC_ENUMERATED)) {
OUT("#define %s_", MKID(ref_type));
OUT("%s\t", MKID(expr));
OUT("((%s)", asn1c_type_name(arg, expr, TNF_CTYPE));
OUT("%s)\n", asn1p_itoa(expr->value->value.v_integer));
}

REDIR(saved_target);
arg->target = tmp.target;
return 0;
}

int
asn1c_lang_C_type_REFERENCE(arg_t *arg) {
asn1p_ref_t *ref;
3 changes: 3 additions & 0 deletions libasn1compiler/asn1c_C.h
Original file line number Diff line number Diff line change
@@ -15,8 +15,11 @@ int asn1c_lang_C_type_common_INTEGER(arg_t *);
int asn1c_lang_C_type_BIT_STRING(arg_t *);
int asn1c_lang_C_type_REAL(arg_t *);
int asn1c_lang_C_type_SIMPLE_TYPE(arg_t *);
int asn1c_lang_C_type_REFERENCE_Value(arg_t *);

static asn1_language_map_t asn1_lang_C[] __attribute__ ((unused)) = {
{ AMT_VALUE, A1TC_REFERENCE, asn1c_lang_C_type_REFERENCE_Value },

{ AMT_TYPE, A1TC_REFERENCE, asn1c_lang_C_type_REFERENCE },
{ AMT_TYPEREF, A1TC_REFERENCE, asn1c_lang_C_type_REFERENCE },
{ AMT_TYPE, A1TC_EXTENSIBLE, asn1c_lang_C_type_EXTENSIBLE },
12 changes: 8 additions & 4 deletions libasn1compiler/asn1c_save.c
Original file line number Diff line number Diff line change
@@ -73,7 +73,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb) {
[arg->expr->expr_type].type_cb &&
(arg->expr->meta_type != AMT_VALUE)) {
safe_fprintf(mkf, "\t\\\n\t%s%s.c", destdir,
asn1c_make_identifier(AMI_MASK_ONLY_SPACES, arg->expr, 0));
}
@@ -83,7 +84,8 @@ asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(asn1_lang_map[arg->expr->meta_type]
[arg->expr->expr_type].type_cb) {
[arg->expr->expr_type].type_cb &&
(arg->expr->meta_type != AMT_VALUE)) {
safe_fprintf(
mkf, "\t\\\n\t%s%s.h", destdir,
asn1c_make_identifier(AMI_MASK_ONLY_SPACES, arg->expr, 0));
@@ -395,7 +397,8 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir, const char *destdir,
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
TQ_FOR(arg->expr, &(mod->members), next) {
if(asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type]
.type_cb) {
.type_cb &&
(arg->expr->meta_type != AMT_VALUE)) {
ret = asn1c_dump_streams(arg, deps, destdir, optc, argv);
if(ret) break;
}
@@ -927,7 +930,8 @@ pdu_collection_has_unused_types(arg_t *arg) {

static enum include_type_result
include_type_to_pdu_collection(arg_t *arg) {
if(!asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type].type_cb)
if(!asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type].type_cb ||
(arg->expr->meta_type == AMT_VALUE))
return 0;

/* Parameterized types can't serve as PDU's without instantiation. */
3 changes: 1 addition & 2 deletions libasn1compiler/asn1compiler.c
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@

static void default_logger_cb(int, const char *fmt, ...);
static int asn1c_compile_expr(arg_t *arg, const asn1c_ioc_table_and_objset_t *);
static int asn1c_attach_streams(asn1p_expr_t *expr);
static int asn1c_detach_streams(asn1p_expr_t *expr);

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

static int
int
asn1c_attach_streams(asn1p_expr_t *expr) {
compiler_streams_t *cs;
int i;
2 changes: 2 additions & 0 deletions libasn1compiler/asn1compiler.h
Original file line number Diff line number Diff line change
@@ -110,4 +110,6 @@ void asn1c_debug_type_naming(asn1p_t *asn, enum asn1c_flags,

void asn1c__add_pdu_type(const char *typename);

int asn1c_attach_streams(asn1p_expr_t *expr);

#endif /* ASN1_COMPILER_H */

0 comments on commit f38c31e

Please sign in to comment.