diff --git a/tools/qfcc/include/function.h b/tools/qfcc/include/function.h index 3ae7c845f..355edea37 100644 --- a/tools/qfcc/include/function.h +++ b/tools/qfcc/include/function.h @@ -137,12 +137,14 @@ struct expr_s *find_function (struct expr_s *fexpr, struct expr_s *params); function_t *new_function (const char *name, const char *nice_name); void add_function (function_t *f); function_t *begin_function (struct symbol_s *sym, const char *nicename, - struct symtab_s *parent, int far); + struct symtab_s *parent, int far, + enum storage_class_e storage); function_t *build_code_function (struct symbol_s *fsym, struct expr_s *state_expr, struct expr_s *statements); function_t *build_builtin_function (struct symbol_s *sym, - struct expr_s *bi_val, int far); + struct expr_s *bi_val, int far, + enum storage_class_e storage); void finish_function (function_t *f); void emit_function (function_t *f, struct expr_s *e); int function_parms (function_t *f, byte *parm_size); diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index b61be1d26..dfaf638c8 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -1507,7 +1507,6 @@ class_finish_module (void) symbol_t *exec_class_sym; symbol_t *init_sym; expr_t *init_expr; - storage_class_t save_storage; data.refs = emit_selectors (); if (class_hash) { @@ -1563,12 +1562,8 @@ class_finish_module (void) build_function_call (new_symbol_expr (exec_class_sym), exec_class_sym->type, module_expr)); - save_storage = current_storage; - current_storage = sc_static; - current_func = begin_function (init_sym, 0, current_symtab, 1); + current_func = begin_function (init_sym, 0, current_symtab, 1, sc_static); build_code_function (init_sym, 0, init_expr); - current_func = 0; - current_storage = save_storage; } protocol_t * diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 4e7ef61f3..e448990b2 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -584,7 +584,7 @@ add_function (function_t *f) function_t * begin_function (symbol_t *sym, const char *nicename, symtab_t *parent, - int far) + int far, storage_class_t storage) { defspace_t *space; @@ -601,7 +601,7 @@ begin_function (symbol_t *sym, const char *nicename, symtab_t *parent, space = sym->table->space; if (far) space = pr.far_data; - make_function (sym, nicename, space, current_storage); + make_function (sym, nicename, space, storage); if (!sym->s.func->def->external) { sym->s.func->def->initialized = 1; sym->s.func->def->constant = 1; @@ -651,7 +651,8 @@ build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements) } function_t * -build_builtin_function (symbol_t *sym, expr_t *bi_val, int far) +build_builtin_function (symbol_t *sym, expr_t *bi_val, int far, + storage_class_t storage) { int bi; defspace_t *space; @@ -671,7 +672,7 @@ build_builtin_function (symbol_t *sym, expr_t *bi_val, int far) space = sym->table->space; if (far) space = pr.far_data; - make_function (sym, 0, space, current_storage); + make_function (sym, 0, space, storage); if (sym->s.func->def->external) return 0; diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 32161c4b7..89a7a2405 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -423,7 +423,8 @@ function_body save_storage { $$ = current_symtab; - current_func = begin_function ($2, 0, current_symtab, 0); + current_func = begin_function ($2, 0, current_symtab, 0, + $-1.storage); current_symtab = current_func->symtab; current_storage = sc_local; } @@ -442,7 +443,7 @@ function_body $-1.type = type_default; sym->type = find_type (append_type (sym->type, $-1.type)); sym = function_symbol (sym, $-1.is_overload, 1); - build_builtin_function (sym, $3, 0); + build_builtin_function (sym, $3, 0, $-1.storage); } ; @@ -1095,7 +1096,7 @@ non_code_func if ($-1.storage == sc_extern) { error (0, "initializing external variable"); } - build_builtin_function ($0, $3, 0); + build_builtin_function ($0, $3, 0, $-1.storage); } | '=' expr { @@ -1135,7 +1136,8 @@ code_func save_storage { $$ = current_symtab; - current_func = begin_function ($0, 0, current_symtab, 0); + current_func = begin_function ($0, 0, current_symtab, 0, + $-1.storage); current_symtab = current_func->symtab; current_storage = sc_local; } @@ -1965,7 +1967,8 @@ methoddef $$ = current_symtab; ivar_scope = class_ivar_scope (current_class, current_symtab); - current_func = begin_function (sym, nicename, ivar_scope, 1); + current_func = begin_function (sym, nicename, ivar_scope, 1, + sc_static); class_finish_ivar_scope (current_class, ivar_scope, current_func->symtab); method->func = sym->s.func; @@ -1988,7 +1991,7 @@ methoddef method->instance = $1; method = class_find_method (current_class, method); sym = method_symbol (current_class, method); - build_builtin_function (sym, $5, 1); + build_builtin_function (sym, $5, 1, sc_static); method->func = sym->s.func; method->def = sym->s.func->def; } diff --git a/tools/qfcc/source/qp-parse.y b/tools/qfcc/source/qp-parse.y index 15159deb0..28f54bb87 100644 --- a/tools/qfcc/source/qp-parse.y +++ b/tools/qfcc/source/qp-parse.y @@ -154,7 +154,8 @@ build_dotmain (symbol_t *program) exitcode = new_symbol_expr (symtab_lookup (current_symtab, "ExitCode")); - current_func = begin_function (dotmain, 0, current_symtab, 0); + current_func = begin_function (dotmain, 0, current_symtab, 0, + current_storage); current_symtab = current_func->symtab; code = new_block_expr (); append_expr (code, function_expr (new_symbol_expr (program), 0)); @@ -177,7 +178,8 @@ program symtab_removesymbol (current_symtab, $1); symtab_addsymbol (current_symtab, $1); - current_func = begin_function ($1, 0, current_symtab, 0); + current_func = begin_function ($1, 0, current_symtab, 0, + current_storage); current_symtab = current_func->symtab; build_code_function ($1, 0, $4); current_symtab = st; @@ -261,7 +263,8 @@ subprogram_declaration : subprogram_head ';' { $$ = current_storage; - current_func = begin_function ($1, 0, current_symtab, 0); + current_func = begin_function ($1, 0, current_symtab, 0, + current_storage); current_symtab = current_func->symtab; current_storage = sc_local; } @@ -274,7 +277,7 @@ subprogram_declaration } | subprogram_head ASSIGNOP '#' VALUE ';' { - build_builtin_function ($1, $4, 0); + build_builtin_function ($1, $4, 0, current_storage); } ;