vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | #include "asn1fix_internal.h" |
| 2 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 3 | asn1p_expr_t * |
vlm | 2e0c194 | 2004-08-22 03:10:23 +0000 | [diff] [blame] | 4 | asn1f_class_access(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) { |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 5 | asn1p_expr_t *ioclass; |
| 6 | asn1p_expr_t *classfield; |
| 7 | asn1p_expr_t *expr; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | asn1p_ref_t tmpref; |
| 9 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 10 | assert(ref->comp_count > 1); |
| 11 | |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 12 | DEBUG("ClassAccess lookup (%s) for line %d", asn1f_printable_reference(ref), ref->_lineno); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * Fetch the first part of the reference (OBJECT or ObjectSet). |
| 16 | * OBJECT.&<something>... |
| 17 | * ObjectSet.&<something>... |
| 18 | */ |
| 19 | assert(isupper(ref->components[0].name[0])); |
| 20 | |
| 21 | tmpref = *ref; |
| 22 | tmpref.comp_count = 1; |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 23 | ioclass = asn1f_lookup_symbol(arg, mod, &tmpref); |
| 24 | if(ioclass == NULL) { |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 25 | errno = ESRCH; |
| 26 | return NULL; |
| 27 | } |
vlm | 72a6e62 | 2006-03-17 02:37:08 +0000 | [diff] [blame] | 28 | if(ioclass->expr_type == A1TC_REFERENCE) { |
| 29 | ioclass = asn1f_lookup_symbol(arg, |
| 30 | ioclass->module, ioclass->reference); |
| 31 | if(ioclass == NULL) { |
| 32 | errno = ESRCH; |
| 33 | return NULL; |
| 34 | } |
| 35 | } |
| 36 | if(ioclass->expr_type != A1TC_CLASSDEF) { |
| 37 | if(!(ioclass->_mark & TM_BROKEN)) { |
| 38 | ioclass->_mark |= TM_BROKEN; |
| 39 | FATAL("Class field %s lookup at line %d in something that is not a class: %s at line %d", |
| 40 | asn1f_printable_reference(ref), ref->_lineno, |
| 41 | ioclass->Identifier, |
| 42 | ioclass->_lineno); |
| 43 | } |
| 44 | errno = EINVAL; |
| 45 | return NULL; |
| 46 | } |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 48 | classfield = asn1f_lookup_child(ioclass, ref->components[1].name); |
| 49 | if(classfield == NULL) { |
| 50 | DEBUG("CLASS %s does not contain field %s", |
| 51 | ioclass->Identifier, ref->components[1].name); |
| 52 | errno = ESRCH; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 53 | return NULL; |
| 54 | } |
| 55 | |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 56 | assert(classfield->meta_type == AMT_OBJECTFIELD); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 58 | DEBUG("CLASS %s -> %s (%d)", ioclass->Identifier, |
| 59 | classfield->Identifier, classfield->expr_type); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 60 | |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 61 | switch(classfield->expr_type) { |
| 62 | case A1TC_CLASSFIELD_TFS: |
| 63 | if(TQ_FIRST(&classfield->members)) { |
| 64 | /* Already have something */ |
| 65 | } else { |
| 66 | expr = asn1p_expr_new(classfield->_lineno); |
| 67 | expr->expr_type = ASN_TYPE_ANY; |
| 68 | expr->meta_type = AMT_TYPE; |
| 69 | asn1p_expr_add(classfield, expr); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 70 | } |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 71 | /* Fall through */ |
| 72 | case A1TC_CLASSFIELD_FTVFS: |
| 73 | expr = TQ_FIRST(&classfield->members); |
| 74 | assert(expr); |
| 75 | return expr; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 76 | break; |
| 77 | default: |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 78 | FATAL("%s.%s: field type not yet supported. " |
| 79 | "Consider donation to the asn1c author.", |
| 80 | ioclass->Identifier, classfield->Identifier); |
| 81 | return NULL; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 82 | } |
| 83 | |
vlm | dc7cf04 | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 84 | return NULL; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 85 | } |
vlm | 51aed88 | 2006-03-14 15:53:59 +0000 | [diff] [blame] | 86 | |