Skip to content

Commit

Permalink
Zcu: allow node_offset_var_decl_* source location for function decl…
Browse files Browse the repository at this point in the history
…arations
  • Loading branch information
mlugg committed Dec 19, 2024
1 parent eac87ea commit 58b8b1a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Zcu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -836,20 +836,38 @@ pub const SrcLoc = struct {
.node_offset_var_decl_align => |node_off| {
const tree = try src_loc.file_scope.getTree(gpa);
const node = src_loc.relativeToNodeIndex(node_off);
const full = tree.fullVarDecl(node).?;
return tree.nodeToSpan(full.ast.align_node);
var buf: [1]Ast.Node.Index = undefined;
const align_node = if (tree.fullVarDecl(node)) |v|
v.ast.align_node
else if (tree.fullFnProto(&buf, node)) |f|
f.ast.align_expr
else
unreachable;
return tree.nodeToSpan(align_node);
},
.node_offset_var_decl_section => |node_off| {
const tree = try src_loc.file_scope.getTree(gpa);
const node = src_loc.relativeToNodeIndex(node_off);
const full = tree.fullVarDecl(node).?;
return tree.nodeToSpan(full.ast.section_node);
var buf: [1]Ast.Node.Index = undefined;
const section_node = if (tree.fullVarDecl(node)) |v|
v.ast.section_node
else if (tree.fullFnProto(&buf, node)) |f|
f.ast.section_expr
else
unreachable;
return tree.nodeToSpan(section_node);
},
.node_offset_var_decl_addrspace => |node_off| {
const tree = try src_loc.file_scope.getTree(gpa);
const node = src_loc.relativeToNodeIndex(node_off);
const full = tree.fullVarDecl(node).?;
return tree.nodeToSpan(full.ast.addrspace_node);
var buf: [1]Ast.Node.Index = undefined;
const addrspace_node = if (tree.fullVarDecl(node)) |v|
v.ast.addrspace_node
else if (tree.fullFnProto(&buf, node)) |f|
f.ast.addrspace_expr
else
unreachable;
return tree.nodeToSpan(addrspace_node);
},
.node_offset_var_decl_init => |node_off| {
const tree = try src_loc.file_scope.getTree(gpa);
Expand Down

0 comments on commit 58b8b1a

Please sign in to comment.