aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-07-20 00:02:20 +0300
committerAndrew Kelley <andrew@ziglang.org>2022-07-21 12:21:30 -0700
commit821e4063f9f32f71cce263265fdbacc632bd5af9 (patch)
tree7c4b2683520ab47a6a4a4e5cb7340554dade7913 /src/Module.zig
parent79ef0cdf306c48d3cc447ce14530db4021f8c5de (diff)
downloadzig-821e4063f9f32f71cce263265fdbacc632bd5af9.tar.gz
zig-821e4063f9f32f71cce263265fdbacc632bd5af9.zip
Sema: better source location for function call args
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index a1081517c0..5f441790b7 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -5911,6 +5911,31 @@ pub fn paramSrc(
}
}
+pub fn argSrc(
+ call_node_offset: i32,
+ gpa: Allocator,
+ decl: *Decl,
+ arg_i: usize,
+) LazySrcLoc {
+ @setCold(true);
+ const tree = decl.getFileScope().getTree(gpa) catch |err| {
+ // In this case we emit a warning + a less precise source location.
+ log.warn("unable to load {s}: {s}", .{
+ decl.getFileScope().sub_file_path, @errorName(err),
+ });
+ return LazySrcLoc.nodeOffset(0);
+ };
+ const node_tags = tree.nodes.items(.tag);
+ const node = decl.relativeToNodeIndex(call_node_offset);
+ var args: [1]Ast.Node.Index = undefined;
+ const full = switch (node_tags[node]) {
+ .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(&args, node),
+ .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node),
+ else => unreachable,
+ };
+ return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full.ast.params[arg_i]));
+}
+
/// Called from `performAllTheWork`, after all AstGen workers have finished,
/// and before the main semantic analysis loop begins.
pub fn processOutdatedAndDeletedDecls(mod: *Module) !void {