mirror of https://gerrit.osmocom.org/asn1c
add constraint debug
This commit is contained in:
parent
fc4f37a5a2
commit
a28cbb9f66
|
@ -2151,7 +2151,8 @@ emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
|||
|
||||
INDENT(+1);
|
||||
|
||||
range = asn1constraint_compute_OER_range(etype, expr->combined_constraints,
|
||||
range = asn1constraint_compute_OER_range(expr->Identifier, etype,
|
||||
expr->combined_constraints,
|
||||
ACT_EL_RANGE, 0, 0, 0);
|
||||
if(emit_single_member_OER_constraint(arg, range, 0)) {
|
||||
return -1;
|
||||
|
@ -2160,7 +2161,8 @@ emit_member_OER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
|||
|
||||
OUT(",\n");
|
||||
|
||||
range = asn1constraint_compute_OER_range(etype, expr->combined_constraints,
|
||||
range = asn1constraint_compute_OER_range(expr->Identifier, etype,
|
||||
expr->combined_constraints,
|
||||
ACT_CT_SIZE, 0, 0, 0);
|
||||
if(emit_single_member_OER_constraint(arg, range, "SIZE")) {
|
||||
return -1;
|
||||
|
@ -2233,7 +2235,7 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
|||
if(emit_single_member_PER_constraint(arg, &tmprng, 0, 0))
|
||||
return -1;
|
||||
} else if(etype & ASN_STRING_KM_MASK) {
|
||||
range = asn1constraint_compute_PER_range(etype,
|
||||
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
|
||||
expr->combined_constraints, ACT_CT_FROM,
|
||||
0, 0, 0);
|
||||
DEBUG("Emitting FROM constraint for %s", expr->Identifier);
|
||||
|
@ -2263,7 +2265,7 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
|||
avoid:
|
||||
asn1constraint_range_free(range);
|
||||
} else {
|
||||
range = asn1constraint_compute_PER_range(etype,
|
||||
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
|
||||
expr->combined_constraints, ACT_EL_RANGE,
|
||||
0, 0, 0);
|
||||
if(emit_single_member_PER_constraint(arg, range, 0, 0))
|
||||
|
@ -2272,7 +2274,7 @@ emit_member_PER_constraints(arg_t *arg, asn1p_expr_t *expr, const char *pfx) {
|
|||
}
|
||||
OUT(",\n");
|
||||
|
||||
range = asn1constraint_compute_PER_range(etype,
|
||||
range = asn1constraint_compute_PER_range(expr->Identifier, etype,
|
||||
expr->combined_constraints, ACT_CT_SIZE, 0, 0, 0);
|
||||
if(emit_single_member_PER_constraint(arg, range, 0, "SIZE"))
|
||||
return -1;
|
||||
|
|
|
@ -43,8 +43,8 @@ asn1c_emit_constraint_checking_code(arg_t *arg) {
|
|||
|
||||
etype = _find_terminal_type(arg);
|
||||
|
||||
r_value=asn1constraint_compute_PER_range(etype, ct, ACT_EL_RANGE,0,0,0);
|
||||
r_size =asn1constraint_compute_PER_range(etype, ct, ACT_CT_SIZE, 0,0,0);
|
||||
r_value=asn1constraint_compute_constraint_range(expr->Identifier, etype, ct, ACT_EL_RANGE,0,0,0);
|
||||
r_size =asn1constraint_compute_constraint_range(expr->Identifier, etype, ct, ACT_CT_SIZE, 0,0,0);
|
||||
if(r_value) {
|
||||
if(r_value->incompatible
|
||||
|| r_value->empty_constraint
|
||||
|
@ -251,7 +251,7 @@ asn1c_emit_constraint_tables(arg_t *arg, int got_size) {
|
|||
|
||||
etype = _find_terminal_type(arg);
|
||||
|
||||
range = asn1constraint_compute_PER_range(etype, ct, ACT_CT_FROM, 0,0,0);
|
||||
range = asn1constraint_compute_constraint_range(arg->expr->Identifier, etype, ct, ACT_CT_FROM, 0,0,0);
|
||||
if(!range) return 0;
|
||||
|
||||
if(range->incompatible
|
||||
|
|
|
@ -359,7 +359,8 @@ asn1c_type_fits_long(arg_t *arg, asn1p_expr_t *expr) {
|
|||
* applied (non-standard! but we can deal with this) to the type.
|
||||
* Check the range.
|
||||
*/
|
||||
range = asn1constraint_compute_PER_range(expr->expr_type,
|
||||
range = asn1constraint_compute_constraint_range(expr->Identifier,
|
||||
expr->expr_type,
|
||||
expr->combined_constraints, ACT_CT_SIZE, 0, 0,
|
||||
CPR_simulate_fbless_SIZE);
|
||||
if(range) {
|
||||
|
@ -375,7 +376,7 @@ asn1c_type_fits_long(arg_t *arg, asn1p_expr_t *expr) {
|
|||
/*
|
||||
* Third, pull up the PER visible range of the INTEGER.
|
||||
*/
|
||||
range = asn1constraint_compute_PER_range(expr->expr_type,
|
||||
range = asn1constraint_compute_PER_range(expr->Identifier, expr->expr_type,
|
||||
expr->combined_constraints, ACT_EL_RANGE, 0, 0, 0);
|
||||
|
||||
if(!range
|
||||
|
|
|
@ -448,7 +448,8 @@ asn1f_check_constraints(arg_t *arg) {
|
|||
RET2RVAL(ret, rvalue);
|
||||
|
||||
for(i = 0; i < sizeof(test_types)/sizeof(test_types[0]); i++) {
|
||||
range = asn1constraint_compute_PER_range(
|
||||
range = asn1constraint_compute_constraint_range(
|
||||
arg->expr->Identifier,
|
||||
etype,
|
||||
arg->expr->combined_constraints,
|
||||
test_types[i], 0, 0,
|
||||
|
|
|
@ -699,17 +699,21 @@ _range_canonicalize(asn1cnst_range_t *range) {
|
|||
}
|
||||
|
||||
asn1cnst_range_t *
|
||||
asn1constraint_compute_OER_range(asn1p_expr_type_e expr_type, const asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, const asn1cnst_range_t *minmax, int *exmet, enum cpr_flags cpr_flags) {
|
||||
return asn1constraint_compute_constraint_range(expr_type, ct, type, minmax, exmet, cpr_flags);
|
||||
asn1constraint_compute_OER_range(const char *dbg_name, asn1p_expr_type_e expr_type, const asn1p_constraint_t *ct, enum asn1p_constraint_type_e requested_ct_type
|
||||
, const asn1cnst_range_t *minmax, int *exmet, enum cpr_flags cpr_flags) {
|
||||
return asn1constraint_compute_constraint_range(dbg_name, expr_type, ct, requested_ct_type, minmax, exmet, cpr_flags | CPR_strict_OER_visibility);
|
||||
}
|
||||
|
||||
asn1cnst_range_t *
|
||||
asn1constraint_compute_PER_range(asn1p_expr_type_e expr_type, const asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, const asn1cnst_range_t *minmax, int *exmet, enum cpr_flags cpr_flags) {
|
||||
return asn1constraint_compute_constraint_range(expr_type, ct, type, minmax, exmet, cpr_flags);
|
||||
asn1constraint_compute_PER_range(const char *dbg_name, asn1p_expr_type_e expr_type, const asn1p_constraint_t *ct, enum asn1p_constraint_type_e requested_ct_type
|
||||
, const asn1cnst_range_t *minmax, int *exmet, enum cpr_flags cpr_flags) {
|
||||
if(0) return asn1constraint_compute_constraint_range(dbg_name, expr_type, ct, requested_ct_type, minmax, exmet, cpr_flags | CPR_strict_PER_visibility);
|
||||
/* Due to pecularities of PER constraint handling, we don't enable strict PER visibility upfront here. */
|
||||
return asn1constraint_compute_constraint_range(dbg_name, expr_type, ct, requested_ct_type, minmax, exmet, cpr_flags);
|
||||
}
|
||||
|
||||
asn1cnst_range_t *
|
||||
asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type, const asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, const asn1cnst_range_t *minmax, int *exmet, enum cpr_flags cpr_flags) {
|
||||
asn1constraint_compute_constraint_range(const char *dbg_name, asn1p_expr_type_e expr_type, const asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, const asn1cnst_range_t *minmax, int *exmet, enum cpr_flags cpr_flags) {
|
||||
asn1cnst_range_t *range;
|
||||
asn1cnst_range_t *tmp;
|
||||
asn1p_value_t *vmin;
|
||||
|
@ -824,7 +828,7 @@ asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type, const asn1p
|
|||
return range;
|
||||
}
|
||||
assert(ct->el_count == 1);
|
||||
tmp = asn1constraint_compute_constraint_range(expr_type,
|
||||
tmp = asn1constraint_compute_constraint_range(dbg_name, expr_type,
|
||||
ct->elements[0], type, minmax, exmet, cpr_flags);
|
||||
if(tmp) {
|
||||
_range_free(range);
|
||||
|
@ -843,7 +847,7 @@ asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type, const asn1p
|
|||
|
||||
/* AND constraints, one after another. */
|
||||
for(i = 0; i < ct->el_count; i++) {
|
||||
tmp = asn1constraint_compute_constraint_range(expr_type,
|
||||
tmp = asn1constraint_compute_constraint_range(dbg_name, expr_type,
|
||||
ct->elements[i], type,
|
||||
ct->type==ACT_CA_SET?range:minmax, exmet,
|
||||
cpr_flags);
|
||||
|
@ -913,7 +917,7 @@ asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type, const asn1p
|
|||
*/
|
||||
tmp = 0;
|
||||
for(i = 0; i < ct->el_count; i++) {
|
||||
tmp = asn1constraint_compute_constraint_range(expr_type,
|
||||
tmp = asn1constraint_compute_constraint_range(dbg_name, expr_type,
|
||||
ct->elements[i], type, minmax, exmet,
|
||||
cpr_flags);
|
||||
if(!tmp) {
|
||||
|
@ -946,7 +950,7 @@ asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type, const asn1p
|
|||
* Canonicalizator will do the union magic.
|
||||
*/
|
||||
for(; i < ct->el_count; i++) {
|
||||
tmp = asn1constraint_compute_constraint_range(expr_type,
|
||||
tmp = asn1constraint_compute_constraint_range(dbg_name, expr_type,
|
||||
ct->elements[i], type, minmax, exmet,
|
||||
cpr_flags);
|
||||
if(!tmp) {
|
||||
|
@ -1021,7 +1025,7 @@ asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type, const asn1p
|
|||
*/
|
||||
assert(ct->el_count >= 1);
|
||||
_range_free(range);
|
||||
range = asn1constraint_compute_constraint_range(expr_type,
|
||||
range = asn1constraint_compute_constraint_range(dbg_name, expr_type,
|
||||
ct->elements[0], type, minmax, exmet, cpr_flags);
|
||||
return range;
|
||||
default:
|
||||
|
|
|
@ -45,20 +45,23 @@ enum cpr_flags {
|
|||
CPR_strict_PER_visibility = 0x02,
|
||||
CPR_simulate_fbless_SIZE = 0x04,
|
||||
};
|
||||
asn1cnst_range_t *asn1constraint_compute_OER_range(asn1p_expr_type_e expr_type,
|
||||
asn1cnst_range_t *asn1constraint_compute_OER_range(const char *dbg_name,
|
||||
asn1p_expr_type_e expr_type,
|
||||
const asn1p_constraint_t *ct,
|
||||
enum asn1p_constraint_type_e required_type,
|
||||
const asn1cnst_range_t *minmax,
|
||||
int *expectation_met,
|
||||
enum cpr_flags);
|
||||
asn1cnst_range_t *asn1constraint_compute_PER_range(asn1p_expr_type_e expr_type,
|
||||
asn1cnst_range_t *asn1constraint_compute_PER_range(const char *dbg_name,
|
||||
asn1p_expr_type_e expr_type,
|
||||
const asn1p_constraint_t *ct,
|
||||
enum asn1p_constraint_type_e required_type,
|
||||
const asn1cnst_range_t *minmax,
|
||||
int *expectation_met,
|
||||
enum cpr_flags);
|
||||
/* Base implementation */
|
||||
asn1cnst_range_t *asn1constraint_compute_constraint_range(asn1p_expr_type_e expr_type,
|
||||
asn1cnst_range_t *asn1constraint_compute_constraint_range(const char *dbg_name,
|
||||
asn1p_expr_type_e expr_type,
|
||||
const asn1p_constraint_t *ct,
|
||||
enum asn1p_constraint_type_e required_type,
|
||||
const asn1cnst_range_t *minmax,
|
||||
|
|
|
@ -483,12 +483,12 @@ asn1print_crange_value(asn1cnst_edge_t *edge, int as_char) {
|
|||
}
|
||||
|
||||
static int
|
||||
asn1print_constraint_explain_type(asn1p_expr_type_e expr_type, asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, enum cpr_flags cpr) {
|
||||
asn1print_constraint_explain_type(const char *dbg_name, asn1p_expr_type_e expr_type, asn1p_constraint_t *ct, enum asn1p_constraint_type_e type, enum cpr_flags cpr) {
|
||||
asn1cnst_range_t *range;
|
||||
int as_char = (type==ACT_CT_FROM);
|
||||
int i;
|
||||
|
||||
range = asn1constraint_compute_constraint_range(expr_type, ct, type, 0, 0, cpr);
|
||||
range = asn1constraint_compute_constraint_range(dbg_name, expr_type, ct, type, 0, 0, cpr);
|
||||
if(!range) return -1;
|
||||
|
||||
if(range->incompatible) return 0;
|
||||
|
@ -538,14 +538,14 @@ asn1print_constraint_explain_type(asn1p_expr_type_e expr_type, asn1p_constraint_
|
|||
}
|
||||
|
||||
static int
|
||||
asn1print_constraint_explain(asn1p_expr_type_e expr_type,
|
||||
asn1print_constraint_explain(const char *dbg_name, asn1p_expr_type_e expr_type,
|
||||
asn1p_constraint_t *ct, enum cpr_flags cpr) {
|
||||
|
||||
asn1print_constraint_explain_type(expr_type, ct, ACT_EL_RANGE, cpr);
|
||||
asn1print_constraint_explain_type(dbg_name, expr_type, ct, ACT_EL_RANGE, cpr);
|
||||
safe_printf(" ");
|
||||
asn1print_constraint_explain_type(expr_type, ct, ACT_CT_SIZE, cpr);
|
||||
asn1print_constraint_explain_type(dbg_name, expr_type, ct, ACT_CT_SIZE, cpr);
|
||||
safe_printf(" ");
|
||||
asn1print_constraint_explain_type(expr_type, ct, ACT_CT_FROM, cpr);
|
||||
asn1print_constraint_explain_type(dbg_name, expr_type, ct, ACT_CT_FROM, cpr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -758,15 +758,18 @@ asn1print_expr(asn1p_t *asn, asn1p_module_t *mod, asn1p_expr_t *tc, enum asn1pri
|
|||
if(top_parent) {
|
||||
safe_printf("\n-- Practical constraints (%s): ",
|
||||
top_parent->Identifier);
|
||||
asn1print_constraint_explain(top_parent->expr_type,
|
||||
asn1print_constraint_explain(top_parent->Identifier,
|
||||
top_parent->expr_type,
|
||||
tc->combined_constraints, 0);
|
||||
safe_printf("\n-- OER-visible constraints (%s): ",
|
||||
top_parent->Identifier);
|
||||
asn1print_constraint_explain(top_parent->expr_type,
|
||||
asn1print_constraint_explain(top_parent->Identifier,
|
||||
top_parent->expr_type,
|
||||
tc->combined_constraints, CPR_strict_OER_visibility);
|
||||
safe_printf("\n-- PER-visible constraints (%s): ",
|
||||
top_parent->Identifier);
|
||||
asn1print_constraint_explain(top_parent->expr_type,
|
||||
asn1print_constraint_explain(top_parent->Identifier,
|
||||
top_parent->expr_type,
|
||||
tc->combined_constraints, CPR_strict_PER_visibility);
|
||||
}
|
||||
safe_printf("\n");
|
||||
|
|
Loading…
Reference in New Issue