authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-26 18:35:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-26 18:35:15-07:00
logda731e18c94fdd985812ec27cfdacff5199e55d2
tree47715840c4bef1fc8004c1b3a16c7976b50f4051
parenta72bfd00cf07da50a94a024d6f74167aa41382c5

stage2: implement source location: .node_offset_var_decl_ty


2 files changed, 36 insertions(+), 16 deletions(-)

src/Module.zig+23-3
......@@ -1608,7 +1608,27 @@ pub const SrcLoc = struct {
16081608 const token_starts = tree.tokens.items(.start);
16091609 return token_starts[tok_index];
16101610 },
1611 .node_offset_var_decl_ty => @panic("TODO"),
1611 .node_offset_var_decl_ty => |node_off| {
1612 const decl = src_loc.container.decl;
1613 const node = decl.relativeToNodeIndex(node_off);
1614 const tree = decl.container.file_scope.base.tree();
1615 const node_tags = tree.nodes.items(.tag);
1616 const full = switch (node_tags[node]) {
1617 .global_var_decl => tree.globalVarDecl(node),
1618 .local_var_decl => tree.localVarDecl(node),
1619 .simple_var_decl => tree.simpleVarDecl(node),
1620 .aligned_var_decl => tree.alignedVarDecl(node),
1621 else => unreachable,
1622 };
1623 const tok_index = if (full.ast.type_node != 0) blk: {
1624 const main_tokens = tree.nodes.items(.main_token);
1625 break :blk main_tokens[full.ast.type_node];
1626 } else blk: {
1627 break :blk full.ast.mut_token + 1; // the name token
1628 };
1629 const token_starts = tree.tokens.items(.start);
1630 return token_starts[tok_index];
1631 },
16121632 .node_offset_builtin_call_arg0 => @panic("TODO"),
16131633 .node_offset_builtin_call_arg1 => @panic("TODO"),
16141634 .node_offset_builtin_call_argn => unreachable, // Handled specially in `Sema`.
......@@ -1625,7 +1645,7 @@ pub const SrcLoc = struct {
16251645 const node = decl.relativeToNodeIndex(node_off);
16261646 const tree = decl.container.file_scope.base.tree();
16271647 const node_tags = tree.nodes.items(.tag);
1628 const cond_expr = switch (node_tags[node]) {
1648 const src_node = switch (node_tags[node]) {
16291649 .if_simple => tree.ifSimple(node).ast.cond_expr,
16301650 .@"if" => tree.ifFull(node).ast.cond_expr,
16311651 .while_simple => tree.whileSimple(node).ast.cond_expr,
......@@ -1636,7 +1656,7 @@ pub const SrcLoc = struct {
16361656 else => unreachable,
16371657 };
16381658 const main_tokens = tree.nodes.items(.main_token);
1639 const tok_index = main_tokens[cond_expr];
1659 const tok_index = main_tokens[src_node];
16401660 const token_starts = tree.tokens.items(.start);
16411661 return token_starts[tok_index];
16421662 },
test/stage2/test.zig+13-13
......@@ -1232,11 +1232,11 @@ pub fn addCases(ctx: *TestContext) !void {
12321232 \\ foo: while (true) {}
12331233 \\}
12341234 , &[_][]const u8{":2:5: error: unused while loop label"});
1235 //case.addError(
1236 // \\comptime {
1237 // \\ foo: for ("foo") |_| {}
1238 // \\}
1239 //, &[_][]const u8{":2:5: error: unused for loop label"});
1235 case.addError(
1236 \\comptime {
1237 \\ foo: for ("foo") |_| {}
1238 \\}
1239 , &[_][]const u8{":2:5: error: unused for loop label"});
12401240 case.addError(
12411241 \\comptime {
12421242 \\ blk: {blk: {}}
......@@ -1247,14 +1247,14 @@ pub fn addCases(ctx: *TestContext) !void {
12471247 });
12481248 }
12491249
1250 //{
1251 // var case = ctx.exe("bad inferred variable type", linux_x64);
1252 // case.addError(
1253 // \\export fn foo() void {
1254 // \\ var x = null;
1255 // \\}
1256 // , &[_][]const u8{":2:9: error: variable of type '@Type(.Null)' must be const or comptime"});
1257 //}
1250 {
1251 var case = ctx.exe("bad inferred variable type", linux_x64);
1252 case.addError(
1253 \\export fn foo() void {
1254 \\ var x = null;
1255 \\}
1256 , &[_][]const u8{":2:9: error: variable of type '@Type(.Null)' must be const or comptime"});
1257 }
12581258
12591259 {
12601260 var case = ctx.exe("compile error in inline fn call fixed", linux_x64);