blob: b3bfae576dbf64a58cc0a332779a3b6936c1dc4e [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 }
vlm72a6e622006-03-17 02:37:08 +000028 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 }
vlmfa67ddc2004-06-03 03:38:44 +000047
vlmdc7cf042006-03-09 08:49:26 +000048 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;
vlmfa67ddc2004-06-03 03:38:44 +000053 return NULL;
54 }
55
vlmdc7cf042006-03-09 08:49:26 +000056 assert(classfield->meta_type == AMT_OBJECTFIELD);
vlmfa67ddc2004-06-03 03:38:44 +000057
vlmdc7cf042006-03-09 08:49:26 +000058 DEBUG("CLASS %s -> %s (%d)", ioclass->Identifier,
59 classfield->Identifier, classfield->expr_type);
vlmfa67ddc2004-06-03 03:38:44 +000060
vlmdc7cf042006-03-09 08:49:26 +000061 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);
vlmfa67ddc2004-06-03 03:38:44 +000070 }
vlmdc7cf042006-03-09 08:49:26 +000071 /* Fall through */
72 case A1TC_CLASSFIELD_FTVFS:
73 expr = TQ_FIRST(&classfield->members);
74 assert(expr);
75 return expr;
vlmfa67ddc2004-06-03 03:38:44 +000076 break;
77 default:
vlmdc7cf042006-03-09 08:49:26 +000078 FATAL("%s.%s: field type not yet supported. "
79 "Consider donation to the asn1c author.",
80 ioclass->Identifier, classfield->Identifier);
81 return NULL;
vlmfa67ddc2004-06-03 03:38:44 +000082 }
83
vlmdc7cf042006-03-09 08:49:26 +000084 return NULL;
vlmfa67ddc2004-06-03 03:38:44 +000085}
vlm51aed882006-03-14 15:53:59 +000086