From c95a34b68f6075d7a9d305d17a6b03bc9fd1fff2 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 18 Oct 2022 13:45:06 +0300 Subject: stage2: improve source location of assignment --- src/Module.zig | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 396e92ed79..cdcf551847 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2878,6 +2878,32 @@ pub const SrcLoc = struct { }; return nodeToSpan(tree, full.ast.type_expr); }, + .node_offset_store_ptr => |node_off| { + const tree = try src_loc.file_scope.getTree(gpa); + const node_tags = tree.nodes.items(.tag); + const node_datas = tree.nodes.items(.data); + const node = src_loc.declRelativeToNodeIndex(node_off); + + switch (node_tags[node]) { + .assign => { + return nodeToSpan(tree, node_datas[node].lhs); + }, + else => return nodeToSpan(tree, node), + } + }, + .node_offset_store_operand => |node_off| { + const tree = try src_loc.file_scope.getTree(gpa); + const node_tags = tree.nodes.items(.tag); + const node_datas = tree.nodes.items(.data); + const node = src_loc.declRelativeToNodeIndex(node_off); + + switch (node_tags[node]) { + .assign => { + return nodeToSpan(tree, node_datas[node].rhs); + }, + else => return nodeToSpan(tree, node), + } + }, } } @@ -3213,6 +3239,12 @@ pub const LazySrcLoc = union(enum) { /// The source location points to the type of an array or struct initializer. /// The Decl is determined contextually. node_offset_init_ty: i32, + /// The source location points to the LHS of an assignment. + /// The Decl is determined contextually. + node_offset_store_ptr: i32, + /// The source location points to the RHS of an assignment. + /// The Decl is determined contextually. + node_offset_store_operand: i32, pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; @@ -3296,6 +3328,8 @@ pub const LazySrcLoc = union(enum) { .node_offset_container_tag, .node_offset_field_default, .node_offset_init_ty, + .node_offset_store_ptr, + .node_offset_store_operand, => .{ .file_scope = decl.getFileScope(), .parent_decl_node = decl.src_node, -- cgit v1.2.3