mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-28 05:01:28 +00:00
[qfcc] Pass initialize_def the symtab to use as a parameter
This takes care of an old FIXME.
This commit is contained in:
parent
9c51c3d2e1
commit
1f802716e1
7 changed files with 39 additions and 30 deletions
|
@ -40,6 +40,7 @@
|
|||
///@{
|
||||
|
||||
struct symbol_s;
|
||||
struct symtab_s;
|
||||
struct expr_s;
|
||||
|
||||
/** Represent a memory location that holds a QuakeC/Ruamoko object.
|
||||
|
@ -242,10 +243,11 @@ void def_to_ddef (def_t *def, ddef_t *ddef, int aux);
|
|||
\param init If not null, the expressions to use to initialize the def.
|
||||
\param space The space from which to allocate space for the def.
|
||||
\param storage The storage class of the def.
|
||||
\param symtab The symbol table into which the def will be placed.
|
||||
*/
|
||||
void initialize_def (struct symbol_s *sym,
|
||||
struct expr_s *init, struct defspace_s *space,
|
||||
storage_class_t storage);
|
||||
storage_class_t storage, struct symtab_s *symtab);
|
||||
|
||||
/** Determine if two defs overlap.
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ init_elements (struct def_s *def, expr_t *eles)
|
|||
}
|
||||
|
||||
static void
|
||||
init_vector_components (symbol_t *vector_sym, int is_field)
|
||||
init_vector_components (symbol_t *vector_sym, int is_field, symtab_t *symtab)
|
||||
{
|
||||
expr_t *vector_expr;
|
||||
int i;
|
||||
|
@ -425,9 +425,9 @@ init_vector_components (symbol_t *vector_sym, int is_field)
|
|||
const char *name;
|
||||
|
||||
name = va (0, "%s_%s", vector_sym->name, fields[i]);
|
||||
sym = symtab_lookup (current_symtab, name);
|
||||
sym = symtab_lookup (symtab, name);
|
||||
if (sym) {
|
||||
if (sym->table == current_symtab) {
|
||||
if (sym->table == symtab) {
|
||||
if (sym->sy_type != sy_expr) {
|
||||
error (0, "%s redefined", name);
|
||||
sym = 0;
|
||||
|
@ -461,12 +461,13 @@ init_vector_components (symbol_t *vector_sym, int is_field)
|
|||
sym->sy_type = sy_expr;
|
||||
sym->s.expr = expr;
|
||||
if (!sym->table)
|
||||
symtab_addsymbol (current_symtab, sym);
|
||||
symtab_addsymbol (symtab, sym);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_field_def (def_t *def, expr_t *init, storage_class_t storage)
|
||||
init_field_def (def_t *def, expr_t *init, storage_class_t storage,
|
||||
symtab_t *symtab)
|
||||
{
|
||||
type_t *type = (type_t *) dereference_type (def->type);//FIXME cast
|
||||
def_t *field_def;
|
||||
|
@ -499,7 +500,7 @@ init_field_def (def_t *def, expr_t *init, storage_class_t storage)
|
|||
}
|
||||
// no support for initialized field vector componets (yet?)
|
||||
if (is_vector(type) && options.code.vector_components)
|
||||
init_vector_components (field_sym, 1);
|
||||
init_vector_components (field_sym, 1, symtab);
|
||||
} else if (init->type == ex_symbol) {
|
||||
symbol_t *sym = init->e.symbol;
|
||||
symbol_t *field = symtab_lookup (pr.entity_fields, sym->name);
|
||||
|
@ -523,12 +524,12 @@ num_elements (expr_t *e)
|
|||
|
||||
void
|
||||
initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
|
||||
storage_class_t storage)
|
||||
storage_class_t storage, symtab_t *symtab)
|
||||
{
|
||||
symbol_t *check = symtab_lookup (current_symtab, sym->name);
|
||||
symbol_t *check = symtab_lookup (symtab, sym->name);
|
||||
reloc_t *relocs = 0;
|
||||
|
||||
if (check && check->table == current_symtab) {
|
||||
if (check && check->table == symtab) {
|
||||
if (check->sy_type != sy_var || !type_same (check->type, sym->type)) {
|
||||
error (0, "%s redefined", sym->name);
|
||||
} else {
|
||||
|
@ -549,7 +550,7 @@ initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
|
|||
}
|
||||
sym->sy_type = sy_var;
|
||||
if (!sym->table)
|
||||
symtab_addsymbol (current_symtab, sym);
|
||||
symtab_addsymbol (symtab, sym);
|
||||
|
||||
if (sym->s.def && sym->s.def->external) {
|
||||
//FIXME this really is not the right way
|
||||
|
@ -567,10 +568,10 @@ initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
|
|||
reloc_attach_relocs (relocs, &sym->s.def->relocs);
|
||||
}
|
||||
if (is_vector(sym->type) && options.code.vector_components)
|
||||
init_vector_components (sym, 0);
|
||||
init_vector_components (sym, 0, symtab);
|
||||
if (sym->type->type == ev_field && storage != sc_local
|
||||
&& storage != sc_param)
|
||||
init_field_def (sym->s.def, init, storage);
|
||||
init_field_def (sym->s.def, init, storage, symtab);
|
||||
if (storage == sc_extern) {
|
||||
if (init)
|
||||
error (0, "initializing external variable");
|
||||
|
|
|
@ -156,7 +156,8 @@ super_expr (class_type_t *class_type)
|
|||
sym = symtab_lookup (current_symtab, ".super");
|
||||
if (!sym || sym->table != current_symtab) {
|
||||
sym = new_symbol_type (".super", &type_super);
|
||||
initialize_def (sym, 0, current_symtab->space, sc_local);
|
||||
initialize_def (sym, 0, current_symtab->space, sc_local,
|
||||
current_symtab);
|
||||
}
|
||||
super = new_symbol_expr (sym);
|
||||
|
||||
|
|
|
@ -494,7 +494,6 @@ build_scope (symbol_t *fsym, symtab_t *parent)
|
|||
symbol_t *param;
|
||||
symtab_t *parameters;
|
||||
symtab_t *locals;
|
||||
symtab_t *cs = current_symtab;//FIXME
|
||||
|
||||
check_function (fsym);
|
||||
|
||||
|
@ -508,8 +507,6 @@ build_scope (symbol_t *fsym, symtab_t *parent)
|
|||
locals->space = defspace_new (ds_virtual);
|
||||
fsym->s.func->locals = locals;
|
||||
|
||||
current_symtab = locals;//FIXME
|
||||
|
||||
if (!fsym->s.func) {
|
||||
internal_error (0, "function %s not defined", fsym->name);
|
||||
}
|
||||
|
@ -518,7 +515,7 @@ build_scope (symbol_t *fsym, symtab_t *parent)
|
|||
}
|
||||
if (fsym->s.func->type->t.func.num_params < 0) {
|
||||
args = new_symbol_type (".args", &type_va_list);
|
||||
initialize_def (args, 0, parameters->space, sc_param);
|
||||
initialize_def (args, 0, parameters->space, sc_param, locals);
|
||||
}
|
||||
|
||||
for (p = fsym->params, i = 0; p; p = p->next) {
|
||||
|
@ -531,18 +528,17 @@ build_scope (symbol_t *fsym, symtab_t *parent)
|
|||
p->name = save_string ("");
|
||||
}
|
||||
param = new_symbol_type (p->name, p->type);
|
||||
initialize_def (param, 0, parameters->space, sc_param);
|
||||
initialize_def (param, 0, parameters->space, sc_param, locals);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (args) {
|
||||
while (i < PR_MAX_PARAMS) {
|
||||
param = new_symbol_type (va (0, ".par%d", i), &type_param);
|
||||
initialize_def (param, 0, parameters->space, sc_param);
|
||||
initialize_def (param, 0, parameters->space, sc_param, locals);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
current_symtab = cs;
|
||||
}
|
||||
|
||||
function_t *
|
||||
|
|
|
@ -554,7 +554,8 @@ external_decl
|
|||
$1->type=find_type (alias_type ($1->type, $1->type, $1->name));
|
||||
symtab_addsymbol (current_symtab, $1);
|
||||
} else {
|
||||
initialize_def ($1, 0, current_symtab->space, spec.storage);
|
||||
initialize_def ($1, 0, current_symtab->space, spec.storage,
|
||||
current_symtab);
|
||||
if ($1->s.def)
|
||||
$1->s.def->nosave |= spec.nosave;
|
||||
}
|
||||
|
@ -570,7 +571,8 @@ external_decl
|
|||
$1->type=find_type (alias_type ($1->type, $1->type, $1->name));
|
||||
symtab_addsymbol (current_symtab, $1);
|
||||
} else {
|
||||
initialize_def ($1, $2, current_symtab->space, spec.storage);
|
||||
initialize_def ($1, $2, current_symtab->space, spec.storage,
|
||||
current_symtab);
|
||||
if ($1->s.def)
|
||||
$1->s.def->nosave |= spec.nosave;
|
||||
}
|
||||
|
@ -1152,7 +1154,7 @@ decl
|
|||
if (sc == sc_static)
|
||||
space = pr.near_data;
|
||||
$1->type = find_type (append_type ($1->type, spec.type));
|
||||
initialize_def ($1, $2, space, sc);
|
||||
initialize_def ($1, $2, space, sc, current_symtab);
|
||||
if ($1->s.def)
|
||||
$1->s.def->nosave |= spec.nosave;
|
||||
}
|
||||
|
@ -1214,7 +1216,8 @@ non_code_func
|
|||
if (local_expr) {
|
||||
symbol_t *sym = $<symbol>0;
|
||||
specifier_t spec = $<spec>-1;
|
||||
initialize_def (sym, $2, current_symtab->space, spec.storage);
|
||||
initialize_def (sym, $2, current_symtab->space, spec.storage,
|
||||
current_symtab);
|
||||
if (sym->s.def)
|
||||
sym->s.def->nosave |= spec.nosave;
|
||||
} else {
|
||||
|
@ -1235,7 +1238,8 @@ non_code_func
|
|||
if (sym->sy_type == sy_func)
|
||||
make_function (sym, 0, sym->table->space, spec.storage);
|
||||
} else {
|
||||
initialize_def (sym, 0, current_symtab->space, spec.storage);
|
||||
initialize_def (sym, 0, current_symtab->space, spec.storage,
|
||||
current_symtab);
|
||||
if (sym->s.def)
|
||||
sym->s.def->nosave |= spec.nosave;
|
||||
}
|
||||
|
@ -1524,7 +1528,8 @@ init_var_decl
|
|||
specifier_t spec = $<spec>0;
|
||||
$1->type = find_type (append_type ($1->type, spec.type));
|
||||
$1->sy_type = sy_var;
|
||||
initialize_def ($1, 0, current_symtab->space, spec.storage);
|
||||
initialize_def ($1, 0, current_symtab->space, spec.storage,
|
||||
current_symtab);
|
||||
$$ = assign_expr (new_symbol_expr ($1), $2);
|
||||
}
|
||||
;
|
||||
|
|
|
@ -199,7 +199,8 @@ program_head
|
|||
{
|
||||
symbol_t *sym = new_symbol ("ExitCode");
|
||||
sym->type = &type_int;
|
||||
initialize_def (sym, 0, current_symtab->space, sc_global);
|
||||
initialize_def (sym, 0, current_symtab->space, sc_global,
|
||||
current_symtab);
|
||||
if (sym->s.def) {
|
||||
sym->s.def->nosave = 1;
|
||||
}
|
||||
|
@ -234,7 +235,8 @@ declarations
|
|||
while ($3) {
|
||||
symbol_t *next = $3->next;
|
||||
$3->type = $5;
|
||||
initialize_def ($3, 0, current_symtab->space, current_storage);
|
||||
initialize_def ($3, 0, current_symtab->space, current_storage,
|
||||
current_symtab);
|
||||
$3 = next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "tools/qfcc/include/options.h"
|
||||
#include "tools/qfcc/include/qfcc.h"
|
||||
#include "tools/qfcc/include/reloc.h"
|
||||
#include "tools/qfcc/include/shared.h"
|
||||
#include "tools/qfcc/include/switch.h"
|
||||
#include "tools/qfcc/include/symtab.h"
|
||||
#include "tools/qfcc/include/type.h"
|
||||
|
@ -348,7 +349,8 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
|
|||
table_sym = new_symbol_type (table_name,
|
||||
array_type (&type_int,
|
||||
high - low + 1));
|
||||
initialize_def (table_sym, table_init, pr.near_data, sc_static);
|
||||
initialize_def (table_sym, table_init, pr.near_data, sc_static,
|
||||
current_symtab);
|
||||
table_expr = new_symbol_expr (table_sym);
|
||||
|
||||
if (tree->left) {
|
||||
|
|
Loading…
Reference in a new issue