fix some namespace issues with names both being a field and an ivar

This commit is contained in:
Bill Currie 2003-07-23 18:28:31 +00:00
parent 14a9ff2e6b
commit 778cd78c35
3 changed files with 39 additions and 12 deletions

View file

@ -114,6 +114,7 @@ scope_t *new_scope (scope_type type, defspace_t *space, scope_t *parent);
defspace_t *new_defspace (void);
void defspace_adddata (defspace_t *space, pr_type_t *data, int size);
def_t *field_def (const char *name);
def_t *get_def (struct type_s *type, const char *name, scope_t *scope,
storage_class_t storage);
def_t *new_def (struct type_s *type, const char *name, scope_t *scope);

View file

@ -73,18 +73,14 @@ static scope_t *free_scopes;
static locref_t *free_free_locs;
static hashtab_t *defs_by_name;
static hashtab_t *field_defs;
static const char *
defs_get_key (void *_def, void *_tab)
defs_get_key (void *_def, void *unused)
{
def_t *def = (def_t *) _def;
hashtab_t **tab = (hashtab_t **) _tab;
if (tab == &defs_by_name) {
return def->name;
}
return "";
}
static def_t *
check_for_name (type_t *type, const char *name, scope_t *scope,
@ -93,7 +89,8 @@ check_for_name (type_t *type, const char *name, scope_t *scope,
def_t *def;
if (!defs_by_name) {
defs_by_name = Hash_NewTable (16381, defs_get_key, 0, &defs_by_name);
defs_by_name = Hash_NewTable (16381, defs_get_key, 0, 0);
field_defs = Hash_NewTable (16381, defs_get_key, 0, 0);
}
if (!name)
return 0;
@ -220,6 +217,12 @@ vector_component (int is_field, def_t *vec, int comp, scope_t *scope,
Hash_Add (defs_by_name, d);
}
def_t *
field_def (const char *name)
{
return Hash_Find (field_defs, name);
}
/*
get_def
@ -296,6 +299,7 @@ get_def (type_t *type, const char *name, scope_t *scope,
vector_component (1, def, 1, scope, storage);
vector_component (1, def, 2, scope, storage);
}
Hash_Add (field_defs, def);
}
}
@ -477,6 +481,10 @@ flush_scope (scope_t *scope, int force_used)
}
if (!def->removed) {
Hash_Del (defs_by_name, def->name);
if (def->type->type == ev_field) {
if (Hash_Find (field_defs, def->name) == def)
Hash_Del (field_defs, def->name);
}
def->removed = 1;
}
}
@ -509,6 +517,8 @@ def_initialized (def_t *d)
void
clear_defs (void)
{
if (field_defs)
Hash_FlushTable (field_defs);
if (defs_by_name)
Hash_FlushTable (defs_by_name);
}

View file

@ -1191,6 +1191,21 @@ field_expr (expr_t *e1, expr_t *e2)
break;
case ev_entity:
check_initialized (e1);
if (e2->type == ex_name) {
def_t *d = field_def (e2->e.string_val);
if (!d) {
t2 = get_type (e2);
if (e2->type == ex_error)
return e2;
break;
}
e2 = new_def_expr (d);
t2 = get_type (e2);
e = new_binary_expr ('.', e1, e2);
e->e.expr.type = t2->aux_type;
return e;
} else {
t2 = get_type (e2);
if (e2->type == ex_error)
return e2;
@ -1199,6 +1214,7 @@ field_expr (expr_t *e1, expr_t *e2)
e->e.expr.type = t2->aux_type;
return e;
}
}
break;
case ev_vector:
if (!options.traditional && e2->type == ex_name) {