Commit d8e07c5f authored by Lev Walkin's avatar Lev Walkin

parameterized referencing of information object sets

parent a45518f5
......@@ -4,6 +4,7 @@ AM_CFLAGS = @ADD_CFLAGS@
AM_CPPFLAGS = \
-I$(top_srcdir)/libasn1common \
-I$(top_srcdir)/libasn1parser \
-I$(top_srcdir)/libasn1print \
-I$(top_srcdir)/libasn1fix
noinst_LTLIBRARIES = libasn1compiler.la
......
......@@ -8,6 +8,7 @@
#include "asn1c_out.h"
#include "asn1c_misc.h"
#include "asn1c_ioc.h"
#include <asn1print.h>
#include <asn1fix_crange.h> /* constraint groker from libasn1fix */
#include <asn1fix_export.h> /* other exportables from libasn1fix */
#include <asn1parser.h>
......@@ -320,6 +321,7 @@ is_open_type(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_objset_t *opt_i
&& expr->reference->comp_count == 2
&& expr->reference->components[1].lex_type
== RLT_AmpUppercase) {
DEBUG("%s is a true open type", MKID(expr));
return 1;
}
......@@ -461,7 +463,8 @@ asn1c_lang_C_type_SEQUENCE_def(arg_t *arg, asn1c_ioc_table_and_objset_t *opt_ioc
}
if(v->marker.flags & EM_OMITABLE)
comp_mode == 1 ? ++aoms_count : ++roms_count;
emit_member_table(arg, v, opt_ioc);
if(emit_member_table(arg, v, opt_ioc) < 0)
return -1;
elements++;
});
OUT("};\n");
......@@ -2709,16 +2712,16 @@ emit_member_type_selector(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_ob
return 0;
}
if(crc->el_count <= 1 || crc->elements[0]->type != ACT_EL_VALUE
|| crc->elements[0]->value->type != ATV_REFERENCED
|| crc->elements[0]->value->value.reference->comp_count != 1) {
FATAL(
"Reference does not look like an object set");
const asn1p_ref_t *objset_ref =
asn1c_get_information_object_set_reference_from_constraint(arg, crc);
if(!objset_ref || objset_ref->comp_count != 1) {
FATAL("Reference %s does not look like an object set type %s",
asn1p_constraint_string(crc), asn1p_ref_string(objset_ref));
return -1;
}
const char *objset_name =
crc->elements[0]->value->value.reference->components[0].name;
const char *objset_name = objset_ref->components[0].name;
if(strcmp(objset_name, opt_ioc->objset->Identifier) != 0) {
FATAL("Object Set references do not match: %s != %s", objset_name,
opt_ioc->objset->Identifier);
......@@ -3006,7 +3009,8 @@ emit_member_table(arg_t *arg, asn1p_expr_t *expr, asn1c_ioc_table_and_objset_t *
if(C99_MODE) OUT(".type_selector = ");
if(opt_ioc) {
emit_member_type_selector(arg, expr, opt_ioc);
if(emit_member_type_selector(arg, expr, opt_ioc) < 0)
return -1;
} else {
OUT("0");
}
......
......@@ -3,6 +3,7 @@
#include "asn1c_out.h"
#include "asn1c_misc.h"
#include <asn1fix_export.h>
#include <asn1print.h>
#define MKID(expr) asn1c_make_identifier(0, (expr), 0)
......@@ -10,18 +11,26 @@
* Given the table constraint or component relation constraint
* ({ObjectSetName}{...}) returns "ObjectSetName" as a reference.
*/
static const asn1p_ref_t *
asn1c_get_information_object_set_reference_from_constraint(
const asn1p_ref_t *
asn1c_get_information_object_set_reference_from_constraint(arg_t *arg,
const asn1p_constraint_t *ct) {
if(!ct) return NULL;
assert(ct->type == ACT_CA_CRC);
assert(ct->el_count >= 1);
DEBUG("Component Relation Constraint: %s", asn1p_constraint_string(ct));
assert(ct->elements[0]->type == ACT_EL_VALUE);
asn1p_value_t *val = ct->elements[0]->value;
if(val->type == ATV_VALUESET && val->value.constraint->type == ACT_EL_TYPE && val->value.constraint->containedSubtype && val->value.constraint->containedSubtype->type == ATV_REFERENCED) {
return val->value.constraint->containedSubtype->value.reference;
}
if(val->type != ATV_REFERENCED) {
FATAL("Set reference: %s", asn1f_printable_value(val));
assert(val->type == ATV_REFERENCED);
}
return val->value.reference;
}
......@@ -53,17 +62,12 @@ asn1c_get_ioc_table(arg_t *arg) {
asn1c_ioc_table_and_objset_t safe_ioc_tao = {0, 0, 0};
asn1c_ioc_table_and_objset_t failed_ioc_tao = { 0, 0, 1 };
if(expr->lhs_params) {
if(0) WARNING(
"Can not process Information Object Set on a parameterized type %s",
MKID(expr));
return safe_ioc_tao;
}
TQ_FOR(memb, &(expr->members), next) {
const asn1p_constraint_t *cr_ct =
asn1p_get_component_relation_constraint(memb->constraints);
const asn1p_ref_t *tmpref =
asn1c_get_information_object_set_reference_from_constraint(
asn1p_get_component_relation_constraint(memb->constraints));
asn1c_get_information_object_set_reference_from_constraint(arg,
cr_ct);
if(tmpref) {
if(objset_ref && asn1p_ref_compare(objset_ref, tmpref) != 0) {
FATAL(
......@@ -74,6 +78,7 @@ asn1c_get_ioc_table(arg_t *arg) {
}
objset_ref = tmpref;
}
}
if(!objset_ref) {
......
......@@ -15,5 +15,8 @@ asn1c_ioc_table_and_objset_t asn1c_get_ioc_table(arg_t *arg);
int emit_ioc_table(arg_t *arg, asn1p_expr_t *context,
asn1c_ioc_table_and_objset_t);
const asn1p_ref_t *asn1c_get_information_object_set_reference_from_constraint(
arg_t *arg, const asn1p_constraint_t *ct);
#endif /* ASN1_IOC_H */
......@@ -27,10 +27,6 @@ asn1f_parameterization_fork(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *rhs_ps
assert(expr->lhs_params);
assert(expr->parent_expr == 0);
DEBUG("Forking parameterization at %d for %s (%d alr)",
rhs_pspecs->_lineno, expr->Identifier,
expr->specializations.pspecs_count);
/*
* Find if this exact specialization has been used already.
*/
......@@ -45,6 +41,10 @@ asn1f_parameterization_fork(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *rhs_ps
}
}
DEBUG("Forking parameterization at %d for %s (%d alr)",
rhs_pspecs->_lineno, expr->Identifier,
expr->specializations.pspecs_count);
rarg.resolver = resolve_expr;
rarg.arg = arg;
rarg.original_expr = expr;
......

-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .144
ModuleInformationObjectParameterization
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 144 }
DEFINITIONS ::=
BEGIN
MYID ::= CLASS {
&id INTEGER UNIQUE,
&Type
} WITH SYNTAX {&Type IDENTIFIED BY &id}
RegionalExtension MYID ::= {
{INTEGER IDENTIFIED BY 1} |
{BOOLEAN IDENTIFIED BY 2},
...
}
Message ::= SEQUENCE {
content SpecializedContent {{RegionalExtension}}
}
SpecializedContent {MYID : Set} ::= SEQUENCE {
id MYID.&id({Set}),
value MYID.&Type({Set}{@id})
}
END
/*** <<< INCLUDES [Message] >>> ***/
#include "SpecializedContent.h"
#include <constr_SEQUENCE.h>
/*** <<< TYPE-DECLS [Message] >>> ***/
typedef struct Message {
SpecializedContent_30P0_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_30P0,
.type_selector = 0,
.memb_constraints = 0, /* Defer constraints checking to the member type */
.oer_constraints = 0, /* OER is not compiled, use -gen-OER */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.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),
asn_MAP_Message_tag2el_1,
1, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_Message = {
"Message",
"Message",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_compare,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No OER support, use "-gen-OER" to enable */
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
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, /* No OER visible constraints */
0, /* No PER visible constraints */
asn_MBR_Message_1,
1, /* Elements count */
&asn_SPC_Message_specs_1 /* Additional specs */
};
/*** <<< INCLUDES [SpecializedContent] >>> ***/
#include <NativeInteger.h>
#include <ANY.h>
#include <asn_ioc.h>
#include <OPEN_TYPE.h>
#include <BOOLEAN.h>
#include <constr_CHOICE.h>
#include <constr_SEQUENCE.h>
/*** <<< DEPS [SpecializedContent] >>> ***/
typedef enum value_PR {
value_PR_NOTHING, /* No components present */
value_PR_INTEGER,
value_PR_BOOLEAN
} value_PR;
/*** <<< TYPE-DECLS [SpecializedContent] >>> ***/
typedef struct SpecializedContent_30P0 {
long id;
struct value {
value_PR present;
union value_u {
long INTEGER;
BOOLEAN_t BOOLEAN;
} 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_30P0_t;
/*** <<< FUNC-DECLS [SpecializedContent] >>> ***/
extern asn_TYPE_descriptor_t asn_DEF_SpecializedContent_30P0;
extern asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_30P0_specs_1;
extern asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[2];
/*** <<< IOC-TABLES [SpecializedContent] >>> ***/
static const long asn_VAL_1_1 = 1;
static const long asn_VAL_2_2 = 2;
static const asn_ioc_cell_t asn_IOS_RegionalExtension_1_rows[] = {
{ "&id", aioc__value, &asn_DEF_NativeInteger, &asn_VAL_1_1 },
{ "&Type", ,
{ "&id", aioc__value, &asn_DEF_NativeInteger, &asn_VAL_2_2 },
{ "&Type",
};
static const asn_ioc_set_t asn_IOS_RegionalExtension_1[] = {
2, 2, asn_IOS_RegionalExtension_1_rows
};
/*** <<< CODE [SpecializedContent] >>> ***/
static int
memb_id_constraint_1(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->check_constraints(td, sptr, ctfailcb, app_key);
}
static asn_type_selector_result_t
select_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_RegionalExtension_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_30P0, 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->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(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->check_constraints(td, sptr, ctfailcb, app_key);
}
/*** <<< 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,
.memb_constraints = 0, /* Defer constraints checking to the member type */
.oer_constraints = 0, /* OER is not compiled, use -gen-OER */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.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,
.memb_constraints = 0, /* Defer constraints checking to the member type */
.oer_constraints = 0, /* OER is not compiled, use -gen-OER */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "BOOLEAN"
},
};
static const asn_TYPE_tag2member_t asn_MAP_value_tag2el_3[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (1 << 2)), 1, 0, 0 }, /* BOOLEAN */
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* INTEGER */
};
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),
asn_MAP_value_tag2el_3,
2, /* Count of tags in the map */
.canonical_order = 0,
.ext_start = -1 /* Extensions start */
};
static /* Use -fall-defs-global to expose */
asn_TYPE_descriptor_t asn_DEF_value_3 = {
"value",
"value",
OPEN_TYPE_free,
OPEN_TYPE_print,
OPEN_TYPE_compare,
OPEN_TYPE_constraint,
OPEN_TYPE_decode_ber,
OPEN_TYPE_encode_der,
OPEN_TYPE_decode_xer,
OPEN_TYPE_encode_xer,
0, 0, /* No OER support, use "-gen-OER" to enable */
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
0, /* No effective tags (pointer) */
0, /* No effective tags (count) */
0, /* No tags (pointer) */
0, /* No tags (count) */
0, /* No OER visible constraints */
0, /* No PER visible constraints */
asn_MBR_value_3,
2, /* Elements count */
&asn_SPC_value_specs_3 /* Additional specs */
};
asn_TYPE_member_t asn_MBR_SpecializedContent_30P0_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_30P0, id),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
.tag_mode = 0,
.type = &asn_DEF_NativeInteger,
.type_selector = 0,
.memb_constraints = memb_id_constraint_1,
.oer_constraints = 0, /* OER is not compiled, use -gen-OER */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "id"
},
{ ATF_OPEN_TYPE | ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_30P0, value),
.tag = -1 /* Ambiguous tag (ANY?) */,
.tag_mode = 0,
.type = &asn_DEF_value_3,
.type_selector = select_value_type,
.memb_constraints = memb_value_constraint_1,
.oer_constraints = 0, /* OER is not compiled, use -gen-OER */
.per_constraints = 0, /* PER is not compiled, use -gen-PER */
.default_value = 0,
.name = "value"
},
};
static const ber_tlv_tag_t asn_DEF_SpecializedContent_30P0_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_SpecializedContent_30P0_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* id */
};
asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_30P0_specs_1 = {
sizeof(struct SpecializedContent_30P0),
offsetof(struct SpecializedContent_30P0, _asn_ctx),
asn_MAP_SpecializedContent_30P0_tag2el_1,
1, /* Count of tags in the map */
0, 0, 0, /* Optional elements (not needed) */
-1, /* Start extensions */
-1 /* Stop extensions */
};
asn_TYPE_descriptor_t asn_DEF_SpecializedContent_30P0 = {
"SpecializedContent",
"SpecializedContent",
SEQUENCE_free,
SEQUENCE_print,
SEQUENCE_compare,
SEQUENCE_constraint,
SEQUENCE_decode_ber,
SEQUENCE_encode_der,
SEQUENCE_decode_xer,
SEQUENCE_encode_xer,
0, 0, /* No OER support, use "-gen-OER" to enable */
0, 0, /* No PER support, use "-gen-PER" to enable */
0, /* Use generic outmost tag fetcher */
asn_DEF_SpecializedContent_30P0_tags_1,
sizeof(asn_DEF_SpecializedContent_30P0_tags_1)
/sizeof(asn_DEF_SpecializedContent_30P0_tags_1[0]), /* 1 */
asn_DEF_SpecializedContent_30P0_tags_1, /* Same as above */
sizeof(asn_DEF_SpecializedContent_30P0_tags_1)
/sizeof(asn_DEF_SpecializedContent_30P0_tags_1[0]), /* 1 */
0, /* No OER visible constraints */
0, /* No PER visible constraints */
asn_MBR_SpecializedContent_30P0_1,
2, /* Elements count */
&asn_SPC_SpecializedContent_30P0_specs_1 /* Additional specs */
};
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