mirror of https://gerrit.osmocom.org/asn1c
generating enumeration tables for INTEGER types
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@954 59561ff5-6e30-0410-9f3c-9617f08c8826
This commit is contained in:
parent
5d89c3d031
commit
4573af0d96
|
@ -1,8 +1,9 @@
|
|||
|
||||
0.9.17: 2005-Aug-13
|
||||
0.9.18: 2005-Aug-13
|
||||
|
||||
* The obsolete X.208 syntax is handled gracefully now (compound types'
|
||||
member names are invented on the fly). (Test case 87).
|
||||
* Generating enumeration tables for INTEGER types (Test case 88).
|
||||
|
||||
0.9.17: 2005-Aug-07
|
||||
|
||||
|
|
|
@ -105,19 +105,16 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) {
|
|||
int el_count = expr_elements_count(arg, expr);
|
||||
struct value2enum *v2e;
|
||||
int map_is_extensible = (expr->expr_type == ASN_BASIC_INTEGER);
|
||||
int eidx;
|
||||
|
||||
v2e = alloca((el_count + 1) * sizeof(*v2e));
|
||||
|
||||
/*
|
||||
* For all ENUMERATED types [and for those INTEGER types which
|
||||
* have identifiers -- prohibited by X.693:8.3.4],
|
||||
* print out an enumeration table and a mapping
|
||||
* between identifiers and associated values.
|
||||
* For all ENUMERATED types and for those INTEGER types which
|
||||
* have identifiers, print out an enumeration table.
|
||||
*/
|
||||
if(expr->expr_type == ASN_BASIC_ENUMERATED
|
||||
|| (0 && el_count /* -- prohibited by X.693:8.3.4 */)) {
|
||||
int eidx = 0;
|
||||
|
||||
if(expr->expr_type == ASN_BASIC_ENUMERATED || el_count) {
|
||||
eidx = 0;
|
||||
REDIR(OT_DEPS);
|
||||
OUT("typedef enum ");
|
||||
out_name_chain(arg, 1);
|
||||
|
@ -149,6 +146,14 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) {
|
|||
out_name_chain(arg, 0);
|
||||
OUT("_e;\n");
|
||||
assert(eidx == el_count);
|
||||
}
|
||||
|
||||
/*
|
||||
* For all ENUMERATED types print out a mapping table
|
||||
* between identifiers and associated values.
|
||||
* This is prohibited for INTEGER types by by X.693:8.3.4.
|
||||
*/
|
||||
if(expr->expr_type == ASN_BASIC_ENUMERATED) {
|
||||
|
||||
/*
|
||||
* Generate a enumerationName<->value map for XER codec.
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
-- OK: Everything is fine
|
||||
|
||||
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
|
||||
-- .spelio.software.asn1c.test (9363.1.5.1)
|
||||
-- .88
|
||||
|
||||
ModuleIntegerEnumeration
|
||||
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
|
||||
spelio(9363) software(1) asn1c(5) test(1) 88 }
|
||||
DEFINITIONS ::=
|
||||
BEGIN
|
||||
|
||||
T ::= INTEGER { a(1), b(2) }
|
||||
|
||||
END
|
|
@ -0,0 +1,125 @@
|
|||
|
||||
/*** <<< INCLUDES [T] >>> ***/
|
||||
|
||||
#include <INTEGER.h>
|
||||
|
||||
/*** <<< DEPS [T] >>> ***/
|
||||
|
||||
typedef enum T {
|
||||
T_a = 1,
|
||||
T_b = 2
|
||||
} T_e;
|
||||
|
||||
/*** <<< TYPE-DECLS [T] >>> ***/
|
||||
|
||||
typedef INTEGER_t T_t;
|
||||
|
||||
/*** <<< FUNC-DECLS [T] >>> ***/
|
||||
|
||||
extern asn_TYPE_descriptor_t asn_DEF_T;
|
||||
asn_struct_free_f T_free;
|
||||
asn_struct_print_f T_print;
|
||||
asn_constr_check_f T_constraint;
|
||||
ber_type_decoder_f T_decode_ber;
|
||||
der_type_encoder_f T_encode_der;
|
||||
xer_type_decoder_f T_decode_xer;
|
||||
xer_type_encoder_f T_encode_xer;
|
||||
|
||||
/*** <<< CODE [T] >>> ***/
|
||||
|
||||
int
|
||||
T_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
|
||||
asn_app_consume_bytes_f *app_errlog, void *app_key) {
|
||||
/* Replace with underlying type checker */
|
||||
td->check_constraints = asn_DEF_INTEGER.check_constraints;
|
||||
return td->check_constraints(td, sptr, app_errlog, app_key);
|
||||
}
|
||||
|
||||
/*
|
||||
* This type is implemented using INTEGER,
|
||||
* so here we adjust the DEF accordingly.
|
||||
*/
|
||||
static void
|
||||
T_1_inherit_TYPE_descriptor(asn_TYPE_descriptor_t *td) {
|
||||
td->free_struct = asn_DEF_INTEGER.free_struct;
|
||||
td->print_struct = asn_DEF_INTEGER.print_struct;
|
||||
td->ber_decoder = asn_DEF_INTEGER.ber_decoder;
|
||||
td->der_encoder = asn_DEF_INTEGER.der_encoder;
|
||||
td->xer_decoder = asn_DEF_INTEGER.xer_decoder;
|
||||
td->xer_encoder = asn_DEF_INTEGER.xer_encoder;
|
||||
td->elements = asn_DEF_INTEGER.elements;
|
||||
td->elements_count = asn_DEF_INTEGER.elements_count;
|
||||
td->specifics = asn_DEF_INTEGER.specifics;
|
||||
}
|
||||
|
||||
void
|
||||
T_free(asn_TYPE_descriptor_t *td,
|
||||
void *struct_ptr, int contents_only) {
|
||||
T_1_inherit_TYPE_descriptor(td);
|
||||
td->free_struct(td, struct_ptr, contents_only);
|
||||
}
|
||||
|
||||
int
|
||||
T_print(asn_TYPE_descriptor_t *td, const void *struct_ptr,
|
||||
int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
T_1_inherit_TYPE_descriptor(td);
|
||||
return td->print_struct(td, struct_ptr, ilevel, cb, app_key);
|
||||
}
|
||||
|
||||
asn_dec_rval_t
|
||||
T_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const void *bufptr, size_t size, int tag_mode) {
|
||||
T_1_inherit_TYPE_descriptor(td);
|
||||
return td->ber_decoder(opt_codec_ctx, td, structure, bufptr, size, tag_mode);
|
||||
}
|
||||
|
||||
asn_enc_rval_t
|
||||
T_encode_der(asn_TYPE_descriptor_t *td,
|
||||
void *structure, int tag_mode, ber_tlv_tag_t tag,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
T_1_inherit_TYPE_descriptor(td);
|
||||
return td->der_encoder(td, structure, tag_mode, tag, cb, app_key);
|
||||
}
|
||||
|
||||
asn_dec_rval_t
|
||||
T_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
|
||||
void **structure, const char *opt_mname, const void *bufptr, size_t size) {
|
||||
T_1_inherit_TYPE_descriptor(td);
|
||||
return td->xer_decoder(opt_codec_ctx, td, structure, opt_mname, bufptr, size);
|
||||
}
|
||||
|
||||
asn_enc_rval_t
|
||||
T_encode_xer(asn_TYPE_descriptor_t *td, void *structure,
|
||||
int ilevel, enum xer_encoder_flags_e flags,
|
||||
asn_app_consume_bytes_f *cb, void *app_key) {
|
||||
T_1_inherit_TYPE_descriptor(td);
|
||||
return td->xer_encoder(td, structure, ilevel, flags, cb, app_key);
|
||||
}
|
||||
|
||||
|
||||
/*** <<< STAT-DEFS [T] >>> ***/
|
||||
|
||||
static ber_tlv_tag_t asn_DEF_T_1_tags[] = {
|
||||
(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
|
||||
};
|
||||
asn_TYPE_descriptor_t asn_DEF_T = {
|
||||
"T",
|
||||
"T",
|
||||
T_free,
|
||||
T_print,
|
||||
T_constraint,
|
||||
T_decode_ber,
|
||||
T_encode_der,
|
||||
T_decode_xer,
|
||||
T_encode_xer,
|
||||
0, /* Use generic outmost tag fetcher */
|
||||
asn_DEF_T_1_tags,
|
||||
sizeof(asn_DEF_T_1_tags)
|
||||
/sizeof(asn_DEF_T_1_tags[0]), /* 1 */
|
||||
asn_DEF_T_1_tags, /* Same as above */
|
||||
sizeof(asn_DEF_T_1_tags)
|
||||
/sizeof(asn_DEF_T_1_tags[0]), /* 1 */
|
||||
0, 0, /* Defined elsewhere */
|
||||
0 /* No specifics */
|
||||
};
|
||||
|
Loading…
Reference in New Issue