From 7198be57264b01c50b06163c5a7e2d0df2dcf55a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 8 Mar 2011 19:28:11 +0900 Subject: [PATCH] Treat entities a bit like structures in field_expr (). Look in the entity field symbol table for the field before looking in the normal symbol table. This allows entity fields to be accessed even when the current scope has symbol of the same name. However, checking the normal symbol table where there is no such field allows for field variables when I get around to implementing them. --- tools/qfcc/source/expr.c | 23 +++++++++++++++++------ tools/qfcc/source/type.c | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index dc6100620..53d753076 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -877,7 +877,7 @@ get_struct_field (type_t *t1, expr_t *e1, expr_t *e2) return 0; } field = symtab_lookup (strct, sym->name); - if (!field) { + if (!field && t1 != &type_entity) { error (e2, "'%s' has no member named '%s'", t1->name + 4, sym->name); e1->type = ex_error; } @@ -894,13 +894,24 @@ field_expr (expr_t *e1, expr_t *e2) return e1; t1 = get_type (e1); if (t1->type == ev_entity) { - t2 = get_type (e2); - if (e2->type == ex_error) - return e2; - if (t2->type == ev_field) { + symbol_t *field = 0; + + if (e2->type == ex_symbol) + field = get_struct_field (&type_entity, e1, e2); + if (field) { + e2 = new_field_expr (0, field->type, field->s.def); e = new_binary_expr ('.', e1, e2); - e->e.expr.type = t2->t.fldptr.type; + e->e.expr.type = field->type; return e; + } else { + t2 = get_type (e2); + if (e2->type == ex_error) + return e2; + if (t2->type == ev_field) { + e = new_binary_expr ('.', e1, e2); + e->e.expr.type = t2->t.fldptr.type; + return e; + } } } else if (t1->type == ev_pointer) { if (is_struct (t1->t.fldptr.type)) { diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index 3e576e000..9d69bcd33 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -867,6 +867,7 @@ chain_initial_types (void) chain_type (&type_string); chain_type (&type_float); chain_type (&type_vector); + type_entity.t.symtab = pr.entity_fields; chain_type (&type_entity); chain_type (&type_field); chain_type (&type_function);