From a0f09b13cf437bd4ac3c4054756fc44f340292c5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 11 Dec 2024 16:05:50 +0900 Subject: [PATCH] [qfcc] Set current function for inlined functions It improves error reporting and is even a solution for what to do with return statements in inline functions. --- tools/qfcc/include/expr.h | 2 ++ tools/qfcc/source/expr_call.c | 1 + tools/qfcc/source/expr_process.c | 5 +++++ tools/qfcc/source/function.c | 1 + 4 files changed, 9 insertions(+) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 313eb96fb..4739655a1 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -38,6 +38,7 @@ typedef struct type_s type_t; typedef struct expr_s expr_t; typedef struct algebra_s algebra_t; +typedef struct function_s function_t; /** \defgroup qfcc_expr Expressions \ingroup qfcc @@ -404,6 +405,7 @@ typedef struct { typedef struct { const expr_t *expr; + function_t *function; ///< for better reporting in inline functions } ex_process_t; typedef struct expr_s { diff --git a/tools/qfcc/source/expr_call.c b/tools/qfcc/source/expr_call.c index 5edec8c9e..090f9fb2b 100644 --- a/tools/qfcc/source/expr_call.c +++ b/tools/qfcc/source/expr_call.c @@ -279,6 +279,7 @@ build_inline_call (symbol_t *fsym, const type_t *ftype, append_expr (call, expr); auto proc = new_process_expr (call); + proc->process.function = func; return proc; } diff --git a/tools/qfcc/source/expr_process.c b/tools/qfcc/source/expr_process.c index 70b82f2e1..829d27c97 100644 --- a/tools/qfcc/source/expr_process.c +++ b/tools/qfcc/source/expr_process.c @@ -717,7 +717,12 @@ expr_process (const expr_t *expr, rua_ctx_t *ctx) auto proc = funcs[expr->type] (expr, ctx); if (proc && proc->type == ex_process) { + auto func = current_func; + if (proc->process.function) { + current_func = proc->process.function; + } proc = expr_process (proc->process.expr, ctx); + current_func = func; } return proc; } diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 25716a456..5fd9c641f 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -982,6 +982,7 @@ find_function (const expr_t *fexpr, const expr_t *params) // the call will be inlined, so a new scope is needed every // time sym->metafunc->func = new_function (sym->name, gen->name); + sym->metafunc->func->type = sym->type; build_generic_scope (sym, current_symtab, gen, ref_types); } return new_symbol_expr (sym);