Add defer catch/try. Fix missing defer invoked on return a > 0 ? Foo.ABC! : 1

This commit is contained in:
Christoffer Lerno
2023-02-21 20:10:03 +01:00
parent b5a2b5c68a
commit 8f5676b488
12 changed files with 247 additions and 33 deletions

View File

@@ -60,13 +60,18 @@ void context_change_scope_for_label(SemaContext *context, Decl *label)
}
}
AstId context_get_defers(SemaContext *context, AstId defer_top, AstId defer_bottom)
AstId context_get_defers(SemaContext *context, AstId defer_top, AstId defer_bottom, bool is_success)
{
AstId first = 0;
AstId *next = &first;
while (defer_bottom != defer_top)
{
Ast *defer = astptr(defer_top);
if ((is_success && defer->defer_stmt.is_catch) || (!is_success && defer->defer_stmt.is_try))
{
defer_top = defer->defer_stmt.prev_defer;
continue;
}
Ast *defer_body = copy_ast_defer(astptr(defer->defer_stmt.body));
*next = astid(defer_body);
next = &defer_body->next;
@@ -84,9 +89,12 @@ void context_pop_defers(SemaContext *context, AstId *next)
while (defer_current != defer_start)
{
Ast *defer = astptr(defer_current);
Ast *defer_body = copy_ast_defer(astptr(defer->defer_stmt.body));
*next = astid(defer_body);
next = &defer_body->next;
if (!defer->defer_stmt.is_catch)
{
Ast *defer_body = copy_ast_defer(astptr(defer->defer_stmt.body));
*next = astid(defer_body);
next = &defer_body->next;
}
defer_current = defer->defer_stmt.prev_defer;
}
}