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