From 86cf9383ea5a15cbc3b41f4e3b5a3ee160a04f64 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 27 May 2018 13:49:55 +0100 Subject: Fix delayed assert collection --- src/checker.cpp | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 51689d027..4d1b2c46a 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -215,7 +215,7 @@ bool decl_info_has_init(DeclInfo *d) { Scope *create_scope(Scope *parent, gbAllocator allocator) { Scope *s = gb_alloc_item(allocator, Scope); s->parent = parent; - map_init(&s->elements, heap_allocator()); + map_init(&s->elements, heap_allocator()); ptr_set_init(&s->implicit, heap_allocator()); ptr_set_init(&s->imported, heap_allocator()); ptr_set_init(&s->exported, heap_allocator()); @@ -2119,6 +2119,16 @@ void check_collect_entities(Checker *c, Array nodes) { for_array(decl_index, nodes) { AstNode *decl = nodes[decl_index]; if (!is_ast_node_decl(decl) && !is_ast_node_when_stmt(decl)) { + + if (c->context.scope->is_file && decl->kind == AstNode_ExprStmt) { + AstNode *expr = decl->ExprStmt.expr; + if (expr->kind == AstNode_CallExpr && + expr->CallExpr.proc->kind == AstNode_BasicDirective && + expr->CallExpr.proc->BasicDirective.name == "assert") { + array_add(&c->context.scope->delayed_asserts, expr); + continue; + } + } continue; } @@ -2158,18 +2168,6 @@ void check_collect_entities(Checker *c, Array nodes) { check_add_foreign_block_decl(c, decl); case_end; - - case_ast_node(ce, CallExpr, decl); - if (c->context.scope->is_file && - ce->proc->kind == AstNode_BasicDirective && - ce->proc->BasicDirective.name == "assert") { - array_add(&c->context.scope->delayed_asserts, decl); - } else { - goto error_case; - } - case_end; - - error_case: default: if (c->context.scope->is_file) { error(decl, "Only declarations are allowed at file scope"); @@ -2709,17 +2707,6 @@ void check_import_entities(Checker *c) { GB_ASSERT(node->scope->is_package); AstPackage *p = node->scope->package; - - - for_array(i, p->files.entries) { - AstFile *f = p->files.entries[i].value; - - CheckerContext prev_context = c->context; - defer (c->context = prev_context); - add_curr_ast_file(c, f); - check_collect_entities(c, f->decls); - } - for_array(i, p->files.entries) { AstFile *f = p->files.entries[i].value; CheckerContext prev_context = c->context; -- cgit v1.2.3