mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
wip
This commit is contained in:
parent
8e72a25285
commit
1884ad0ea3
12 changed files with 803 additions and 802 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -61,11 +61,11 @@ const Block = struct {
|
|||
consumes_res_ptr: bool,
|
||||
};
|
||||
|
||||
pub fn annotate(gpa: Allocator, arena: Allocator, tree: Ast) Allocator.Error!RlNeededSet {
|
||||
pub fn annotate(gpa: Allocator, arena: Allocator, tree: *const Ast) Allocator.Error!RlNeededSet {
|
||||
var astrl: AstRlAnnotate = .{
|
||||
.gpa = gpa,
|
||||
.arena = arena,
|
||||
.tree = &tree,
|
||||
.tree = tree,
|
||||
};
|
||||
defer astrl.deinit(gpa);
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ fn containerDecl(
|
|||
/// Returns true if `rl` provides a result pointer and the expression consumes it.
|
||||
fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultInfo) Allocator.Error!bool {
|
||||
const tree = astrl.tree;
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.root,
|
||||
.switch_case_one,
|
||||
.switch_case_inline_one,
|
||||
|
|
@ -142,11 +142,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
=> unreachable,
|
||||
|
||||
.@"errdefer" => {
|
||||
_ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).opt_token_and_node[1], block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.@"defer" => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
|
||||
|
|
@ -166,11 +166,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return false;
|
||||
},
|
||||
.@"usingnamespace" => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.test_decl => {
|
||||
_ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).opt_token_and_node[1], block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.global_var_decl,
|
||||
|
|
@ -214,7 +214,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return false;
|
||||
},
|
||||
.assign => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.typed_ptr);
|
||||
return false;
|
||||
|
|
@ -237,13 +237,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
.assign_mul_wrap,
|
||||
.assign_mul_sat,
|
||||
=> {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.shl, .shr => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.type_only);
|
||||
return false;
|
||||
|
|
@ -271,20 +271,20 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
.less_or_equal,
|
||||
.array_cat,
|
||||
=> {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
|
||||
.array_mult => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.error_union, .merge_error_sets => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.none);
|
||||
return false;
|
||||
|
|
@ -292,17 +292,17 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
.bool_and,
|
||||
.bool_or,
|
||||
=> {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.type_only);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.bool_not => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.bit_not, .negation, .negation_wrap => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
|
||||
|
|
@ -347,7 +347,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
for (full.ast.params) |param_node| {
|
||||
_ = try astrl.expr(param_node, block, ResultInfo.type_only);
|
||||
}
|
||||
return switch (tree.nodeTag(node)) {
|
||||
return switch (node.tag(tree)) {
|
||||
.call_one,
|
||||
.call_one_comma,
|
||||
.call,
|
||||
|
|
@ -363,7 +363,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
},
|
||||
|
||||
.@"return" => {
|
||||
if (tree.nodeData(node).opt_node.unwrap()) |lhs| {
|
||||
if (node.data(tree).opt_node.unwrap()) |lhs| {
|
||||
const ret_val_consumes_rl = try astrl.expr(lhs, block, ResultInfo.typed_ptr);
|
||||
if (ret_val_consumes_rl) {
|
||||
try astrl.nodes_need_rl.putNoClobber(astrl.gpa, node, {});
|
||||
|
|
@ -373,7 +373,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
},
|
||||
|
||||
.field_access => {
|
||||
const lhs, _ = tree.nodeData(node).node_and_token;
|
||||
const lhs, _ = node.data(tree).node_and_token;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
|
|
@ -436,8 +436,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
break :label try astrl.identString(label_token);
|
||||
} else null;
|
||||
for (full.ast.inputs) |input| {
|
||||
if (tree.nodeTag(input) == .for_range) {
|
||||
const lhs, const opt_rhs = tree.nodeData(input).node_and_opt_node;
|
||||
if (input.tag(tree) == .for_range) {
|
||||
const lhs, const opt_rhs = input.data(tree).node_and_opt_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.type_only);
|
||||
if (opt_rhs.unwrap()) |rhs| {
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.type_only);
|
||||
|
|
@ -466,13 +466,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
},
|
||||
|
||||
.slice_open => {
|
||||
const sliced, const start = tree.nodeData(node).node_and_node;
|
||||
const sliced, const start = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(sliced, block, ResultInfo.none);
|
||||
_ = try astrl.expr(start, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.slice => {
|
||||
const sliced, const extra_index = tree.nodeData(node).node_and_extra;
|
||||
const sliced, const extra_index = node.data(tree).node_and_extra;
|
||||
const extra = tree.extraData(extra_index, Ast.Node.Slice);
|
||||
_ = try astrl.expr(sliced, block, ResultInfo.none);
|
||||
_ = try astrl.expr(extra.start, block, ResultInfo.type_only);
|
||||
|
|
@ -480,7 +480,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return false;
|
||||
},
|
||||
.slice_sentinel => {
|
||||
const sliced, const extra_index = tree.nodeData(node).node_and_extra;
|
||||
const sliced, const extra_index = node.data(tree).node_and_extra;
|
||||
const extra = tree.extraData(extra_index, Ast.Node.SliceSentinel);
|
||||
_ = try astrl.expr(sliced, block, ResultInfo.none);
|
||||
_ = try astrl.expr(extra.start, block, ResultInfo.type_only);
|
||||
|
|
@ -491,24 +491,24 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return false;
|
||||
},
|
||||
.deref => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.address_of => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.optional_type => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.type_only);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.@"try",
|
||||
.@"await",
|
||||
.@"nosuspend",
|
||||
=> return astrl.expr(tree.nodeData(node).node, block, ri),
|
||||
=> return astrl.expr(node.data(tree).node, block, ri),
|
||||
.grouped_expression,
|
||||
.unwrap_optional,
|
||||
=> return astrl.expr(tree.nodeData(node).node_and_token[0], block, ri),
|
||||
=> return astrl.expr(node.data(tree).node_and_token[0], block, ri),
|
||||
|
||||
.block_two,
|
||||
.block_two_semicolon,
|
||||
|
|
@ -520,12 +520,12 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return astrl.blockExpr(block, ri, node, statements);
|
||||
},
|
||||
.anyframe_type => {
|
||||
_, const child_type = tree.nodeData(node).token_and_node;
|
||||
_, const child_type = node.data(tree).token_and_node;
|
||||
_ = try astrl.expr(child_type, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.@"catch", .@"orelse" => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
const rhs_consumes_rl = try astrl.expr(rhs, block, ri);
|
||||
if (rhs_consumes_rl) {
|
||||
|
|
@ -577,7 +577,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
},
|
||||
|
||||
.@"break" => {
|
||||
const opt_label, const opt_rhs = tree.nodeData(node).opt_token_and_opt_node;
|
||||
const opt_label, const opt_rhs = node.data(tree).opt_token_and_opt_node;
|
||||
const rhs = opt_rhs.unwrap() orelse {
|
||||
// Breaks with void are not interesting
|
||||
return false;
|
||||
|
|
@ -609,13 +609,13 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
},
|
||||
|
||||
.array_type => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.type_only);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.type_only);
|
||||
return false;
|
||||
},
|
||||
.array_type_sentinel => {
|
||||
const len_expr, const extra_index = tree.nodeData(node).node_and_extra;
|
||||
const len_expr, const extra_index = node.data(tree).node_and_extra;
|
||||
const extra = tree.extraData(extra_index, Ast.Node.ArrayTypeSentinel);
|
||||
_ = try astrl.expr(len_expr, block, ResultInfo.type_only);
|
||||
_ = try astrl.expr(extra.elem_type, block, ResultInfo.type_only);
|
||||
|
|
@ -623,7 +623,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return false;
|
||||
},
|
||||
.array_access => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.type_only);
|
||||
return false;
|
||||
|
|
@ -631,11 +631,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
.@"comptime" => {
|
||||
// AstGen will emit an error if the scope is already comptime, so we can assume it is
|
||||
// not. This means the result location is not forwarded.
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.@"switch", .switch_comma => {
|
||||
const operand_node, const extra_index = tree.nodeData(node).node_and_extra;
|
||||
const operand_node, const extra_index = node.data(tree).node_and_extra;
|
||||
const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index);
|
||||
|
||||
_ = try astrl.expr(operand_node, block, ResultInfo.none);
|
||||
|
|
@ -644,8 +644,8 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
for (case_nodes) |case_node| {
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
for (case.ast.values) |item_node| {
|
||||
if (tree.nodeTag(item_node) == .switch_range) {
|
||||
const lhs, const rhs = tree.nodeData(item_node).node_and_node;
|
||||
if (item_node.tag(tree) == .switch_range) {
|
||||
const lhs, const rhs = item_node.data(tree).node_and_node;
|
||||
_ = try astrl.expr(lhs, block, ResultInfo.none);
|
||||
_ = try astrl.expr(rhs, block, ResultInfo.none);
|
||||
} else {
|
||||
|
|
@ -662,11 +662,11 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
return any_prong_consumed_rl;
|
||||
},
|
||||
.@"suspend" => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
.@"resume" => {
|
||||
_ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none);
|
||||
_ = try astrl.expr(node.data(tree).node, block, ResultInfo.none);
|
||||
return false;
|
||||
},
|
||||
|
||||
|
|
@ -752,7 +752,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI
|
|||
=> |tag| {
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const full = tree.fullFnProto(&buf, node).?;
|
||||
const body_node = if (tag == .fn_decl) tree.nodeData(node).node_and_node[1].toOptional() else .none;
|
||||
const body_node = if (tag == .fn_decl) node.data(tree).node_and_node[1].toOptional() else .none;
|
||||
{
|
||||
var it = full.iterate(tree);
|
||||
while (it.next()) |param| {
|
||||
|
|
@ -800,7 +800,7 @@ fn identString(astrl: *AstRlAnnotate, token: Ast.TokenIndex) ![]const u8 {
|
|||
fn blockExpr(astrl: *AstRlAnnotate, parent_block: ?*Block, ri: ResultInfo, node: Ast.Node.Index, statements: []const Ast.Node.Index) !bool {
|
||||
const tree = astrl.tree;
|
||||
|
||||
const lbrace = tree.nodeMainToken(node);
|
||||
const lbrace = node.mainToken(tree);
|
||||
if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) {
|
||||
// Labeled block
|
||||
var new_block: Block = .{
|
||||
|
|
@ -830,7 +830,7 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast.
|
|||
_ = ri; // Currently, no builtin consumes its result location.
|
||||
|
||||
const tree = astrl.tree;
|
||||
const builtin_token = tree.nodeMainToken(node);
|
||||
const builtin_token = node.mainToken(tree);
|
||||
const builtin_name = tree.tokenSlice(builtin_token);
|
||||
const info = BuiltinFn.list.get(builtin_name) orelse return false;
|
||||
if (info.param_count) |expected| {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Ingests an `Ast` and produces a `Zoir`.
|
||||
|
||||
gpa: Allocator,
|
||||
tree: Ast,
|
||||
tree: *const Ast,
|
||||
|
||||
options: Options,
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ pub const Options = struct {
|
|||
parse_str_lits: bool = true,
|
||||
};
|
||||
|
||||
pub fn generate(gpa: Allocator, tree: Ast, options: Options) Allocator.Error!Zoir {
|
||||
pub fn generate(gpa: Allocator, tree: *const Ast, options: Options) Allocator.Error!Zoir {
|
||||
assert(tree.mode == .zon);
|
||||
|
||||
var zg: ZonGen = .{
|
||||
|
|
@ -98,7 +98,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
|
|||
const gpa = zg.gpa;
|
||||
const tree = zg.tree;
|
||||
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.root => unreachable,
|
||||
.@"usingnamespace" => unreachable,
|
||||
.test_decl => unreachable,
|
||||
|
|
@ -170,7 +170,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
|
|||
.bool_not,
|
||||
.bit_not,
|
||||
.negation_wrap,
|
||||
=> try zg.addErrorTok(tree.nodeMainToken(node), "operator '{s}' is not allowed in ZON", .{tree.tokenSlice(tree.nodeMainToken(node))}),
|
||||
=> try zg.addErrorTok(node.mainToken(tree), "operator '{s}' is not allowed in ZON", .{tree.tokenSlice(node.mainToken(tree))}),
|
||||
|
||||
.error_union,
|
||||
.merge_error_sets,
|
||||
|
|
@ -248,8 +248,8 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
|
|||
.slice_sentinel,
|
||||
=> try zg.addErrorNode(node, "slice operator is not allowed in ZON", .{}),
|
||||
|
||||
.deref, .address_of => try zg.addErrorTok(tree.nodeMainToken(node), "pointers are not available in ZON", .{}),
|
||||
.unwrap_optional => try zg.addErrorTok(tree.nodeMainToken(node), "optionals are not available in ZON", .{}),
|
||||
.deref, .address_of => try zg.addErrorTok(node.mainToken(tree), "pointers are not available in ZON", .{}),
|
||||
.unwrap_optional => try zg.addErrorTok(node.mainToken(tree), "optionals are not available in ZON", .{}),
|
||||
.error_value => try zg.addErrorNode(node, "errors are not available in ZON", .{}),
|
||||
|
||||
.array_access => try zg.addErrorNode(node, "array indexing is not allowed in ZON", .{}),
|
||||
|
|
@ -294,18 +294,18 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
|
|||
},
|
||||
|
||||
.grouped_expression => {
|
||||
try zg.addErrorTokNotes(tree.nodeMainToken(node), "expression grouping is not allowed in ZON", .{}, &.{
|
||||
try zg.errNoteTok(tree.nodeMainToken(node), "these parentheses are always redundant", .{}),
|
||||
try zg.addErrorTokNotes(node.mainToken(tree), "expression grouping is not allowed in ZON", .{}, &.{
|
||||
try zg.errNoteTok(node.mainToken(tree), "these parentheses are always redundant", .{}),
|
||||
});
|
||||
return zg.expr(tree.nodeData(node).node_and_token[0], dest_node);
|
||||
return zg.expr(node.data(tree).node_and_token[0], dest_node);
|
||||
},
|
||||
|
||||
.negation => {
|
||||
const child_node = tree.nodeData(node).node;
|
||||
switch (tree.nodeTag(child_node)) {
|
||||
const child_node = node.data(tree).node;
|
||||
switch (child_node.tag(tree)) {
|
||||
.number_literal => return zg.numberLiteral(child_node, node, dest_node, .negative),
|
||||
.identifier => {
|
||||
const child_ident = tree.tokenSlice(tree.nodeMainToken(child_node));
|
||||
const child_ident = tree.tokenSlice(child_node.mainToken(tree));
|
||||
if (mem.eql(u8, child_ident, "inf")) {
|
||||
zg.setNode(dest_node, .{
|
||||
.tag = .neg_inf,
|
||||
|
|
@ -317,7 +317,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
|
|||
},
|
||||
else => {},
|
||||
}
|
||||
try zg.addErrorTok(tree.nodeMainToken(node), "expected number or 'inf' after '-'", .{});
|
||||
try zg.addErrorTok(node.mainToken(tree), "expected number or 'inf' after '-'", .{});
|
||||
},
|
||||
.number_literal => try zg.numberLiteral(node, node, dest_node, .positive),
|
||||
.char_literal => try zg.charLiteral(node, dest_node),
|
||||
|
|
@ -325,7 +325,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
|
|||
.identifier => try zg.identifier(node, dest_node),
|
||||
|
||||
.enum_literal => {
|
||||
const str_index = zg.identAsString(tree.nodeMainToken(node)) catch |err| switch (err) {
|
||||
const str_index = zg.identAsString(node.mainToken(tree)) catch |err| switch (err) {
|
||||
error.BadString => undefined, // doesn't matter, there's an error
|
||||
error.OutOfMemory => |e| return e,
|
||||
};
|
||||
|
|
@ -486,17 +486,17 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) !u32 {
|
|||
}
|
||||
|
||||
/// Estimates the size of a string node without parsing it.
|
||||
pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize {
|
||||
switch (tree.nodeTag(node)) {
|
||||
pub fn strLitSizeHint(tree: *const Ast, node: Ast.Node.Index) usize {
|
||||
switch (node.tag(tree)) {
|
||||
// Parsed string literals are typically around the size of the raw strings.
|
||||
.string_literal => {
|
||||
const token = tree.nodeMainToken(node);
|
||||
const token = node.mainToken(tree);
|
||||
const raw_string = tree.tokenSlice(token);
|
||||
return raw_string.len;
|
||||
},
|
||||
// Multiline string literal lengths can be computed exactly.
|
||||
.multiline_string_literal => {
|
||||
const first_tok, const last_tok = tree.nodeData(node).token_and_token;
|
||||
const first_tok, const last_tok = node.data(tree).token_and_token;
|
||||
|
||||
var size = tree.tokenSlice(first_tok)[2..].len;
|
||||
for (first_tok + 1..last_tok + 1) |tok_idx| {
|
||||
|
|
@ -511,18 +511,18 @@ pub fn strLitSizeHint(tree: Ast, node: Ast.Node.Index) usize {
|
|||
|
||||
/// Parses the given node as a string literal.
|
||||
pub fn parseStrLit(
|
||||
tree: Ast,
|
||||
tree: *const Ast,
|
||||
node: Ast.Node.Index,
|
||||
writer: anytype,
|
||||
) error{OutOfMemory}!std.zig.string_literal.Result {
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.string_literal => {
|
||||
const token = tree.nodeMainToken(node);
|
||||
const token = node.mainToken(tree);
|
||||
const raw_string = tree.tokenSlice(token);
|
||||
return std.zig.string_literal.parseWrite(writer, raw_string);
|
||||
},
|
||||
.multiline_string_literal => {
|
||||
const first_tok, const last_tok = tree.nodeData(node).token_and_token;
|
||||
const first_tok, const last_tok = node.data(tree).token_and_token;
|
||||
|
||||
// First line: do not append a newline.
|
||||
{
|
||||
|
|
@ -560,7 +560,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) !StringLiteralResult {
|
|||
switch (try parseStrLit(zg.tree, str_node, zg.string_bytes.writer(zg.gpa))) {
|
||||
.success => {},
|
||||
.failure => |err| {
|
||||
const token = zg.tree.nodeMainToken(str_node);
|
||||
const token = str_node.mainToken(zg.tree);
|
||||
const raw_string = zg.tree.tokenSlice(token);
|
||||
try zg.lowerStrLitError(err, token, raw_string, 0);
|
||||
return error.BadString;
|
||||
|
|
@ -608,7 +608,7 @@ fn identAsString(zg: *ZonGen, ident_token: Ast.TokenIndex) !Zoir.NullTerminatedS
|
|||
|
||||
fn numberLiteral(zg: *ZonGen, num_node: Ast.Node.Index, src_node: Ast.Node.Index, dest_node: Zoir.Node.Index, sign: enum { negative, positive }) !void {
|
||||
const tree = zg.tree;
|
||||
const num_token = tree.nodeMainToken(num_node);
|
||||
const num_token = num_node.mainToken(tree);
|
||||
const num_bytes = tree.tokenSlice(num_token);
|
||||
|
||||
switch (std.zig.parseNumberLiteral(num_bytes)) {
|
||||
|
|
@ -712,8 +712,8 @@ fn setBigIntLiteralNode(zg: *ZonGen, dest_node: Zoir.Node.Index, src_node: Ast.N
|
|||
|
||||
fn charLiteral(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !void {
|
||||
const tree = zg.tree;
|
||||
assert(tree.nodeTag(node) == .char_literal);
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
assert(node.tag(tree) == .char_literal);
|
||||
const main_token = node.mainToken(tree);
|
||||
const slice = tree.tokenSlice(main_token);
|
||||
switch (std.zig.parseCharLiteral(slice)) {
|
||||
.success => |codepoint| zg.setNode(dest_node, .{
|
||||
|
|
@ -727,8 +727,8 @@ fn charLiteral(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !v
|
|||
|
||||
fn identifier(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) !void {
|
||||
const tree = zg.tree;
|
||||
assert(tree.nodeTag(node) == .identifier);
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
assert(node.tag(tree) == .identifier);
|
||||
const main_token = node.mainToken(tree);
|
||||
const ident = tree.tokenSlice(main_token);
|
||||
|
||||
const tag: Zoir.Node.Repr.Tag = t: {
|
||||
|
|
|
|||
|
|
@ -75,11 +75,11 @@ pub const Fixups = struct {
|
|||
const Render = struct {
|
||||
gpa: Allocator,
|
||||
ais: *Ais,
|
||||
tree: Ast,
|
||||
tree: *const Ast,
|
||||
fixups: Fixups,
|
||||
};
|
||||
|
||||
pub fn renderTree(buffer: *std.ArrayList(u8), tree: Ast, fixups: Fixups) Error!void {
|
||||
pub fn renderTree(buffer: *std.ArrayList(u8), tree: *const Ast, fixups: Fixups) Error!void {
|
||||
assert(tree.errors.len == 0); // Cannot render an invalid tree.
|
||||
var auto_indenting_stream = Ais.init(buffer, indent_delta);
|
||||
defer auto_indenting_stream.deinit();
|
||||
|
|
@ -144,13 +144,13 @@ fn renderMember(
|
|||
const ais = r.ais;
|
||||
if (r.fixups.omit_nodes.contains(decl)) return;
|
||||
try renderDocComments(r, tree.firstToken(decl));
|
||||
switch (tree.nodeTag(decl)) {
|
||||
switch (decl.tag(tree)) {
|
||||
.fn_decl => {
|
||||
// Some examples:
|
||||
// pub extern "foo" fn ...
|
||||
// export fn ...
|
||||
const fn_proto, const body_node = tree.nodeData(decl).node_and_node;
|
||||
const fn_token = tree.nodeMainToken(fn_proto);
|
||||
const fn_proto, const body_node = decl.data(tree).node_and_node;
|
||||
const fn_token = fn_proto.mainToken(tree);
|
||||
// Go back to the first token we should render here.
|
||||
var i = fn_token;
|
||||
while (i > 0) {
|
||||
|
|
@ -174,18 +174,18 @@ fn renderMember(
|
|||
while (i < fn_token) : (i += 1) {
|
||||
try renderToken(r, i, .space);
|
||||
}
|
||||
switch (tree.nodeTag(fn_proto)) {
|
||||
switch (fn_proto.tag(tree)) {
|
||||
.fn_proto_one, .fn_proto => {
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const opt_callconv_expr = if (tree.nodeTag(fn_proto) == .fn_proto_one)
|
||||
const opt_callconv_expr = if (fn_proto.tag(tree) == .fn_proto_one)
|
||||
tree.fnProtoOne(&buf, fn_proto).ast.callconv_expr
|
||||
else
|
||||
tree.fnProto(fn_proto).ast.callconv_expr;
|
||||
|
||||
// Keep in sync with logic in `renderFnProto`. Search this file for the marker PROMOTE_CALLCONV_INLINE
|
||||
if (opt_callconv_expr.unwrap()) |callconv_expr| {
|
||||
if (tree.nodeTag(callconv_expr) == .enum_literal) {
|
||||
if (mem.eql(u8, "@\"inline\"", tree.tokenSlice(tree.nodeMainToken(callconv_expr)))) {
|
||||
if (callconv_expr.tag(tree) == .enum_literal) {
|
||||
if (mem.eql(u8, "@\"inline\"", tree.tokenSlice(callconv_expr.mainToken(tree)))) {
|
||||
try ais.writer().writeAll("inline ");
|
||||
}
|
||||
}
|
||||
|
|
@ -197,7 +197,7 @@ fn renderMember(
|
|||
try renderExpression(r, fn_proto, .space);
|
||||
if (r.fixups.gut_functions.contains(decl)) {
|
||||
try ais.pushIndent(.normal);
|
||||
const lbrace = tree.nodeMainToken(body_node);
|
||||
const lbrace = body_node.mainToken(tree);
|
||||
try renderToken(r, lbrace, .newline);
|
||||
try discardAllParams(r, fn_proto);
|
||||
try ais.writer().writeAll("@trap();");
|
||||
|
|
@ -206,12 +206,12 @@ fn renderMember(
|
|||
try renderToken(r, tree.lastToken(body_node), space); // rbrace
|
||||
} else if (r.fixups.unused_var_decls.count() != 0) {
|
||||
try ais.pushIndent(.normal);
|
||||
const lbrace = tree.nodeMainToken(body_node);
|
||||
const lbrace = body_node.mainToken(tree);
|
||||
try renderToken(r, lbrace, .newline);
|
||||
|
||||
var fn_proto_buf: [1]Ast.Node.Index = undefined;
|
||||
const full_fn_proto = tree.fullFnProto(&fn_proto_buf, fn_proto).?;
|
||||
var it = full_fn_proto.iterate(&tree);
|
||||
var it = full_fn_proto.iterate(tree);
|
||||
while (it.next()) |param| {
|
||||
const name_ident = param.name_token.?;
|
||||
assert(tree.tokenTag(name_ident) == .identifier);
|
||||
|
|
@ -236,7 +236,7 @@ fn renderMember(
|
|||
=> {
|
||||
// Extern function prototypes are parsed as these tags.
|
||||
// Go back to the first token we should render here.
|
||||
const fn_token = tree.nodeMainToken(decl);
|
||||
const fn_token = decl.mainToken(tree);
|
||||
var i = fn_token;
|
||||
while (i > 0) {
|
||||
i -= 1;
|
||||
|
|
@ -263,8 +263,8 @@ fn renderMember(
|
|||
},
|
||||
|
||||
.@"usingnamespace" => {
|
||||
const main_token = tree.nodeMainToken(decl);
|
||||
const expr = tree.nodeData(decl).node;
|
||||
const main_token = decl.mainToken(tree);
|
||||
const expr = decl.data(tree).node;
|
||||
if (tree.isTokenPrecededByTags(main_token, &.{.keyword_pub})) {
|
||||
try renderToken(r, main_token - 1, .space); // pub
|
||||
}
|
||||
|
|
@ -284,8 +284,8 @@ fn renderMember(
|
|||
},
|
||||
|
||||
.test_decl => {
|
||||
const test_token = tree.nodeMainToken(decl);
|
||||
const opt_name_token, const block_node = tree.nodeData(decl).opt_token_and_node;
|
||||
const test_token = decl.mainToken(tree);
|
||||
const opt_name_token, const block_node = decl.data(tree).opt_token_and_node;
|
||||
try renderToken(r, test_token, .space);
|
||||
if (opt_name_token.unwrap()) |name_token| {
|
||||
switch (tree.tokenTag(name_token)) {
|
||||
|
|
@ -329,9 +329,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
} else if (r.fixups.replace_nodes_with_node.get(node)) |replacement| {
|
||||
return renderExpression(r, replacement, space);
|
||||
}
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.identifier => {
|
||||
const token_index = tree.nodeMainToken(node);
|
||||
const token_index = node.mainToken(tree);
|
||||
return renderIdentifier(r, token_index, space, .preserve_when_shadowing);
|
||||
},
|
||||
|
||||
|
|
@ -340,12 +340,12 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
.unreachable_literal,
|
||||
.anyframe_literal,
|
||||
.string_literal,
|
||||
=> return renderToken(r, tree.nodeMainToken(node), space),
|
||||
=> return renderToken(r, node.mainToken(tree), space),
|
||||
|
||||
.multiline_string_literal => {
|
||||
try ais.maybeInsertNewline();
|
||||
|
||||
const first_tok, const last_tok = tree.nodeData(node).token_and_token;
|
||||
const first_tok, const last_tok = node.data(tree).token_and_token;
|
||||
for (first_tok..last_tok + 1) |i| {
|
||||
try renderToken(r, @intCast(i), .newline);
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.error_value => {
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
const main_token = node.mainToken(tree);
|
||||
try renderToken(r, main_token, .none);
|
||||
try renderToken(r, main_token + 1, .none);
|
||||
return renderIdentifier(r, main_token + 2, space, .eagerly_unquote);
|
||||
|
|
@ -389,8 +389,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.@"errdefer" => {
|
||||
const defer_token = tree.nodeMainToken(node);
|
||||
const maybe_payload_token, const expr = tree.nodeData(node).opt_token_and_node;
|
||||
const defer_token = node.mainToken(tree);
|
||||
const maybe_payload_token, const expr = node.data(tree).opt_token_and_node;
|
||||
|
||||
try renderToken(r, defer_token, .space);
|
||||
if (maybe_payload_token.unwrap()) |payload_token| {
|
||||
|
|
@ -406,15 +406,15 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
.@"nosuspend",
|
||||
.@"suspend",
|
||||
=> {
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
const item = tree.nodeData(node).node;
|
||||
const main_token = node.mainToken(tree);
|
||||
const item = node.data(tree).node;
|
||||
try renderToken(r, main_token, .space);
|
||||
return renderExpression(r, item, space);
|
||||
},
|
||||
|
||||
.@"catch" => {
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const main_token = node.mainToken(tree);
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
const fallback_first = tree.firstToken(rhs);
|
||||
|
||||
const same_line = tree.tokensOnSameLine(main_token, fallback_first);
|
||||
|
|
@ -437,7 +437,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.field_access => {
|
||||
const lhs, const name_token = tree.nodeData(node).node_and_token;
|
||||
const lhs, const name_token = node.data(tree).node_and_token;
|
||||
const dot_token = name_token - 1;
|
||||
|
||||
try ais.pushIndent(.field_access);
|
||||
|
|
@ -458,19 +458,19 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
.error_union,
|
||||
.switch_range,
|
||||
=> {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
try renderExpression(r, lhs, .none);
|
||||
try renderToken(r, tree.nodeMainToken(node), .none);
|
||||
try renderToken(r, node.mainToken(tree), .none);
|
||||
return renderExpression(r, rhs, space);
|
||||
},
|
||||
.for_range => {
|
||||
const start, const opt_end = tree.nodeData(node).node_and_opt_node;
|
||||
const start, const opt_end = node.data(tree).node_and_opt_node;
|
||||
try renderExpression(r, start, .none);
|
||||
if (opt_end.unwrap()) |end| {
|
||||
try renderToken(r, tree.nodeMainToken(node), .none);
|
||||
try renderToken(r, node.mainToken(tree), .none);
|
||||
return renderExpression(r, end, space);
|
||||
} else {
|
||||
return renderToken(r, tree.nodeMainToken(node), space);
|
||||
return renderToken(r, node.mainToken(tree), space);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -493,9 +493,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
.assign_mul_wrap,
|
||||
.assign_mul_sat,
|
||||
=> {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
try renderExpression(r, lhs, .space);
|
||||
const op_token = tree.nodeMainToken(node);
|
||||
const op_token = node.mainToken(tree);
|
||||
try ais.pushIndent(.after_equals);
|
||||
if (tree.tokensOnSameLine(op_token, op_token + 1)) {
|
||||
try renderToken(r, op_token, .space);
|
||||
|
|
@ -536,9 +536,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
.sub_sat,
|
||||
.@"orelse",
|
||||
=> {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
try renderExpression(r, lhs, .space);
|
||||
const op_token = tree.nodeMainToken(node);
|
||||
const op_token = node.mainToken(tree);
|
||||
try ais.pushIndent(.binop);
|
||||
if (tree.tokensOnSameLine(op_token, op_token + 1)) {
|
||||
try renderToken(r, op_token, .space);
|
||||
|
|
@ -557,7 +557,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
|
||||
for (full.ast.variables, 0..) |variable_node, i| {
|
||||
const variable_space: Space = if (i == full.ast.variables.len - 1) .space else .comma_space;
|
||||
switch (tree.nodeTag(variable_node)) {
|
||||
switch (variable_node.tag(tree)) {
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
|
|
@ -585,16 +585,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
.optional_type,
|
||||
.address_of,
|
||||
=> {
|
||||
try renderToken(r, tree.nodeMainToken(node), .none);
|
||||
return renderExpression(r, tree.nodeData(node).node, space);
|
||||
try renderToken(r, node.mainToken(tree), .none);
|
||||
return renderExpression(r, node.data(tree).node, space);
|
||||
},
|
||||
|
||||
.@"try",
|
||||
.@"resume",
|
||||
.@"await",
|
||||
=> {
|
||||
try renderToken(r, tree.nodeMainToken(node), .space);
|
||||
return renderExpression(r, tree.nodeData(node).node, space);
|
||||
try renderToken(r, node.mainToken(tree), .space);
|
||||
return renderExpression(r, node.data(tree).node, space);
|
||||
},
|
||||
|
||||
.array_type,
|
||||
|
|
@ -647,7 +647,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.array_access => {
|
||||
const lhs, const rhs = tree.nodeData(node).node_and_node;
|
||||
const lhs, const rhs = node.data(tree).node_and_node;
|
||||
const lbracket = tree.firstToken(rhs) - 1;
|
||||
const rbracket = tree.lastToken(rhs) + 1;
|
||||
const one_line = tree.tokensOnSameLine(lbracket, rbracket);
|
||||
|
|
@ -666,12 +666,12 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
=> return renderSlice(r, node, tree.fullSlice(node).?, space),
|
||||
|
||||
.deref => {
|
||||
try renderExpression(r, tree.nodeData(node).node, .none);
|
||||
return renderToken(r, tree.nodeMainToken(node), space);
|
||||
try renderExpression(r, node.data(tree).node, .none);
|
||||
return renderToken(r, node.mainToken(tree), space);
|
||||
},
|
||||
|
||||
.unwrap_optional => {
|
||||
const lhs, const question_mark = tree.nodeData(node).node_and_token;
|
||||
const lhs, const question_mark = node.data(tree).node_and_token;
|
||||
const dot_token = question_mark - 1;
|
||||
try renderExpression(r, lhs, .none);
|
||||
try renderToken(r, dot_token, .none);
|
||||
|
|
@ -679,8 +679,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.@"break", .@"continue" => {
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
const opt_label_token, const opt_target = tree.nodeData(node).opt_token_and_opt_node;
|
||||
const main_token = node.mainToken(tree);
|
||||
const opt_label_token, const opt_target = node.data(tree).opt_token_and_opt_node;
|
||||
if (opt_label_token == .none and opt_target == .none) {
|
||||
try renderToken(r, main_token, space); // break/continue
|
||||
} else if (opt_label_token == .none and opt_target != .none) {
|
||||
|
|
@ -703,18 +703,18 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.@"return" => {
|
||||
if (tree.nodeData(node).opt_node.unwrap()) |expr| {
|
||||
try renderToken(r, tree.nodeMainToken(node), .space);
|
||||
if (node.data(tree).opt_node.unwrap()) |expr| {
|
||||
try renderToken(r, node.mainToken(tree), .space);
|
||||
try renderExpression(r, expr, space);
|
||||
} else {
|
||||
try renderToken(r, tree.nodeMainToken(node), space);
|
||||
try renderToken(r, node.mainToken(tree), space);
|
||||
}
|
||||
},
|
||||
|
||||
.grouped_expression => {
|
||||
const expr, const rparen = tree.nodeData(node).node_and_token;
|
||||
const expr, const rparen = node.data(tree).node_and_token;
|
||||
try ais.pushIndent(.normal);
|
||||
try renderToken(r, tree.nodeMainToken(node), .none); // lparen
|
||||
try renderToken(r, node.mainToken(tree), .none); // lparen
|
||||
try renderExpression(r, expr, .none);
|
||||
ais.popIndent();
|
||||
return renderToken(r, rparen, space);
|
||||
|
|
@ -738,8 +738,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.error_set_decl => {
|
||||
const error_token = tree.nodeMainToken(node);
|
||||
const lbrace, const rbrace = tree.nodeData(node).token_and_token;
|
||||
const error_token = node.mainToken(tree);
|
||||
const lbrace, const rbrace = node.data(tree).token_and_token;
|
||||
|
||||
try renderToken(r, error_token, .none);
|
||||
|
||||
|
|
@ -796,7 +796,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
=> {
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const params = tree.builtinCallParams(&buf, node).?;
|
||||
return renderBuiltinCall(r, tree.nodeMainToken(node), params, space);
|
||||
return renderBuiltinCall(r, node.mainToken(tree), params, space);
|
||||
},
|
||||
|
||||
.fn_proto_simple,
|
||||
|
|
@ -809,10 +809,10 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
},
|
||||
|
||||
.anyframe_type => {
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
const main_token = node.mainToken(tree);
|
||||
try renderToken(r, main_token, .none); // anyframe
|
||||
try renderToken(r, main_token + 1, .none); // ->
|
||||
return renderExpression(r, tree.nodeData(node).token_and_node[1], space);
|
||||
return renderExpression(r, node.data(tree).token_and_node[1], space);
|
||||
},
|
||||
|
||||
.@"switch",
|
||||
|
|
@ -869,8 +869,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
|||
=> return renderAsm(r, tree.fullAsm(node).?, space),
|
||||
|
||||
.enum_literal => {
|
||||
try renderToken(r, tree.nodeMainToken(node) - 1, .none); // .
|
||||
return renderIdentifier(r, tree.nodeMainToken(node), space, .eagerly_unquote); // name
|
||||
try renderToken(r, node.mainToken(tree) - 1, .none); // .
|
||||
return renderIdentifier(r, node.mainToken(tree), space, .eagerly_unquote); // name
|
||||
},
|
||||
|
||||
.fn_decl => unreachable,
|
||||
|
|
@ -932,7 +932,7 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi
|
|||
// this pointer type and rely on the child to render our asterisk
|
||||
// as well when it renders the ** token.
|
||||
if (tree.tokenTag(main_token) == .asterisk_asterisk and
|
||||
main_token == tree.nodeMainToken(ptr_type.ast.child_type))
|
||||
main_token == ptr_type.ast.child_type.mainToken(tree))
|
||||
{
|
||||
return renderExpression(r, ptr_type.ast.child_type, space);
|
||||
}
|
||||
|
|
@ -1017,8 +1017,8 @@ fn renderSlice(
|
|||
space: Space,
|
||||
) Error!void {
|
||||
const tree = r.tree;
|
||||
const after_start_space_bool = nodeCausesSliceOpSpace(tree.nodeTag(slice.ast.start)) or
|
||||
if (slice.ast.end.unwrap()) |end| nodeCausesSliceOpSpace(tree.nodeTag(end)) else false;
|
||||
const after_start_space_bool = nodeCausesSliceOpSpace(slice.ast.start.tag(tree)) or
|
||||
if (slice.ast.end.unwrap()) |end| nodeCausesSliceOpSpace(end.tag(tree)) else false;
|
||||
const after_start_space = if (after_start_space_bool) Space.space else Space.none;
|
||||
const after_dots_space = if (slice.ast.end != .none)
|
||||
after_start_space
|
||||
|
|
@ -1050,8 +1050,8 @@ fn renderAsmOutput(
|
|||
space: Space,
|
||||
) Error!void {
|
||||
const tree = r.tree;
|
||||
assert(tree.nodeTag(asm_output) == .asm_output);
|
||||
const symbolic_name = tree.nodeMainToken(asm_output);
|
||||
assert(asm_output.tag(tree) == .asm_output);
|
||||
const symbolic_name = asm_output.mainToken(tree);
|
||||
|
||||
try renderToken(r, symbolic_name - 1, .none); // lbracket
|
||||
try renderIdentifier(r, symbolic_name, .none, .eagerly_unquote); // ident
|
||||
|
|
@ -1060,7 +1060,7 @@ fn renderAsmOutput(
|
|||
try renderToken(r, symbolic_name + 3, .none); // lparen
|
||||
|
||||
if (tree.tokenTag(symbolic_name + 4) == .arrow) {
|
||||
const type_expr, const rparen = tree.nodeData(asm_output).opt_node_and_token;
|
||||
const type_expr, const rparen = asm_output.data(tree).opt_node_and_token;
|
||||
try renderToken(r, symbolic_name + 4, .space); // ->
|
||||
try renderExpression(r, type_expr.unwrap().?, Space.none);
|
||||
return renderToken(r, rparen, space);
|
||||
|
|
@ -1076,9 +1076,9 @@ fn renderAsmInput(
|
|||
space: Space,
|
||||
) Error!void {
|
||||
const tree = r.tree;
|
||||
assert(tree.nodeTag(asm_input) == .asm_input);
|
||||
const symbolic_name = tree.nodeMainToken(asm_input);
|
||||
const expr, const rparen = tree.nodeData(asm_input).node_and_token;
|
||||
assert(asm_input.tag(tree) == .asm_input);
|
||||
const symbolic_name = asm_input.mainToken(tree);
|
||||
const expr, const rparen = asm_input.data(tree).node_and_token;
|
||||
|
||||
try renderToken(r, symbolic_name - 1, .none); // lbracket
|
||||
try renderIdentifier(r, symbolic_name, .none, .eagerly_unquote); // ident
|
||||
|
|
@ -1318,7 +1318,7 @@ fn renderThenElse(
|
|||
) Error!void {
|
||||
const tree = r.tree;
|
||||
const ais = r.ais;
|
||||
const then_expr_is_block = nodeIsBlock(tree.nodeTag(then_expr));
|
||||
const then_expr_is_block = nodeIsBlock(then_expr.tag(tree));
|
||||
const indent_then_expr = !then_expr_is_block and
|
||||
!tree.tokensOnSameLine(last_prefix_token, tree.firstToken(then_expr));
|
||||
|
||||
|
|
@ -1353,8 +1353,8 @@ fn renderThenElse(
|
|||
}
|
||||
|
||||
const indent_else_expr = indent_then_expr and
|
||||
!nodeIsBlock(tree.nodeTag(else_expr)) and
|
||||
!nodeIsIfForWhileSwitch(tree.nodeTag(else_expr));
|
||||
!nodeIsBlock(else_expr.tag(tree)) and
|
||||
!nodeIsIfForWhileSwitch(else_expr.tag(tree));
|
||||
if (indent_else_expr) {
|
||||
try ais.pushIndent(.normal);
|
||||
try renderToken(r, last_else_token, .newline);
|
||||
|
|
@ -1449,7 +1449,7 @@ fn renderContainerField(
|
|||
const tree = r.tree;
|
||||
const ais = r.ais;
|
||||
var field = field_param;
|
||||
if (container != .tuple) field.convertToNonTupleLike(&tree);
|
||||
if (container != .tuple) field.convertToNonTupleLike(tree);
|
||||
const quote: QuoteBehavior = switch (container) {
|
||||
.@"enum" => .eagerly_unquote_except_underscore,
|
||||
.tuple, .other => .eagerly_unquote,
|
||||
|
|
@ -1569,7 +1569,7 @@ fn renderBuiltinCall(
|
|||
const slice = tree.tokenSlice(builtin_token);
|
||||
if (mem.eql(u8, slice, "@import")) f: {
|
||||
const param = params[0];
|
||||
const str_lit_token = tree.nodeMainToken(param);
|
||||
const str_lit_token = param.mainToken(tree);
|
||||
assert(tree.tokenTag(str_lit_token) == .string_literal);
|
||||
const token_bytes = tree.tokenSlice(str_lit_token);
|
||||
const imported_string = std.zig.string_literal.parseAlloc(r.gpa, token_bytes) catch |err| switch (err) {
|
||||
|
|
@ -1829,7 +1829,7 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi
|
|||
|
||||
if (fn_proto.ast.callconv_expr.unwrap()) |callconv_expr| {
|
||||
// Keep in sync with logic in `renderMember`. Search this file for the marker PROMOTE_CALLCONV_INLINE
|
||||
const is_callconv_inline = mem.eql(u8, "@\"inline\"", tree.tokenSlice(tree.nodeMainToken(callconv_expr)));
|
||||
const is_callconv_inline = mem.eql(u8, "@\"inline\"", tree.tokenSlice(callconv_expr.mainToken(tree)));
|
||||
const is_declaration = fn_proto.name_token != null;
|
||||
if (!(is_declaration and is_callconv_inline)) {
|
||||
const callconv_lparen = tree.firstToken(callconv_expr) - 1;
|
||||
|
|
@ -1882,7 +1882,7 @@ fn renderSwitchCase(
|
|||
}
|
||||
|
||||
// Render the arrow and everything after it
|
||||
const pre_target_space = if (tree.nodeTag(switch_case.ast.target_expr) == .multiline_string_literal)
|
||||
const pre_target_space = if (switch_case.ast.target_expr.tag(tree) == .multiline_string_literal)
|
||||
// Newline gets inserted when rendering the target expr.
|
||||
Space.none
|
||||
else
|
||||
|
|
@ -1917,7 +1917,7 @@ fn renderBlock(
|
|||
) Error!void {
|
||||
const tree = r.tree;
|
||||
const ais = r.ais;
|
||||
const lbrace = tree.nodeMainToken(block_node);
|
||||
const lbrace = block_node.mainToken(tree);
|
||||
|
||||
if (tree.isTokenPrecededByTags(lbrace, &.{ .identifier, .colon })) {
|
||||
try renderIdentifier(r, lbrace - 2, .none, .eagerly_unquote); // identifier
|
||||
|
|
@ -1946,7 +1946,7 @@ fn finishRenderBlock(
|
|||
if (i != 0) try renderExtraNewline(r, stmt);
|
||||
if (r.fixups.omit_nodes.contains(stmt)) continue;
|
||||
try ais.pushSpace(.semicolon);
|
||||
switch (tree.nodeTag(stmt)) {
|
||||
switch (stmt.tag(tree)) {
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
|
|
@ -1996,7 +1996,7 @@ fn renderStructInit(
|
|||
// Don't output a space after the = if expression is a multiline string,
|
||||
// since then it will start on the next line.
|
||||
const field_node = struct_init.ast.fields[0];
|
||||
const expr = tree.nodeTag(field_node);
|
||||
const expr = field_node.tag(tree);
|
||||
var space_after_equal: Space = if (expr == .multiline_string_literal) .none else .space;
|
||||
try renderToken(r, struct_init.ast.lbrace + 3, space_after_equal); // =
|
||||
|
||||
|
|
@ -2009,7 +2009,7 @@ fn renderStructInit(
|
|||
try renderExtraNewlineToken(r, init_token - 3);
|
||||
try renderToken(r, init_token - 3, .none); // .
|
||||
try renderIdentifier(r, init_token - 2, .space, .eagerly_unquote); // name
|
||||
space_after_equal = if (tree.nodeTag(field_init) == .multiline_string_literal) .none else .space;
|
||||
space_after_equal = if (field_init.tag(tree) == .multiline_string_literal) .none else .space;
|
||||
try renderToken(r, init_token - 1, space_after_equal); // =
|
||||
|
||||
try ais.pushSpace(.comma);
|
||||
|
|
@ -2361,7 +2361,7 @@ fn renderContainerDecl(
|
|||
}
|
||||
for (container_decl.ast.members, 0..) |member, i| {
|
||||
if (i != 0) try renderExtraNewline(r, member);
|
||||
switch (tree.nodeTag(member)) {
|
||||
switch (member.tag(tree)) {
|
||||
// For container fields, ensure a trailing comma is added if necessary.
|
||||
.container_field_init,
|
||||
.container_field_align,
|
||||
|
|
@ -2919,7 +2919,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void {
|
|||
/// `start_token` to `end_token`. This is used to determine if e.g. a
|
||||
/// fn_proto should be wrapped and have a trailing comma inserted even if
|
||||
/// there is none in the source.
|
||||
fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
|
||||
fn hasComment(tree: *const Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
|
||||
for (start_token..end_token) |i| {
|
||||
const token: Ast.TokenIndex = @intCast(i);
|
||||
const start = tree.tokenStart(token) + tree.tokenSlice(token).len;
|
||||
|
|
@ -2932,7 +2932,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
|
|||
|
||||
/// Returns true if there exists a multiline string literal between the start
|
||||
/// of token `start_token` and the start of token `end_token`.
|
||||
fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
|
||||
fn hasMultilineString(tree: *const Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
|
||||
return std.mem.indexOfScalar(
|
||||
Token.Tag,
|
||||
tree.tokens.items(.tag)[start_token..end_token],
|
||||
|
|
@ -3084,7 +3084,7 @@ fn renderContainerDocComments(r: *Render, start_token: Ast.TokenIndex) Error!voi
|
|||
}
|
||||
|
||||
fn discardAllParams(r: *Render, fn_proto_node: Ast.Node.Index) Error!void {
|
||||
const tree = &r.tree;
|
||||
const tree = r.tree;
|
||||
const ais = r.ais;
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const fn_proto = tree.fullFnProto(&buf, fn_proto_node).?;
|
||||
|
|
@ -3094,12 +3094,12 @@ fn discardAllParams(r: *Render, fn_proto_node: Ast.Node.Index) Error!void {
|
|||
assert(tree.tokenTag(name_ident) == .identifier);
|
||||
const w = ais.writer();
|
||||
try w.writeAll("_ = ");
|
||||
try w.writeAll(tokenSliceForRender(r.tree, name_ident));
|
||||
try w.writeAll(tokenSliceForRender(tree, name_ident));
|
||||
try w.writeAll(";\n");
|
||||
}
|
||||
}
|
||||
|
||||
fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
|
||||
fn tokenSliceForRender(tree: *const Ast, token_index: Ast.TokenIndex) []const u8 {
|
||||
var ret = tree.tokenSlice(token_index);
|
||||
switch (tree.tokenTag(token_index)) {
|
||||
.container_doc_comment, .doc_comment => {
|
||||
|
|
@ -3110,7 +3110,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
|
|||
return ret;
|
||||
}
|
||||
|
||||
fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool {
|
||||
fn hasSameLineComment(tree: *const Ast, token_index: Ast.TokenIndex) bool {
|
||||
const between_source = tree.source[tree.tokenStart(token_index)..tree.tokenStart(token_index + 1)];
|
||||
for (between_source) |byte| switch (byte) {
|
||||
'\n' => return false,
|
||||
|
|
@ -3122,7 +3122,7 @@ fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool {
|
|||
|
||||
/// Returns `true` if and only if there are any tokens or line comments between
|
||||
/// start_token and end_token.
|
||||
fn anythingBetween(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
|
||||
fn anythingBetween(tree: *const Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
|
||||
if (start_token + 1 != end_token) return true;
|
||||
const between_source = tree.source[tree.tokenStart(start_token)..tree.tokenStart(start_token + 1)];
|
||||
for (between_source) |byte| switch (byte) {
|
||||
|
|
@ -3217,7 +3217,7 @@ fn nodeCausesSliceOpSpace(tag: Ast.Node.Tag) bool {
|
|||
}
|
||||
|
||||
// Returns the number of nodes in `exprs` that are on the same line as `rtoken`.
|
||||
fn rowSize(tree: Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usize {
|
||||
fn rowSize(tree: *const Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usize {
|
||||
const first_token = tree.firstToken(exprs[0]);
|
||||
if (tree.tokensOnSameLine(first_token, rtoken)) {
|
||||
const maybe_comma = rtoken - 1;
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ pub const Error = union(enum) {
|
|||
return location;
|
||||
} else {
|
||||
const ast_node: Ast.Node.Index = @enumFromInt(node_or_offset);
|
||||
const token = ast.nodeMainToken(ast_node);
|
||||
const token = ast_node.mainToken(ast);
|
||||
return ast.tokenLocation(0, token);
|
||||
}
|
||||
}
|
||||
|
|
@ -644,7 +644,7 @@ const Parser = struct {
|
|||
switch (try ZonGen.parseStrLit(self.ast, ast_node, buf.writer(self.gpa))) {
|
||||
.success => {},
|
||||
.failure => |err| {
|
||||
const token = self.ast.nodeMainToken(ast_node);
|
||||
const token = ast_node.mainToken(self.ast);
|
||||
const raw_string = self.ast.tokenSlice(token);
|
||||
return self.failTokenFmt(token, @intCast(err.offset()), "{s}", .{err.fmt(raw_string)});
|
||||
},
|
||||
|
|
@ -1017,7 +1017,7 @@ const Parser = struct {
|
|||
args: anytype,
|
||||
) error{ OutOfMemory, ParseZon } {
|
||||
@branchHint(.cold);
|
||||
const token = self.ast.nodeMainToken(node.getAstNode(self.zoir));
|
||||
const token = node.getAstNode(self.zoir).mainToken(self.ast);
|
||||
return self.failTokenFmt(token, 0, fmt, args);
|
||||
}
|
||||
|
||||
|
|
@ -1036,7 +1036,7 @@ const Parser = struct {
|
|||
message: []const u8,
|
||||
) error{ParseZon} {
|
||||
@branchHint(.cold);
|
||||
const token = self.ast.nodeMainToken(node.getAstNode(self.zoir));
|
||||
const token = node.getAstNode(self.zoir).mainToken(self.ast);
|
||||
return self.failToken(.{
|
||||
.token = token,
|
||||
.offset = 0,
|
||||
|
|
@ -1069,7 +1069,7 @@ const Parser = struct {
|
|||
const struct_init = self.ast.fullStructInit(&buf, node.getAstNode(self.zoir)).?;
|
||||
const field_node = struct_init.ast.fields[f];
|
||||
break :b self.ast.firstToken(field_node) - 2;
|
||||
} else self.ast.nodeMainToken(node.getAstNode(self.zoir));
|
||||
} else node.getAstNode(self.zoir).mainToken(self.ast);
|
||||
switch (@typeInfo(T)) {
|
||||
inline .@"struct", .@"union", .@"enum" => |info| {
|
||||
const note: Error.TypeCheckFailure.Note = if (info.fields.len == 0) b: {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ pub const ParseOptions = struct {
|
|||
pub const Error = Allocator.Error;
|
||||
|
||||
pub fn parse(gpa: Allocator, ast: Ast, options: ParseOptions) Error!Manifest {
|
||||
const main_node_index = ast.nodeData(.root).node;
|
||||
const main_node_index = Ast.Node.Index.root.data(&ast).node;
|
||||
|
||||
var arena_instance = std.heap.ArenaAllocator.init(gpa);
|
||||
errdefer arena_instance.deinit();
|
||||
|
|
@ -158,8 +158,8 @@ const Parse = struct {
|
|||
const InnerError = error{ ParseFailure, OutOfMemory };
|
||||
|
||||
fn parseRoot(p: *Parse, node: Ast.Node.Index) !void {
|
||||
const ast = p.ast;
|
||||
const main_token = ast.nodeMainToken(node);
|
||||
const ast = &p.ast;
|
||||
const main_token = node.mainToken(ast);
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const struct_init = ast.fullStructInit(&buf, node) orelse {
|
||||
|
|
@ -192,17 +192,17 @@ const Parse = struct {
|
|||
p.version_node = field_init;
|
||||
const version_text = try parseString(p, field_init);
|
||||
if (version_text.len > max_version_len) {
|
||||
try appendError(p, ast.nodeMainToken(field_init), "version string length {d} exceeds maximum of {d}", .{ version_text.len, max_version_len });
|
||||
try appendError(p, field_init.mainToken(ast), "version string length {d} exceeds maximum of {d}", .{ version_text.len, max_version_len });
|
||||
}
|
||||
p.version = std.SemanticVersion.parse(version_text) catch |err| v: {
|
||||
try appendError(p, ast.nodeMainToken(field_init), "unable to parse semantic version: {s}", .{@errorName(err)});
|
||||
try appendError(p, field_init.mainToken(ast), "unable to parse semantic version: {s}", .{@errorName(err)});
|
||||
break :v undefined;
|
||||
};
|
||||
have_version = true;
|
||||
} else if (mem.eql(u8, field_name, "minimum_zig_version")) {
|
||||
const version_text = try parseString(p, field_init);
|
||||
p.minimum_zig_version = std.SemanticVersion.parse(version_text) catch |err| v: {
|
||||
try appendError(p, ast.nodeMainToken(field_init), "unable to parse semantic version: {s}", .{@errorName(err)});
|
||||
try appendError(p, field_init.mainToken(ast), "unable to parse semantic version: {s}", .{@errorName(err)});
|
||||
break :v null;
|
||||
};
|
||||
} else {
|
||||
|
|
@ -244,11 +244,11 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseDependencies(p: *Parse, node: Ast.Node.Index) !void {
|
||||
const ast = p.ast;
|
||||
const ast = &p.ast;
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const struct_init = ast.fullStructInit(&buf, node) orelse {
|
||||
const tok = ast.nodeMainToken(node);
|
||||
const tok = node.mainToken(ast);
|
||||
return fail(p, tok, "expected dependencies expression to be a struct", .{});
|
||||
};
|
||||
|
||||
|
|
@ -261,11 +261,11 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseDependency(p: *Parse, node: Ast.Node.Index) !Dependency {
|
||||
const ast = p.ast;
|
||||
const ast = &p.ast;
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const struct_init = ast.fullStructInit(&buf, node) orelse {
|
||||
const tok = ast.nodeMainToken(node);
|
||||
const tok = node.mainToken(ast);
|
||||
return fail(p, tok, "expected dependency expression to be a struct", .{});
|
||||
};
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ const Parse = struct {
|
|||
// that is desirable on a per-field basis.
|
||||
if (mem.eql(u8, field_name, "url")) {
|
||||
if (has_location) {
|
||||
return fail(p, ast.nodeMainToken(field_init), "dependency should specify only one of 'url' and 'path' fields.", .{});
|
||||
return fail(p, field_init.mainToken(ast), "dependency should specify only one of 'url' and 'path' fields.", .{});
|
||||
}
|
||||
dep.location = .{
|
||||
.url = parseString(p, field_init) catch |err| switch (err) {
|
||||
|
|
@ -300,11 +300,11 @@ const Parse = struct {
|
|||
},
|
||||
};
|
||||
has_location = true;
|
||||
dep.location_tok = ast.nodeMainToken(field_init);
|
||||
dep.location_tok = field_init.mainToken(ast);
|
||||
dep.location_node = field_init;
|
||||
} else if (mem.eql(u8, field_name, "path")) {
|
||||
if (has_location) {
|
||||
return fail(p, ast.nodeMainToken(field_init), "dependency should specify only one of 'url' and 'path' fields.", .{});
|
||||
return fail(p, field_init.mainToken(ast), "dependency should specify only one of 'url' and 'path' fields.", .{});
|
||||
}
|
||||
dep.location = .{
|
||||
.path = parseString(p, field_init) catch |err| switch (err) {
|
||||
|
|
@ -313,14 +313,14 @@ const Parse = struct {
|
|||
},
|
||||
};
|
||||
has_location = true;
|
||||
dep.location_tok = ast.nodeMainToken(field_init);
|
||||
dep.location_tok = field_init.mainToken(ast);
|
||||
dep.location_node = field_init;
|
||||
} else if (mem.eql(u8, field_name, "hash")) {
|
||||
dep.hash = parseHash(p, field_init) catch |err| switch (err) {
|
||||
error.ParseFailure => continue,
|
||||
else => |e| return e,
|
||||
};
|
||||
dep.hash_tok = .fromToken(ast.nodeMainToken(field_init));
|
||||
dep.hash_tok = .fromToken(field_init.mainToken(ast));
|
||||
dep.hash_node = field_init.toOptional();
|
||||
} else if (mem.eql(u8, field_name, "lazy")) {
|
||||
dep.lazy = parseBool(p, field_init) catch |err| switch (err) {
|
||||
|
|
@ -334,18 +334,18 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
if (!has_location) {
|
||||
try appendError(p, ast.nodeMainToken(node), "dependency requires location field, one of 'url' or 'path'.", .{});
|
||||
try appendError(p, node.mainToken(ast), "dependency requires location field, one of 'url' or 'path'.", .{});
|
||||
}
|
||||
|
||||
return dep;
|
||||
}
|
||||
|
||||
fn parseIncludedPaths(p: *Parse, node: Ast.Node.Index) !void {
|
||||
const ast = p.ast;
|
||||
const ast = &p.ast;
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const array_init = ast.fullArrayInit(&buf, node) orelse {
|
||||
const tok = ast.nodeMainToken(node);
|
||||
const tok = node.mainToken(ast);
|
||||
return fail(p, tok, "expected paths expression to be a list of strings", .{});
|
||||
};
|
||||
|
||||
|
|
@ -359,11 +359,11 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseBool(p: *Parse, node: Ast.Node.Index) !bool {
|
||||
const ast = p.ast;
|
||||
if (ast.nodeTag(node) != .identifier) {
|
||||
return fail(p, ast.nodeMainToken(node), "expected identifier", .{});
|
||||
const ast = &p.ast;
|
||||
if (node.tag(ast) != .identifier) {
|
||||
return fail(p, node.mainToken(ast), "expected identifier", .{});
|
||||
}
|
||||
const ident_token = ast.nodeMainToken(node);
|
||||
const ident_token = node.mainToken(ast);
|
||||
const token_bytes = ast.tokenSlice(ident_token);
|
||||
if (mem.eql(u8, token_bytes, "true")) {
|
||||
return true;
|
||||
|
|
@ -375,9 +375,9 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseFingerprint(p: *Parse, node: Ast.Node.Index) !Package.Fingerprint {
|
||||
const ast = p.ast;
|
||||
const main_token = ast.nodeMainToken(node);
|
||||
if (ast.nodeTag(node) != .number_literal) {
|
||||
const ast = &p.ast;
|
||||
const main_token = node.mainToken(ast);
|
||||
if (node.tag(ast) != .number_literal) {
|
||||
return fail(p, main_token, "expected integer literal", .{});
|
||||
}
|
||||
const token_bytes = ast.tokenSlice(main_token);
|
||||
|
|
@ -392,10 +392,10 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseName(p: *Parse, node: Ast.Node.Index) ![]const u8 {
|
||||
const ast = p.ast;
|
||||
const main_token = ast.nodeMainToken(node);
|
||||
const ast = &p.ast;
|
||||
const main_token = node.mainToken(ast);
|
||||
|
||||
if (p.allow_name_string and ast.nodeTag(node) == .string_literal) {
|
||||
if (p.allow_name_string and node.tag(ast) == .string_literal) {
|
||||
const name = try parseString(p, node);
|
||||
if (!std.zig.isValidId(name))
|
||||
return fail(p, main_token, "name must be a valid bare zig identifier (hint: switch from string to enum literal)", .{});
|
||||
|
|
@ -408,7 +408,7 @@ const Parse = struct {
|
|||
return name;
|
||||
}
|
||||
|
||||
if (ast.nodeTag(node) != .enum_literal)
|
||||
if (node.tag(ast) != .enum_literal)
|
||||
return fail(p, main_token, "expected enum literal", .{});
|
||||
|
||||
const ident_name = ast.tokenSlice(main_token);
|
||||
|
|
@ -424,11 +424,11 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseString(p: *Parse, node: Ast.Node.Index) ![]const u8 {
|
||||
const ast = p.ast;
|
||||
if (ast.nodeTag(node) != .string_literal) {
|
||||
return fail(p, ast.nodeMainToken(node), "expected string literal", .{});
|
||||
const ast = &p.ast;
|
||||
if (node.tag(ast) != .string_literal) {
|
||||
return fail(p, node.mainToken(ast), "expected string literal", .{});
|
||||
}
|
||||
const str_lit_token = ast.nodeMainToken(node);
|
||||
const str_lit_token = node.mainToken(ast);
|
||||
const token_bytes = ast.tokenSlice(str_lit_token);
|
||||
p.buf.clearRetainingCapacity();
|
||||
try parseStrLit(p, str_lit_token, &p.buf, token_bytes, 0);
|
||||
|
|
@ -437,8 +437,8 @@ const Parse = struct {
|
|||
}
|
||||
|
||||
fn parseHash(p: *Parse, node: Ast.Node.Index) ![]const u8 {
|
||||
const ast = p.ast;
|
||||
const tok = ast.nodeMainToken(node);
|
||||
const ast = &p.ast;
|
||||
const tok = node.mainToken(ast);
|
||||
const h = try parseString(p, node);
|
||||
|
||||
if (h.len > Package.Hash.max_len) {
|
||||
|
|
@ -450,7 +450,7 @@ const Parse = struct {
|
|||
|
||||
/// TODO: try to DRY this with AstGen.identifierTokenString
|
||||
fn identifierTokenString(p: *Parse, token: Ast.TokenIndex) InnerError![]const u8 {
|
||||
const ast = p.ast;
|
||||
const ast = &p.ast;
|
||||
assert(ast.tokenTag(token) == .identifier);
|
||||
const ident_name = ast.tokenSlice(token);
|
||||
if (!mem.startsWith(u8, ident_name, "@")) {
|
||||
|
|
|
|||
|
|
@ -17298,7 +17298,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
|
|||
break :name null;
|
||||
};
|
||||
const node = src_node.toAbsolute(src_base_node);
|
||||
const token = tree.nodeMainToken(node);
|
||||
const token = node.mainToken(tree);
|
||||
break :name tree.tokenSlice(token);
|
||||
};
|
||||
|
||||
|
|
@ -17326,7 +17326,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
|
|||
break :name null;
|
||||
};
|
||||
const node = src_node.toAbsolute(src_base_node);
|
||||
const token = tree.nodeMainToken(node);
|
||||
const token = node.mainToken(tree);
|
||||
break :name tree.tokenSlice(token);
|
||||
};
|
||||
|
||||
|
|
|
|||
102
src/Zcu.zig
102
src/Zcu.zig
|
|
@ -1143,7 +1143,7 @@ pub const SrcLoc = struct {
|
|||
.node_offset_main_token => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
const main_token = tree.nodeMainToken(node);
|
||||
const main_token = node.mainToken(tree);
|
||||
return tree.tokensToSpan(main_token, main_token, main_token);
|
||||
},
|
||||
.node_offset_bin_op => |node_off| {
|
||||
|
|
@ -1157,20 +1157,20 @@ pub const SrcLoc = struct {
|
|||
return tree.tokensToSpan(
|
||||
tree.firstToken(node) - 3,
|
||||
tree.lastToken(node),
|
||||
tree.nodeMainToken(node) - 2,
|
||||
node.mainToken(tree) - 2,
|
||||
);
|
||||
},
|
||||
.node_offset_var_decl_ty => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
const full = switch (tree.nodeTag(node)) {
|
||||
const full = switch (node.tag(tree)) {
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.simple_var_decl,
|
||||
.aligned_var_decl,
|
||||
=> tree.fullVarDecl(node).?,
|
||||
.@"usingnamespace" => {
|
||||
return tree.nodeToSpan(tree.nodeData(node).node);
|
||||
return tree.nodeToSpan(node.data(tree).node);
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
|
|
@ -1221,7 +1221,7 @@ pub const SrcLoc = struct {
|
|||
.node_offset_var_decl_init => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
const init_node = switch (tree.nodeTag(node)) {
|
||||
const init_node = switch (node.tag(tree)) {
|
||||
.global_var_decl,
|
||||
.local_var_decl,
|
||||
.aligned_var_decl,
|
||||
|
|
@ -1244,16 +1244,16 @@ pub const SrcLoc = struct {
|
|||
|
||||
var node = node_off.toAbsolute(src_loc.base_node);
|
||||
while (true) {
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.builtin_call_two, .builtin_call_two_comma => {},
|
||||
else => break,
|
||||
}
|
||||
|
||||
const first_arg, const second_arg = tree.nodeData(node).opt_node_and_opt_node;
|
||||
const first_arg, const second_arg = node.data(tree).opt_node_and_opt_node;
|
||||
if (first_arg == .none) break; // 0 args
|
||||
if (second_arg != .none) break; // 2 args
|
||||
|
||||
const builtin_token = tree.nodeMainToken(node);
|
||||
const builtin_token = node.mainToken(tree);
|
||||
const builtin_name = tree.tokenSlice(builtin_token);
|
||||
const info = BuiltinFn.list.get(builtin_name) orelse break;
|
||||
|
||||
|
|
@ -1275,7 +1275,7 @@ pub const SrcLoc = struct {
|
|||
.node_offset_array_access_index => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
return tree.nodeToSpan(tree.nodeData(node).node_and_node[1]);
|
||||
return tree.nodeToSpan(node.data(tree).node_and_node[1]);
|
||||
},
|
||||
.node_offset_slice_ptr,
|
||||
.node_offset_slice_start,
|
||||
|
|
@ -1305,8 +1305,8 @@ pub const SrcLoc = struct {
|
|||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
var buf: [1]Ast.Node.Index = undefined;
|
||||
const tok_index = switch (tree.nodeTag(node)) {
|
||||
.field_access => tree.nodeData(node).node_and_token[1],
|
||||
const tok_index = switch (node.tag(tree)) {
|
||||
.field_access => node.data(tree).node_and_token[1],
|
||||
.call_one,
|
||||
.call_one_comma,
|
||||
.async_call_one,
|
||||
|
|
@ -1349,13 +1349,13 @@ pub const SrcLoc = struct {
|
|||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
const full = tree.fullAsm(node).?;
|
||||
const asm_output = full.outputs[0];
|
||||
return tree.nodeToSpan(tree.nodeData(asm_output).opt_node_and_token[0].unwrap().?);
|
||||
return tree.nodeToSpan(asm_output.data(tree).opt_node_and_token[0].unwrap().?);
|
||||
},
|
||||
|
||||
.node_offset_if_cond => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
const src_node = switch (tree.nodeTag(node)) {
|
||||
const src_node = switch (node.tag(tree)) {
|
||||
.if_simple,
|
||||
.@"if",
|
||||
=> tree.fullIf(node).?.ast.cond_expr,
|
||||
|
|
@ -1433,9 +1433,9 @@ pub const SrcLoc = struct {
|
|||
const node = call_arg.call_node_offset.toAbsolute(src_loc.base_node);
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
const call_full = tree.fullCall(buf[0..1], node) orelse {
|
||||
assert(tree.nodeTag(node) == .builtin_call);
|
||||
const call_args_node: Ast.Node.Index = @enumFromInt(tree.extra_data[@intFromEnum(tree.nodeData(node).extra_range.end) - 1]);
|
||||
switch (tree.nodeTag(call_args_node)) {
|
||||
assert(node.tag(tree) == .builtin_call);
|
||||
const call_args_node: Ast.Node.Index = @enumFromInt(tree.extra_data[@intFromEnum(node.data(tree).extra_range.end) - 1]);
|
||||
switch (call_args_node.tag(tree)) {
|
||||
.array_init_one,
|
||||
.array_init_one_comma,
|
||||
.array_init_dot_two,
|
||||
|
|
@ -1496,23 +1496,23 @@ pub const SrcLoc = struct {
|
|||
.node_offset_bin_lhs => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
return tree.nodeToSpan(tree.nodeData(node).node_and_node[0]);
|
||||
return tree.nodeToSpan(node.data(tree).node_and_node[0]);
|
||||
},
|
||||
.node_offset_bin_rhs => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
return tree.nodeToSpan(tree.nodeData(node).node_and_node[1]);
|
||||
return tree.nodeToSpan(node.data(tree).node_and_node[1]);
|
||||
},
|
||||
.array_cat_lhs, .array_cat_rhs => |cat| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = cat.array_cat_offset.toAbsolute(src_loc.base_node);
|
||||
const arr_node = if (src_loc.lazy == .array_cat_lhs)
|
||||
tree.nodeData(node).node_and_node[0]
|
||||
node.data(tree).node_and_node[0]
|
||||
else
|
||||
tree.nodeData(node).node_and_node[1];
|
||||
node.data(tree).node_and_node[1];
|
||||
|
||||
var buf: [2]Ast.Node.Index = undefined;
|
||||
switch (tree.nodeTag(arr_node)) {
|
||||
switch (arr_node.tag(tree)) {
|
||||
.array_init_one,
|
||||
.array_init_one_comma,
|
||||
.array_init_dot_two,
|
||||
|
|
@ -1532,27 +1532,27 @@ pub const SrcLoc = struct {
|
|||
.node_offset_try_operand => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
return tree.nodeToSpan(tree.nodeData(node).node);
|
||||
return tree.nodeToSpan(node.data(tree).node);
|
||||
},
|
||||
|
||||
.node_offset_switch_operand => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
const condition, _ = tree.nodeData(node).node_and_extra;
|
||||
const condition, _ = node.data(tree).node_and_extra;
|
||||
return tree.nodeToSpan(condition);
|
||||
},
|
||||
|
||||
.node_offset_switch_special_prong => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const switch_node = node_off.toAbsolute(src_loc.base_node);
|
||||
_, const extra_index = tree.nodeData(switch_node).node_and_extra;
|
||||
_, const extra_index = switch_node.data(tree).node_and_extra;
|
||||
const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index);
|
||||
for (case_nodes) |case_node| {
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
const is_special = (case.ast.values.len == 0) or
|
||||
(case.ast.values.len == 1 and
|
||||
tree.nodeTag(case.ast.values[0]) == .identifier and
|
||||
mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_"));
|
||||
case.ast.values[0].tag(tree) == .identifier and
|
||||
mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_"));
|
||||
if (!is_special) continue;
|
||||
|
||||
return tree.nodeToSpan(case_node);
|
||||
|
|
@ -1562,18 +1562,18 @@ pub const SrcLoc = struct {
|
|||
.node_offset_switch_range => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const switch_node = node_off.toAbsolute(src_loc.base_node);
|
||||
_, const extra_index = tree.nodeData(switch_node).node_and_extra;
|
||||
_, const extra_index = switch_node.data(tree).node_and_extra;
|
||||
const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index);
|
||||
for (case_nodes) |case_node| {
|
||||
const case = tree.fullSwitchCase(case_node).?;
|
||||
const is_special = (case.ast.values.len == 0) or
|
||||
(case.ast.values.len == 1 and
|
||||
tree.nodeTag(case.ast.values[0]) == .identifier and
|
||||
mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_"));
|
||||
case.ast.values[0].tag(tree) == .identifier and
|
||||
mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_"));
|
||||
if (is_special) continue;
|
||||
|
||||
for (case.ast.values) |item_node| {
|
||||
if (tree.nodeTag(item_node) == .switch_range) {
|
||||
if (item_node.tag(tree) == .switch_range) {
|
||||
return tree.nodeToSpan(item_node);
|
||||
}
|
||||
}
|
||||
|
|
@ -1632,7 +1632,7 @@ pub const SrcLoc = struct {
|
|||
},
|
||||
.token_offset_param => |token_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const main_token = tree.nodeMainToken(src_loc.base_node);
|
||||
const main_token = src_loc.base_node.mainToken(tree);
|
||||
const tok_index = token_off.toAbsolute(main_token);
|
||||
|
||||
var first_tok = tok_index;
|
||||
|
|
@ -1650,7 +1650,7 @@ pub const SrcLoc = struct {
|
|||
.node_offset_anyframe_type => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const parent_node = node_off.toAbsolute(src_loc.base_node);
|
||||
_, const child_type = tree.nodeData(parent_node).token_and_node;
|
||||
_, const child_type = parent_node.data(tree).token_and_node;
|
||||
return tree.nodeToSpan(child_type);
|
||||
},
|
||||
|
||||
|
|
@ -1689,7 +1689,7 @@ pub const SrcLoc = struct {
|
|||
.node_offset_un_op => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
return tree.nodeToSpan(tree.nodeData(node).node);
|
||||
return tree.nodeToSpan(node.data(tree).node);
|
||||
},
|
||||
.node_offset_ptr_elem => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
|
|
@ -1737,7 +1737,7 @@ pub const SrcLoc = struct {
|
|||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const parent_node = node_off.toAbsolute(src_loc.base_node);
|
||||
|
||||
switch (tree.nodeTag(parent_node)) {
|
||||
switch (parent_node.tag(tree)) {
|
||||
.container_decl_arg, .container_decl_arg_trailing => {
|
||||
const full = tree.containerDeclArg(parent_node);
|
||||
const arg_node = full.ast.arg.unwrap().?;
|
||||
|
|
@ -1750,7 +1750,7 @@ pub const SrcLoc = struct {
|
|||
return tree.tokensToSpan(
|
||||
tree.firstToken(arg_node) - 2,
|
||||
tree.lastToken(arg_node) + 1,
|
||||
tree.nodeMainToken(arg_node),
|
||||
arg_node.mainToken(tree),
|
||||
);
|
||||
},
|
||||
else => unreachable,
|
||||
|
|
@ -1760,7 +1760,7 @@ pub const SrcLoc = struct {
|
|||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const parent_node = node_off.toAbsolute(src_loc.base_node);
|
||||
|
||||
const full: Ast.full.ContainerField = switch (tree.nodeTag(parent_node)) {
|
||||
const full: Ast.full.ContainerField = switch (parent_node.tag(tree)) {
|
||||
.container_field => tree.containerField(parent_node),
|
||||
.container_field_init => tree.containerFieldInit(parent_node),
|
||||
else => unreachable,
|
||||
|
|
@ -1782,7 +1782,7 @@ pub const SrcLoc = struct {
|
|||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.assign,
|
||||
.assign_mul,
|
||||
.assign_div,
|
||||
|
|
@ -1801,7 +1801,7 @@ pub const SrcLoc = struct {
|
|||
.assign_mul_sat,
|
||||
.assign_add_sat,
|
||||
.assign_sub_sat,
|
||||
=> return tree.nodeToSpan(tree.nodeData(node).node_and_node[0]),
|
||||
=> return tree.nodeToSpan(node.data(tree).node_and_node[0]),
|
||||
else => return tree.nodeToSpan(node),
|
||||
}
|
||||
},
|
||||
|
|
@ -1809,7 +1809,7 @@ pub const SrcLoc = struct {
|
|||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
|
||||
switch (tree.nodeTag(node)) {
|
||||
switch (node.tag(tree)) {
|
||||
.assign,
|
||||
.assign_mul,
|
||||
.assign_div,
|
||||
|
|
@ -1828,15 +1828,15 @@ pub const SrcLoc = struct {
|
|||
.assign_mul_sat,
|
||||
.assign_add_sat,
|
||||
.assign_sub_sat,
|
||||
=> return tree.nodeToSpan(tree.nodeData(node).node_and_node[1]),
|
||||
=> return tree.nodeToSpan(node.data(tree).node_and_node[1]),
|
||||
else => return tree.nodeToSpan(node),
|
||||
}
|
||||
},
|
||||
.node_offset_return_operand => |node_off| {
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const node = node_off.toAbsolute(src_loc.base_node);
|
||||
if (tree.nodeTag(node) == .@"return") {
|
||||
if (tree.nodeData(node).opt_node.unwrap()) |lhs| {
|
||||
if (node.tag(tree) == .@"return") {
|
||||
if (node.data(tree).opt_node.unwrap()) |lhs| {
|
||||
return tree.nodeToSpan(lhs);
|
||||
}
|
||||
}
|
||||
|
|
@ -1900,7 +1900,7 @@ pub const SrcLoc = struct {
|
|||
return tree.tokensToSpan(
|
||||
tree.firstToken(field_node) - 3,
|
||||
tree.lastToken(field_node),
|
||||
tree.nodeMainToken(field_node) - 2,
|
||||
field_node.mainToken(tree) - 2,
|
||||
);
|
||||
} else unreachable;
|
||||
},
|
||||
|
|
@ -1944,7 +1944,7 @@ pub const SrcLoc = struct {
|
|||
return tree.tokensToSpan(
|
||||
name_token - 1,
|
||||
tree.lastToken(field_node),
|
||||
tree.nodeMainToken(field_node) - 2,
|
||||
field_node.mainToken(tree) - 2,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1969,7 +1969,7 @@ pub const SrcLoc = struct {
|
|||
|
||||
const tree = try src_loc.file_scope.getTree(gpa);
|
||||
const switch_node = switch_node_offset.toAbsolute(src_loc.base_node);
|
||||
_, const extra_index = tree.nodeData(switch_node).node_and_extra;
|
||||
_, const extra_index = switch_node.data(tree).node_and_extra;
|
||||
const case_nodes = tree.extraDataSlice(tree.extraData(extra_index, Ast.Node.SubRange), Ast.Node.Index);
|
||||
|
||||
var multi_i: u32 = 0;
|
||||
|
|
@ -1978,8 +1978,8 @@ pub const SrcLoc = struct {
|
|||
const case = tree.fullSwitchCase(case_node).?;
|
||||
const is_special = special: {
|
||||
if (case.ast.values.len == 0) break :special true;
|
||||
if (case.ast.values.len == 1 and tree.nodeTag(case.ast.values[0]) == .identifier) {
|
||||
break :special mem.eql(u8, tree.tokenSlice(tree.nodeMainToken(case.ast.values[0])), "_");
|
||||
if (case.ast.values.len == 1 and case.ast.values[0].tag(tree) == .identifier) {
|
||||
break :special mem.eql(u8, tree.tokenSlice(case.ast.values[0].mainToken(tree)), "_");
|
||||
}
|
||||
break :special false;
|
||||
};
|
||||
|
|
@ -1991,7 +1991,7 @@ pub const SrcLoc = struct {
|
|||
}
|
||||
|
||||
const is_multi = case.ast.values.len != 1 or
|
||||
tree.nodeTag(case.ast.values[0]) == .switch_range;
|
||||
case.ast.values[0].tag(tree) == .switch_range;
|
||||
|
||||
switch (want_case_idx.kind) {
|
||||
.scalar => if (!is_multi and want_case_idx.index == scalar_i) break case,
|
||||
|
|
@ -2034,7 +2034,7 @@ pub const SrcLoc = struct {
|
|||
.single => {
|
||||
var item_i: u32 = 0;
|
||||
for (case.ast.values) |item_node| {
|
||||
if (tree.nodeTag(item_node) == .switch_range) continue;
|
||||
if (item_node.tag(tree) == .switch_range) continue;
|
||||
if (item_i != want_item.index) {
|
||||
item_i += 1;
|
||||
continue;
|
||||
|
|
@ -2045,12 +2045,12 @@ pub const SrcLoc = struct {
|
|||
.range => {
|
||||
var range_i: u32 = 0;
|
||||
for (case.ast.values) |item_node| {
|
||||
if (tree.nodeTag(item_node) != .switch_range) continue;
|
||||
if (item_node.tag(tree) != .switch_range) continue;
|
||||
if (range_i != want_item.index) {
|
||||
range_i += 1;
|
||||
continue;
|
||||
}
|
||||
const first, const last = tree.nodeData(item_node).node_and_node;
|
||||
const first, const last = item_node.data(tree).node_and_node;
|
||||
return switch (src_loc.lazy) {
|
||||
.switch_case_item => tree.nodeToSpan(item_node),
|
||||
.switch_case_item_range_first => tree.nodeToSpan(first),
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ pub fn updateFile(
|
|||
};
|
||||
},
|
||||
.zon => {
|
||||
file.zoir = try ZonGen.generate(gpa, file.tree.?, .{});
|
||||
file.zoir = try ZonGen.generate(gpa, &file.tree.?, .{});
|
||||
Zcu.saveZoirCache(cache_file, stat, file.zoir.?) catch |err| {
|
||||
log.warn("unable to write cached ZOIR code for {}{s} to {}{s}: {s}", .{
|
||||
file.mod.root, file.sub_file_path, cache_directory, &hex_digest, @errorName(err),
|
||||
|
|
|
|||
|
|
@ -106,28 +106,28 @@ pub fn run(
|
|||
|
||||
if (check_ast_flag) {
|
||||
if (!force_zon) {
|
||||
var zir = try std.zig.AstGen.generate(gpa, tree);
|
||||
var zir = try std.zig.AstGen.generate(gpa, &tree);
|
||||
defer zir.deinit(gpa);
|
||||
|
||||
if (zir.hasCompileErrors()) {
|
||||
var wip_errors: std.zig.ErrorBundle.Wip = undefined;
|
||||
try wip_errors.init(gpa);
|
||||
defer wip_errors.deinit();
|
||||
try wip_errors.addZirErrorMessages(zir, tree, source_code, "<stdin>");
|
||||
try wip_errors.addZirErrorMessages(zir, &tree, source_code, "<stdin>");
|
||||
var error_bundle = try wip_errors.toOwnedBundle("");
|
||||
defer error_bundle.deinit(gpa);
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
process.exit(2);
|
||||
}
|
||||
} else {
|
||||
const zoir = try std.zig.ZonGen.generate(gpa, tree, .{});
|
||||
const zoir = try std.zig.ZonGen.generate(gpa, &tree, .{});
|
||||
defer zoir.deinit(gpa);
|
||||
|
||||
if (zoir.hasCompileErrors()) {
|
||||
var wip_errors: std.zig.ErrorBundle.Wip = undefined;
|
||||
try wip_errors.init(gpa);
|
||||
defer wip_errors.deinit();
|
||||
try wip_errors.addZoirErrorMessages(zoir, tree, source_code, "<stdin>");
|
||||
try wip_errors.addZoirErrorMessages(zoir, &tree, source_code, "<stdin>");
|
||||
var error_bundle = try wip_errors.toOwnedBundle("");
|
||||
defer error_bundle.deinit(gpa);
|
||||
error_bundle.renderToStdErr(color.renderOptions());
|
||||
|
|
|
|||
|
|
@ -6454,7 +6454,7 @@ fn cmdAstCheck(
|
|||
}
|
||||
},
|
||||
.zon => {
|
||||
const zoir = try ZonGen.generate(gpa, file.tree.?, .{});
|
||||
const zoir = try ZonGen.generate(gpa, &file.tree.?, .{});
|
||||
defer zoir.deinit(gpa);
|
||||
|
||||
if (zoir.hasCompileErrors()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue