asn1c/libasn1fix/asn1fix_class.c

92 lines
2.4 KiB
C
Raw Permalink Normal View History

2004-06-03 03:38:44 +00:00
#include "asn1fix_internal.h"
asn1p_expr_t *
2017-08-22 08:48:23 +00:00
asn1f_class_access(arg_t *arg, asn1p_expr_t *rhs_pspecs, const asn1p_ref_t *ref) {
2006-03-09 08:49:26 +00:00
asn1p_expr_t *ioclass;
asn1p_expr_t *classfield;
asn1p_expr_t *expr;
2004-06-03 03:38:44 +00:00
asn1p_ref_t tmpref;
assert(ref->comp_count > 1);
2017-08-22 08:48:23 +00:00
DEBUG("ClassAccess lookup (%s%s) for line %d",
asn1f_printable_reference(ref), rhs_pspecs ? ", parameterized" : "",
ref->_lineno);
2004-06-03 03:38:44 +00:00
2017-08-22 08:48:23 +00:00
/*
2004-06-03 03:38:44 +00:00
* Fetch the first part of the reference (OBJECT or ObjectSet).
* OBJECT.&<something>...
* ObjectSet.&<something>...
*/
assert(isupper(ref->components[0].name[0]));
tmpref = *ref;
tmpref.comp_count = 1;
2017-08-22 08:48:23 +00:00
ioclass = asn1f_lookup_symbol(arg, rhs_pspecs, &tmpref);
2006-03-09 08:49:26 +00:00
if(ioclass == NULL) {
2017-08-22 08:48:23 +00:00
DEBUG("ClassAccess lookup (%s) failed",
asn1f_printable_reference(&tmpref));
errno = ESRCH;
2004-06-03 03:38:44 +00:00
return NULL;
}
2006-03-17 02:37:08 +00:00
if(ioclass->expr_type == A1TC_REFERENCE) {
2017-08-22 08:48:23 +00:00
ioclass = WITH_MODULE(
ioclass->module,
asn1f_lookup_symbol(arg, ioclass->rhs_pspecs, ioclass->reference));
if(ioclass == NULL) {
2006-03-17 02:37:08 +00:00
errno = ESRCH;
return NULL;
}
}
if(ioclass->expr_type != A1TC_CLASSDEF) {
if(!(ioclass->_mark & TM_BROKEN)) {
ioclass->_mark |= TM_BROKEN;
FATAL("Class field %s lookup at line %d in something that is not a class: %s at line %d",
asn1f_printable_reference(ref), ref->_lineno,
ioclass->Identifier,
ioclass->_lineno);
}
errno = EINVAL;
return NULL;
}
2004-06-03 03:38:44 +00:00
2006-03-09 08:49:26 +00:00
classfield = asn1f_lookup_child(ioclass, ref->components[1].name);
if(classfield == NULL) {
DEBUG("CLASS %s does not contain field %s",
ioclass->Identifier, ref->components[1].name);
errno = ESRCH;
2004-06-03 03:38:44 +00:00
return NULL;
}
2006-03-09 08:49:26 +00:00
assert(classfield->meta_type == AMT_OBJECTFIELD);
2004-06-03 03:38:44 +00:00
2006-03-09 08:49:26 +00:00
DEBUG("CLASS %s -> %s (%d)", ioclass->Identifier,
classfield->Identifier, classfield->expr_type);
2004-06-03 03:38:44 +00:00
2006-03-09 08:49:26 +00:00
switch(classfield->expr_type) {
case A1TC_CLASSFIELD_TFS:
if(TQ_FIRST(&classfield->members)) {
/* Already have something */
} else {
2017-08-22 08:48:23 +00:00
expr = asn1p_expr_new(classfield->_lineno, arg->mod);
2006-03-09 08:49:26 +00:00
expr->expr_type = ASN_TYPE_ANY;
expr->meta_type = AMT_TYPE;
asn1p_expr_add(classfield, expr);
2004-06-03 03:38:44 +00:00
}
2006-03-09 08:49:26 +00:00
/* Fall through */
case A1TC_CLASSFIELD_FTVFS:
expr = TQ_FIRST(&classfield->members);
assert(expr);
return expr;
2004-06-03 03:38:44 +00:00
break;
default:
2006-03-09 08:49:26 +00:00
FATAL("%s.%s: field type not yet supported. "
"Consider donation to the asn1c author.",
ioclass->Identifier, classfield->Identifier);
return NULL;
2004-06-03 03:38:44 +00:00
}
2006-03-09 08:49:26 +00:00
return NULL;
2004-06-03 03:38:44 +00:00
}
2006-03-14 15:53:59 +00:00