authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-06 11:36:39+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-07 10:50:06+03:00
log2ca752ea1ad4afb9d510687ae097c709668316b9
treeeaff16d368cff38f09a05d8dec03ec3dea040435
parent89cef9f5f731f8f33dc935aac3c21bd57c92900d

Module: add `.node_offset_un_op`


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
812812
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 }
25062516
...@@ -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,
27312744
2732 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;2745 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
27332746
...@@ -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}
38683868
3869fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {3869fn 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);
38753875
...@@ -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.
97589758
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 };
97629762
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 location10260 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
1026110261
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 location10296 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
1029710297
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
1315913159
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);
1316413164
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 operand265 /// 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,