extensions of conditional native-typing to -fbless-SIZE constraints


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@959 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/libasn1fix/asn1fix.c b/libasn1fix/asn1fix.c
index 1d06dba..aa7a233 100644
--- a/libasn1fix/asn1fix.c
+++ b/libasn1fix/asn1fix.c
@@ -414,7 +414,8 @@
 		range = asn1constraint_compute_PER_range(
 				etype,
 				arg->expr->combined_constraints,
-				test_types[i], 0, 0, 0);
+				test_types[i], 0, 0,
+				CPR_noflags /* ignore -fbless-SIZE */);
 		if(!range && errno == EPERM) {
 			FATAL("This error happened for \"%s\" (meta %d) "
 				"at line %d",
diff --git a/libasn1fix/asn1fix_constraint.c b/libasn1fix/asn1fix_constraint.c
index 0faee51..4afca5a 100644
--- a/libasn1fix/asn1fix_constraint.c
+++ b/libasn1fix/asn1fix_constraint.c
@@ -168,15 +168,13 @@
 
 	if(etype != A1TC_INVALID) {
 
-		ret = asn1constraint_compatible(etype, real_constraint_type);
+		ret = asn1constraint_compatible(etype, real_constraint_type,
+				arg->flags & A1F_EXTENDED_SizeConstraint);
 		switch(ret) {
 		case -1:	/* If unknown, assume OK. */
 		case  1:
 			break;
 		case 0:
-			if(effective_type == ACT_CT_SIZE
-			&& (arg->flags & A1F_EXTENDED_SizeConstraint))
-				break;
 		default:
 			FATAL("%s at line %d: "
 				"Constraint type %s is not applicable to %s",
diff --git a/libasn1fix/asn1fix_constraint_compat.c b/libasn1fix/asn1fix_constraint_compat.c
index 676717e..844045f 100644
--- a/libasn1fix/asn1fix_constraint_compat.c
+++ b/libasn1fix/asn1fix_constraint_compat.c
@@ -7,7 +7,7 @@
  */
 int
 asn1constraint_compatible(asn1p_expr_type_e expr_type,
-	enum asn1p_constraint_type_e constr_type) {
+	enum asn1p_constraint_type_e constr_type, int fbless_SIZE) {
 
 	/*
 	 * X.680-0207, Table 9.
@@ -49,6 +49,11 @@
 		return 0;
 	case ACT_CT_SIZE:
 		switch(expr_type) {
+		case ASN_BASIC_INTEGER:
+		case ASN_BASIC_ENUMERATED:
+			if(fbless_SIZE)
+				return 1;
+			break;
 		case ASN_BASIC_BIT_STRING:
 		case ASN_BASIC_OCTET_STRING:
 		case ASN_BASIC_CHARACTER_STRING:
diff --git a/libasn1fix/asn1fix_crange.c b/libasn1fix/asn1fix_crange.c
index 5975bc1..86b629c 100644
--- a/libasn1fix/asn1fix_crange.c
+++ b/libasn1fix/asn1fix_crange.c
@@ -711,7 +711,7 @@
 }
 
 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, int strict_PV) {
+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) {
 	asn1cnst_range_t *range;
 	asn1cnst_range_t *tmp;
 	asn1p_value_t *vmin;
@@ -729,7 +729,8 @@
 	 * Check if the requested constraint is theoretically compatible
 	 * with the given expression type.
 	 */
-	if(asn1constraint_compatible(expr_type, type) != 1) {
+	if(asn1constraint_compatible(expr_type, type,
+			cpr_flags & CPR_simulate_fbless_SIZE) != 1) {
 		errno = EINVAL;
 		return 0;
 	}
@@ -776,7 +777,8 @@
 	if((expr_type & ASN_STRING_NKM_MASK))
 		range->not_PER_visible = 1;
 
-	if(!ct || (strict_PV && range->not_PER_visible))
+	if(!ct
+	|| (range->not_PER_visible && (cpr_flags & CPR_strict_PER_visibility)))
 		return range;
 
 	switch(ct->type) {
@@ -809,7 +811,7 @@
 		}
 		assert(ct->el_count == 1);
 		tmp = asn1constraint_compute_PER_range(expr_type,
-			ct->elements[0], type, minmax, exmet, strict_PV);
+			ct->elements[0], type, minmax, exmet, cpr_flags);
 		if(tmp) {
 			_range_free(range);
 		} else {
@@ -830,7 +832,7 @@
 			tmp = asn1constraint_compute_PER_range(expr_type,
 				ct->elements[i], type,
 				ct->type==ACT_CA_SET?range:minmax, exmet,
-				strict_PV);
+				cpr_flags);
 			if(!tmp) {
 				if(errno == ERANGE) {
 					continue;
@@ -851,7 +853,8 @@
 				continue;
 			}
 
-			if(strict_PV && tmp->not_PER_visible) {
+			if(tmp->not_PER_visible
+			&& (cpr_flags & CPR_strict_PER_visibility)) {
 				if(ct->type == ACT_CA_SET) {
 					/*
 					 * X.691, #9.3.18:
@@ -889,7 +892,7 @@
 		for(i = 0; i < ct->el_count; i++) {
 			tmp = asn1constraint_compute_PER_range(expr_type,
 				ct->elements[i], type, minmax, exmet,
-				strict_PV);
+				cpr_flags);
 			if(!tmp) {
 				if(errno == ERANGE) {
 					range->extensible = 1;
@@ -922,7 +925,7 @@
 		for(; i < ct->el_count; i++) {
 			tmp = asn1constraint_compute_PER_range(expr_type,
 				ct->elements[i], type, minmax, exmet,
-				strict_PV);
+				cpr_flags);
 			if(!tmp) {
 				if(errno == ERANGE) {
 					range->extensible = 1;
@@ -963,7 +966,8 @@
 			range->not_PER_visible = 1;
 		}
 
-		if(strict_PV && range->not_PER_visible) {
+		if(range->not_PER_visible
+		&& (cpr_flags & CPR_strict_PER_visibility)) {
 			/*
 			 * X.691, #9.3.19:
 			 * If not PER-visible constraint is part of UNION,
@@ -987,7 +991,7 @@
 		assert(ct->el_count >= 1);
 		_range_free(range);
 		range = asn1constraint_compute_PER_range(expr_type,
-			ct->elements[0], type, minmax, exmet, strict_PV);
+			ct->elements[0], type, minmax, exmet, cpr_flags);
 		return range;
 	default:
 		range->incompatible = 1;
diff --git a/libasn1fix/asn1fix_crange.h b/libasn1fix/asn1fix_crange.h
index 0681779..b5ae3a3 100644
--- a/libasn1fix/asn1fix_crange.h
+++ b/libasn1fix/asn1fix_crange.h
@@ -38,12 +38,17 @@
  * 	ENOMEM:	Memory allocation failure.
  * 	EPERM:	Invalid constraint reference.
  */
+enum cpr_flags {
+	CPR_noflags			= 0x00,
+	CPR_strict_PER_visibility	= 0x01,
+	CPR_simulate_fbless_SIZE	= 0x02,
+};
 asn1cnst_range_t *asn1constraint_compute_PER_range(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,
-	int strict_PER_visibility);
+	enum cpr_flags);
 void asn1constraint_range_free(asn1cnst_range_t *);
 
 /*
@@ -51,7 +56,7 @@
  * with the given expression type.
  */
 int asn1constraint_compatible(asn1p_expr_type_e expr_type,
-	enum asn1p_constraint_type_e constr_type);
+	enum asn1p_constraint_type_e constr_type, int fbless_SIZE);
 
 /*
  * Fetch a default alphabet for this type.
diff --git a/libasn1fix/asn1fix_value.c b/libasn1fix/asn1fix_value.c
index 50d8da2..0e60ef7 100644
--- a/libasn1fix/asn1fix_value.c
+++ b/libasn1fix/asn1fix_value.c
@@ -80,7 +80,7 @@
 	 */
 	if(opt_constr_type)
 		ret = asn1constraint_compatible(val_type_expr->expr_type,
-			*opt_constr_type);
+			*opt_constr_type, 0 /* must not matter here */);
 	else
 		ret = asn1f_check_type_compatibility(arg,
 			type_expr, val_type_expr);
diff --git a/libasn1fix/check_fixer.c b/libasn1fix/check_fixer.c
index 320eebb..6a13fda 100644
--- a/libasn1fix/check_fixer.c
+++ b/libasn1fix/check_fixer.c
@@ -76,15 +76,15 @@
 			filename = dp->d_name;
 #endif	/* WIN32 */
 			len = strlen(filename);
-			if(len && strcmp(filename + len - 5, ".asn1") == 0) {
-				ret = check(filename, parser_flags,fixer_flags);
-				if(ret) {
-					fprintf(stderr, "FAILED: %s\n",
-						filename);
-					failed++;
-				}
-				completed++;
+			if(len <= 5 || strcmp(filename + len - 5, ".asn1"))
+				continue;
+			ret = check(filename, parser_flags, fixer_flags);
+			if(ret) {
+				fprintf(stderr, "FAILED: %s\n",
+					filename);
+				failed++;
 			}
+			completed++;
 #ifdef	WIN32
 		} while(_findnext(dir, &c_file) == 0);
 		_findclose(dir);
@@ -152,6 +152,10 @@
 		return -1;
 	}
 
+	/* Flag modifiers */
+	if(strstr(fname, "-blessSize-"))
+		fixer_flags |= A1F_EXTENDED_SizeConstraint;
+
 	fprintf(stderr, "[=> %s]\n", fname);
 
 	/*