From 5e6832294ead73474d592c1d2c51353a55786e05 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 20 Aug 2024 15:19:31 +0900 Subject: [PATCH] [qfcc] Handle parsing generic builtin functions Generic qc-style prototypes don't work but both c and qc style definitions get as far as trying to build the builtin function. It starting to look like I need to rework function handling, which isn't all that surprising as it hasn't changed much over 22 years. --- tools/qfcc/source/qc-parse.y | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index 16bcae647..076d82b04 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -508,10 +508,15 @@ make_selector (const char *selector, const type_t *type, const char *name) static param_t * make_qc_param (specifier_t spec, symbol_t *sym) { - spec = default_type (spec, sym); - sym->type = spec.type; - param_t *param = new_param (0, sym->type, sym->name); - return param; + if (spec.type_expr) { + auto param = new_generic_param (spec.type_expr, spec.sym->name); + return param; + } else { + spec = default_type (spec, spec.sym); + sym->type = spec.type; + auto param = new_param (0, spec.type, sym->name); + return param; + } } static param_t * @@ -744,7 +749,10 @@ qc_nocode_func symbol_t *sym = $1; const expr_t *expr = $4; sym->params = spec.sym->params; - sym = function_sym_type (spec, sym); + + if (!spec.is_generic) { + sym = function_sym_type (spec, sym); + } sym = function_symbol (sym, spec); build_builtin_function (sym, expr, 0, spec.storage); } @@ -1120,10 +1128,16 @@ function_body } | '=' '#' expr ';' { - specifier_t spec = default_type ($0, $0.sym); - symbol_t *sym = function_sym_type (spec, spec.sym); + specifier_t spec = $0; + symbol_t *sym = spec.sym; + const expr_t *expr = $3; + + if (!spec.is_generic) { + spec = default_type (spec, spec.sym); + sym = function_sym_type (spec, sym); + } sym = function_symbol (sym, spec); - build_builtin_function (sym, $3, 0, spec.storage); + build_builtin_function (sym, expr, 0, spec.storage); } ; @@ -2481,11 +2495,12 @@ methoddef { symbol_t *sym; method_t *method = $2; + const expr_t *expr = $5; method->instance = $1; method = class_find_method (current_class, method); sym = method_symbol (current_class, method); - build_builtin_function (sym, $5, 1, sc_static); + build_builtin_function (sym, expr, 1, sc_static); method->func = sym->func; method->def = sym->func->def; }