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 | 6fec44d | 2004-08-22 03:10:23 +0000 | [diff] [blame] | 4 | asn1f_class_access(arg_t *arg, asn1p_module_t *mod, 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 | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 23 | ioclass = asn1f_lookup_symbol(arg, mod, &tmpref); |
| 24 | if(ioclass == NULL) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 25 | errno = ESRCH; |
| 26 | return NULL; |
| 27 | } |
| 28 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 29 | classfield = asn1f_lookup_child(ioclass, ref->components[1].name); |
| 30 | if(classfield == NULL) { |
| 31 | DEBUG("CLASS %s does not contain field %s", |
| 32 | ioclass->Identifier, ref->components[1].name); |
| 33 | errno = ESRCH; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 34 | return NULL; |
| 35 | } |
| 36 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 37 | assert(classfield->meta_type == AMT_OBJECTFIELD); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 39 | DEBUG("CLASS %s -> %s (%d)", ioclass->Identifier, |
| 40 | classfield->Identifier, classfield->expr_type); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 41 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 42 | switch(classfield->expr_type) { |
| 43 | case A1TC_CLASSFIELD_TFS: |
| 44 | if(TQ_FIRST(&classfield->members)) { |
| 45 | /* Already have something */ |
| 46 | } else { |
| 47 | expr = asn1p_expr_new(classfield->_lineno); |
| 48 | expr->expr_type = ASN_TYPE_ANY; |
| 49 | expr->meta_type = AMT_TYPE; |
| 50 | asn1p_expr_add(classfield, expr); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | } |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 52 | /* Fall through */ |
| 53 | case A1TC_CLASSFIELD_FTVFS: |
| 54 | expr = TQ_FIRST(&classfield->members); |
| 55 | assert(expr); |
| 56 | return expr; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | break; |
| 58 | default: |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 59 | FATAL("%s.%s: field type not yet supported. " |
| 60 | "Consider donation to the asn1c author.", |
| 61 | ioclass->Identifier, classfield->Identifier); |
| 62 | return NULL; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Lev Walkin | 9c2285a | 2006-03-09 08:49:26 +0000 | [diff] [blame] | 65 | return NULL; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 66 | } |