Commit 8d0f6857 authored by Bi-Ruei, Chiu's avatar Bi-Ruei, Chiu

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.
parent e436f61a
......@@ -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;
......
......@@ -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 },
......
......@@ -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. */
......@@ -952,6 +956,7 @@ static abuf *
generate_constant_collection(arg_t *arg) {
asn1p_module_t *mod;
abuf *buf = abuf_new();
int empty_file = 1;
abuf_printf(buf, "/*\n * Generated by asn1c-" VERSION
" (http://lionet.info/asn1c)\n */\n\n");
......@@ -968,18 +973,30 @@ generate_constant_collection(arg_t *arg) {
abuf_printf(buf, "#define %s (%s)\n",
asn1c_make_identifier(0, arg->expr, 0),
asn1p_itoa(arg->expr->value->value.v_integer));
empty_file = 0;
}
}
}
abuf_printf(buf, "\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* _ASN_CONSTANT_H */\n");
if(empty_file) {
abuf_free(buf);
return 0;
}
return buf;
}
static int
generate_constant_file(arg_t *arg, const char *destdir) {
abuf *buf = generate_constant_collection(arg);
assert(buf);
if(!buf) return 0;
if(arg->flags & A1C_PRINT_COMPILED) {
printf("\n/*** <<< asn_constant.h >>> ***/\n\n");
safe_fwrite(buf->buffer, buf->length, 1, stdout);
} else {
FILE *fp = asn1c_open_file(destdir, "asn_constant", ".h", 0);
if(fp == NULL) {
......@@ -988,8 +1005,9 @@ generate_constant_file(arg_t *arg, const char *destdir) {
}
safe_fwrite(buf->buffer, buf->length, 1, fp);
fclose(fp);
abuf_free(buf);
}
safe_fprintf(stderr, "Generated asn_constant.h\n");
abuf_free(buf);
return 0;
}
......@@ -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;
......
......@@ -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 */
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