Simplify the logic of accessing codec function for specific TYPE
diff --git a/libasn1fix/asn1fix_export.c b/libasn1fix/asn1fix_export.c
index 6eb8cda..bb598bf 100644
--- a/libasn1fix/asn1fix_export.c
+++ b/libasn1fix/asn1fix_export.c
@@ -57,6 +57,21 @@
 	return asn1f_find_terminal_type(&arg, expr);
 }
 
+asn1p_expr_t *
+asn1f_find_ancestor_type_with_PER_constraint_ex(asn1p_t *asn, asn1p_expr_t *expr) {
+	arg_t arg;
+
+	memset(&arg, 0, sizeof(arg));
+
+	arg.asn = asn;
+	arg.mod = expr->module;
+	arg.expr = expr;
+	arg.eh = a1f_replace_me_with_proper_interface_arg.eh;
+	arg.debug = a1f_replace_me_with_proper_interface_arg.debug;
+
+	return asn1f_find_ancestor_type_with_PER_constraint(&arg, expr);
+}
+
 int
 asn1f_fix_dereference_values_ex(asn1p_t *asn, asn1p_module_t *mod,
         asn1p_expr_t *expr) {
diff --git a/libasn1fix/asn1fix_export.h b/libasn1fix/asn1fix_export.h
index be06623..0411843 100644
--- a/libasn1fix/asn1fix_export.h
+++ b/libasn1fix/asn1fix_export.h
@@ -38,4 +38,10 @@
 int asn1f_fix_dereference_values_ex(asn1p_t *asn, asn1p_module_t *mod,
 	asn1p_expr_t *expr);
 
+/*
+ * Exportable version of asn1f_find_ancestor_type_with_PER_constraint().
+ */
+asn1p_expr_t *asn1f_find_ancestor_type_with_PER_constraint_ex(asn1p_t *asn,
+	asn1p_expr_t *expr);
+
 #endif	/* ASN1FIX_EXPORT_H */
diff --git a/libasn1fix/asn1fix_retrieve.c b/libasn1fix/asn1fix_retrieve.c
index 86540b9..1700914 100644
--- a/libasn1fix/asn1fix_retrieve.c
+++ b/libasn1fix/asn1fix_retrieve.c
@@ -3,6 +3,7 @@
 enum ftt_what {
 	FTT_TYPE,	/* Find the type of the given expression */
 	FTT_VALUE,	/* Find the value of the given expression */
+	FTT_CONSTR_TYPE /* Find the type of the given expression having constraint */ 
 };
 
 static asn1p_expr_t *asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, enum ftt_what);
@@ -382,6 +383,11 @@
 	return asn1f_find_terminal_thing(arg, expr, FTT_VALUE);
 }
 
+asn1p_expr_t *
+asn1f_find_ancestor_type_with_PER_constraint(arg_t *arg, asn1p_expr_t *expr) {
+	return asn1f_find_terminal_thing(arg, expr, FTT_CONSTR_TYPE);
+}
+
 static asn1p_expr_t *
 asn1f_find_terminal_thing(arg_t *arg, asn1p_expr_t *expr, enum ftt_what what) {
 	asn1p_ref_t *ref = 0;
@@ -389,6 +395,7 @@
 
 	switch(what) {
 	case FTT_TYPE:
+	case FTT_CONSTR_TYPE:
 		/* Expression may be a terminal type itself */
 		if(expr->expr_type != A1TC_REFERENCE)
 			return expr;
@@ -455,6 +462,10 @@
 	}
 
 	tc->_type_referenced = 1;
+
+	if((what == FTT_CONSTR_TYPE) && (tc->constraints))
+		return tc;
+
 	tc->_mark |= TM_RECURSION;
 	WITH_MODULE(tc->module,
 		expr = asn1f_find_terminal_thing(arg, tc, what));
@@ -463,6 +474,7 @@
 	return expr;
 }
 
+
 /*
  * Make sure that the specified name is present or otherwise does
  * not contradict with the EXPORTS clause of the specified module.
diff --git a/libasn1fix/asn1fix_retrieve.h b/libasn1fix/asn1fix_retrieve.h
index 5323904..2d529ef 100644
--- a/libasn1fix/asn1fix_retrieve.h
+++ b/libasn1fix/asn1fix_retrieve.h
@@ -68,4 +68,11 @@
  */
 asn1p_expr_t *asn1f_find_terminal_value(arg_t *arg, asn1p_expr_t *tc);
 
+/*
+ * Recursively find the original type with constraint for the given
+ * expression.
+ */
+asn1p_expr_t *asn1f_find_ancestor_type_with_PER_constraint(arg_t *arg, asn1p_expr_t *tc);
+
+
 #endif	/* ASN1FIX_RETRIEVE_H */