From ea02e4364feb7ea919a5884dab0bbc1445afeb64 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sun, 12 Mar 2023 23:49:21 +0100 Subject: [PATCH] remove `had_root` global --- src/analysis.zig | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 6200a53..030693d 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -2418,9 +2418,7 @@ pub fn makeDocumentScope(allocator: std.mem.Allocator, tree: Ast) !DocumentScope }; errdefer document_scope.deinit(allocator); - // pass root node index ('0') - had_root = false; - try makeScopeInternal(allocator, .{ + try makeInnerScope(allocator, .{ .scopes = &document_scope.scopes, .errors = &document_scope.error_completions, .enums = &document_scope.enum_completions, @@ -2490,9 +2488,9 @@ fn makeInnerScope(allocator: std.mem.Allocator, context: ScopeContext, node_idx: } } -// Whether we have already visited the root node. -var had_root = true; fn makeScopeInternal(allocator: std.mem.Allocator, context: ScopeContext, node_idx: Ast.Node.Index) error{OutOfMemory}!void { + if (node_idx == 0) return; + const scopes = context.scopes; const tree = context.tree; const tags = tree.nodes.items(.tag); @@ -2501,14 +2499,8 @@ fn makeScopeInternal(allocator: std.mem.Allocator, context: ScopeContext, node_i const main_tokens = tree.nodes.items(.main_token); const node_tag = tags[node_idx]; - if (node_idx == 0) { - if (had_root) - return - else - had_root = true; - } - switch (node_tag) { + .root => unreachable, .container_decl, .container_decl_trailing, .container_decl_arg, @@ -2521,7 +2513,6 @@ fn makeScopeInternal(allocator: std.mem.Allocator, context: ScopeContext, node_i .tagged_union_two_trailing, .tagged_union_enum_tag, .tagged_union_enum_tag_trailing, - .root, => { try makeInnerScope(allocator, context, node_idx); },