diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index 7df5baa1d..6233b3c2a 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -986,6 +986,8 @@ class_pointer_symbol (class_t *class) sym = make_symbol (va ("_OBJ_CLASS_POINTER_%s", class->name), pointer_type (class->type), pr.far_data, st_static); + if (!sym->table) + symtab_addsymbol (pr.symtab, sym); def = sym->s.def; if (def->initialized) return sym; diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 57b932e23..053f3ef43 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2404,6 +2404,8 @@ selector_expr (keywordarg_t *selector) index *= type_size (type_SEL.t.fldptr.type); sel_sym = make_symbol ("_OBJ_SELECTOR_TABLE", type_SEL.t.fldptr.type, 0, st_extern); + if (!sel_sym->table) + symtab_addsymbol (pr.symtab, sel_sym); sel = new_symbol_expr (sel_sym); dstring_delete (sel_id); return address_expr (sel, new_short_expr (index), 0); diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 4253471af..2f3449c81 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -446,12 +446,14 @@ build_scope (symbol_t *fsym, symtab_t *parent) symbol_t *args = 0; symbol_t *param; symtab_t *symtab; + symtab_t *cs = current_symtab; check_function (fsym); symtab = new_symtab (parent, stab_local); fsym->s.func->symtab = symtab; symtab->space = new_defspace (); + current_symtab = symtab; if (fsym->type->t.func.num_params < 0) { args = new_symbol_type (".args", &type_va_list); @@ -466,7 +468,6 @@ build_scope (symbol_t *fsym, symtab_t *parent) continue; // non-param selector param = new_symbol_type (p->name, p->type); initialize_def (param, param->type, 0, symtab->space, st_local); - symtab_addsymbol (symtab, param); i++; } @@ -477,6 +478,7 @@ build_scope (symbol_t *fsym, symtab_t *parent) i++; } } + current_symtab = cs; } function_t * diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index 606ffc0f9..ca3839782 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -374,6 +374,7 @@ get_selector (expr_t *sel) def_t * emit_selectors (void) { + symbol_t *sel_sym; def_t *sel_def; type_t *sel_type; pr_sel_t *sel; @@ -383,8 +384,11 @@ emit_selectors (void) return 0; sel_type = array_type (type_SEL.t.fldptr.type, sel_index); - sel_def = make_symbol ("_OBJ_SELECTOR_TABLE", type_SEL.t.fldptr.type, - pr.far_data, st_static)->s.def; + sel_sym = make_symbol ("_OBJ_SELECTOR_TABLE", type_SEL.t.fldptr.type, + pr.far_data, st_static); + if (!sel_sym->table) + symtab_addsymbol (pr.symtab, sel_sym); + sel_def = sel_sym->s.def; sel_def->initialized = sel_def->constant = 1; sel_def->nosave = 1; diff --git a/tools/qfcc/source/symtab.c b/tools/qfcc/source/symtab.c index e6e031ce8..4832c97bc 100644 --- a/tools/qfcc/source/symtab.c +++ b/tools/qfcc/source/symtab.c @@ -108,6 +108,9 @@ symbol_t * symtab_addsymbol (symtab_t *symtab, symbol_t *symbol) { symbol_t *s; + if (symbol->table) + internal_error (0, "symbol '%s' is already in another symbol table", + symbol->name); if ((s = Hash_Find (symtab->tab, symbol->name))) return s; Hash_Add (symtab->tab, symbol); @@ -193,7 +196,6 @@ make_symbol (const char *name, type_t *type, defspace_t *space, sym = symtab_lookup (pr.symtab, name); if (!sym) { sym = new_symbol_type (name, type); - symtab_addsymbol (pr.symtab, sym); } if (sym->type != type) { error (0, "%s redefined", name);