[qfcc] Move semantic processing into build_code_function

In the end, I could have done the null context check for pascal, but I
think the xvalue support will come in handy for implementing inline
functions.
This commit is contained in:
Bill Currie 2024-12-08 20:01:06 +09:00
parent 7379b1226d
commit 306306fc5a
5 changed files with 20 additions and 22 deletions

View file

@ -215,8 +215,8 @@ const expr_t *find_function (const expr_t *fexpr, const expr_t *params);
function_t *begin_function (symbol_t *sym, const char *nicename,
symtab_t *parent, int far,
enum storage_class_e storage);
function_t *build_code_function (symbol_t *fsym,
const expr_t *state_expr, expr_t *statements);
function_t *build_code_function (symbol_t *fsym, const expr_t *state_expr,
expr_t *statements, rua_ctx_t *ctx);
function_t *build_builtin_function (symbol_t *sym, const char *ext_name,
const expr_t *bi_val, int far,
enum storage_class_e storage);

View file

@ -1179,8 +1179,11 @@ build_function (symbol_t *fsym)
function_t *
build_code_function (symbol_t *fsym, const expr_t *state_expr,
expr_t *statements)
expr_t *statements, rua_ctx_t *ctx)
{
if (ctx) {
statements = (expr_t *) expr_process (statements, ctx);
}
if (fsym->sy_type != sy_func) // probably in error recovery
return 0;
build_function (fsym);
@ -1315,5 +1318,5 @@ emit_ctor (void)
auto ctor_sym = new_symbol_type (".ctor", &type_func);
ctor_sym = function_symbol ((specifier_t) { .sym = ctor_sym });
current_func = begin_function (ctor_sym, 0, current_symtab, 1, sc_static);
build_code_function (ctor_sym, 0, pr.ctor_exprs);
build_code_function (ctor_sym, 0, pr.ctor_exprs, nullptr);
}

View file

@ -344,8 +344,7 @@ function_definition
{
auto spec = $1;
auto sym = spec.sym;
expr_t *statments = (expr_t *) expr_process ($3, ctx);
build_code_function (sym, nullptr, statments);
build_code_function (sym, nullptr, (expr_t *) $3, ctx);
current_symtab = $<symtab>2;
current_storage = sc_global;//FIXME
current_func = nullptr;

View file

@ -873,8 +873,7 @@ qc_code_func
}
compound_statement_ns
{
auto statements = (expr_t *) expr_process ($6, ctx);
build_code_function ($1, $3, statements);
build_code_function ($1, $3, $6, ctx);
current_symtab = $<funcstate>5.symtab;
current_func = $<funcstate>5.function;
restore_storage ($4);
@ -1191,8 +1190,7 @@ function_body
}
compound_statement_ns
{
auto statements = (expr_t *) expr_process ($5, ctx);
build_code_function ($<symbol>2, $1, statements);
build_code_function ($<symbol>2, $1, $5, ctx);
current_symtab = $<funcstate>4.symtab;
current_func = $<funcstate>4.function;
restore_storage ($3);
@ -2634,8 +2632,7 @@ methoddef
}
compound_statement_ns
{
auto statements = (expr_t *) expr_process ($7, ctx);
build_code_function ($<symbol>4, $3, statements);
build_code_function ($<symbol>4, $3, $7, ctx);
current_symtab = $<funcstate>6.symtab;
current_func = $<funcstate>6.function;
restore_storage ($5);

View file

@ -148,7 +148,7 @@ int yylex (void);
%{
static void
build_dotmain (symbol_t *program)
build_dotmain (symbol_t *program, rua_ctx_t *ctx)
{
symbol_t *dotmain = new_symbol (".main");
expr_t *code;
@ -163,11 +163,12 @@ build_dotmain (symbol_t *program)
current_func = begin_function (dotmain, 0, current_symtab, 0,
current_storage);
current_symtab = current_func->locals;
code = new_block_expr (0);
append_expr (code, function_expr (new_symbol_expr (program), 0));
append_expr (code, return_expr (current_func, exitcode));
build_code_function (dotmain, 0, code);
code->block.scope = current_func->locals;
auto call = new_call_expr (new_symbol_expr (program), nullptr, nullptr);
append_expr (code, call);
append_expr (code, new_return_expr (exitcode));
build_code_function (dotmain, 0, code, ctx);
}
static const expr_t *
@ -283,11 +284,10 @@ program
current_func = begin_function ($1, 0, current_symtab, 0,
current_storage);
current_symtab = current_func->locals;
auto statements = (expr_t *) expr_process ($4, ctx);
build_code_function ($1, 0, statements);
build_code_function ($1, 0, $4, ctx);
current_symtab = st;
build_dotmain ($1);
build_dotmain ($1, ctx);
current_symtab = st;
}
;
@ -393,8 +393,7 @@ subprogram_declaration
}
auto ret_expr = new_return_expr (function_return (current_func));
append_expr (statements, ret_expr);
statements = (expr_t *) expr_process (statements, ctx);
build_code_function (fsym, 0, statements);
build_code_function (fsym, 0, statements, ctx);
current_symtab = current_func->parameters->parent;
current_storage = $<spec>3.storage;
}