diff --git a/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1 b/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1 index 5d93c636..c9f31384 100644 --- a/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1 +++ b/tests/tests-asn1c-compiler/155-parameterization-more-than-two-level-OK.asn1 @@ -6,8 +6,8 @@ -- .155 ModuleParameterizationMoreThanTwoLevel - { iso org(3) dod(6) internet(1) private(4) enterprise(1) - spelio(9363) software(1) asn1c(5) test(1) 155 } + { iso org(3) dod(6) internet(1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 155 } DEFINITIONS ::= BEGIN id-TYPE1 PacketId ::= 1 @@ -19,10 +19,10 @@ DEFINITIONS ::= BEGIN Valid ::= ENUMERATED { crc-nok, crc-ok(1) } PACKET ::= CLASS { - &id PacketId UNIQUE, - &color Color, - &Value, - &valid Valid + &id PacketId UNIQUE, + &color Color, + &Value, + &valid Valid } WITH SYNTAX { ID &id diff --git a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1 b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1 index 83ba27c6..efdf4671 100644 --- a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1 +++ b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1 @@ -5,58 +5,42 @@ -- .spelio.software.asn1c.test (9363.1.5.1) -- .156 -ModuleParameterizationMoreThanTwoLevel - { iso org(3) dod(6) internet(1) private(4) enterprise(1) - spelio(9363) software(1) asn1c(5) test(1) 156 } +ModuleUnionIOS + { iso org(3) dod(6) internet(1) private(4) enterprise(1) + spelio(9363) software(1) asn1c(5) test(1) 156 } DEFINITIONS ::= BEGIN - TOTAL-CLASS SAMPLE-CLASS ::= { - CLASS-1 | - CLASS-2, - ... + MYID ::= CLASS { + &id INTEGER UNIQUE, + &Type + } WITH SYNTAX {&Type IDENTIFIED BY &id} + + TotalRegionExtension MYID ::= { + RegionalExtension1 | + RegionalExtension2 } - CLASS-1 SAMPLE-CLASS ::= { - item1-1 | - item1-2, + RegionalExtension1 MYID ::= { + {INTEGER IDENTIFIED BY 1} | + {BOOLEAN IDENTIFIED BY 2}, ..., - item1-3 + {OCTET STRING IDENTIFIED BY 3} } - CLASS-2 SAMPLE-CLASS ::= { - item2-1, - ..., - item2-2 | - item2-3 + RegionalExtension2 MYID ::= { + {INTEGER IDENTIFIED BY 1}, + ..., + {BOOLEAN IDENTIFIED BY 2} | + {OCTET STRING IDENTIFIED BY 3} } - SAMPLE-CLASS ::= CLASS { - &id RELATIVE-OID UNIQUE, - &code ENUMERATED { request, response, status } - DEFAULT request, - &Type OPTIONAL - } WITH SYNTAX { [TYPE &Type] [WITH CODE &code] IDENTIFIED BY &id } + Message ::= SEQUENCE { + content SpecializedContent {{TotalRegionExtension}} + } - item1-1 SAMPLE-CLASS ::= { IDENTIFIED BY id1-1 } - - item1-2 SAMPLE-CLASS ::= { WITH CODE 1 IDENTIFIED BY id1-2 } - - item1-3 SAMPLE-CLASS ::= { TYPE SampleType WITH CODE 2 IDENTIFIED BY id1-3 } - - item2-1 SAMPLE-CLASS ::= { IDENTIFIED BY id2-1 } - - item2-2 SAMPLE-CLASS ::= { WITH CODE 1 IDENTIFIED BY id2-2 } - - item2-3 SAMPLE-CLASS ::= { TYPE SampleType WITH CODE 2 IDENTIFIED BY id2-3 } - - id1-1 RELATIVE-OID ::= { 1 1 } - id1-2 RELATIVE-OID ::= { 1 2 } - id1-3 RELATIVE-OID ::= { 1 3 } - id2-1 RELATIVE-OID ::= { 2 1 } - id2-2 RELATIVE-OID ::= { 2 2 } - id2-3 RELATIVE-OID ::= { 2 3 } - - SampleType ::= SEQUENCE { ... } - Salt ::= SET { ... } + SpecializedContent {MYID : Set} ::= SEQUENCE { + id MYID.&id({Set}), + value MYID.&Type({Set}{@id}) + } END diff --git a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-EFprint-class-matrix b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-EFprint-class-matrix deleted file mode 100644 index 8d21c9f1..00000000 --- a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-EFprint-class-matrix +++ /dev/null @@ -1,108 +0,0 @@ -ModuleParameterizationMoreThanTwoLevel { iso org(3) dod(6) internet(1) - private(4) enterprise(1) spelio(9363) software(1) asn1c(5) test(1) - 156 } -DEFINITIONS ::= -BEGIN - -TOTAL-CLASS SAMPLE-CLASS ::= {({ IDENTIFIED BY id1-1 } | { WITH CODE 1 IDENTIFIED BY id1-2 }) ({ IDENTIFIED BY id1-1 } | { WITH CODE 1 IDENTIFIED BY id1-2 }) | ({ IDENTIFIED BY id2-1 }) ({ IDENTIFIED BY id2-1 }),...} --- Information Object Set has 4 entries: --- [ &id][ &code][ &Type] --- [1] id1-1 --- [2] id1-2 1 --- [3] id2-2 1 --- [4] id2-3 2 SampleType - - -CLASS-1 SAMPLE-CLASS ::= {{ IDENTIFIED BY id1-1 } | { WITH CODE 1 IDENTIFIED BY id1-2 },...,{ TYPE SampleType WITH CODE 2 IDENTIFIED BY id1-3 }} --- Information Object Set has 2 entries: --- [ &id][&code][&Type] --- [1] id1-1 --- [2] id1-2 1 --- [ ] ... - - -CLASS-2 SAMPLE-CLASS ::= {{ IDENTIFIED BY id2-1 },...,{ WITH CODE 1 IDENTIFIED BY id2-2 } | { TYPE SampleType WITH CODE 2 IDENTIFIED BY id2-3 }} --- Information Object Set has 2 entries: --- [ &id][ &code][ &Type] --- [1] id2-2 1 --- [2] id2-3 2 SampleType --- [ ] ... - - -SAMPLE-CLASS ::= CLASS { - &id RELATIVE-OID UNIQUE, - &code ENUMERATED { - request(0), - response(1), - status(2) - } DEFAULT 0, - &Type OPTIONAL -} WITH SYNTAX { [TYPE &Type] [WITH CODE &code] IDENTIFIED BY &id } - --- Information Object Set has 6 entries: --- [ &id][ &code][ &Type] --- [1] id1-1 --- [2] id1-2 1 --- [3] id2-2 1 --- [4] id2-3 2 SampleType --- [5] id1-3 2 SampleType --- [6] id2-1 - - -item1-1 SAMPLE-CLASS ::= { IDENTIFIED BY id1-1 } --- Information Object Set has 1 entry: --- [ &id][&code][&Type] --- [1] id1-1 - - -item1-2 SAMPLE-CLASS ::= { WITH CODE 1 IDENTIFIED BY id1-2 } --- Information Object Set has 1 entry: --- [ &id][&code][&Type] --- [1] id1-2 1 - - -item1-3 SAMPLE-CLASS ::= { TYPE SampleType WITH CODE 2 IDENTIFIED BY id1-3 } --- Information Object Set has 1 entry: --- [ &id][ &code][ &Type] --- [1] id1-3 2 SampleType - - -item2-1 SAMPLE-CLASS ::= { IDENTIFIED BY id2-1 } --- Information Object Set has 1 entry: --- [ &id][&code][&Type] --- [1] id2-1 - - -item2-2 SAMPLE-CLASS ::= { WITH CODE 1 IDENTIFIED BY id2-2 } --- Information Object Set has 1 entry: --- [ &id][&code][&Type] --- [1] id2-2 1 - - -item2-3 SAMPLE-CLASS ::= { TYPE SampleType WITH CODE 2 IDENTIFIED BY id2-3 } --- Information Object Set has 1 entry: --- [ &id][ &code][ &Type] --- [1] id2-3 2 SampleType - - -id1-1 RELATIVE-OID ::= { 1 1 } - -id1-2 RELATIVE-OID ::= { 1 2 } - -id1-3 RELATIVE-OID ::= { 1 3 } - -id2-1 RELATIVE-OID ::= { 2 1 } - -id2-2 RELATIVE-OID ::= { 2 2 } - -id2-3 RELATIVE-OID ::= { 2 3 } - -SampleType ::= SEQUENCE { - ... -} - -Salt ::= SET { - ... -} - -END diff --git a/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER new file mode 100644 index 00000000..b574e564 --- /dev/null +++ b/tests/tests-asn1c-compiler/156-union-ios-OK.asn1.-Pgen-PER @@ -0,0 +1,332 @@ + +/*** <<< INCLUDES [Message] >>> ***/ + +#include "SpecializedContent.h" +#include + +/*** <<< TYPE-DECLS [Message] >>> ***/ + +typedef struct Message { + SpecializedContent_42P0_t content; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Message_t; + +/*** <<< FUNC-DECLS [Message] >>> ***/ + +extern asn_TYPE_descriptor_t asn_DEF_Message; + +/*** <<< STAT-DEFS [Message] >>> ***/ + +static asn_TYPE_member_t asn_MBR_Message_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct Message, content), + .tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), + .tag_mode = 0, + .type = &asn_DEF_SpecializedContent_42P0, + .type_selector = 0, + { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 }, + 0, 0, /* No default value */ + .name = "content" + }, +}; +static const ber_tlv_tag_t asn_DEF_Message_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_Message_tag2el_1[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 0, 0, 0 } /* content */ +}; +static asn_SEQUENCE_specifics_t asn_SPC_Message_specs_1 = { + sizeof(struct Message), + offsetof(struct Message, _asn_ctx), + .tag2el = asn_MAP_Message_tag2el_1, + .tag2el_count = 1, /* Count of tags in the map */ + 0, 0, 0, /* Optional elements (not needed) */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_Message = { + "Message", + "Message", + &asn_OP_SEQUENCE, + asn_DEF_Message_tags_1, + sizeof(asn_DEF_Message_tags_1) + /sizeof(asn_DEF_Message_tags_1[0]), /* 1 */ + asn_DEF_Message_tags_1, /* Same as above */ + sizeof(asn_DEF_Message_tags_1) + /sizeof(asn_DEF_Message_tags_1[0]), /* 1 */ + { 0, 0, SEQUENCE_constraint }, + asn_MBR_Message_1, + 1, /* Elements count */ + &asn_SPC_Message_specs_1 /* Additional specs */ +}; + + +/*** <<< INCLUDES [SpecializedContent] >>> ***/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/*** <<< DEPS [SpecializedContent] >>> ***/ + +typedef enum value_PR { + value_PR_NOTHING, /* No components present */ + value_PR_INTEGER, + value_PR_BOOLEAN, + value_PR_BOOLEAN, + value_PR_OCTET_STRING +} value_PR; + +/*** <<< TYPE-DECLS [SpecializedContent] >>> ***/ + +typedef struct SpecializedContent_42P0 { + long id; + struct value { + value_PR present; + union SpecializedContent_42P0__value_u { + long INTEGER; + BOOLEAN_t BOOLEAN; + ; + OCTET_STRING_t OCTET_STRING; + } 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; +} SpecializedContent_42P0_t; + +/*** <<< FUNC-DECLS [SpecializedContent] >>> ***/ + +extern asn_TYPE_descriptor_t asn_DEF_SpecializedContent_42P0; +extern asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_42P0_specs_1; +extern asn_TYPE_member_t asn_MBR_SpecializedContent_42P0_1[2]; + +/*** <<< IOC-TABLES [SpecializedContent] >>> ***/ + +static const long asn_VAL_1_1 = 1; +static const long asn_VAL_2_2 = 2; +static const long asn_VAL_3_2 = 2; +static const long asn_VAL_4_3 = 3; +static const asn_ioc_cell_t asn_IOS_TotalRegionExtension_1_rows[] = { + { "&id", aioc__value, &asn_DEF_NativeInteger, &asn_VAL_1_1 }, + { "&Type", , + { "&id", aioc__value, &asn_DEF_NativeInteger, &asn_VAL_2_2 }, + { "&Type", , + { "&id", aioc__value, &asn_DEF_NativeInteger, &asn_VAL_3_2 }, + { "&Type", , + { "&id", aioc__value, &asn_DEF_NativeInteger, &asn_VAL_4_3 }, + { "&Type", +}; +static const asn_ioc_set_t asn_IOS_TotalRegionExtension_1[] = { + 4, 2, asn_IOS_TotalRegionExtension_1_rows +}; + +/*** <<< CODE [SpecializedContent] >>> ***/ + +static int +memb_id_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + + if(1 /* No applicable constraints whatsoever */) { + /* Nothing is here. See below */ + } + + return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key); +} + +static asn_type_selector_result_t +select_SpecializedContent_42P0_value_type(const asn_TYPE_descriptor_t *parent_type, const void *parent_sptr) { + asn_type_selector_result_t result = {0, 0}; + const asn_ioc_set_t *itable = asn_IOS_TotalRegionExtension_1; + size_t constraining_column = 0; /* &id */ + size_t for_column = 1; /* &Type */ + size_t row; + const long *constraining_value = (const long *)((const char *)parent_sptr + offsetof(struct SpecializedContent_42P0, id)); + + for(row=0; row < itable->rows_count; row++) { + const asn_ioc_cell_t *constraining_cell = &itable->rows[row * itable->columns_count + constraining_column]; + const asn_ioc_cell_t *type_cell = &itable->rows[row * itable->columns_count + for_column]; + + if(constraining_cell->type_descriptor->op->compare_struct(constraining_cell->type_descriptor, constraining_value, constraining_cell->value_sptr) == 0) { + result.type_descriptor = type_cell->type_descriptor; + result.presence_index = row + 1; + break; + } + } + + return result; +} + +static int +memb_value_constraint_1(const asn_TYPE_descriptor_t *td, const void *sptr, + asn_app_constraint_failed_f *ctfailcb, void *app_key) { + + if(!sptr) { + ASN__CTFAIL(app_key, td, sptr, + "%s: value not given (%s:%d)", + td->name, __FILE__, __LINE__); + return -1; + } + + + if(1 /* No applicable constraints whatsoever */) { + /* Nothing is here. See below */ + } + + return td->encoding_constraints.general_constraints(td, sptr, ctfailcb, app_key); +} + + +/*** <<< CTDEFS [SpecializedContent] >>> ***/ + +static asn_per_constraints_t asn_PER_memb_id_constr_2 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; +static asn_per_constraints_t asn_PER_memb_value_constr_3 CC_NOTUSED = { + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + { APC_UNCONSTRAINED, -1, -1, 0, 0 }, + 0, 0 /* No PER value map */ +}; + +/*** <<< STAT-DEFS [SpecializedContent] >>> ***/ + +static asn_TYPE_member_t asn_MBR_value_3[] = { + { ATF_NOFLAGS, 0, offsetof(struct value, choice.INTEGER), + .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + .tag_mode = 0, + .type = &asn_DEF_NativeInteger, + .type_selector = 0, + { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 }, + 0, 0, /* No default value */ + .name = "INTEGER" + }, + { ATF_NOFLAGS, 0, offsetof(struct value, choice.BOOLEAN), + .tag = (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), + .tag_mode = 0, + .type = &asn_DEF_BOOLEAN, + .type_selector = 0, + { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 }, + 0, 0, /* No default value */ + .name = "BOOLEAN" + }, + { ATF_NOFLAGS, 0, offsetof(struct value, choice.BOOLEAN), + .tag = (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), + .tag_mode = 0, + .type = &asn_DEF_BOOLEAN, + .type_selector = 0, + { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 }, + 0, 0, /* No default value */ + .name = "BOOLEAN" + }, + { ATF_NOFLAGS, 0, offsetof(struct value, choice.OCTET_STRING), + .tag = (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), + .tag_mode = 0, + .type = &asn_DEF_OCTET_STRING, + .type_selector = 0, + { .oer_constraints = 0, .per_constraints = 0, .general_constraints = 0 }, + 0, 0, /* No default value */ + .name = "OCTET STRING" + }, +}; +static const unsigned asn_MAP_value_to_canonical_3[] = { 1, 2, 0, 3 }; +static const unsigned asn_MAP_value_from_canonical_3[] = { 2, 0, 1, 3 }; +static const asn_TYPE_tag2member_t asn_MAP_value_tag2el_3[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), 1, 0, 1 }, /* BOOLEAN */ + { (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), 2, -1, 0 }, /* BOOLEAN */ + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 }, /* INTEGER */ + { (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)), 3, 0, 0 } /* OCTET STRING */ +}; +static asn_CHOICE_specifics_t asn_SPC_value_specs_3 = { + sizeof(struct value), + offsetof(struct value, _asn_ctx), + offsetof(struct value, present), + sizeof(((struct value *)0)->present), + .tag2el = asn_MAP_value_tag2el_3, + .tag2el_count = 4, /* Count of tags in the map */ + .to_canonical_order = asn_MAP_value_to_canonical_3, + .from_canonical_order = asn_MAP_value_from_canonical_3, + .first_extension = -1 /* Extensions start */ +}; +static /* Use -fall-defs-global to expose */ +asn_TYPE_descriptor_t asn_DEF_value_3 = { + "value", + "value", + &asn_OP_OPEN_TYPE, + 0, /* No effective tags (pointer) */ + 0, /* No effective tags (count) */ + 0, /* No tags (pointer) */ + 0, /* No tags (count) */ + { 0, 0, OPEN_TYPE_constraint }, + asn_MBR_value_3, + 4, /* Elements count */ + &asn_SPC_value_specs_3 /* Additional specs */ +}; + +asn_TYPE_member_t asn_MBR_SpecializedContent_42P0_1[] = { + { ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_42P0, id), + .tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), + .tag_mode = 0, + .type = &asn_DEF_NativeInteger, + .type_selector = 0, + { .oer_constraints = 0, .per_constraints = &asn_PER_memb_id_constr_2, .general_constraints = memb_id_constraint_1 }, + 0, 0, /* No default value */ + .name = "id" + }, + { ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_42P0, value), + .tag = -1 /* Ambiguous tag (ANY?) */, + .tag_mode = 0, + .type = &asn_DEF_value_3, + .type_selector = select_SpecializedContent_42P0_value_type, + { .oer_constraints = 0, .per_constraints = &asn_PER_memb_value_constr_3, .general_constraints = memb_value_constraint_1 }, + 0, 0, /* No default value */ + .name = "value" + }, +}; +static const ber_tlv_tag_t asn_DEF_SpecializedContent_42P0_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)) +}; +static const asn_TYPE_tag2member_t asn_MAP_SpecializedContent_42P0_tag2el_1[] = { + { (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* id */ +}; +asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_42P0_specs_1 = { + sizeof(struct SpecializedContent_42P0), + offsetof(struct SpecializedContent_42P0, _asn_ctx), + .tag2el = asn_MAP_SpecializedContent_42P0_tag2el_1, + .tag2el_count = 1, /* Count of tags in the map */ + 0, 0, 0, /* Optional elements (not needed) */ + -1, /* First extension addition */ +}; +asn_TYPE_descriptor_t asn_DEF_SpecializedContent_42P0 = { + "SpecializedContent", + "SpecializedContent", + &asn_OP_SEQUENCE, + asn_DEF_SpecializedContent_42P0_tags_1, + sizeof(asn_DEF_SpecializedContent_42P0_tags_1) + /sizeof(asn_DEF_SpecializedContent_42P0_tags_1[0]), /* 1 */ + asn_DEF_SpecializedContent_42P0_tags_1, /* Same as above */ + sizeof(asn_DEF_SpecializedContent_42P0_tags_1) + /sizeof(asn_DEF_SpecializedContent_42P0_tags_1[0]), /* 1 */ + { 0, 0, SEQUENCE_constraint }, + asn_MBR_SpecializedContent_42P0_1, + 2, /* Elements count */ + &asn_SPC_SpecializedContent_42P0_specs_1 /* Additional specs */ +}; +