From a648f043de193ccd14883e5d74329bd019bdc698 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 25 Jan 2011 12:34:45 +0900 Subject: [PATCH] Give functions their own defspace. The defspace is propogated through the function's sub-scopes. --- tools/qfcc/include/symtab.h | 1 + tools/qfcc/source/function.c | 1 + tools/qfcc/source/qc-parse.y | 6 ++++-- tools/qfcc/source/qfcc.c | 5 +++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/include/symtab.h b/tools/qfcc/include/symtab.h index be86f4db6..ce0741733 100644 --- a/tools/qfcc/include/symtab.h +++ b/tools/qfcc/include/symtab.h @@ -89,6 +89,7 @@ typedef struct symtab_s { struct hashtab_s *tab; ///< symbols defined in this table symbol_t *symbols; ///< chain of symbols in this table symbol_t **symtail; ///< keep chain in declaration order + struct defspace_s *space; ///< storage for vars in scope symtabs } symtab_t; /** Create a new, empty named symbol. diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 9acb56004..fe3cd36f9 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -424,6 +424,7 @@ build_scope (symbol_t *fsym, symtab_t *parent) symtab = new_symtab (parent, stab_local); fsym->s.func->symtab = symtab; + symtab->space = new_defspace (); if (fsym->type->t.func.num_params < 0) { args = new_symbol_type (".args", &type_va_list); diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 23f7860de..7be6db78b 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -508,7 +508,7 @@ def_list def_item : def_name opt_initializer { - initialize_def ($1, $0, $2, pr.near_data, //FIXME right space + initialize_def ($1, $0, $2, current_symtab->space, current_storage); } ; @@ -636,8 +636,10 @@ opt_comma statement_block : '{' { - if (!options.traditional) + if (!options.traditional) { current_symtab = new_symtab (current_symtab, stab_local); + current_symtab->space = current_symtab->parent->space; + } } statements '}' { diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 1cb922da8..1ef3248df 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -141,7 +141,9 @@ InitData (void) pr.near_data->data = calloc (65536, sizeof (pr_type_t)); pr.near_data->max_size = 65536; pr.near_data->grow = 0; - //FIXME pr.scope = new_scope (sc_global, pr.near_data, 0); + + pr.symtab = new_symtab (0, stab_global); + pr.symtab->space = pr.near_data; pr.entity_data = new_defspace (); @@ -360,7 +362,6 @@ setup_param_block (void) size_t i; symbol_t *sym; - pr.symtab = new_symtab (0, stab_global); for (i = 0; i < sizeof (defs) / sizeof (defs[0]); i++) { sym = new_symbol_type (defs[i].name, defs[i].type); symtab_addsymbol (pr.symtab, sym);