1 #include "asn1fix_internal.h"
3 static int _compare_value(asn1p_expr_t *expr1, asn1p_expr_t *expr2) {
4 if(expr2->value->type == ATV_INTEGER
5 && expr1->value->type == ATV_INTEGER) {
6 return expr2->value->value.v_integer
7 - expr1->value->value.v_integer;
14 * Check the validity of an INTEGER type.
17 asn1f_fix_integer(arg_t *arg) {
18 asn1p_expr_t *expr = arg->expr;
23 if(expr->expr_type != ASN_BASIC_INTEGER)
24 return 0; /* Just ignore it */
26 DEBUG("(\"%s\", %x) for line %d",
27 expr->Identifier, expr->expr_type, expr->_lineno);
30 * Scan the integer values in search for inconsistencies.
32 TQ_FOR(iv, &(expr->members), next) {
34 DEBUG("\tItem %s(%s)", iv->Identifier,
35 asn1f_printable_value(iv->value));
38 * Found "...", check correctness.
40 if(iv->expr_type == A1TC_EXTENSIBLE) {
41 FATAL("INTEGER %s at line %d: "
42 "Extension marker is not allowed",
49 if(iv->Identifier == NULL
50 || iv->expr_type != A1TC_UNIVERVAL) {
51 FATAL("INTEGER %s at line %d: "
52 "Unsupported enumeration element %s",
55 iv->Identifier?iv->Identifier:"<Anonymous>"
61 if(iv->value == NULL) {
62 FATAL("INTEGER %s at line %d: "
63 "Value for the identifier %s "
64 "must be set explicitly",
71 } else if(iv->value->type == ATV_REFERENCED) {
73 * Resolve the value, once and for all.
75 if(asn1f_value_resolve(arg, iv, 0)) {
76 /* This function will emit messages */
82 if(iv->value->type != ATV_INTEGER) {
83 FATAL("INTEGER %s at line %d: "
84 "Value for the identifier %s "
85 "is not compatible with INTEGER type",
93 * Check that all identifiers are distinct.
95 ret = asn1f_check_unique_expr_child(arg, iv, 0, "identifier");
96 RET2RVAL(ret, rvalue);
98 * Check that all values are distinct.
100 ret = asn1f_check_unique_expr_child(arg, iv,
101 _compare_value, "value");
102 RET2RVAL(ret, rvalue);
111 _asn1f_make_sure_type_is(arg_t *arg, asn1p_expr_t *expr, asn1p_expr_type_e type) {
112 asn1p_expr_t *next_expr;
113 asn1p_expr_type_e expr_type;
116 expr_type = expr->expr_type;
119 * Here we're trying to make sure that the type of the given
120 * expression is really what is expected.
121 * This is ensured in two ways.
122 * First, if the immediate type matches the provided one,
123 * this is a clear hit.
125 if(expr_type == type)
129 * Otherwise, it must be either a reference or a different type.
131 if(expr_type != A1TC_REFERENCE) {
136 assert(expr_type == A1TC_REFERENCE);
137 assert(expr->reference);
140 * Then, it is a reference. For a reference, try to resolve type
143 next_expr = asn1f_lookup_symbol(arg, expr->module,
144 expr->rhs_pspecs, expr->reference);
145 if(next_expr == NULL) {
151 * If symbol is here, recursively check that it conforms to the type.
153 WITH_MODULE(next_expr->module,
154 ret = _asn1f_make_sure_type_is(arg, next_expr, type));