specialization fix, tested on value specialization

This commit is contained in:
Lev Walkin 2017-08-23 04:44:18 -07:00
parent 9ded96c6b2
commit f75b874253
2 changed files with 288 additions and 43 deletions

View File

@ -9,7 +9,7 @@ typedef struct resolver_arg {
} resolver_arg_t;
static asn1p_expr_t *resolve_expr(asn1p_expr_t *, void *resolver_arg);
static int compare_specializations(arg_t *, asn1p_expr_t *a, asn1p_expr_t *b);
static int compare_specializations(const asn1p_expr_t *a, const asn1p_expr_t *b);
static asn1p_expr_t *find_target_specialization_byref(resolver_arg_t *rarg, asn1p_ref_t *ref);
static asn1p_expr_t *find_target_specialization_bystr(resolver_arg_t *rarg, char *str);
@ -37,7 +37,7 @@ asn1f_parameterization_fork(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *rhs_ps
for(npspecs = 0;
npspecs < expr->specializations.pspecs_count;
npspecs++) {
if(compare_specializations(arg, rhs_pspecs,
if(compare_specializations(rhs_pspecs,
expr->specializations.pspec[npspecs].rhs_pspecs) == 0) {
DEBUG("Reused parameterization for %s",
expr->Identifier);
@ -89,47 +89,8 @@ asn1f_parameterization_fork(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_t *rhs_ps
}
static int
compare_specializations(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b) {
asn1p_expr_t *ac = TQ_FIRST(&a->members);
asn1p_expr_t *bc = TQ_FIRST(&b->members);
for(;ac && bc; ac = TQ_NEXT(ac, next), bc = TQ_NEXT(bc, next)) {
retry:
if(ac == bc) continue;
if(ac->meta_type != bc->meta_type) break;
if(ac->expr_type != bc->expr_type) break;
/* Maybe different object sets */
if(ac->constraints && bc->constraints
&& ac->constraints->containedSubtype
&& bc->constraints->containedSubtype
&& ac->constraints->containedSubtype->type == ATV_REFERENCED
&& bc->constraints->containedSubtype->type == ATV_REFERENCED
&& strcmp(ac->constraints->containedSubtype->value.reference->components[0].name,
bc->constraints->containedSubtype->value.reference->components[0].name))
break;
if(!ac->reference && !bc->reference)
continue;
if(ac->reference) {
ac = WITH_MODULE(
ac->module,
asn1f_lookup_symbol(arg, ac->rhs_pspecs, ac->reference));
if(!ac) break;
}
if(bc->reference) {
bc = WITH_MODULE(
bc->module,
asn1f_lookup_symbol(arg, bc->rhs_pspecs, bc->reference));
if(!bc) break;
}
goto retry;
}
if(ac || bc)
/* Specializations do not match: different size option sets */
return -1;
return 0;
compare_specializations(const asn1p_expr_t *a, const asn1p_expr_t *b) {
return asn1p_expr_compare(a, b);
}
static asn1p_expr_t *

View File

@ -0,0 +1,284 @@
/*** <<< INCLUDES [Message] >>> ***/
#include "SpecializedContent.h"
#include <constr_SEQUENCE.h>
/*** <<< TYPE-DECLS [Message] >>> ***/
typedef struct Message {
SpecializedContent_21P0_t content13;
SpecializedContent_21P1_t content42;
/* 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, content13),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
.tag_mode = 0,
.type = &asn_DEF_SpecializedContent_21P0,
.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 = "content13"
},
{ ATF_NOFLAGS, 0, offsetof(struct Message, content42),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)),
.tag_mode = 0,
.type = &asn_DEF_SpecializedContent_21P1,
.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 = "content42"
},
};
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, 1 }, /* content13 */
{ (ASN_TAG_CLASS_UNIVERSAL | (16 << 2)), 1, -1, 0 } /* content42 */
};
static asn_SEQUENCE_specifics_t asn_SPC_Message_specs_1 = {
sizeof(struct Message),
offsetof(struct Message, _asn_ctx),
asn_MAP_Message_tag2el_1,
2, /* 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,
2, /* Elements count */
&asn_SPC_Message_specs_1 /* Additional specs */
};
/*** <<< INCLUDES [SpecializedContent] >>> ***/
#include <NativeInteger.h>
#include <constr_SEQUENCE.h>
/*** <<< TYPE-DECLS [SpecializedContent] >>> ***/
typedef struct SpecializedContent_21P0 {
long id;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} SpecializedContent_21P0_t;
typedef struct SpecializedContent_21P1 {
long id;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} SpecializedContent_21P1_t;
/*** <<< FUNC-DECLS [SpecializedContent] >>> ***/
extern asn_TYPE_descriptor_t asn_DEF_SpecializedContent_21P0;
extern asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_21P0_specs_1;
extern asn_TYPE_member_t asn_MBR_SpecializedContent_21P0_1[1];
extern asn_TYPE_descriptor_t asn_DEF_SpecializedContent_21P1;
extern asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_21P1_specs_3;
extern asn_TYPE_member_t asn_MBR_SpecializedContent_21P1_3[1];
/*** <<< 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) {
long value;
if(!sptr) {
ASN__CTFAIL(app_key, td, sptr,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
value = *(const long *)sptr;
if((value == 13)) {
/* Constraint check succeeded */
return 0;
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
static int
memb_id_constraint_3(asn_TYPE_descriptor_t *td, const void *sptr,
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
long value;
if(!sptr) {
ASN__CTFAIL(app_key, td, sptr,
"%s: value not given (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
value = *(const long *)sptr;
if((value == 42)) {
/* Constraint check succeeded */
return 0;
} else {
ASN__CTFAIL(app_key, td, sptr,
"%s: constraint failed (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
}
/*** <<< STAT-DEFS [SpecializedContent] >>> ***/
asn_TYPE_member_t asn_MBR_SpecializedContent_21P0_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_21P0, 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"
},
};
static const ber_tlv_tag_t asn_DEF_SpecializedContent_21P0_tags_1[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_SpecializedContent_21P0_tag2el_1[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* id */
};
asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_21P0_specs_1 = {
sizeof(struct SpecializedContent_21P0),
offsetof(struct SpecializedContent_21P0, _asn_ctx),
asn_MAP_SpecializedContent_21P0_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_21P0 = {
"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_21P0_tags_1,
sizeof(asn_DEF_SpecializedContent_21P0_tags_1)
/sizeof(asn_DEF_SpecializedContent_21P0_tags_1[0]), /* 1 */
asn_DEF_SpecializedContent_21P0_tags_1, /* Same as above */
sizeof(asn_DEF_SpecializedContent_21P0_tags_1)
/sizeof(asn_DEF_SpecializedContent_21P0_tags_1[0]), /* 1 */
0, /* No OER visible constraints */
0, /* No PER visible constraints */
asn_MBR_SpecializedContent_21P0_1,
1, /* Elements count */
&asn_SPC_SpecializedContent_21P0_specs_1 /* Additional specs */
};
asn_TYPE_member_t asn_MBR_SpecializedContent_21P1_3[] = {
{ ATF_NOFLAGS, 0, offsetof(struct SpecializedContent_21P1, id),
.tag = (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)),
.tag_mode = 0,
.type = &asn_DEF_NativeInteger,
.type_selector = 0,
.memb_constraints = memb_id_constraint_3,
.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"
},
};
static const ber_tlv_tag_t asn_DEF_SpecializedContent_21P1_tags_3[] = {
(ASN_TAG_CLASS_UNIVERSAL | (16 << 2))
};
static const asn_TYPE_tag2member_t asn_MAP_SpecializedContent_21P1_tag2el_3[] = {
{ (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)), 0, 0, 0 } /* id */
};
asn_SEQUENCE_specifics_t asn_SPC_SpecializedContent_21P1_specs_3 = {
sizeof(struct SpecializedContent_21P1),
offsetof(struct SpecializedContent_21P1, _asn_ctx),
asn_MAP_SpecializedContent_21P1_tag2el_3,
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_21P1 = {
"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_21P1_tags_3,
sizeof(asn_DEF_SpecializedContent_21P1_tags_3)
/sizeof(asn_DEF_SpecializedContent_21P1_tags_3[0]), /* 1 */
asn_DEF_SpecializedContent_21P1_tags_3, /* Same as above */
sizeof(asn_DEF_SpecializedContent_21P1_tags_3)
/sizeof(asn_DEF_SpecializedContent_21P1_tags_3[0]), /* 1 */
0, /* No OER visible constraints */
0, /* No PER visible constraints */
asn_MBR_SpecializedContent_21P1_3,
1, /* Elements count */
&asn_SPC_SpecializedContent_21P1_specs_3 /* Additional specs */
};