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
812812
813813 .deref => {
814814 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);
816816 switch (rl) {
817817 .ref => return lhs,
818818 else => {
src/Module.zig+14
......@@ -2501,6 +2501,16 @@ pub const SrcLoc = struct {
25012501 const token_starts = tree.tokens.items(.start);
25022502 return token_starts[tok_index];
25032503 },
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 },
25042514 }
25052515 }
25062516
......@@ -2728,6 +2738,9 @@ pub const LazySrcLoc = union(enum) {
27282738 /// to the elem expression.
27292739 /// The Decl is determined contextually.
27302740 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
27322745 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
27332746
......@@ -2788,6 +2801,7 @@ pub const LazySrcLoc = union(enum) {
27882801 .node_offset_array_type_len,
27892802 .node_offset_array_type_sentinel,
27902803 .node_offset_array_type_elem,
2804 .node_offset_un_op,
27912805 => .{
27922806 .file_scope = decl.getFileScope(),
27932807 .parent_decl_node = decl.src_node,
src/Sema.zig+6-6
......@@ -3867,9 +3867,9 @@ fn zirValidateArrayInit(
38673867}
38683868
38693869fn 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;
38713871 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 };
38733873 const operand = try sema.resolveInst(inst_data.operand);
38743874 const operand_ty = sema.typeOf(operand);
38753875
......@@ -9758,7 +9758,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
97589758
97599759 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
97609760 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
97639763 const operand = try sema.resolveInst(inst_data.operand);
97649764 const operand_type = sema.typeOf(operand);
......@@ -10257,7 +10257,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1025710257 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1025810258 const src = inst_data.src();
1025910259 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 };
1026110261
1026210262 const rhs = try sema.resolveInst(inst_data.operand);
1026310263 const rhs_ty = sema.typeOf(rhs);
......@@ -10293,7 +10293,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1029310293 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1029410294 const src = inst_data.src();
1029510295 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 };
1029710297
1029810298 const rhs = try sema.resolveInst(inst_data.operand);
1029910299 const rhs_ty = sema.typeOf(rhs);
......@@ -13159,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1315913159
1316013160 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1316113161 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 };
1316313163 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1316413164
1316513165 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 {
244244 /// Uses the pl_node field with payload `Bin`.
245245 bitcast,
246246 /// Bitwise NOT. `~`
247 /// Uses `un_node`.
247 /// Uses `un_tok`.
248248 bit_not,
249249 /// Bitwise OR. `|`
250250 bit_or,
......@@ -260,7 +260,7 @@ pub const Inst = struct {
260260 /// Uses the `pl_node` union field. Payload is `Block`.
261261 suspend_block,
262262 /// Boolean NOT. See also `bit_not`.
263 /// Uses the `un_node` field.
263 /// Uses the `un_tok` field.
264264 bool_not,
265265 /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand
266266 /// is a block, which is evaluated if `lhs` is `true`.
......@@ -729,7 +729,7 @@ pub const Inst = struct {
729729 /// resulting array initialization value is within a comptime scope.
730730 validate_array_init_comptime,
731731 /// Check that operand type supports the dereference operand (.*).
732 /// Uses the `un_tok` field.
732 /// Uses the `un_node` field.
733733 validate_deref,
734734 /// A struct literal with a specified type, with no fields.
735735 /// Uses the `un_node` field.
......@@ -1704,7 +1704,7 @@ pub const Inst = struct {
17041704 .validate_struct_init_comptime = .pl_node,
17051705 .validate_array_init = .pl_node,
17061706 .validate_array_init_comptime = .pl_node,
1707 .validate_deref = .un_tok,
1707 .validate_deref = .un_node,
17081708 .struct_init_empty = .un_node,
17091709 .field_type = .pl_node,
17101710 .field_type_ref = .pl_node,