From 92eaa22c309d714d2dbb89f84098232ad0a3bb44 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:03:54 +0200 Subject: [PATCH] implement `iterateChildren` on asm --- src/ast.zig | 21 ++++++++++++++++----- tests/lsp_features/references.zig | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/ast.zig b/src/ast.zig index 588dbe5..faa9c2d 100644 --- a/src/ast.zig +++ b/src/ast.zig @@ -1176,6 +1176,8 @@ pub fn iterateChildren( ) Error!void { const node_tags = tree.nodes.items(.tag); const node_data = tree.nodes.items(.data); + const main_tokens = tree.nodes.items(.main_token); + const token_tags = tree.tokens.items(.tag); if (node > tree.nodes.len) return; @@ -1494,16 +1496,25 @@ pub fn iterateChildren( }, .@"asm" => { - const asm_ast = tree.asmFull(node).ast; - try callback(context, tree, asm_ast.template); - for (asm_ast.items) |child| { - try callback(context, tree, child); + const asm_node = tree.asmFull(node); + + try callback(context, tree, asm_node.ast.template); + + for (asm_node.outputs) |output_node| { + const has_arrow = token_tags[main_tokens[output_node] + 4] == .arrow; + if (has_arrow) { + try callback(context, tree, node_data[output_node].lhs); + } + } + + for (asm_node.inputs) |input_node| { + try callback(context, tree, node_data[input_node].lhs); } }, .asm_output, .asm_input, - => {}, // TODO + => unreachable, .@"continue", .anyframe_literal, diff --git a/tests/lsp_features/references.zig b/tests/lsp_features/references.zig index 774ee91..fd83e1d 100644 --- a/tests/lsp_features/references.zig +++ b/tests/lsp_features/references.zig @@ -120,6 +120,24 @@ test "references - label" { ); } +test "references - asm" { + try testReferences( + \\fn foo(<0>: u32) void { + \\ asm ("bogus" + \\ : [ret] "={rax}" (-> void), + \\ : [bar] "{rax}" (<0>), + \\ ); + \\} + ); + try testReferences( + \\fn foo(comptime <0>: type) void { + \\ asm ("bogus" + \\ : [ret] "={rax}" (-> <0>), + \\ ); + \\} + ); +} + test "references - cross-file reference" { if (true) return error.SkipZigTest; // TODO try testMFReferences(&.{