| ... | @@ -1608,7 +1608,27 @@ pub const SrcLoc = struct { | ... | @@ -1608,7 +1608,27 @@ pub const SrcLoc = struct { |
| 1608 | const token_starts = tree.tokens.items(.start); | 1608 | const token_starts = tree.tokens.items(.start); |
| 1609 | return token_starts[tok_index]; | 1609 | return token_starts[tok_index]; |
| 1610 | }, | 1610 | }, |
| 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 | }, |
| 1612 | .node_offset_builtin_call_arg0 => @panic("TODO"), | 1632 | .node_offset_builtin_call_arg0 => @panic("TODO"), |
| 1613 | .node_offset_builtin_call_arg1 => @panic("TODO"), | 1633 | .node_offset_builtin_call_arg1 => @panic("TODO"), |
| 1614 | .node_offset_builtin_call_argn => unreachable, // Handled specially in `Sema`. | 1634 | .node_offset_builtin_call_argn => unreachable, // Handled specially in `Sema`. |
| ... | @@ -1625,7 +1645,7 @@ pub const SrcLoc = struct { | ... | @@ -1625,7 +1645,7 @@ pub const SrcLoc = struct { |
| 1625 | const node = decl.relativeToNodeIndex(node_off); | 1645 | const node = decl.relativeToNodeIndex(node_off); |
| 1626 | const tree = decl.container.file_scope.base.tree(); | 1646 | const tree = decl.container.file_scope.base.tree(); |
| 1627 | const node_tags = tree.nodes.items(.tag); | 1647 | const node_tags = tree.nodes.items(.tag); |
| 1628 | const cond_expr = switch (node_tags[node]) { | 1648 | const src_node = switch (node_tags[node]) { |
| 1629 | .if_simple => tree.ifSimple(node).ast.cond_expr, | 1649 | .if_simple => tree.ifSimple(node).ast.cond_expr, |
| 1630 | .@"if" => tree.ifFull(node).ast.cond_expr, | 1650 | .@"if" => tree.ifFull(node).ast.cond_expr, |
| 1631 | .while_simple => tree.whileSimple(node).ast.cond_expr, | 1651 | .while_simple => tree.whileSimple(node).ast.cond_expr, |
| ... | @@ -1636,7 +1656,7 @@ pub const SrcLoc = struct { | ... | @@ -1636,7 +1656,7 @@ pub const SrcLoc = struct { |
| 1636 | else => unreachable, | 1656 | else => unreachable, |
| 1637 | }; | 1657 | }; |
| 1638 | const main_tokens = tree.nodes.items(.main_token); | 1658 | const main_tokens = tree.nodes.items(.main_token); |
| 1639 | const tok_index = main_tokens[cond_expr]; | 1659 | const tok_index = main_tokens[src_node]; |
| 1640 | const token_starts = tree.tokens.items(.start); | 1660 | const token_starts = tree.tokens.items(.start); |
| 1641 | return token_starts[tok_index]; | 1661 | return token_starts[tok_index]; |
| 1642 | }, | 1662 | }, |