vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #include "asn1fix_internal.h" |
| 2 | |
vlm | 8fbd562 | 2004-09-10 06:07:04 +0000 | [diff] [blame] | 3 | #define AFT_MAGIC_ANY 1 /* _fetch_tag() flag */ |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 4 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 5 | static int _asn1f_check_if_tag_must_be_explicit(arg_t *arg, asn1p_expr_t *v); |
| 6 | static int _asn1f_compare_tags(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b); |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 7 | static int _asn1f_fix_type_tag(arg_t *arg, asn1p_expr_t *expr); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 9 | int |
| 10 | asn1f_pull_components_of(arg_t *arg) { |
| 11 | TQ_HEAD(asn1p_expr_t) list; |
| 12 | asn1p_expr_t *expr = arg->expr; |
| 13 | asn1p_expr_t *memb; |
| 14 | int r_value = 0; |
| 15 | |
| 16 | switch(expr->expr_type) { |
| 17 | case ASN_CONSTR_SEQUENCE: |
| 18 | case ASN_CONSTR_SET: |
| 19 | break; |
| 20 | default: |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | TQ_INIT(&list); |
| 25 | |
| 26 | /* |
| 27 | * Look into |
| 28 | */ |
| 29 | while((memb = TQ_REMOVE(&(expr->members), next))) { |
| 30 | asn1p_expr_t *coft; /* COMPONENTS OF thing itself */ |
| 31 | asn1p_expr_t *terminal; /* Terminal of the referenced type */ |
| 32 | |
| 33 | if(memb->expr_type != A1TC_COMPONENTS_OF) { |
| 34 | TQ_ADD(&list, memb, next); |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | coft = TQ_FIRST(&memb->members); |
| 39 | assert(coft); |
| 40 | assert(!TQ_NEXT(coft, next)); |
| 41 | |
| 42 | /* |
| 43 | * Find the referenced type. |
| 44 | */ |
| 45 | terminal = asn1f_find_terminal_type(arg, coft); |
| 46 | if(!terminal || (terminal->expr_type != expr->expr_type)) { |
| 47 | FATAL("COMPONENTS OF at line %d " |
| 48 | "must reference a %s type", |
| 49 | coft->_lineno, |
| 50 | expr->expr_type==ASN_CONSTR_SET |
| 51 | ? "SET" : "SEQUENCE" |
| 52 | ); |
| 53 | TQ_ADD(&list, memb, next); |
| 54 | r_value = -1; |
| 55 | continue; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * Clone the final structure. |
| 60 | */ |
| 61 | |
| 62 | coft = asn1p_expr_clone(terminal, 1 /* Skip extensions */); |
| 63 | if(!coft) return -1; /* ENOMEM */ |
| 64 | |
| 65 | asn1p_expr_free(memb); /* Don't need it anymore*/ |
| 66 | |
| 67 | /* |
| 68 | * Move all components of the cloned structure |
| 69 | * into the current one. |
| 70 | */ |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 71 | while((memb = TQ_REMOVE(&(coft->members), next))) { |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 72 | TQ_ADD(&list, memb, next); |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 73 | memb->parent_expr = expr; |
| 74 | } |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 75 | |
| 76 | asn1p_expr_free(coft); /* Remove wrapper */ |
| 77 | } |
| 78 | |
| 79 | /* Move the stuff back */ |
vlm | b6fd3b2 | 2004-08-25 00:42:25 +0000 | [diff] [blame] | 80 | TQ_MOVE(&(expr->members), &list); |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 81 | |
| 82 | return r_value; |
| 83 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 84 | |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 85 | /* |
| 86 | * Fix extensibility parts inside constructed types (SEQUENCE, SET, CHOICE). |
| 87 | */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 88 | int |
| 89 | asn1f_fix_constr_ext(arg_t *arg) { |
| 90 | asn1p_expr_t *expr = arg->expr; |
| 91 | asn1p_expr_t *v; |
| 92 | TQ_HEAD(asn1p_expr_t) root_list; |
| 93 | TQ_HEAD(asn1p_expr_t) ext_list; |
| 94 | TQ_HEAD(asn1p_expr_t) *cur_list; |
| 95 | int r_value = 0; |
| 96 | int ext_count = 0; |
| 97 | |
| 98 | switch(expr->expr_type) { |
| 99 | case ASN_CONSTR_SEQUENCE: |
| 100 | case ASN_CONSTR_SET: |
| 101 | case ASN_CONSTR_CHOICE: |
| 102 | break; |
| 103 | default: |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | DEBUG("%s(%s) for line %d", __func__, |
| 108 | expr->Identifier, expr->_lineno); |
| 109 | |
| 110 | TQ_INIT(&root_list); |
| 111 | TQ_INIT(&ext_list); |
| 112 | cur_list = (void *)&root_list; |
| 113 | |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Split the set of fields into two lists, the root list |
| 116 | * and the extensions list. |
| 117 | */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 118 | while((v = TQ_REMOVE(&(expr->members), next))) { |
| 119 | if(v->expr_type == A1TC_EXTENSIBLE) { |
| 120 | ext_count++; |
| 121 | switch(ext_count) { |
| 122 | case 1: cur_list = (void *)&ext_list; break; |
| 123 | case 2: |
| 124 | cur_list = (void *)&root_list; |
| 125 | if(v->value) { |
| 126 | FATAL("Optional extension marker " |
| 127 | "must not contain " |
| 128 | "an exception mark " |
| 129 | "at line %d", v->_lineno); |
| 130 | r_value = -1; |
| 131 | } |
| 132 | asn1p_expr_free(v); |
| 133 | continue; |
| 134 | case 3: |
| 135 | FATAL("Third extension marker " |
| 136 | "is not allowed at line %d", v->_lineno); |
| 137 | default: |
| 138 | r_value = -1; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | TQ_ADD(cur_list, v, next); |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * Copy the root list and extension list back into the main list. |
| 147 | */ |
vlm | b6fd3b2 | 2004-08-25 00:42:25 +0000 | [diff] [blame] | 148 | TQ_MOVE(&(expr->members), &root_list); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 149 | while((v = TQ_REMOVE(&ext_list, next))) |
| 150 | TQ_ADD(&(expr->members), v, next); |
| 151 | |
| 152 | if(arg->mod->module_flags & MSF_EXTENSIBILITY_IMPLIED |
vlm | b6fd3b2 | 2004-08-25 00:42:25 +0000 | [diff] [blame] | 153 | && ext_count == 0) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 154 | v = asn1p_expr_new(0); |
| 155 | if(v) { |
| 156 | v->Identifier = strdup("..."); |
| 157 | v->expr_type = A1TC_EXTENSIBLE; |
| 158 | v->meta_type = AMT_TYPE; |
vlm | 4f4f56d | 2004-07-01 00:51:31 +0000 | [diff] [blame] | 159 | v->_lineno = expr->_lineno; /* The best we can do */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 160 | if(v->Identifier == NULL) { |
| 161 | asn1p_expr_free(v); |
| 162 | r_value = -1; |
| 163 | } else { |
vlm | 6a02a8a | 2004-09-08 00:28:11 +0000 | [diff] [blame] | 164 | asn1p_expr_add(expr, v); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 165 | } |
| 166 | } else { |
| 167 | r_value = -1; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | return r_value; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | int |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 176 | asn1f_fix_constr_tag(arg_t *arg, int fix_top_level) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 177 | asn1p_expr_t *expr = arg->expr; |
| 178 | asn1p_expr_t *v; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 179 | int root_tagged = 0; /* The root component is manually tagged */ |
| 180 | int ext_tagged = 0; /* The extensions are manually tagged */ |
| 181 | int component_number = 0; |
| 182 | int r_value = 0; |
| 183 | |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 184 | DEBUG("%s(%s) for line %d", __func__, |
| 185 | expr->Identifier, expr->_lineno); |
| 186 | |
| 187 | /* |
| 188 | * Fix the top-level type itself first. |
| 189 | */ |
| 190 | if(fix_top_level) { |
| 191 | if(expr->tag.tag_class == TC_NOCLASS) |
| 192 | return r_value; |
| 193 | |
| 194 | if(_asn1f_fix_type_tag(arg, expr)) |
| 195 | r_value = -1; |
| 196 | |
| 197 | return r_value; |
| 198 | } |
| 199 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 200 | switch(expr->expr_type) { |
| 201 | case ASN_CONSTR_SEQUENCE: |
| 202 | case ASN_CONSTR_SET: |
| 203 | case ASN_CONSTR_CHOICE: |
| 204 | break; |
| 205 | default: |
| 206 | return 0; |
| 207 | } |
| 208 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 209 | TQ_FOR(v, &(expr->members), next) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 210 | |
| 211 | if(v->expr_type == A1TC_EXTENSIBLE) { |
| 212 | component_number++; |
| 213 | continue; |
| 214 | } |
| 215 | |
| 216 | if(v->tag.tag_class == TC_NOCLASS) { |
| 217 | continue; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 218 | } |
| 219 | |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 220 | switch(component_number) { |
| 221 | case 0: case 2: |
| 222 | root_tagged = 1; break; |
| 223 | default: |
| 224 | ext_tagged = 1; break; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 225 | } |
| 226 | |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 227 | if(_asn1f_fix_type_tag(arg, v)) |
| 228 | r_value = -1; |
| 229 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 230 | } |
| 231 | |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 232 | if((arg->mod->module_flags & MSF_AUTOMATIC_TAGS) |
| 233 | && !root_tagged) { |
| 234 | if(ext_tagged) { |
| 235 | /* X.690: 28.4 */ |
| 236 | FATAL("In %s at line %d: " |
| 237 | "extensions are tagged " |
| 238 | "but root components are not", |
| 239 | expr->Identifier, expr->_lineno); |
| 240 | r_value = -1; |
| 241 | } else { |
| 242 | /* Make a decision on automatic tagging */ |
| 243 | expr->auto_tags_OK = 1; |
| 244 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return r_value; |
| 248 | } |
| 249 | |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 250 | static int |
| 251 | _asn1f_fix_type_tag(arg_t *arg, asn1p_expr_t *expr) { |
| 252 | int must_explicit = _asn1f_check_if_tag_must_be_explicit(arg, expr); |
| 253 | int fl_impl_tags = (arg->mod->module_flags & MSF_IMPLICIT_TAGS); |
| 254 | int r_value = 0; |
| 255 | |
| 256 | if(fl_impl_tags) { |
| 257 | if(expr->tag.tag_mode != TM_EXPLICIT) { |
| 258 | if(must_explicit) |
| 259 | expr->tag.tag_mode = TM_EXPLICIT; |
| 260 | else |
| 261 | expr->tag.tag_mode = TM_IMPLICIT; |
| 262 | } |
| 263 | } else { |
| 264 | if(expr->tag.tag_mode == TM_DEFAULT) { |
| 265 | expr->tag.tag_mode = TM_EXPLICIT; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Perform a final sanity check. |
| 271 | */ |
| 272 | if(must_explicit) { |
| 273 | if(expr->tag.tag_mode == TM_IMPLICIT) { |
| 274 | FATAL("%s tagged in IMPLICIT mode " |
| 275 | "but must be EXPLICIT at line %d", |
| 276 | expr->Identifier, expr->_lineno); |
| 277 | r_value = -1; |
| 278 | } else { |
| 279 | expr->tag.tag_mode = TM_EXPLICIT; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return r_value; |
| 284 | } |
| 285 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 286 | int |
| 287 | asn1f_fix_constr_autotag(arg_t *arg) { |
| 288 | asn1p_expr_t *expr = arg->expr; |
| 289 | asn1p_expr_t *v; |
| 290 | asn1_integer_t tag_value = 0; |
| 291 | int r_value = 0; |
| 292 | |
| 293 | switch(expr->expr_type) { |
| 294 | case ASN_CONSTR_SEQUENCE: |
| 295 | case ASN_CONSTR_SET: |
| 296 | case ASN_CONSTR_CHOICE: |
| 297 | if(expr->auto_tags_OK) |
| 298 | break; |
| 299 | /* Automatic tagging is not applicable */ |
| 300 | /* Fall through */ |
| 301 | default: |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | DEBUG("%s(%s) for line %d", __func__, |
| 306 | expr->Identifier, expr->_lineno); |
| 307 | |
| 308 | TQ_FOR(v, &(expr->members), next) { |
| 309 | int must_explicit; |
| 310 | |
| 311 | if(v->expr_type == A1TC_EXTENSIBLE) |
| 312 | break; |
| 313 | |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 314 | if(0) { |
| 315 | /* This may be not true in case COMPONENTS OF */ |
| 316 | assert(v->tag.tag_class == TC_NOCLASS); |
| 317 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 318 | |
| 319 | must_explicit = _asn1f_check_if_tag_must_be_explicit(arg, v); |
| 320 | |
| 321 | v->tag.tag_class = TC_CONTEXT_SPECIFIC; |
| 322 | v->tag.tag_mode = must_explicit ? TM_EXPLICIT : TM_IMPLICIT; |
| 323 | v->tag.tag_value = tag_value++; |
| 324 | } |
| 325 | |
| 326 | return r_value; |
| 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Check that tags are distinct. |
| 331 | */ |
| 332 | int |
| 333 | asn1f_check_constr_tags_distinct(arg_t *arg) { |
| 334 | asn1p_expr_t *expr = arg->expr; |
| 335 | asn1p_expr_t *v; |
| 336 | int r_value = 0; |
| 337 | |
| 338 | switch(expr->expr_type) { |
| 339 | case ASN_CONSTR_SEQUENCE: |
| 340 | case ASN_CONSTR_SET: |
| 341 | case ASN_CONSTR_CHOICE: |
| 342 | break; |
| 343 | default: |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | TQ_FOR(v, &(expr->members), next) { |
| 348 | /* |
| 349 | * In every series of non-mandatory components, |
| 350 | * the tags must be distinct from each other AND the |
| 351 | * tag of the following mandatory component. |
| 352 | * For SET and CHOICE treat everything as a big set of |
| 353 | * non-mandatory components. |
| 354 | */ |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 355 | if(expr->expr_type != ASN_CONSTR_SEQUENCE || v->marker.flags) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 356 | asn1p_expr_t *nv; |
| 357 | for(nv = v; (nv = TQ_NEXT(nv, next));) { |
| 358 | if(_asn1f_compare_tags(arg, v, nv)) |
| 359 | r_value = -1; |
| 360 | if(expr->expr_type == ASN_CONSTR_SEQUENCE |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 361 | && !nv->marker.flags) break; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return r_value; |
| 367 | } |
| 368 | |
| 369 | static int |
| 370 | _asn1f_check_if_tag_must_be_explicit(arg_t *arg, asn1p_expr_t *v) { |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 371 | struct asn1p_type_tag_s tag; |
| 372 | struct asn1p_type_tag_s save_tag; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 373 | asn1p_expr_t *reft; |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 374 | int ret; |
| 375 | |
| 376 | /* |
| 377 | * Fetch the _next_ tag for this type. |
| 378 | */ |
| 379 | save_tag = v->tag; /* Save existing tag */ |
| 380 | memset(&v->tag, 0, sizeof(v->tag)); /* Remove it temporarily */ |
vlm | 8fbd562 | 2004-09-10 06:07:04 +0000 | [diff] [blame] | 381 | ret = asn1f_fetch_outmost_tag(arg->asn, arg->mod, v, &tag, 0); |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 382 | v->tag = save_tag; /* Restore the tag back */ |
| 383 | |
| 384 | if(ret == 0) return 0; /* If found tag, it's okay */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 385 | |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 386 | reft = asn1f_find_terminal_type(arg, v); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 387 | if(reft) { |
| 388 | switch(reft->expr_type) { |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 389 | case ASN_TYPE_ANY: |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 390 | case ASN_CONSTR_CHOICE: |
| 391 | return 1; |
| 392 | default: |
| 393 | return 0; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Check that the tags are distinct. |
| 402 | */ |
| 403 | static int |
| 404 | _asn1f_compare_tags(arg_t *arg, asn1p_expr_t *a, asn1p_expr_t *b) { |
| 405 | struct asn1p_type_tag_s ta, tb; |
| 406 | int ra, rb; |
| 407 | int ret; |
| 408 | |
vlm | 8fbd562 | 2004-09-10 06:07:04 +0000 | [diff] [blame] | 409 | ra = asn1f_fetch_outmost_tag(arg->asn, arg->mod, a, &ta, AFT_MAGIC_ANY); |
| 410 | rb = asn1f_fetch_outmost_tag(arg->asn, arg->mod, b, &tb, AFT_MAGIC_ANY); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 411 | |
| 412 | /* |
| 413 | * If both tags are explicitly or implicitly given, use them. |
| 414 | */ |
| 415 | if(ra == 0 && rb == 0) { |
| 416 | /* |
| 417 | * Simple case: fetched both tags. |
| 418 | */ |
vlm | 7614245 | 2004-09-05 10:36:22 +0000 | [diff] [blame] | 419 | |
| 420 | if((ta.tag_value == tb.tag_value |
| 421 | && ta.tag_class == tb.tag_class) |
| 422 | || ta.tag_value == -1 /* Spread IMAGINARY ANY tag... */ |
| 423 | || tb.tag_value == -1 /* ...it is an evil virus, fear it! */ |
| 424 | ) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 425 | char *p = (a->expr_type == A1TC_EXTENSIBLE) |
| 426 | ?"potentially ":""; |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 427 | FATAL("Processing %s at line %d: component \"%s\" at line %d %shas the same tag " |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 428 | "with component \"%s\" at line %d", |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 429 | arg->expr->Identifier, |
| 430 | arg->expr->_lineno, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 431 | a->Identifier, |
| 432 | a->_lineno, |
| 433 | p, |
| 434 | b->Identifier, |
| 435 | b->_lineno |
| 436 | ); |
vlm | 4f4f56d | 2004-07-01 00:51:31 +0000 | [diff] [blame] | 437 | if((arg->mod->module_flags & MSF_EXTENSIBILITY_IMPLIED) |
| 438 | && (a->expr_type == A1TC_EXTENSIBLE) |
| 439 | && (b->expr_type == A1TC_EXTENSIBLE)) { |
| 440 | FATAL("The previous error is due to " |
| 441 | "improper use of " |
| 442 | "EXTENSIBILITY IMPLIED flag " |
| 443 | "of module %s", |
| 444 | arg->mod->Identifier); |
| 445 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 446 | return -1; |
| 447 | } else { |
| 448 | /* Tags are distinct */ |
| 449 | return 0; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /********************************************************** |
| 454 | * Now we must perform some very funny recursion to check |
| 455 | * multiple components of CHOICE type, etc. |
| 456 | */ |
| 457 | |
| 458 | DEBUG("Comparing tags %s:%x <-> %s:%x", |
| 459 | a->Identifier, a->expr_type, |
| 460 | b->Identifier, b->expr_type); |
| 461 | |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 462 | if(ra && a->meta_type == AMT_TYPEREF) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 463 | |
| 464 | DEBUG(" %s is a type reference", a->Identifier); |
| 465 | |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 466 | a = asn1f_lookup_symbol(arg, a->module, a->reference); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 467 | if(!a) return 0; /* Already FATAL()'ed somewhere else */ |
vlm | f645aff | 2004-08-22 03:09:24 +0000 | [diff] [blame] | 468 | WITH_MODULE(a->module, ret = _asn1f_compare_tags(arg, a, b)); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 469 | return ret; |
| 470 | } |
| 471 | |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 472 | if(ra && a->expr_type == ASN_CONSTR_CHOICE) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 473 | asn1p_expr_t *v; |
| 474 | |
| 475 | DEBUG(" %s is a choice type (%d)", a->Identifier, a->_mark); |
| 476 | |
| 477 | /* |
| 478 | * Iterate over members of CHOICE. |
| 479 | */ |
| 480 | //if(a->_mark & TM_RECURSION) return 0; |
| 481 | TQ_FOR(v, &(a->members), next) { |
| 482 | //a->_mark |= TM_RECURSION; |
| 483 | ret = _asn1f_compare_tags(arg, v, b); |
| 484 | //a->_mark &= ~TM_RECURSION; |
| 485 | if(ret) return ret; |
| 486 | } |
| 487 | return 0; |
| 488 | } |
| 489 | |
vlm | 387a088 | 2004-09-15 11:48:34 +0000 | [diff] [blame] | 490 | if(rb && b->expr_type == ASN_CONSTR_CHOICE) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 491 | return _asn1f_compare_tags(arg, b, a); |
| 492 | } |
| 493 | |
| 494 | if(a->_mark & TM_RECURSION) return 0; |
| 495 | if(b->_mark & TM_RECURSION) return 0; |
| 496 | a->_mark |= TM_RECURSION; |
| 497 | b->_mark |= TM_RECURSION; |
| 498 | ret = _asn1f_compare_tags(arg, b, a); |
| 499 | a->_mark &= ~TM_RECURSION; |
| 500 | b->_mark &= ~TM_RECURSION; |
| 501 | |
| 502 | return ret; |
| 503 | } |
| 504 | |