diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-06 12:17:04 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-07 10:50:06 +0300 |
| commit | 27ee4141592c7a9d77a2d73f5fa6a3c6262ac7fc (patch) | |
| tree | 9077c3617875ad8511d3da525d5a0554ecbb2c98 /src/Module.zig | |
| parent | 2ca752ea1ad4afb9d510687ae097c709668316b9 (diff) | |
| download | zig-27ee4141592c7a9d77a2d73f5fa6a3c6262ac7fc.tar.gz zig-27ee4141592c7a9d77a2d73f5fa6a3c6262ac7fc.zip | |
Sema: improve slice source locations
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig index d4e981f834..3c4962c587 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2171,7 +2171,11 @@ pub const SrcLoc = struct { const token_starts = tree.tokens.items(.start); return token_starts[tok_index]; }, - .node_offset_slice_sentinel => |node_off| { + .node_offset_slice_ptr, + .node_offset_slice_start, + .node_offset_slice_end, + .node_offset_slice_sentinel, + => |node_off| { const tree = try src_loc.file_scope.getTree(gpa); const node_tags = tree.nodes.items(.tag); const node = src_loc.declRelativeToNodeIndex(node_off); @@ -2182,7 +2186,15 @@ pub const SrcLoc = struct { else => unreachable, }; const main_tokens = tree.nodes.items(.main_token); - const tok_index = main_tokens[full.ast.sentinel]; + const tok_index = main_tokens[ + switch (src_loc.lazy) { + .node_offset_slice_ptr => full.ast.sliced, + .node_offset_slice_start => full.ast.start, + .node_offset_slice_end => full.ast.end, + .node_offset_slice_sentinel => full.ast.sentinel, + else => unreachable, + } + ]; const token_starts = tree.tokens.items(.start); return token_starts[tok_index]; }, @@ -2624,6 +2636,24 @@ pub const LazySrcLoc = union(enum) { /// to the index expression. /// The Decl is determined contextually. node_offset_array_access_index: i32, + /// The source location points to the LHS of a slice expression + /// expression, found by taking this AST node index offset from the containing + /// Decl AST node, which points to a slice AST node. Next, navigate + /// to the sentinel expression. + /// The Decl is determined contextually. + node_offset_slice_ptr: i32, + /// The source location points to start expression of a slice expression + /// expression, found by taking this AST node index offset from the containing + /// Decl AST node, which points to a slice AST node. Next, navigate + /// to the sentinel expression. + /// The Decl is determined contextually. + node_offset_slice_start: i32, + /// The source location points to the end expression of a slice + /// expression, found by taking this AST node index offset from the containing + /// Decl AST node, which points to a slice AST node. Next, navigate + /// to the sentinel expression. + /// The Decl is determined contextually. + node_offset_slice_end: i32, /// The source location points to the sentinel expression of a slice /// expression, found by taking this AST node index offset from the containing /// Decl AST node, which points to a slice AST node. Next, navigate @@ -2781,6 +2811,9 @@ pub const LazySrcLoc = union(enum) { .node_offset_builtin_call_arg4, .node_offset_builtin_call_arg5, .node_offset_array_access_index, + .node_offset_slice_ptr, + .node_offset_slice_start, + .node_offset_slice_end, .node_offset_slice_sentinel, .node_offset_call_func, .node_offset_field_name, |
