diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-06 11:36:39 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-07 10:50:06 +0300 |
| commit | 2ca752ea1ad4afb9d510687ae097c709668316b9 (patch) | |
| tree | eaff16d368cff38f09a05d8dec03ec3dea040435 /src | |
| parent | 89cef9f5f731f8f33dc935aac3c21bd57c92900d (diff) | |
| download | zig-2ca752ea1ad4afb9d510687ae097c709668316b9.tar.gz zig-2ca752ea1ad4afb9d510687ae097c709668316b9.zip | |
Module: add `.node_offset_un_op`
Diffstat (limited to 'src')
| -rw-r--r-- | src/AstGen.zig | 2 | ||||
| -rw-r--r-- | src/Module.zig | 14 | ||||
| -rw-r--r-- | src/Sema.zig | 12 | ||||
| -rw-r--r-- | src/Zir.zig | 8 |
4 files changed, 25 insertions, 11 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index a44ac04557..33526524d8 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr .deref => { const lhs = try expr(gz, scope, .none, node_datas[node].lhs); - _ = try gz.addUnTok(.validate_deref, lhs, main_tokens[node]); + _ = try gz.addUnNode(.validate_deref, lhs, node); switch (rl) { .ref => return lhs, else => { diff --git a/src/Module.zig b/src/Module.zig index 1f70a44df5..d4e981f834 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2501,6 +2501,16 @@ pub const SrcLoc = struct { const token_starts = tree.tokens.items(.start); return token_starts[tok_index]; }, + .node_offset_un_op => |node_off| { + const tree = try src_loc.file_scope.getTree(gpa); + const node_datas = tree.nodes.items(.data); + const node = src_loc.declRelativeToNodeIndex(node_off); + + const main_tokens = tree.nodes.items(.main_token); + const tok_index = main_tokens[node_datas[node].lhs]; + const token_starts = tree.tokens.items(.start); + return token_starts[tok_index]; + }, } } @@ -2728,6 +2738,9 @@ pub const LazySrcLoc = union(enum) { /// to the elem expression. /// The Decl is determined contextually. node_offset_array_type_elem: i32, + /// The source location points to the operand of an unary expression. + /// The Decl is determined contextually. + node_offset_un_op: i32, pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; @@ -2788,6 +2801,7 @@ pub const LazySrcLoc = union(enum) { .node_offset_array_type_len, .node_offset_array_type_sentinel, .node_offset_array_type_elem, + .node_offset_un_op, => .{ .file_scope = decl.getFileScope(), .parent_decl_node = decl.src_node, diff --git a/src/Sema.zig b/src/Sema.zig index c224194176..31ba644ea8 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3867,9 +3867,9 @@ fn zirValidateArrayInit( } fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { - const inst_data = sema.code.instructions.items(.data)[inst].un_tok; + const inst_data = sema.code.instructions.items(.data)[inst].un_node; const src = inst_data.src(); - const operand_src: LazySrcLoc = .{ .token_offset = inst_data.src_tok + 1 }; + const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); const operand_ty = sema.typeOf(operand); @@ -9758,7 +9758,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const inst_data = sema.code.instructions.items(.data)[inst].un_node; const src = inst_data.src(); - const operand_src = src; // TODO put this on the operand, not the '~' + const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const operand = try sema.resolveInst(inst_data.operand); const operand_type = sema.typeOf(operand); @@ -10257,7 +10257,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const inst_data = sema.code.instructions.items(.data)[inst].un_node; const src = inst_data.src(); const lhs_src = src; - const rhs_src = src; // TODO better source location + const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const rhs = try sema.resolveInst(inst_data.operand); const rhs_ty = sema.typeOf(rhs); @@ -10293,7 +10293,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! const inst_data = sema.code.instructions.items(.data)[inst].un_node; const src = inst_data.src(); const lhs_src = src; - const rhs_src = src; // TODO better source location + const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const rhs = try sema.resolveInst(inst_data.operand); const rhs_ty = sema.typeOf(rhs); @@ -13159,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const inst_data = sema.code.instructions.items(.data)[inst].un_node; const src = inst_data.src(); - const operand_src = src; // TODO put this on the operand, not the `!` + const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; const uncasted_operand = try sema.resolveInst(inst_data.operand); const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); diff --git a/src/Zir.zig b/src/Zir.zig index 8735ba636d..3a07c56c40 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -244,7 +244,7 @@ pub const Inst = struct { /// Uses the pl_node field with payload `Bin`. bitcast, /// Bitwise NOT. `~` - /// Uses `un_node`. + /// Uses `un_tok`. bit_not, /// Bitwise OR. `|` bit_or, @@ -260,7 +260,7 @@ pub const Inst = struct { /// Uses the `pl_node` union field. Payload is `Block`. suspend_block, /// Boolean NOT. See also `bit_not`. - /// Uses the `un_node` field. + /// Uses the `un_tok` field. bool_not, /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand /// is a block, which is evaluated if `lhs` is `true`. @@ -729,7 +729,7 @@ pub const Inst = struct { /// resulting array initialization value is within a comptime scope. validate_array_init_comptime, /// Check that operand type supports the dereference operand (.*). - /// Uses the `un_tok` field. + /// Uses the `un_node` field. validate_deref, /// A struct literal with a specified type, with no fields. /// Uses the `un_node` field. @@ -1704,7 +1704,7 @@ pub const Inst = struct { .validate_struct_init_comptime = .pl_node, .validate_array_init = .pl_node, .validate_array_init_comptime = .pl_node, - .validate_deref = .un_tok, + .validate_deref = .un_node, .struct_init_empty = .un_node, .field_type = .pl_node, .field_type_ref = .pl_node, |
