From 0dd32cca3b8ad7e2a34ec815996e68e2f81c1da1 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 25 Feb 2026 22:54:10 +0200 Subject: filter out empty nodes from statement list + Fixes tail call analysis that was accidentally broken by 64146b46da45ce69ab380add00459f7b60fe9196 + Kind of wasteful to first allocate empty node and then just throw it away, but I don't have any better ideas at the moment --- src/ast.c | 13 +++++++++++++ src/parser.y | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ast.c b/src/ast.c index a39cb94..d7d97e0 100644 --- a/src/ast.c +++ b/src/ast.c @@ -567,6 +567,19 @@ struct type *reverse_type_list(struct type *root) return new_root; } +struct ast *filter_empty(struct ast *root) +{ + struct ast *ret = root; + while (root) { + if (root->n && root->n->k == AST_EMPTY) + root->n = root->n->n; + + root = root->n; + } + + return ret; +} + void fix_closures(struct ast *root) { while (root) { diff --git a/src/parser.y b/src/parser.y index dad3210..6210a95 100644 --- a/src/parser.y +++ b/src/parser.y @@ -454,7 +454,10 @@ rev_statements | statement statements - : rev_statements { $$ = reverse_ast_list($1); fix_closures($$); } + : rev_statements { + $$ = filter_empty(reverse_ast_list($1)); + fix_closures($$); + } opt_statements : statements -- cgit v1.2.3