[qfcc] Defer return expressions

This commit is contained in:
Bill Currie 2024-10-08 11:46:52 +09:00
parent c3f11ba754
commit 9cd480640d
2 changed files with 18 additions and 2 deletions

View file

@ -210,6 +210,21 @@ proc_branch (const expr_t *expr)
}
}
static const expr_t *
proc_return (const expr_t *expr)
{
scoped_src_loc (expr);
auto ret_val = expr->retrn.ret_val;
if (ret_val) {
ret_val = expr_process (ret_val);
}
if (expr->retrn.at_return) {
return at_return_expr (current_func, ret_val);
} else {
return return_expr (current_func, ret_val);
}
}
static const expr_t *
proc_decl (const expr_t *expr)
{
@ -263,6 +278,7 @@ expr_process (const expr_t *expr)
[ex_compound] = proc_compound,
[ex_assign] = proc_assign,
[ex_branch] = proc_branch,
[ex_return] = proc_return,
[ex_decl] = proc_decl,
};

View file

@ -1275,8 +1275,8 @@ jump_statement
error (nullptr, "continue outside of loop or switch");
}
}
| RETURN ';' { $$ = return_expr (current_func, nullptr); }
| RETURN expression ';' { $$ = return_expr (current_func, $2); }
| RETURN ';' { $$ = new_return_expr (nullptr); }
| RETURN expression ';' { $$ = new_return_expr ($2); }
| DISCARD ';' { $$ = nullptr; } //XXX
;