implement iterateChildren on asm

This commit is contained in:
Techatrix 2023-04-17 23:03:54 +02:00
parent 5457cec8da
commit 92eaa22c30
2 changed files with 34 additions and 5 deletions

View File

@ -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,

View File

@ -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(&.{