From 625c53180fdf2609d046bf50ef8ed90fb10fa394 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 23 Dec 2024 22:02:00 +0900 Subject: [PATCH] [qfcc] Propagate rua_ctx_t to more functions It will eventually get to most places, but this set is necessary for using expr_process in expr_type.c --- tools/qfcc/include/class.h | 4 +- tools/qfcc/include/expr.h | 12 ++-- tools/qfcc/include/function.h | 9 +-- tools/qfcc/include/method.h | 6 +- tools/qfcc/include/symtab.h | 2 +- tools/qfcc/source/class.c | 4 +- tools/qfcc/source/expr.c | 8 +-- tools/qfcc/source/expr_obj.c | 4 +- tools/qfcc/source/expr_process.c | 6 +- tools/qfcc/source/expr_type.c | 99 ++++++++++++++-------------- tools/qfcc/source/function.c | 37 ++++++----- tools/qfcc/source/glsl-declaration.c | 4 +- tools/qfcc/source/glsl-parse.y | 4 +- tools/qfcc/source/method.c | 8 +-- tools/qfcc/source/qc-parse.y | 67 ++++++++----------- tools/qfcc/source/qfcc.c | 6 +- tools/qfcc/source/qp-parse.y | 20 +++--- tools/qfcc/source/rua-declaration.c | 4 +- tools/qfcc/source/symtab.c | 4 +- 19 files changed, 156 insertions(+), 152 deletions(-) diff --git a/tools/qfcc/include/class.h b/tools/qfcc/include/class.h index e1fc6b2a8..7203ea84a 100644 --- a/tools/qfcc/include/class.h +++ b/tools/qfcc/include/class.h @@ -116,6 +116,8 @@ struct method_s; struct symbol_s; struct selector_s; +typedef struct rua_ctx_s rua_ctx_t; + int is_id (const struct type_s *type) __attribute__((pure)); int is_class (const struct type_s *type) __attribute__((pure)); int is_Class (const struct type_s *type) __attribute__((const)); @@ -155,7 +157,7 @@ category_t *get_category (struct symbol_s *class_name, const char *category_name, int create); void category_add_methods (category_t *category, struct methodlist_s *methods); void category_add_protocols (category_t *category, protocollist_t *protocols); -void class_finish_module (void); +void class_finish_module (rua_ctx_t *ctx); struct symtab_s *class_to_struct (class_t *class, struct symtab_s *symtab); void emit_class_ref (const char *class_name); diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 4739655a1..ad7680499 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -1046,9 +1046,9 @@ expr_t *new_memset_expr (const expr_t *dst, const expr_t *val, expr_t *new_type_expr (const type_t *type); const expr_t *type_function (int op, const expr_t *params); symbol_t *type_parameter (symbol_t *sym, const expr_t *type); -const type_t *resolve_type (const expr_t *te); -const type_t **expand_type (const expr_t *te); -const expr_t *evaluate_type (const expr_t *te); +const type_t *resolve_type (const expr_t *te, rua_ctx_t *ctx); +const type_t **expand_type (const expr_t *te, rua_ctx_t *ctx); +const expr_t *evaluate_type (const expr_t *te, rua_ctx_t *ctx); expr_t *append_expr (expr_t *block, const expr_t *e); expr_t *prepend_expr (expr_t *block, const expr_t *e); @@ -1101,8 +1101,8 @@ const expr_t *build_for_statement (const expr_t *init, const expr_t *test, const expr_t *next, const expr_t *statement, const expr_t *break_label, const expr_t *continue_label); -const expr_t *build_state_expr (const expr_t *e); -const expr_t *think_expr (struct symbol_s *think_sym); +const expr_t *build_state_expr (const expr_t *e, rua_ctx_t *ctx); +const expr_t *think_expr (struct symbol_s *think_sym, rua_ctx_t *ctx); bool is_lvalue (const expr_t *expr) __attribute__((pure)); const expr_t *assign_expr (const expr_t *dst, const expr_t *src); const expr_t *cast_expr (const type_t *t, const expr_t *e); @@ -1117,7 +1117,7 @@ const expr_t *protocol_expr (const char *protocol); const expr_t *encode_expr (const type_t *type); const expr_t *super_expr (struct class_type_s *class_type); const expr_t *message_expr (const expr_t *receiver, - struct keywordarg_s *message); + struct keywordarg_s *message, rua_ctx_t *ctx); const expr_t *new_message_expr (const expr_t *receiver, struct keywordarg_s *message); const expr_t *sizeof_expr (const expr_t *expr, const type_t *type); diff --git a/tools/qfcc/include/function.h b/tools/qfcc/include/function.h index ccdcdae9e..f63640912 100644 --- a/tools/qfcc/include/function.h +++ b/tools/qfcc/include/function.h @@ -217,20 +217,21 @@ int value_too_large (const type_t *val_type) __attribute__((pure)); function_t *make_function (symbol_t *sym, const char *nice_name, struct defspace_s *space, enum storage_class_e storage); -symbol_t *function_symbol (specifier_t spec); +symbol_t *function_symbol (specifier_t spec, rua_ctx_t *ctx); const expr_t *find_function (const expr_t *fexpr, const expr_t *params); function_t *begin_function (specifier_t spec, const char *nicename, - symtab_t *parent); + symtab_t *parent, rua_ctx_t *ctx); void build_code_function (specifier_t spec, const expr_t *state_expr, expr_t *statements, rua_ctx_t *ctx); void build_builtin_function (specifier_t spec, const char *ext_name, const expr_t *bi_val); -void build_intrinsic_function (specifier_t spec, const expr_t *intrinsic); +void build_intrinsic_function (specifier_t spec, const expr_t *intrinsic, + rua_ctx_t *ctx); void emit_function (function_t *f, expr_t *e); void clear_functions (void); void add_ctor_expr (const expr_t *expr); -void emit_ctor (void); +void emit_ctor (rua_ctx_t *ctx); ///@} diff --git a/tools/qfcc/include/method.h b/tools/qfcc/include/method.h index becfa464a..563515b05 100644 --- a/tools/qfcc/include/method.h +++ b/tools/qfcc/include/method.h @@ -74,13 +74,15 @@ struct class_s; struct expr_s; struct dstring_s; +typedef struct rua_ctx_s rua_ctx_t; + method_t *new_method (const struct type_s *ret_type, param_t *selector, param_t *opt_parms); const char *method_name (method_t *method); method_t *copy_method (method_t *method); void add_method (methodlist_t *methodlist, method_t *method); struct symbol_s *method_symbol (struct class_type_s *class_type, - method_t *method); + method_t *method, rua_ctx_t *ctx); void method_set_param_names (method_t *dst, method_t *src); methodlist_t *new_methodlist (void); @@ -95,7 +97,7 @@ int method_compare (method_t *m1, method_t *m2); keywordarg_t *new_keywordarg (const char *selector, struct expr_s *expr); keywordarg_t *copy_keywordargs (const keywordarg_t *kwargs); -struct expr_s *send_message (int super); +struct expr_s *send_message (int super, rua_ctx_t *ctx); method_t *find_method (const char *sel_name); method_t *methodlist_find_method (methodlist_t *methodlist, diff --git a/tools/qfcc/include/symtab.h b/tools/qfcc/include/symtab.h index 921ad65db..9d009cfce 100644 --- a/tools/qfcc/include/symtab.h +++ b/tools/qfcc/include/symtab.h @@ -284,7 +284,7 @@ symbol_t *make_symbol (const char *name, const struct type_s *type, struct specifier_s; symbol_t *declare_symbol (struct specifier_s spec, const expr_t *init, - symtab_t *symtab, expr_t *block); + symtab_t *symtab, expr_t *block, rua_ctx_t *ctx); symbol_t *declare_field (struct specifier_s spec, symtab_t *symtab); ///@} diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index f5d22d461..40035edc3 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -1593,7 +1593,7 @@ emit_symtab_defs (def_t *def, void *data, int index) } void -class_finish_module (void) +class_finish_module (rua_ctx_t *ctx) { static struct_def_t symtab_struct[] = { {"sel_ref_cnt", &type_int, emit_symtab_ref_cnt}, @@ -1653,7 +1653,7 @@ class_finish_module (void) &type_exec_class); exec_class_sym = function_symbol ((specifier_t) { .sym = exec_class_sym - }); + }, ctx); make_function (exec_class_sym, 0, exec_class_sym->table->space, sc_extern); } diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index d7abd9681..cea7eab7e 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2793,7 +2793,7 @@ build_for_statement (const expr_t *init, const expr_t *test, const expr_t *next, } const expr_t * -build_state_expr (const expr_t *e) +build_state_expr (const expr_t *e, rua_ctx_t *ctx) { int count = e ? list_count (&e->list) : 0; if (count < 2) { @@ -2809,7 +2809,7 @@ build_state_expr (const expr_t *e) const expr_t *step = state_args[2]; if (think->type == ex_symbol) - think = think_expr (think->symbol); + think = think_expr (think->symbol, ctx); if (is_int_val (frame)) frame = cast_expr (&type_float, frame); if (!type_assignable (&type_float, get_type (frame))) @@ -2826,7 +2826,7 @@ build_state_expr (const expr_t *e) } const expr_t * -think_expr (symbol_t *think_sym) +think_expr (symbol_t *think_sym, rua_ctx_t *ctx) { symbol_t *sym; @@ -2841,7 +2841,7 @@ think_expr (symbol_t *think_sym) } else { think_sym->type = &type_func; } - think_sym = function_symbol ((specifier_t) { .sym = think_sym }); + think_sym = function_symbol ((specifier_t) { .sym = think_sym }, ctx); make_function (think_sym, 0, current_symtab->space, current_storage); return new_symbol_expr (think_sym); } diff --git a/tools/qfcc/source/expr_obj.c b/tools/qfcc/source/expr_obj.c index 43e8dd172..f50d13b8e 100644 --- a/tools/qfcc/source/expr_obj.c +++ b/tools/qfcc/source/expr_obj.c @@ -181,7 +181,7 @@ super_expr (class_type_t *class_type) } const expr_t * -message_expr (const expr_t *receiver, keywordarg_t *message) +message_expr (const expr_t *receiver, keywordarg_t *message, rua_ctx_t *ctx) { const expr_t *selector = selector_expr (message); const expr_t *call; @@ -243,7 +243,7 @@ message_expr (const expr_t *receiver, keywordarg_t *message) expr_append_expr (args, selector); expr_append_expr (args, receiver); - send_msg = send_message (super); + send_msg = send_message (super, ctx); if (method) { const expr_t *err; if ((err = method_check_params (method, args))) diff --git a/tools/qfcc/source/expr_process.c b/tools/qfcc/source/expr_process.c index fdd8152ba..b63d86146 100644 --- a/tools/qfcc/source/expr_process.c +++ b/tools/qfcc/source/expr_process.c @@ -55,7 +55,7 @@ proc_expr (const expr_t *expr, rua_ctx_t *ctx) { scoped_src_loc (expr); if (expr->expr.op == 'C') { - auto type = resolve_type (expr->expr.e1); + auto type = resolve_type (expr->expr.e1, ctx); expr = expr_process (expr->expr.e2, ctx); return cast_expr (type, expr); } @@ -420,7 +420,7 @@ proc_message (const expr_t *expr, rua_ctx_t *ctx) k->expr = (expr_t *) expr_process (k->expr, ctx); } } - return message_expr (receiver, message); + return message_expr (receiver, message, ctx); } static const expr_t * @@ -548,7 +548,7 @@ static const expr_t * proc_type (const expr_t *expr, rua_ctx_t *ctx) { scoped_src_loc (expr); - auto type = resolve_type (expr); + auto type = resolve_type (expr, ctx); return new_type_expr (type); } diff --git a/tools/qfcc/source/expr_type.c b/tools/qfcc/source/expr_type.c index 0f2156021..bbc12234e 100644 --- a/tools/qfcc/source/expr_type.c +++ b/tools/qfcc/source/expr_type.c @@ -59,9 +59,12 @@ typedef struct { typedef struct { const char *name; const char *(*check_params) (int arg_count, const expr_t **args); - const type_t *(*resolve) (int arg_count, const expr_t **args); - const type_t **(*expand) (int arg_count, const expr_t **args); - const expr_t *(*evaluate) (int arg_count, const expr_t **args); + const type_t *(*resolve) (int arg_count, const expr_t **args, + rua_ctx_t *ctx); + const type_t **(*expand) (int arg_count, const expr_t **args, + rua_ctx_t *ctx); + const expr_t *(*evaluate) (int arg_count, const expr_t **args, + rua_ctx_t *ctx); def_t *(*compute) (int arg_count, const expr_t **args, comp_ctx_t *ctx); } type_func_t; @@ -156,14 +159,14 @@ single_type_opt_int_pair (int arg_count, const expr_t **args) } static const expr_t * -evaluate_int (const expr_t *expr) +evaluate_int (const expr_t *expr, rua_ctx_t *ctx) { if (expr->type == ex_expr || expr->type == ex_uexpr) { auto e = new_expr (); *e = *expr; - e->expr.e1 = evaluate_int (expr->expr.e1); - if (expr->type == ex_uexpr) { - e->expr.e2 = evaluate_int (expr->expr.e2); + e->expr.e1 = evaluate_int (expr->expr.e1, ctx); + if (expr->type == ex_expr) { + e->expr.e2 = evaluate_int (expr->expr.e2, ctx); } return fold_constants (e); } @@ -189,16 +192,16 @@ evaluate_int (const expr_t *expr) } static const expr_t * -evaluate_int_op (int arg_count, const expr_t **args) +evaluate_int_op (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - return evaluate_int (args[0]); + return evaluate_int (args[0], ctx); } static const type_t * -resolve_function (int arg_count, const expr_t **args) +resolve_function (int arg_count, const expr_t **args, rua_ctx_t *ctx) { return &type_func;//FIXME - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = field_type (type); type = find_type (type); @@ -207,9 +210,9 @@ resolve_function (int arg_count, const expr_t **args) } static const type_t * -resolve_field (int arg_count, const expr_t **args) +resolve_field (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = field_type (type); type = find_type (type); @@ -218,9 +221,9 @@ resolve_field (int arg_count, const expr_t **args) } static const type_t * -resolve_pointer (int arg_count, const expr_t **args) +resolve_pointer (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = pointer_type (type); type = find_type (type); @@ -229,13 +232,13 @@ resolve_pointer (int arg_count, const expr_t **args) } static const type_t * -resolve_array (int arg_count, const expr_t **args) +resolve_array (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { int count = 0; if (arg_count > 1) { - auto count_expr = evaluate_int (args[1]); + auto count_expr = evaluate_int (args[1], ctx); if (is_error (count_expr)) { return nullptr; } @@ -247,9 +250,9 @@ resolve_array (int arg_count, const expr_t **args) } static const type_t * -resolve_base (int arg_count, const expr_t **args) +resolve_base (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = base_type (type); } @@ -257,13 +260,13 @@ resolve_base (int arg_count, const expr_t **args) } static const type_t * -resolve_vector (int arg_count, const expr_t **args) +resolve_vector (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { int width = 0; if (arg_count > 1) { - auto width_expr = evaluate_int (args[1]); + auto width_expr = evaluate_int (args[1], ctx); if (is_error (width_expr)) { return nullptr; } @@ -280,15 +283,15 @@ resolve_vector (int arg_count, const expr_t **args) } static const type_t * -resolve_matrix (int arg_count, const expr_t **args) +resolve_matrix (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { int rows = 0; int cols = 0; if (arg_count > 1) { - auto rows_expr = evaluate_int (args[2]); - auto cols_expr = evaluate_int (args[1]); + auto rows_expr = evaluate_int (args[2], ctx); + auto cols_expr = evaluate_int (args[1], ctx); if (is_error (rows_expr) || is_error (cols_expr)) { return nullptr; } @@ -307,9 +310,9 @@ resolve_matrix (int arg_count, const expr_t **args) } static const type_t * -resolve_int (int arg_count, const expr_t **args) +resolve_int (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = int_type (type); } @@ -317,9 +320,9 @@ resolve_int (int arg_count, const expr_t **args) } static const type_t * -resolve_uint (int arg_count, const expr_t **args) +resolve_uint (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = uint_type (type); } @@ -327,9 +330,9 @@ resolve_uint (int arg_count, const expr_t **args) } static const type_t * -resolve_bool (int arg_count, const expr_t **args) +resolve_bool (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = bool_type (type); } @@ -337,9 +340,9 @@ resolve_bool (int arg_count, const expr_t **args) } static const type_t * -resolve_float (int arg_count, const expr_t **args) +resolve_float (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - auto type = resolve_type (args[0]); + auto type = resolve_type (args[0], ctx); if (type) { type = float_type (type); } @@ -347,16 +350,16 @@ resolve_float (int arg_count, const expr_t **args) } static const type_t ** -expand_vector (int arg_count, const expr_t **args) +expand_vector (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - const type_t *base = resolve_type (args[0]); + const type_t *base = resolve_type (args[0], ctx); if (!is_bool (base) && !is_scalar (base)) { error (args[0], "invalid vector component type"); return nullptr; } if (arg_count == 2) { - auto comps_expr = evaluate_int (args[1]); + auto comps_expr = evaluate_int (args[1], ctx); if (is_error (comps_expr)) { return nullptr; } @@ -381,9 +384,9 @@ expand_vector (int arg_count, const expr_t **args) } static const type_t ** -expand_matrix (int arg_count, const expr_t **args) +expand_matrix (int arg_count, const expr_t **args, rua_ctx_t *ctx) { - const type_t *base = resolve_type (args[0]); + const type_t *base = resolve_type (args[0], ctx); if (!is_scalar (base)) { error (args[0], "invalid matrix component type"); return nullptr; @@ -391,8 +394,8 @@ expand_matrix (int arg_count, const expr_t **args) // @matrix doesn't include vectors for generic parameters if (arg_count == 3) { - auto rows_expr = evaluate_int (args[2]); - auto cols_expr = evaluate_int (args[1]); + auto rows_expr = evaluate_int (args[2], ctx); + auto cols_expr = evaluate_int (args[1], ctx); if (is_error (rows_expr) || is_error (cols_expr)) { return nullptr; } @@ -705,7 +708,7 @@ type_parameter (symbol_t *sym, const expr_t *type) } const type_t * -resolve_type (const expr_t *te) +resolve_type (const expr_t *te, rua_ctx_t *ctx) { if (te->type == ex_symbol) { auto sym = te->symbol; @@ -736,11 +739,11 @@ resolve_type (const expr_t *te) int arg_count = list_count (&te->typ.params->list); const expr_t *args[arg_count]; list_scatter (&te->typ.params->list, args); - return type_funcs[ind].resolve (arg_count, args); + return type_funcs[ind].resolve (arg_count, args, ctx); } const type_t ** -expand_type (const expr_t *te) +expand_type (const expr_t *te, rua_ctx_t *ctx) { if (te->type != ex_type) { internal_error (te, "not a type expression"); @@ -767,11 +770,11 @@ expand_type (const expr_t *te) int arg_count = list_count (&te->typ.params->list); const expr_t *args[arg_count]; list_scatter (&te->typ.params->list, args); - return type_funcs[ind].expand (arg_count, args); + return type_funcs[ind].expand (arg_count, args, ctx); } const expr_t * -evaluate_type (const expr_t *te) +evaluate_type (const expr_t *te, rua_ctx_t *ctx) { if (te->type != ex_type) { internal_error (te, "not a type expression"); @@ -785,7 +788,7 @@ evaluate_type (const expr_t *te) int arg_count = list_count (&te->typ.params->list); const expr_t *args[arg_count]; list_scatter (&te->typ.params->list, args); - return type_funcs[ind].evaluate (arg_count, args); + return type_funcs[ind].evaluate (arg_count, args, ctx); } static def_t * diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index b1a6391b6..8745d6a3f 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -206,10 +206,10 @@ add_generic_function (genfunc_t *genfunc) } static const type_t ** -valid_type_list (const expr_t *expr) +valid_type_list (const expr_t *expr, rua_ctx_t *ctx) { if (expr->type != ex_list) { - return expand_type (expr); + return expand_type (expr, ctx); } int count = list_count (&expr->list); const expr_t *type_refs[count]; @@ -218,7 +218,7 @@ valid_type_list (const expr_t *expr) types[count] = nullptr; bool err = false; for (int i = 0; i < count; i++) { - if (!(types[i] = resolve_type (type_refs[i]))) { + if (!(types[i] = resolve_type (type_refs[i], ctx))) { error (type_refs[i], "not a constant type ref"); err = true; } @@ -231,7 +231,7 @@ valid_type_list (const expr_t *expr) } static gentype_t -make_gentype (const expr_t *expr) +make_gentype (const expr_t *expr, rua_ctx_t *ctx) { if (expr->type != ex_symbol || expr->symbol->sy_type != sy_type_param) { internal_error (expr, "expected generic type name"); @@ -239,7 +239,7 @@ make_gentype (const expr_t *expr) auto sym = expr->symbol; gentype_t gentype = { .name = save_string (sym->name), - .valid_types = valid_type_list (sym->expr), + .valid_types = valid_type_list (sym->expr, ctx), }; if (!gentype.valid_types) { internal_error (expr, "empty generic type"); @@ -283,7 +283,7 @@ make_genparam (param_t *param, genfunc_t *genfunc) } static genfunc_t * -parse_generic_function (const char *name, specifier_t spec) +parse_generic_function (const char *name, specifier_t spec, rua_ctx_t *ctx) { if (!spec.is_generic) { return nullptr; @@ -345,7 +345,8 @@ parse_generic_function (const char *name, specifier_t spec) continue; } if (strcmp (q->type_expr->symbol->name, s->name) == 0) { - genfunc->types[num_gentype++] = make_gentype (q->type_expr); + genfunc->types[num_gentype++] = make_gentype (q->type_expr, + ctx); break; } } @@ -846,7 +847,7 @@ get_function (const char *name, specifier_t spec) } symbol_t * -function_symbol (specifier_t spec) +function_symbol (specifier_t spec, rua_ctx_t *ctx) { symbol_t *sym = spec.sym; const char *name = sym->name; @@ -863,7 +864,7 @@ function_symbol (specifier_t spec) return err; } - auto genfunc = parse_generic_function (name, spec); + auto genfunc = parse_generic_function (name, spec, ctx); if (genfunc) { add_generic_function (genfunc); @@ -1181,7 +1182,8 @@ add_function (function_t *f) } function_t * -begin_function (specifier_t spec, const char *nicename, symtab_t *parent) +begin_function (specifier_t spec, const char *nicename, symtab_t *parent, + rua_ctx_t *ctx) { auto sym = spec.sym; if (sym->sy_type != sy_func) { @@ -1190,7 +1192,7 @@ begin_function (specifier_t spec, const char *nicename, symtab_t *parent) sym = function_symbol ((specifier_t) { .sym = sym, .is_overload = true - }); + }, ctx); } function_t *func = sym->metafunc->func; if (func && func->def && func->def->initialized) { @@ -1199,7 +1201,7 @@ begin_function (specifier_t spec, const char *nicename, symtab_t *parent) sym = function_symbol ((specifier_t) { .sym = sym, .is_overload = true - }); + }, ctx); } if (spec.is_generic) { @@ -1342,9 +1344,10 @@ build_builtin_function (specifier_t spec, const char *ext_name, } void -build_intrinsic_function (specifier_t spec, const expr_t *intrinsic) +build_intrinsic_function (specifier_t spec, const expr_t *intrinsic, + rua_ctx_t *ctx) { - auto sym = function_symbol (spec); + auto sym = function_symbol (spec, ctx); if (sym->type->func.num_params < 0) { error (intrinsic, "intrinsic functions cannot be variadic"); return; @@ -1390,7 +1393,7 @@ add_ctor_expr (const expr_t *expr) } void -emit_ctor (void) +emit_ctor (rua_ctx_t *ctx) { if (!pr.ctor_exprs) { return; @@ -1401,7 +1404,7 @@ emit_ctor (void) .storage = sc_static, .is_far = true, }; - spec.sym = function_symbol (spec); - current_func = begin_function (spec, nullptr, current_symtab); + spec.sym = function_symbol (spec, ctx); + current_func = begin_function (spec, nullptr, current_symtab, ctx); build_code_function (spec, 0, pr.ctor_exprs, nullptr); } diff --git a/tools/qfcc/source/glsl-declaration.c b/tools/qfcc/source/glsl-declaration.c index 7cea704ca..c5a724a4f 100644 --- a/tools/qfcc/source/glsl-declaration.c +++ b/tools/qfcc/source/glsl-declaration.c @@ -59,7 +59,7 @@ glsl_parse_declaration (specifier_t spec, symbol_t *sym, const expr_t *init, internal_error (id_list, "not a symbol"); } spec.sym = id->expr->symbol; - spec.sym = declare_symbol (spec, init, symtab, block); + spec.sym = declare_symbol (spec, init, symtab, block, ctx); glsl_apply_attributes (attributes, spec); } } else { @@ -97,7 +97,7 @@ glsl_parse_declaration (specifier_t spec, symbol_t *sym, const expr_t *init, } symtab_addsymbol (symtab, sym); } else { - spec.sym = declare_symbol (spec, init, symtab, block); + spec.sym = declare_symbol (spec, init, symtab, block, ctx); } } glsl_apply_attributes (attributes, spec); diff --git a/tools/qfcc/source/glsl-parse.y b/tools/qfcc/source/glsl-parse.y index 3ca5f062d..fd936ed11 100644 --- a/tools/qfcc/source/glsl-parse.y +++ b/tools/qfcc/source/glsl-parse.y @@ -332,8 +332,8 @@ function_definition auto spec = $1; spec.sym->params = spec.params; spec.is_overload = true; - spec.sym = function_symbol (spec); - current_func = begin_function (spec, nullptr, current_symtab); + spec.sym = function_symbol (spec, ctx); + current_func = begin_function (spec, nullptr, current_symtab, ctx); current_symtab = current_func->locals; current_storage = sc_local; $1 = spec; diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index c27192b84..8fd2ab04e 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -165,7 +165,7 @@ add_method (methodlist_t *methodlist, method_t *method) } symbol_t * -method_symbol (class_type_t *class_type, method_t *method) +method_symbol (class_type_t *class_type, method_t *method, rua_ctx_t *ctx) { dstring_t *str = dstring_newstr (); symbol_t *sym; @@ -184,7 +184,7 @@ method_symbol (class_type_t *class_type, method_t *method) //printf ("%s %s %s %ld\n", method->name, method->types, str->str, // str->size); sym = new_symbol_type (str->str, method->type); - sym = function_symbol ((specifier_t) { .sym = sym }); + sym = function_symbol ((specifier_t) { .sym = sym }, ctx); sym->params = method->params; dstring_delete (str); return sym; @@ -355,7 +355,7 @@ copy_keywordargs (const keywordarg_t *kwargs) } expr_t * -send_message (int super) +send_message (int super, rua_ctx_t *ctx) { symbol_t *sym; const char *sm_name = "obj_msgSend"; @@ -370,7 +370,7 @@ send_message (int super) symtab_t *save = current_symtab; current_symtab = pr.symtab; sym = new_symbol_type (sm_name, sm_type); - sym = function_symbol ((specifier_t) { .sym = sym }); + sym = function_symbol ((specifier_t) { .sym = sym }, ctx); make_function (sym, 0, sym->table->space, sc_extern); current_symtab = save; } diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index f2c457c26..71df1fcb8 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -392,11 +392,11 @@ spec_merge (specifier_t spec, specifier_t new) } static const type_t * -resolve_type_spec (specifier_t spec) +resolve_type_spec (specifier_t spec, rua_ctx_t *ctx) { auto type = spec.type; if (spec.type_expr) { - type = resolve_type (spec.type_expr); + type = resolve_type (spec.type_expr, ctx); } return find_type (type); } @@ -755,18 +755,9 @@ fndef ; datadef - : defspecs notype_initdecls ';' - { - expr_process ($2, ctx); - } - | declspecs_nots notype_initdecls ';' - { - expr_process ($2, ctx); - } - | declspecs_ts initdecls ';' - { - expr_process ($2, ctx); - } + : defspecs notype_initdecls ';' { expr_process ($2, ctx); } + | declspecs_nots notype_initdecls ';' { expr_process ($2, ctx); } + | declspecs_ts initdecls ';' { expr_process ($2, ctx); } | declspecs_ts qc_func_params { $$ = qc_function_spec ($1, $2); @@ -872,25 +863,25 @@ qc_nocode_func const expr_t *bi_val = expr_process ($4, ctx); spec.is_overload |= ctx->language->always_overload; - spec.sym = function_symbol (spec); + spec.sym = function_symbol (spec, ctx); build_builtin_function (spec, nullptr, bi_val); } | identifier '=' intrinsic { specifier_t spec = qc_set_symbol ($0, $1); - build_intrinsic_function (spec, $3); + build_intrinsic_function (spec, $3, ctx); } | identifier '=' expr { specifier_t spec = qc_set_symbol ($0, $1); const expr_t *expr = $3; - declare_symbol (spec, expr, current_symtab, local_expr); + declare_symbol (spec, expr, current_symtab, local_expr, ctx); } | identifier { specifier_t spec = qc_set_symbol ($0, $1); - declare_symbol (spec, nullptr, current_symtab, local_expr); + declare_symbol (spec, nullptr, current_symtab, local_expr, ctx); } ; @@ -903,8 +894,8 @@ qc_code_func .function = current_func, }; spec.is_overload |= ctx->language->always_overload; - spec.sym = function_symbol (spec); - current_func = begin_function (spec, nullptr, current_symtab); + spec.sym = function_symbol (spec, ctx); + current_func = begin_function (spec, nullptr, current_symtab, ctx); current_symtab = current_func->locals; current_storage = sc_local; fs.spec = spec; @@ -1128,7 +1119,7 @@ typespec_reserved .type_expr = $1, }; } else { - auto type = resolve_type ($1); + auto type = resolve_type ($1, ctx); $$ = type_spec (type); } } @@ -1218,7 +1209,7 @@ function_body spec = default_type (spec, spec.sym); } spec.is_overload |= ctx->language->always_overload; - spec.sym = function_symbol (spec); + spec.sym = function_symbol (spec, ctx); $$ = spec; } save_storage[storage] @@ -1227,7 +1218,7 @@ function_body .function = current_func, }; auto spec = $2; - current_func = begin_function (spec, nullptr, current_symtab); + current_func = begin_function (spec, nullptr, current_symtab, ctx); current_symtab = current_func->locals; current_storage = sc_local; } @@ -1246,13 +1237,13 @@ function_body const expr_t *bi_val = expr_process ($3, ctx); spec.is_overload |= ctx->language->always_overload; - spec.sym = function_symbol (spec); + spec.sym = function_symbol (spec, ctx); build_builtin_function (spec, nullptr, bi_val); } | '=' intrinsic { specifier_t spec = $0; - build_intrinsic_function (spec, $2); + build_intrinsic_function (spec, $2, ctx); } ; @@ -1791,13 +1782,13 @@ var_initializer compound_init : opt_cast '{' element_list optional_comma '}' { - auto type = resolve_type_spec ($1); + auto type = resolve_type_spec ($1, ctx); $3->compound.type = type; $$ = $3; } | opt_cast '{' '}' { - auto type = resolve_type_spec ($1); + auto type = resolve_type_spec ($1, ctx); if (type) { auto elements = new_compound_init (); elements->compound.type = type; @@ -1815,12 +1806,12 @@ opt_cast method_optional_state_expr : /* emtpy */ { $$ = 0; } - | SHR vector_expr { $$ = build_state_expr ($2); } + | SHR vector_expr { $$ = build_state_expr ($2, ctx); } ; optional_state_expr : /* emtpy */ { $$ = 0; } - | vector_expr { $$ = build_state_expr ($1); } + | vector_expr { $$ = build_state_expr ($1, ctx); } ; element_list @@ -2665,7 +2656,7 @@ methoddef method->instance = $1; $2 = method = class_find_method (current_class, method); - $$ = method_symbol (current_class, method); + $$ = method_symbol (current_class, method, ctx); } save_storage { @@ -2685,7 +2676,7 @@ methoddef .symtab = ivar_scope, .function = current_func, }; - current_func = begin_function (spec, nicename, ivar_scope); + current_func = begin_function (spec, nicename, ivar_scope, ctx); class_finish_ivar_scope (current_class, ivar_scope, current_func->locals); method->func = sym->metafunc->func; @@ -2712,7 +2703,7 @@ methoddef method = class_find_method (current_class, method); auto spec = (specifier_t) { - .sym = method_symbol (current_class, method), + .sym = method_symbol (current_class, method, ctx), .storage = sc_static, .is_far = true, }; @@ -2758,14 +2749,14 @@ methodproto methoddecl : '(' typename ')' unaryselector { - auto type = resolve_type_spec ($2); + auto type = resolve_type_spec ($2, ctx); $$ = new_method (type, $4, 0); } | unaryselector { $$ = new_method (&type_id, $1, 0); } | '(' typename ')' keywordselector optional_param_list { - auto type = resolve_type_spec ($2); + auto type = resolve_type_spec ($2, ctx); $$ = new_method (type, $4, $5); } | keywordselector optional_param_list @@ -2821,14 +2812,14 @@ reserved_word keyworddecl : selector ':' '(' typename ')' identifier { - auto type = resolve_type_spec ($4); + auto type = resolve_type_spec ($4, ctx); $$ = make_selector ($1->name, type, $6->name); } | selector ':' identifier { $$ = make_selector ($1->name, &type_id, $3->name); } | ':' '(' typename ')' identifier { - auto type = resolve_type_spec ($3); + auto type = resolve_type_spec ($3, ctx); $$ = make_selector ("", type, $5->name); } | ':' identifier @@ -2841,7 +2832,7 @@ obj_expr | PROTOCOL '(' identifier ')' { $$ = protocol_expr ($3->name); } | ENCODE '(' typename ')' { - auto type = resolve_type_spec ($3); + auto type = resolve_type_spec ($3, ctx); $$ = encode_expr (type); } | obj_string /* FIXME string object? */ @@ -3257,7 +3248,7 @@ static int qc_finish (const char *file, rua_ctx_t *ctx) if (options.frames_files) { write_frame_macros (va (0, "%s.frame", file_basename (file, 0))); } - class_finish_module (); + class_finish_module (ctx); return pr.error_count; } diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index ee7e96f2a..31f631f52 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -408,7 +408,7 @@ compile_to_obj (const char *file, const char *obj, rua_ctx_t *ctx) err = lang->finish (file, ctx); } if (!err) { - emit_ctor (); + emit_ctor (ctx); debug_finish_module (obj); } err = pr.error_count; @@ -842,8 +842,8 @@ progs_src_compile (void) return 1; } - class_finish_module (); - emit_ctor (); + class_finish_module (&ctx); + emit_ctor (&ctx); debug_finish_module (options.output_file); qfo = qfo_from_progs (&pr); if (options.compile) { diff --git a/tools/qfcc/source/qp-parse.y b/tools/qfcc/source/qp-parse.y index a988b2902..1f3629cd9 100644 --- a/tools/qfcc/source/qp-parse.y +++ b/tools/qfcc/source/qp-parse.y @@ -157,7 +157,7 @@ build_dotmain (symbol_t *program, rua_ctx_t *ctx) dotmain->params = 0; dotmain->type = parse_params (&type_int, 0); dotmain->type = find_type (dotmain->type); - dotmain = function_symbol ((specifier_t) { .sym = dotmain }); + dotmain = function_symbol ((specifier_t) { .sym = dotmain }, ctx); exitcode = new_symbol_expr (symtab_lookup (current_symtab, "ExitCode")); @@ -165,7 +165,7 @@ build_dotmain (symbol_t *program, rua_ctx_t *ctx) .sym = dotmain, .storage = current_storage, }; - current_func = begin_function (spec, nullptr, current_symtab); + current_func = begin_function (spec, nullptr, current_symtab, ctx); code = new_block_expr (0); code->block.scope = current_func->locals; auto call = new_call_expr (new_symbol_expr (program), nullptr, nullptr); @@ -204,7 +204,8 @@ rvalue_expr (const expr_t *expr) } static symbol_t * -function_decl (symbol_t *sym, param_t *params, const type_t *ret_type) +function_decl (symbol_t *sym, param_t *params, const type_t *ret_type, + rua_ctx_t *ctx) { if (sym->table == current_symtab) { error (0, "%s redefined", sym->name); @@ -216,7 +217,7 @@ function_decl (symbol_t *sym, param_t *params, const type_t *ret_type) fsym->params = params; fsym->type = parse_params (ret_type, params); fsym->type = find_type (fsym->type); - fsym = function_symbol ((specifier_t) { .sym = fsym, }); + fsym = function_symbol ((specifier_t) { .sym = fsym, }, ctx); auto fsym_expr = new_symbol_expr (fsym); if (!params) { fsym_expr = new_call_expr (fsym_expr, nullptr, nullptr); @@ -288,7 +289,7 @@ program .sym = $1, .storage = current_storage, }; - current_func = begin_function (spec, nullptr, current_symtab); + current_func = begin_function (spec, nullptr, current_symtab, ctx); current_symtab = current_func->locals; build_code_function (spec, 0, $4, ctx); current_symtab = st; @@ -316,7 +317,7 @@ program_head } $$->type = parse_params (&type_void, 0); $$->type = find_type ($$->type); - $$ = function_symbol ((specifier_t) { .sym = $$ }); + $$ = function_symbol ((specifier_t) { .sym = $$ }, ctx); } ; @@ -382,7 +383,8 @@ subprogram_declaration .sym = fsym, .storage = current_storage, }; - current_func = begin_function (spec, sym->name, current_symtab); + current_func = begin_function (spec, sym->name, current_symtab, + ctx); current_symtab = current_func->locals; current_storage = sc_local; // null for procedures, valid symbol expression for functions @@ -419,11 +421,11 @@ subprogram_declaration subprogram_head : FUNCTION ID arguments ':' standard_type { - $$ = function_decl ($2, $3, $5); + $$ = function_decl ($2, $3, $5, ctx); } | PROCEDURE ID arguments { - $$ = function_decl ($2, $3, &type_void); + $$ = function_decl ($2, $3, &type_void, ctx); } ; diff --git a/tools/qfcc/source/rua-declaration.c b/tools/qfcc/source/rua-declaration.c index 65ddd8e20..a1ab64cc0 100644 --- a/tools/qfcc/source/rua-declaration.c +++ b/tools/qfcc/source/rua-declaration.c @@ -55,7 +55,7 @@ rua_parse_declaration (specifier_t spec, symbol_t *sym, const expr_t *init, internal_error (id_list, "not a symbol"); } spec.sym = id->expr->symbol; - spec.sym = declare_symbol (spec, init, symtab, block); + spec.sym = declare_symbol (spec, init, symtab, block, ctx); } } else { spec.sym = sym; @@ -92,7 +92,7 @@ rua_parse_declaration (specifier_t spec, symbol_t *sym, const expr_t *init, } symtab_addsymbol (symtab, sym); } else { - spec.sym = declare_symbol (spec, init, symtab, block); + spec.sym = declare_symbol (spec, init, symtab, block, ctx); } } } diff --git a/tools/qfcc/source/symtab.c b/tools/qfcc/source/symtab.c index ba93224fe..b9ebb5047 100644 --- a/tools/qfcc/source/symtab.c +++ b/tools/qfcc/source/symtab.c @@ -279,7 +279,7 @@ shadows_param (symbol_t *sym, symtab_t *symtab) symbol_t * declare_symbol (specifier_t spec, const expr_t *init, symtab_t *symtab, - expr_t *block) + expr_t *block, rua_ctx_t *ctx) { symbol_t *sym = spec.sym; @@ -315,7 +315,7 @@ declare_symbol (specifier_t spec, const expr_t *init, symtab_t *symtab, if (init) { error (0, "function %s is initialized", sym->name); } - sym = function_symbol (spec); + sym = function_symbol (spec, ctx); } else { if (!shadows_param (sym, symtab)) { sym->type = find_type (sym->type);