blob: 11acd8b4c8a0e7f3afed47741b37e745d7904753 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001#include "asn1fix_internal.h"
2
vlmfa67ddc2004-06-03 03:38:44 +00003asn1p_expr_t *
vlm2e0c1942004-08-22 03:10:23 +00004asn1f_class_access(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) {
vlmdc7cf042006-03-09 08:49:26 +00005 asn1p_expr_t *ioclass;
6 asn1p_expr_t *classfield;
7 asn1p_expr_t *expr;
vlmfa67ddc2004-06-03 03:38:44 +00008 asn1p_ref_t tmpref;
9
vlmfa67ddc2004-06-03 03:38:44 +000010 assert(ref->comp_count > 1);
11
vlmdc7cf042006-03-09 08:49:26 +000012 DEBUG("ClassAccess lookup (%s) for line %d", asn1f_printable_reference(ref), ref->_lineno);
vlmfa67ddc2004-06-03 03:38:44 +000013
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;
vlmdc7cf042006-03-09 08:49:26 +000023 ioclass = asn1f_lookup_symbol(arg, mod, &tmpref);
24 if(ioclass == NULL) {
vlmfa67ddc2004-06-03 03:38:44 +000025 errno = ESRCH;
26 return NULL;
27 }
28
vlmdc7cf042006-03-09 08:49:26 +000029 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;
vlmfa67ddc2004-06-03 03:38:44 +000034 return NULL;
35 }
36
vlmdc7cf042006-03-09 08:49:26 +000037 assert(classfield->meta_type == AMT_OBJECTFIELD);
vlmfa67ddc2004-06-03 03:38:44 +000038
vlmdc7cf042006-03-09 08:49:26 +000039 DEBUG("CLASS %s -> %s (%d)", ioclass->Identifier,
40 classfield->Identifier, classfield->expr_type);
vlmfa67ddc2004-06-03 03:38:44 +000041
vlmdc7cf042006-03-09 08:49:26 +000042 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);
vlmfa67ddc2004-06-03 03:38:44 +000051 }
vlmdc7cf042006-03-09 08:49:26 +000052 /* Fall through */
53 case A1TC_CLASSFIELD_FTVFS:
54 expr = TQ_FIRST(&classfield->members);
55 assert(expr);
56 return expr;
vlmfa67ddc2004-06-03 03:38:44 +000057 break;
58 default:
vlmdc7cf042006-03-09 08:49:26 +000059 FATAL("%s.%s: field type not yet supported. "
60 "Consider donation to the asn1c author.",
61 ioclass->Identifier, classfield->Identifier);
62 return NULL;
vlmfa67ddc2004-06-03 03:38:44 +000063 }
64
vlmdc7cf042006-03-09 08:49:26 +000065 return NULL;
vlmfa67ddc2004-06-03 03:38:44 +000066}