| author | |
| committer | |
| log | 2ca752ea1ad4afb9d510687ae097c709668316b9 |
| tree | eaff16d368cff38f09a05d8dec03ec3dea040435 |
| parent | 89cef9f5f731f8f33dc935aac3c21bd57c92900d |
4 files changed, 25 insertions(+), 11 deletions(-)
src/AstGen.zig+1-1| ... | @@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr | ... | @@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr |
| 812 | 812 | ||
| 813 | .deref => { | 813 | .deref => { |
| 814 | const lhs = try expr(gz, scope, .none, node_datas[node].lhs); | 814 | const lhs = try expr(gz, scope, .none, node_datas[node].lhs); |
| 815 | _ = try gz.addUnTok(.validate_deref, lhs, main_tokens[node]); | 815 | _ = try gz.addUnNode(.validate_deref, lhs, node); |
| 816 | switch (rl) { | 816 | switch (rl) { |
| 817 | .ref => return lhs, | 817 | .ref => return lhs, |
| 818 | else => { | 818 | else => { |
src/Module.zig+14| ... | @@ -2501,6 +2501,16 @@ pub const SrcLoc = struct { | ... | @@ -2501,6 +2501,16 @@ pub const SrcLoc = struct { |
| 2501 | const token_starts = tree.tokens.items(.start); | 2501 | const token_starts = tree.tokens.items(.start); |
| 2502 | return token_starts[tok_index]; | 2502 | return token_starts[tok_index]; |
| 2503 | }, | 2503 | }, |
| 2504 | .node_offset_un_op => |node_off| { | ||
| 2505 | const tree = try src_loc.file_scope.getTree(gpa); | ||
| 2506 | const node_datas = tree.nodes.items(.data); | ||
| 2507 | const node = src_loc.declRelativeToNodeIndex(node_off); | ||
| 2508 | |||
| 2509 | const main_tokens = tree.nodes.items(.main_token); | ||
| 2510 | const tok_index = main_tokens[node_datas[node].lhs]; | ||
| 2511 | const token_starts = tree.tokens.items(.start); | ||
| 2512 | return token_starts[tok_index]; | ||
| 2513 | }, | ||
| 2504 | } | 2514 | } |
| 2505 | } | 2515 | } |
| 2506 | 2516 | ||
| ... | @@ -2728,6 +2738,9 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -2728,6 +2738,9 @@ pub const LazySrcLoc = union(enum) { |
| 2728 | /// to the elem expression. | 2738 | /// to the elem expression. |
| 2729 | /// The Decl is determined contextually. | 2739 | /// The Decl is determined contextually. |
| 2730 | node_offset_array_type_elem: i32, | 2740 | node_offset_array_type_elem: i32, |
| 2741 | /// The source location points to the operand of an unary expression. | ||
| 2742 | /// The Decl is determined contextually. | ||
| 2743 | node_offset_un_op: i32, | ||
| 2731 | 2744 | ||
| 2732 | pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; | 2745 | pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; |
| 2733 | 2746 | ||
| ... | @@ -2788,6 +2801,7 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -2788,6 +2801,7 @@ pub const LazySrcLoc = union(enum) { |
| 2788 | .node_offset_array_type_len, | 2801 | .node_offset_array_type_len, |
| 2789 | .node_offset_array_type_sentinel, | 2802 | .node_offset_array_type_sentinel, |
| 2790 | .node_offset_array_type_elem, | 2803 | .node_offset_array_type_elem, |
| 2804 | .node_offset_un_op, | ||
| 2791 | => .{ | 2805 | => .{ |
| 2792 | .file_scope = decl.getFileScope(), | 2806 | .file_scope = decl.getFileScope(), |
| 2793 | .parent_decl_node = decl.src_node, | 2807 | .parent_decl_node = decl.src_node, |
src/Sema.zig+6-6| ... | @@ -3867,9 +3867,9 @@ fn zirValidateArrayInit( | ... | @@ -3867,9 +3867,9 @@ fn zirValidateArrayInit( |
| 3867 | } | 3867 | } |
| 3868 | 3868 | ||
| 3869 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 3869 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 3870 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | 3870 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3871 | const src = inst_data.src(); | 3871 | const src = inst_data.src(); |
| 3872 | const operand_src: LazySrcLoc = .{ .token_offset = inst_data.src_tok + 1 }; | 3872 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 3873 | const operand = try sema.resolveInst(inst_data.operand); | 3873 | const operand = try sema.resolveInst(inst_data.operand); |
| 3874 | const operand_ty = sema.typeOf(operand); | 3874 | const operand_ty = sema.typeOf(operand); |
| 3875 | 3875 | ||
| ... | @@ -9758,7 +9758,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -9758,7 +9758,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 9758 | 9758 | ||
| 9759 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9759 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9760 | const src = inst_data.src(); | 9760 | const src = inst_data.src(); |
| 9761 | const operand_src = src; // TODO put this on the operand, not the '~' | 9761 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 9762 | 9762 | ||
| 9763 | const operand = try sema.resolveInst(inst_data.operand); | 9763 | const operand = try sema.resolveInst(inst_data.operand); |
| 9764 | const operand_type = sema.typeOf(operand); | 9764 | const operand_type = sema.typeOf(operand); |
| ... | @@ -10257,7 +10257,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -10257,7 +10257,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 10257 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 10257 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 10258 | const src = inst_data.src(); | 10258 | const src = inst_data.src(); |
| 10259 | const lhs_src = src; | 10259 | const lhs_src = src; |
| 10260 | const rhs_src = src; // TODO better source location | 10260 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 10261 | 10261 | ||
| 10262 | const rhs = try sema.resolveInst(inst_data.operand); | 10262 | const rhs = try sema.resolveInst(inst_data.operand); |
| 10263 | const rhs_ty = sema.typeOf(rhs); | 10263 | const rhs_ty = sema.typeOf(rhs); |
| ... | @@ -10293,7 +10293,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10293,7 +10293,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10293 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 10293 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 10294 | const src = inst_data.src(); | 10294 | const src = inst_data.src(); |
| 10295 | const lhs_src = src; | 10295 | const lhs_src = src; |
| 10296 | const rhs_src = src; // TODO better source location | 10296 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 10297 | 10297 | ||
| 10298 | const rhs = try sema.resolveInst(inst_data.operand); | 10298 | const rhs = try sema.resolveInst(inst_data.operand); |
| 10299 | const rhs_ty = sema.typeOf(rhs); | 10299 | const rhs_ty = sema.typeOf(rhs); |
| ... | @@ -13159,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13159,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13159 | 13159 | ||
| 13160 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 13160 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 13161 | const src = inst_data.src(); | 13161 | const src = inst_data.src(); |
| 13162 | const operand_src = src; // TODO put this on the operand, not the `!` | 13162 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 13163 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | 13163 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 13164 | 13164 | ||
| 13165 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); | 13165 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
src/Zir.zig+4-4| ... | @@ -244,7 +244,7 @@ pub const Inst = struct { | ... | @@ -244,7 +244,7 @@ pub const Inst = struct { |
| 244 | /// Uses the pl_node field with payload `Bin`. | 244 | /// Uses the pl_node field with payload `Bin`. |
| 245 | bitcast, | 245 | bitcast, |
| 246 | /// Bitwise NOT. `~` | 246 | /// Bitwise NOT. `~` |
| 247 | /// Uses `un_node`. | 247 | /// Uses `un_tok`. |
| 248 | bit_not, | 248 | bit_not, |
| 249 | /// Bitwise OR. `|` | 249 | /// Bitwise OR. `|` |
| 250 | bit_or, | 250 | bit_or, |
| ... | @@ -260,7 +260,7 @@ pub const Inst = struct { | ... | @@ -260,7 +260,7 @@ pub const Inst = struct { |
| 260 | /// Uses the `pl_node` union field. Payload is `Block`. | 260 | /// Uses the `pl_node` union field. Payload is `Block`. |
| 261 | suspend_block, | 261 | suspend_block, |
| 262 | /// Boolean NOT. See also `bit_not`. | 262 | /// Boolean NOT. See also `bit_not`. |
| 263 | /// Uses the `un_node` field. | 263 | /// Uses the `un_tok` field. |
| 264 | bool_not, | 264 | bool_not, |
| 265 | /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand | 265 | /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand |
| 266 | /// is a block, which is evaluated if `lhs` is `true`. | 266 | /// is a block, which is evaluated if `lhs` is `true`. |
| ... | @@ -729,7 +729,7 @@ pub const Inst = struct { | ... | @@ -729,7 +729,7 @@ pub const Inst = struct { |
| 729 | /// resulting array initialization value is within a comptime scope. | 729 | /// resulting array initialization value is within a comptime scope. |
| 730 | validate_array_init_comptime, | 730 | validate_array_init_comptime, |
| 731 | /// Check that operand type supports the dereference operand (.*). | 731 | /// Check that operand type supports the dereference operand (.*). |
| 732 | /// Uses the `un_tok` field. | 732 | /// Uses the `un_node` field. |
| 733 | validate_deref, | 733 | validate_deref, |
| 734 | /// A struct literal with a specified type, with no fields. | 734 | /// A struct literal with a specified type, with no fields. |
| 735 | /// Uses the `un_node` field. | 735 | /// Uses the `un_node` field. |
| ... | @@ -1704,7 +1704,7 @@ pub const Inst = struct { | ... | @@ -1704,7 +1704,7 @@ pub const Inst = struct { |
| 1704 | .validate_struct_init_comptime = .pl_node, | 1704 | .validate_struct_init_comptime = .pl_node, |
| 1705 | .validate_array_init = .pl_node, | 1705 | .validate_array_init = .pl_node, |
| 1706 | .validate_array_init_comptime = .pl_node, | 1706 | .validate_array_init_comptime = .pl_node, |
| 1707 | .validate_deref = .un_tok, | 1707 | .validate_deref = .un_node, |
| 1708 | .struct_init_empty = .un_node, | 1708 | .struct_init_empty = .un_node, |
| 1709 | .field_type = .pl_node, | 1709 | .field_type = .pl_node, |
| 1710 | .field_type_ref = .pl_node, | 1710 | .field_type_ref = .pl_node, |