rename std.zig.ast to std.zig.Ast; use top-level fields

This commit is contained in:
Andrew Kelley 2021-08-30 19:22:04 -07:00
parent e41e75a486
commit 3940a1be18
15 changed files with 3396 additions and 3396 deletions

View file

@ -529,7 +529,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/time.zig" "${CMAKE_SOURCE_DIR}/lib/std/time.zig"
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig" "${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/ast.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"

View file

@ -10,7 +10,7 @@ pub const fmtEscapes = fmt.fmtEscapes;
pub const isValidId = fmt.isValidId; pub const isValidId = fmt.isValidId;
pub const parse = @import("zig/parse.zig").parse; pub const parse = @import("zig/parse.zig").parse;
pub const string_literal = @import("zig/string_literal.zig"); pub const string_literal = @import("zig/string_literal.zig");
pub const ast = @import("zig/ast.zig"); pub const Ast = @import("zig/Ast.zig");
pub const system = @import("zig/system.zig"); pub const system = @import("zig/system.zig");
pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget; pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget;

2979
lib/std/zig/Ast.zig Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,19 +1,18 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const assert = std.debug.assert; const assert = std.debug.assert;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const ast = std.zig.ast; const Ast = std.zig.Ast;
const Node = ast.Node; const Node = Ast.Node;
const Tree = ast.Tree; const AstError = Ast.Error;
const AstError = ast.Error; const TokenIndex = Ast.TokenIndex;
const TokenIndex = ast.TokenIndex;
const Token = std.zig.Token; const Token = std.zig.Token;
pub const Error = error{ParseError} || Allocator.Error; pub const Error = error{ParseError} || Allocator.Error;
/// Result should be freed with tree.deinit() when there are /// Result should be freed with tree.deinit() when there are
/// no more references to any of the tokens or nodes. /// no more references to any of the tokens or nodes.
pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Tree { pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast {
var tokens = ast.TokenList{}; var tokens = Ast.TokenList{};
defer tokens.deinit(gpa); defer tokens.deinit(gpa);
// Empirically, the zig std lib has an 8:1 ratio of source bytes to token count. // Empirically, the zig std lib has an 8:1 ratio of source bytes to token count.
@ -69,7 +68,7 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Tree {
}; };
// TODO experiment with compacting the MultiArrayList slices here // TODO experiment with compacting the MultiArrayList slices here
return Tree{ return Ast{
.source = source, .source = source,
.tokens = tokens.toOwnedSlice(), .tokens = tokens.toOwnedSlice(),
.nodes = parser.nodes.toOwnedSlice(), .nodes = parser.nodes.toOwnedSlice(),
@ -80,15 +79,15 @@ pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Tree {
const null_node: Node.Index = 0; const null_node: Node.Index = 0;
/// Represents in-progress parsing, will be converted to an ast.Tree after completion. /// Represents in-progress parsing, will be converted to an Ast after completion.
const Parser = struct { const Parser = struct {
gpa: *Allocator, gpa: *Allocator,
source: []const u8, source: []const u8,
token_tags: []const Token.Tag, token_tags: []const Token.Tag,
token_starts: []const ast.ByteOffset, token_starts: []const Ast.ByteOffset,
tok_i: TokenIndex, tok_i: TokenIndex,
errors: std.ArrayListUnmanaged(AstError), errors: std.ArrayListUnmanaged(AstError),
nodes: ast.NodeList, nodes: Ast.NodeList,
extra_data: std.ArrayListUnmanaged(Node.Index), extra_data: std.ArrayListUnmanaged(Node.Index),
scratch: std.ArrayListUnmanaged(Node.Index), scratch: std.ArrayListUnmanaged(Node.Index),
@ -121,13 +120,13 @@ const Parser = struct {
}; };
} }
fn addNode(p: *Parser, elem: ast.NodeList.Elem) Allocator.Error!Node.Index { fn addNode(p: *Parser, elem: Ast.NodeList.Elem) Allocator.Error!Node.Index {
const result = @intCast(Node.Index, p.nodes.len); const result = @intCast(Node.Index, p.nodes.len);
try p.nodes.append(p.gpa, elem); try p.nodes.append(p.gpa, elem);
return result; return result;
} }
fn setNode(p: *Parser, i: usize, elem: ast.NodeList.Elem) Node.Index { fn setNode(p: *Parser, i: usize, elem: Ast.NodeList.Elem) Node.Index {
p.nodes.set(i, elem); p.nodes.set(i, elem);
return @intCast(Node.Index, i); return @intCast(Node.Index, i);
} }
@ -148,7 +147,7 @@ const Parser = struct {
return result; return result;
} }
fn warn(p: *Parser, tag: ast.Error.Tag) error{OutOfMemory}!void { fn warn(p: *Parser, tag: Ast.Error.Tag) error{OutOfMemory}!void {
@setCold(true); @setCold(true);
try p.warnMsg(.{ .tag = tag, .token = p.tok_i }); try p.warnMsg(.{ .tag = tag, .token = p.tok_i });
} }
@ -161,12 +160,12 @@ const Parser = struct {
.extra = .{ .expected_tag = expected_token }, .extra = .{ .expected_tag = expected_token },
}); });
} }
fn warnMsg(p: *Parser, msg: ast.Error) error{OutOfMemory}!void { fn warnMsg(p: *Parser, msg: Ast.Error) error{OutOfMemory}!void {
@setCold(true); @setCold(true);
try p.errors.append(p.gpa, msg); try p.errors.append(p.gpa, msg);
} }
fn fail(p: *Parser, tag: ast.Error.Tag) error{ ParseError, OutOfMemory } { fn fail(p: *Parser, tag: Ast.Error.Tag) error{ ParseError, OutOfMemory } {
@setCold(true); @setCold(true);
return p.failMsg(.{ .tag = tag, .token = p.tok_i }); return p.failMsg(.{ .tag = tag, .token = p.tok_i });
} }
@ -180,7 +179,7 @@ const Parser = struct {
}); });
} }
fn failMsg(p: *Parser, msg: ast.Error) error{ ParseError, OutOfMemory } { fn failMsg(p: *Parser, msg: Ast.Error) error{ ParseError, OutOfMemory } {
@setCold(true); @setCold(true);
try p.warnMsg(msg); try p.warnMsg(msg);
return error.ParseError; return error.ParseError;

View file

@ -5308,7 +5308,7 @@ fn testCanonical(source: [:0]const u8) !void {
return testTransform(source, source); return testTransform(source, source);
} }
const Error = std.zig.ast.Error.Tag; const Error = std.zig.Ast.Error.Tag;
fn testError(source: [:0]const u8, expected_errors: []const Error) !void { fn testError(source: [:0]const u8, expected_errors: []const Error) !void {
var tree = try std.zig.parse(std.testing.allocator, source); var tree = try std.zig.parse(std.testing.allocator, source);

View file

@ -3,17 +3,17 @@ const assert = std.debug.assert;
const mem = std.mem; const mem = std.mem;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const meta = std.meta; const meta = std.meta;
const ast = std.zig.ast; const Ast = std.zig.Ast;
const Token = std.zig.Token; const Token = std.zig.Token;
const indent_delta = 4; const indent_delta = 4;
const asm_indent_delta = 2; const asm_indent_delta = 2;
pub const Error = ast.Tree.RenderError; pub const Error = Ast.RenderError;
const Ais = AutoIndentingStream(std.ArrayList(u8).Writer); const Ais = AutoIndentingStream(std.ArrayList(u8).Writer);
pub fn renderTree(buffer: *std.ArrayList(u8), tree: ast.Tree) Error!void { pub fn renderTree(buffer: *std.ArrayList(u8), tree: Ast) Error!void {
assert(tree.errors.len == 0); // Cannot render an invalid tree. assert(tree.errors.len == 0); // Cannot render an invalid tree.
var auto_indenting_stream = Ais{ var auto_indenting_stream = Ais{
.indent_delta = indent_delta, .indent_delta = indent_delta,
@ -37,7 +37,7 @@ pub fn renderTree(buffer: *std.ArrayList(u8), tree: ast.Tree) Error!void {
} }
/// Render all members in the given slice, keeping empty lines where appropriate /// Render all members in the given slice, keeping empty lines where appropriate
fn renderMembers(gpa: *Allocator, ais: *Ais, tree: ast.Tree, members: []const ast.Node.Index) Error!void { fn renderMembers(gpa: *Allocator, ais: *Ais, tree: Ast, members: []const Ast.Node.Index) Error!void {
if (members.len == 0) return; if (members.len == 0) return;
try renderMember(gpa, ais, tree, members[0], .newline); try renderMember(gpa, ais, tree, members[0], .newline);
for (members[1..]) |member| { for (members[1..]) |member| {
@ -46,7 +46,7 @@ fn renderMembers(gpa: *Allocator, ais: *Ais, tree: ast.Tree, members: []const as
} }
} }
fn renderMember(gpa: *Allocator, ais: *Ais, tree: ast.Tree, decl: ast.Node.Index, space: Space) Error!void { fn renderMember(gpa: *Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Index, space: Space) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
const datas = tree.nodes.items(.data); const datas = tree.nodes.items(.data);
@ -83,9 +83,9 @@ fn renderMember(gpa: *Allocator, ais: *Ais, tree: ast.Tree, decl: ast.Node.Index
switch (tree.nodes.items(.tag)[fn_proto]) { switch (tree.nodes.items(.tag)[fn_proto]) {
.fn_proto_one, .fn_proto => { .fn_proto_one, .fn_proto => {
const callconv_expr = if (tree.nodes.items(.tag)[fn_proto] == .fn_proto_one) const callconv_expr = if (tree.nodes.items(.tag)[fn_proto] == .fn_proto_one)
tree.extraData(datas[fn_proto].lhs, ast.Node.FnProtoOne).callconv_expr tree.extraData(datas[fn_proto].lhs, Ast.Node.FnProtoOne).callconv_expr
else else
tree.extraData(datas[fn_proto].lhs, ast.Node.FnProto).callconv_expr; tree.extraData(datas[fn_proto].lhs, Ast.Node.FnProto).callconv_expr;
if (callconv_expr != 0 and tree.nodes.items(.tag)[callconv_expr] == .enum_literal) { if (callconv_expr != 0 and tree.nodes.items(.tag)[callconv_expr] == .enum_literal) {
if (mem.eql(u8, "Inline", tree.tokenSlice(main_tokens[callconv_expr]))) { if (mem.eql(u8, "Inline", tree.tokenSlice(main_tokens[callconv_expr]))) {
try ais.writer().writeAll("inline "); try ais.writer().writeAll("inline ");
@ -168,7 +168,7 @@ fn renderMember(gpa: *Allocator, ais: *Ais, tree: ast.Tree, decl: ast.Node.Index
} }
/// Render all expressions in the slice, keeping empty lines where appropriate /// Render all expressions in the slice, keeping empty lines where appropriate
fn renderExpressions(gpa: *Allocator, ais: *Ais, tree: ast.Tree, expressions: []const ast.Node.Index, space: Space) Error!void { fn renderExpressions(gpa: *Allocator, ais: *Ais, tree: Ast, expressions: []const Ast.Node.Index, space: Space) Error!void {
if (expressions.len == 0) return; if (expressions.len == 0) return;
try renderExpression(gpa, ais, tree, expressions[0], space); try renderExpression(gpa, ais, tree, expressions[0], space);
for (expressions[1..]) |expression| { for (expressions[1..]) |expression| {
@ -177,7 +177,7 @@ fn renderExpressions(gpa: *Allocator, ais: *Ais, tree: ast.Tree, expressions: []
} }
} }
fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Space) Error!void { fn renderExpression(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
@ -220,7 +220,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
.block_two, .block_two,
.block_two_semicolon, .block_two_semicolon,
=> { => {
const statements = [2]ast.Node.Index{ datas[node].lhs, datas[node].rhs }; const statements = [2]Ast.Node.Index{ datas[node].lhs, datas[node].rhs };
if (datas[node].lhs == 0) { if (datas[node].lhs == 0) {
return renderBlock(gpa, ais, tree, node, statements[0..0], space); return renderBlock(gpa, ais, tree, node, statements[0..0], space);
} else if (datas[node].rhs == 0) { } else if (datas[node].rhs == 0) {
@ -413,11 +413,11 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
.ptr_type_bit_range => return renderPtrType(gpa, ais, tree, tree.ptrTypeBitRange(node), space), .ptr_type_bit_range => return renderPtrType(gpa, ais, tree, tree.ptrTypeBitRange(node), space),
.array_init_one, .array_init_one_comma => { .array_init_one, .array_init_one_comma => {
var elements: [1]ast.Node.Index = undefined; var elements: [1]Ast.Node.Index = undefined;
return renderArrayInit(gpa, ais, tree, tree.arrayInitOne(&elements, node), space); return renderArrayInit(gpa, ais, tree, tree.arrayInitOne(&elements, node), space);
}, },
.array_init_dot_two, .array_init_dot_two_comma => { .array_init_dot_two, .array_init_dot_two_comma => {
var elements: [2]ast.Node.Index = undefined; var elements: [2]Ast.Node.Index = undefined;
return renderArrayInit(gpa, ais, tree, tree.arrayInitDotTwo(&elements, node), space); return renderArrayInit(gpa, ais, tree, tree.arrayInitDotTwo(&elements, node), space);
}, },
.array_init_dot, .array_init_dot,
@ -428,11 +428,11 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
=> return renderArrayInit(gpa, ais, tree, tree.arrayInit(node), space), => return renderArrayInit(gpa, ais, tree, tree.arrayInit(node), space),
.struct_init_one, .struct_init_one_comma => { .struct_init_one, .struct_init_one_comma => {
var fields: [1]ast.Node.Index = undefined; var fields: [1]Ast.Node.Index = undefined;
return renderStructInit(gpa, ais, tree, node, tree.structInitOne(&fields, node), space); return renderStructInit(gpa, ais, tree, node, tree.structInitOne(&fields, node), space);
}, },
.struct_init_dot_two, .struct_init_dot_two_comma => { .struct_init_dot_two, .struct_init_dot_two_comma => {
var fields: [2]ast.Node.Index = undefined; var fields: [2]Ast.Node.Index = undefined;
return renderStructInit(gpa, ais, tree, node, tree.structInitDotTwo(&fields, node), space); return renderStructInit(gpa, ais, tree, node, tree.structInitDotTwo(&fields, node), space);
}, },
.struct_init_dot, .struct_init_dot,
@ -443,7 +443,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
=> return renderStructInit(gpa, ais, tree, node, tree.structInit(node), space), => return renderStructInit(gpa, ais, tree, node, tree.structInit(node), space),
.call_one, .call_one_comma, .async_call_one, .async_call_one_comma => { .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => {
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
return renderCall(gpa, ais, tree, tree.callOne(&params, node), space); return renderCall(gpa, ais, tree, tree.callOne(&params, node), space);
}, },
@ -536,7 +536,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
=> return renderContainerDecl(gpa, ais, tree, node, tree.containerDecl(node), space), => return renderContainerDecl(gpa, ais, tree, node, tree.containerDecl(node), space),
.container_decl_two, .container_decl_two_trailing => { .container_decl_two, .container_decl_two_trailing => {
var buffer: [2]ast.Node.Index = undefined; var buffer: [2]Ast.Node.Index = undefined;
return renderContainerDecl(gpa, ais, tree, node, tree.containerDeclTwo(&buffer, node), space); return renderContainerDecl(gpa, ais, tree, node, tree.containerDeclTwo(&buffer, node), space);
}, },
.container_decl_arg, .container_decl_arg,
@ -548,7 +548,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
=> return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnion(node), space), => return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnion(node), space),
.tagged_union_two, .tagged_union_two_trailing => { .tagged_union_two, .tagged_union_two_trailing => {
var buffer: [2]ast.Node.Index = undefined; var buffer: [2]Ast.Node.Index = undefined;
return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnionTwo(&buffer, node), space); return renderContainerDecl(gpa, ais, tree, node, tree.taggedUnionTwo(&buffer, node), space);
}, },
.tagged_union_enum_tag, .tagged_union_enum_tag,
@ -619,12 +619,12 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
}, },
.fn_proto_simple => { .fn_proto_simple => {
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
return renderFnProto(gpa, ais, tree, tree.fnProtoSimple(&params, node), space); return renderFnProto(gpa, ais, tree, tree.fnProtoSimple(&params, node), space);
}, },
.fn_proto_multi => return renderFnProto(gpa, ais, tree, tree.fnProtoMulti(node), space), .fn_proto_multi => return renderFnProto(gpa, ais, tree, tree.fnProtoMulti(node), space),
.fn_proto_one => { .fn_proto_one => {
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
return renderFnProto(gpa, ais, tree, tree.fnProtoOne(&params, node), space); return renderFnProto(gpa, ais, tree, tree.fnProtoOne(&params, node), space);
}, },
.fn_proto => return renderFnProto(gpa, ais, tree, tree.fnProto(node), space), .fn_proto => return renderFnProto(gpa, ais, tree, tree.fnProto(node), space),
@ -645,7 +645,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
=> { => {
const switch_token = main_tokens[node]; const switch_token = main_tokens[node];
const condition = datas[node].lhs; const condition = datas[node].lhs;
const extra = tree.extraData(datas[node].rhs, ast.Node.SubRange); const extra = tree.extraData(datas[node].rhs, Ast.Node.SubRange);
const cases = tree.extra_data[extra.start..extra.end]; const cases = tree.extra_data[extra.start..extra.end];
const rparen = tree.lastToken(condition) + 1; const rparen = tree.lastToken(condition) + 1;
@ -704,8 +704,8 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
fn renderArrayType( fn renderArrayType(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
array_type: ast.full.ArrayType, array_type: Ast.full.ArrayType,
space: Space, space: Space,
) Error!void { ) Error!void {
const rbracket = tree.firstToken(array_type.ast.elem_type) - 1; const rbracket = tree.firstToken(array_type.ast.elem_type) - 1;
@ -726,8 +726,8 @@ fn renderArrayType(
fn renderPtrType( fn renderPtrType(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
ptr_type: ast.full.PtrType, ptr_type: Ast.full.PtrType,
space: Space, space: Space,
) Error!void { ) Error!void {
switch (ptr_type.size) { switch (ptr_type.size) {
@ -811,9 +811,9 @@ fn renderPtrType(
fn renderSlice( fn renderSlice(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
slice_node: ast.Node.Index, slice_node: Ast.Node.Index,
slice: ast.full.Slice, slice: Ast.full.Slice,
space: Space, space: Space,
) Error!void { ) Error!void {
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
@ -847,8 +847,8 @@ fn renderSlice(
fn renderAsmOutput( fn renderAsmOutput(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
asm_output: ast.Node.Index, asm_output: Ast.Node.Index,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -877,8 +877,8 @@ fn renderAsmOutput(
fn renderAsmInput( fn renderAsmInput(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
asm_input: ast.Node.Index, asm_input: Ast.Node.Index,
space: Space, space: Space,
) Error!void { ) Error!void {
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
@ -896,7 +896,7 @@ fn renderAsmInput(
return renderToken(ais, tree, datas[asm_input].rhs, space); // rparen return renderToken(ais, tree, datas[asm_input].rhs, space); // rparen
} }
fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: ast.Tree, var_decl: ast.full.VarDecl) Error!void { fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: Ast, var_decl: Ast.full.VarDecl) Error!void {
if (var_decl.visib_token) |visib_token| { if (var_decl.visib_token) |visib_token| {
try renderToken(ais, tree, visib_token, Space.space); // pub try renderToken(ais, tree, visib_token, Space.space); // pub
} }
@ -985,7 +985,7 @@ fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: ast.Tree, var_decl: ast.full.
return renderToken(ais, tree, var_decl.ast.mut_token + 2, .newline); // ; return renderToken(ais, tree, var_decl.ast.mut_token + 2, .newline); // ;
} }
fn renderIf(gpa: *Allocator, ais: *Ais, tree: ast.Tree, if_node: ast.full.If, space: Space) Error!void { fn renderIf(gpa: *Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: Space) Error!void {
return renderWhile(gpa, ais, tree, .{ return renderWhile(gpa, ais, tree, .{
.ast = .{ .ast = .{
.while_token = if_node.ast.if_token, .while_token = if_node.ast.if_token,
@ -1004,7 +1004,7 @@ fn renderIf(gpa: *Allocator, ais: *Ais, tree: ast.Tree, if_node: ast.full.If, sp
/// Note that this function is additionally used to render if and for expressions, with /// Note that this function is additionally used to render if and for expressions, with
/// respective values set to null. /// respective values set to null.
fn renderWhile(gpa: *Allocator, ais: *Ais, tree: ast.Tree, while_node: ast.full.While, space: Space) Error!void { fn renderWhile(gpa: *Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, space: Space) Error!void {
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -1109,8 +1109,8 @@ fn renderWhile(gpa: *Allocator, ais: *Ais, tree: ast.Tree, while_node: ast.full.
fn renderContainerField( fn renderContainerField(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
field: ast.full.ContainerField, field: Ast.full.ContainerField,
space: Space, space: Space,
) Error!void { ) Error!void {
if (field.comptime_token) |t| { if (field.comptime_token) |t| {
@ -1183,9 +1183,9 @@ fn renderContainerField(
fn renderBuiltinCall( fn renderBuiltinCall(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
builtin_token: ast.TokenIndex, builtin_token: Ast.TokenIndex,
params: []const ast.Node.Index, params: []const Ast.Node.Index,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -1238,7 +1238,7 @@ fn renderBuiltinCall(
} }
} }
fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.FnProto, space: Space) Error!void { fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnProto, space: Space) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
@ -1438,8 +1438,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
fn renderSwitchCase( fn renderSwitchCase(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
switch_case: ast.full.SwitchCase, switch_case: Ast.full.SwitchCase,
space: Space, space: Space,
) Error!void { ) Error!void {
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
@ -1491,9 +1491,9 @@ fn renderSwitchCase(
fn renderBlock( fn renderBlock(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
block_node: ast.Node.Index, block_node: Ast.Node.Index,
statements: []const ast.Node.Index, statements: []const Ast.Node.Index,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -1531,9 +1531,9 @@ fn renderBlock(
fn renderStructInit( fn renderStructInit(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
struct_node: ast.Node.Index, struct_node: Ast.Node.Index,
struct_init: ast.full.StructInit, struct_init: Ast.full.StructInit,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -1590,8 +1590,8 @@ fn renderStructInit(
fn renderArrayInit( fn renderArrayInit(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
array_init: ast.full.ArrayInit, array_init: Ast.full.ArrayInit,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -1787,9 +1787,9 @@ fn renderArrayInit(
fn renderContainerDecl( fn renderContainerDecl(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
container_decl_node: ast.Node.Index, container_decl_node: Ast.Node.Index,
container_decl: ast.full.ContainerDecl, container_decl: Ast.full.ContainerDecl,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -1799,7 +1799,7 @@ fn renderContainerDecl(
try renderToken(ais, tree, layout_token, .space); try renderToken(ais, tree, layout_token, .space);
} }
var lbrace: ast.TokenIndex = undefined; var lbrace: Ast.TokenIndex = undefined;
if (container_decl.ast.enum_token) |enum_token| { if (container_decl.ast.enum_token) |enum_token| {
try renderToken(ais, tree, container_decl.ast.main_token, .none); // union try renderToken(ais, tree, container_decl.ast.main_token, .none); // union
try renderToken(ais, tree, enum_token - 1, .none); // lparen try renderToken(ais, tree, enum_token - 1, .none); // lparen
@ -1869,8 +1869,8 @@ fn renderContainerDecl(
fn renderAsm( fn renderAsm(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
asm_node: ast.full.Asm, asm_node: Ast.full.Asm,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -2018,8 +2018,8 @@ fn renderAsm(
fn renderCall( fn renderCall(
gpa: *Allocator, gpa: *Allocator,
ais: *Ais, ais: *Ais,
tree: ast.Tree, tree: Ast,
call: ast.full.Call, call: Ast.full.Call,
space: Space, space: Space,
) Error!void { ) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -2091,7 +2091,7 @@ fn renderCall(
/// Renders the given expression indented, popping the indent before rendering /// Renders the given expression indented, popping the indent before rendering
/// any following line comments /// any following line comments
fn renderExpressionIndented(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Space) Error!void { fn renderExpressionIndented(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void {
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
@ -2148,7 +2148,7 @@ fn renderExpressionIndented(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: as
} }
/// Render an expression, and the comma that follows it, if it is present in the source. /// Render an expression, and the comma that follows it, if it is present in the source.
fn renderExpressionComma(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Space) Error!void { fn renderExpressionComma(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const maybe_comma = tree.lastToken(node) + 1; const maybe_comma = tree.lastToken(node) + 1;
if (token_tags[maybe_comma] == .comma) { if (token_tags[maybe_comma] == .comma) {
@ -2159,7 +2159,7 @@ fn renderExpressionComma(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.N
} }
} }
fn renderTokenComma(ais: *Ais, tree: ast.Tree, token: ast.TokenIndex, space: Space) Error!void { fn renderTokenComma(ais: *Ais, tree: Ast, token: Ast.TokenIndex, space: Space) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const maybe_comma = token + 1; const maybe_comma = token + 1;
if (token_tags[maybe_comma] == .comma) { if (token_tags[maybe_comma] == .comma) {
@ -2191,7 +2191,7 @@ const Space = enum {
skip, skip,
}; };
fn renderToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenIndex, space: Space) Error!void { fn renderToken(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, space: Space) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
@ -2238,7 +2238,7 @@ fn renderToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenIndex, space: Sp
/// `start_token` to `end_token`. This is used to determine if e.g. a /// `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 /// fn_proto should be wrapped and have a trailing comma inserted even if
/// there is none in the source. /// there is none in the source.
fn hasComment(tree: ast.Tree, start_token: ast.TokenIndex, end_token: ast.TokenIndex) bool { fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
var i = start_token; var i = start_token;
@ -2253,7 +2253,7 @@ fn hasComment(tree: ast.Tree, start_token: ast.TokenIndex, end_token: ast.TokenI
/// Returns true if there exists a multiline string literal between the start /// Returns true if there exists a multiline string literal between the start
/// of token `start_token` and the start of token `end_token`. /// of token `start_token` and the start of token `end_token`.
fn hasMultilineString(tree: ast.Tree, start_token: ast.TokenIndex, end_token: ast.TokenIndex) bool { fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
for (token_tags[start_token..end_token]) |tag| { for (token_tags[start_token..end_token]) |tag| {
@ -2268,7 +2268,7 @@ fn hasMultilineString(tree: ast.Tree, start_token: ast.TokenIndex, end_token: as
/// Assumes that start is the first byte past the previous token and /// Assumes that start is the first byte past the previous token and
/// that end is the last byte before the next token. /// that end is the last byte before the next token.
fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!bool { fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool {
var index: usize = start; var index: usize = start;
while (mem.indexOf(u8, tree.source[index..end], "//")) |offset| { while (mem.indexOf(u8, tree.source[index..end], "//")) |offset| {
const comment_start = index + offset; const comment_start = index + offset;
@ -2325,12 +2325,12 @@ fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!boo
return index != start; return index != start;
} }
fn renderExtraNewline(ais: *Ais, tree: ast.Tree, node: ast.Node.Index) Error!void { fn renderExtraNewline(ais: *Ais, tree: Ast, node: Ast.Node.Index) Error!void {
return renderExtraNewlineToken(ais, tree, tree.firstToken(node)); return renderExtraNewlineToken(ais, tree, tree.firstToken(node));
} }
/// Check if there is an empty line immediately before the given token. If so, render it. /// Check if there is an empty line immediately before the given token. If so, render it.
fn renderExtraNewlineToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenIndex) Error!void { fn renderExtraNewlineToken(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex) Error!void {
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
const token_start = token_starts[token_index]; const token_start = token_starts[token_index];
if (token_start == 0) return; if (token_start == 0) return;
@ -2355,7 +2355,7 @@ fn renderExtraNewlineToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenInde
/// end_token is the token one past the last doc comment token. This function /// end_token is the token one past the last doc comment token. This function
/// searches backwards from there. /// searches backwards from there.
fn renderDocComments(ais: *Ais, tree: ast.Tree, end_token: ast.TokenIndex) Error!void { fn renderDocComments(ais: *Ais, tree: Ast, end_token: Ast.TokenIndex) Error!void {
// Search backwards for the first doc comment. // Search backwards for the first doc comment.
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
if (end_token == 0) return; if (end_token == 0) return;
@ -2376,7 +2376,7 @@ fn renderDocComments(ais: *Ais, tree: ast.Tree, end_token: ast.TokenIndex) Error
} }
/// start_token is first container doc comment token. /// start_token is first container doc comment token.
fn renderContainerDocComments(ais: *Ais, tree: ast.Tree, start_token: ast.TokenIndex) Error!void { fn renderContainerDocComments(ais: *Ais, tree: Ast, start_token: Ast.TokenIndex) Error!void {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
var tok = start_token; var tok = start_token;
while (token_tags[tok] == .container_doc_comment) : (tok += 1) { while (token_tags[tok] == .container_doc_comment) : (tok += 1) {
@ -2390,7 +2390,7 @@ fn renderContainerDocComments(ais: *Ais, tree: ast.Tree, start_token: ast.TokenI
} }
} }
fn tokenSliceForRender(tree: ast.Tree, token_index: ast.TokenIndex) []const u8 { fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
var ret = tree.tokenSlice(token_index); var ret = tree.tokenSlice(token_index);
if (tree.tokens.items(.tag)[token_index] == .multiline_string_literal_line) { if (tree.tokens.items(.tag)[token_index] == .multiline_string_literal_line) {
assert(ret[ret.len - 1] == '\n'); assert(ret[ret.len - 1] == '\n');
@ -2399,7 +2399,7 @@ fn tokenSliceForRender(tree: ast.Tree, token_index: ast.TokenIndex) []const u8 {
return ret; return ret;
} }
fn hasSameLineComment(tree: ast.Tree, token_index: ast.TokenIndex) bool { fn hasSameLineComment(tree: Ast, token_index: Ast.TokenIndex) bool {
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
const between_source = tree.source[token_starts[token_index]..token_starts[token_index + 1]]; const between_source = tree.source[token_starts[token_index]..token_starts[token_index + 1]];
for (between_source) |byte| switch (byte) { for (between_source) |byte| switch (byte) {
@ -2412,7 +2412,7 @@ fn hasSameLineComment(tree: ast.Tree, token_index: ast.TokenIndex) bool {
/// Returns `true` if and only if there are any tokens or line comments between /// Returns `true` if and only if there are any tokens or line comments between
/// start_token and end_token. /// start_token and end_token.
fn anythingBetween(tree: ast.Tree, start_token: ast.TokenIndex, end_token: ast.TokenIndex) bool { fn anythingBetween(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
if (start_token + 1 != end_token) return true; if (start_token + 1 != end_token) return true;
const token_starts = tree.tokens.items(.start); const token_starts = tree.tokens.items(.start);
const between_source = tree.source[token_starts[start_token]..token_starts[start_token + 1]]; const between_source = tree.source[token_starts[start_token]..token_starts[start_token + 1]];
@ -2431,7 +2431,7 @@ fn writeFixingWhitespace(writer: std.ArrayList(u8).Writer, slice: []const u8) Er
}; };
} }
fn nodeIsBlock(tag: ast.Node.Tag) bool { fn nodeIsBlock(tag: Ast.Node.Tag) bool {
return switch (tag) { return switch (tag) {
.block, .block,
.block_semicolon, .block_semicolon,
@ -2450,7 +2450,7 @@ fn nodeIsBlock(tag: ast.Node.Tag) bool {
}; };
} }
fn nodeIsIfForWhileSwitch(tag: ast.Node.Tag) bool { fn nodeIsIfForWhileSwitch(tag: Ast.Node.Tag) bool {
return switch (tag) { return switch (tag) {
.@"if", .@"if",
.if_simple, .if_simple,
@ -2466,7 +2466,7 @@ fn nodeIsIfForWhileSwitch(tag: ast.Node.Tag) bool {
}; };
} }
fn nodeCausesSliceOpSpace(tag: ast.Node.Tag) bool { fn nodeCausesSliceOpSpace(tag: Ast.Node.Tag) bool {
return switch (tag) { return switch (tag) {
.@"catch", .@"catch",
.add, .add,
@ -2516,7 +2516,7 @@ fn nodeCausesSliceOpSpace(tag: ast.Node.Tag) bool {
} }
// Returns the number of nodes in `expr` that are on the same line as `rtoken`. // Returns the number of nodes in `expr` that are on the same line as `rtoken`.
fn rowSize(tree: ast.Tree, exprs: []const ast.Node.Index, rtoken: ast.TokenIndex) usize { fn rowSize(tree: Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usize {
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const first_token = tree.firstToken(exprs[0]); const first_token = tree.firstToken(exprs[0]);

File diff suppressed because it is too large Load diff

View file

@ -2408,7 +2408,7 @@ const AstGenSrc = union(enum) {
root, root,
import: struct { import: struct {
importing_file: *Module.Scope.File, importing_file: *Module.Scope.File,
import_tok: std.zig.ast.TokenIndex, import_tok: std.zig.Ast.TokenIndex,
}, },
}; };

View file

@ -11,7 +11,7 @@ const log = std.log.scoped(.module);
const BigIntConst = std.math.big.int.Const; const BigIntConst = std.math.big.int.Const;
const BigIntMutable = std.math.big.int.Mutable; const BigIntMutable = std.math.big.int.Mutable;
const Target = std.Target; const Target = std.Target;
const ast = std.zig.ast; const Ast = std.zig.Ast;
const Module = @This(); const Module = @This();
const Compilation = @import("Compilation.zig"); const Compilation = @import("Compilation.zig");
@ -291,7 +291,7 @@ pub const Decl = struct {
generation: u32, generation: u32,
/// The AST node index of this declaration. /// The AST node index of this declaration.
/// Must be recomputed when the corresponding source file is modified. /// Must be recomputed when the corresponding source file is modified.
src_node: ast.Node.Index, src_node: Ast.Node.Index,
/// Line number corresponding to `src_node`. Stored separately so that source files /// Line number corresponding to `src_node`. Stored separately so that source files
/// do not need to be loaded into memory in order to compute debug line numbers. /// do not need to be loaded into memory in order to compute debug line numbers.
src_line: u32, src_line: u32,
@ -499,19 +499,19 @@ pub const Decl = struct {
return decl.src_line + offset; return decl.src_line + offset;
} }
pub fn relativeToNodeIndex(decl: Decl, offset: i32) ast.Node.Index { pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {
return @bitCast(ast.Node.Index, offset + @bitCast(i32, decl.src_node)); return @bitCast(Ast.Node.Index, offset + @bitCast(i32, decl.src_node));
} }
pub fn nodeIndexToRelative(decl: Decl, node_index: ast.Node.Index) i32 { pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {
return @bitCast(i32, node_index) - @bitCast(i32, decl.src_node); return @bitCast(i32, node_index) - @bitCast(i32, decl.src_node);
} }
pub fn tokSrcLoc(decl: Decl, token_index: ast.TokenIndex) LazySrcLoc { pub fn tokSrcLoc(decl: Decl, token_index: Ast.TokenIndex) LazySrcLoc {
return .{ .token_offset = token_index - decl.srcToken() }; return .{ .token_offset = token_index - decl.srcToken() };
} }
pub fn nodeSrcLoc(decl: Decl, node_index: ast.Node.Index) LazySrcLoc { pub fn nodeSrcLoc(decl: Decl, node_index: Ast.Node.Index) LazySrcLoc {
return .{ .node_offset = decl.nodeIndexToRelative(node_index) }; return .{ .node_offset = decl.nodeIndexToRelative(node_index) };
} }
@ -527,7 +527,7 @@ pub const Decl = struct {
}; };
} }
pub fn srcToken(decl: Decl) ast.TokenIndex { pub fn srcToken(decl: Decl) Ast.TokenIndex {
const tree = &decl.namespace.file_scope.tree; const tree = &decl.namespace.file_scope.tree;
return tree.firstToken(decl.src_node); return tree.firstToken(decl.src_node);
} }
@ -1121,7 +1121,7 @@ pub const Scope = struct {
/// Whether this is populated depends on `status`. /// Whether this is populated depends on `status`.
stat_mtime: i128, stat_mtime: i128,
/// Whether this is populated or not depends on `tree_loaded`. /// Whether this is populated or not depends on `tree_loaded`.
tree: ast.Tree, tree: Ast,
/// Whether this is populated or not depends on `zir_loaded`. /// Whether this is populated or not depends on `zir_loaded`.
zir: Zir, zir: Zir,
/// Package that this file is a part of, managed externally. /// Package that this file is a part of, managed externally.
@ -1220,7 +1220,7 @@ pub const Scope = struct {
return source; return source;
} }
pub fn getTree(file: *File, gpa: *Allocator) !*const ast.Tree { pub fn getTree(file: *File, gpa: *Allocator) !*const Ast {
if (file.tree_loaded) return &file.tree; if (file.tree_loaded) return &file.tree;
const source = try file.getSource(gpa); const source = try file.getSource(gpa);
@ -1565,17 +1565,17 @@ pub const ErrorMsg = struct {
pub const SrcLoc = struct { pub const SrcLoc = struct {
file_scope: *Scope.File, file_scope: *Scope.File,
/// Might be 0 depending on tag of `lazy`. /// Might be 0 depending on tag of `lazy`.
parent_decl_node: ast.Node.Index, parent_decl_node: Ast.Node.Index,
/// Relative to `parent_decl_node`. /// Relative to `parent_decl_node`.
lazy: LazySrcLoc, lazy: LazySrcLoc,
pub fn declSrcToken(src_loc: SrcLoc) ast.TokenIndex { pub fn declSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
const tree = src_loc.file_scope.tree; const tree = src_loc.file_scope.tree;
return tree.firstToken(src_loc.parent_decl_node); return tree.firstToken(src_loc.parent_decl_node);
} }
pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) ast.TokenIndex { pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.TokenIndex {
return @bitCast(ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node)); return @bitCast(Ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node));
} }
pub fn byteOffset(src_loc: SrcLoc, gpa: *Allocator) !u32 { pub fn byteOffset(src_loc: SrcLoc, gpa: *Allocator) !u32 {
@ -1701,7 +1701,7 @@ pub const SrcLoc = struct {
const tree = try src_loc.file_scope.getTree(gpa); const tree = try src_loc.file_scope.getTree(gpa);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const node = src_loc.declRelativeToNodeIndex(node_off); const node = src_loc.declRelativeToNodeIndex(node_off);
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
const full = switch (node_tags[node]) { const full = switch (node_tags[node]) {
.call_one, .call_one,
.call_one_comma, .call_one_comma,
@ -1831,7 +1831,7 @@ pub const SrcLoc = struct {
const node_datas = tree.nodes.items(.data); const node_datas = tree.nodes.items(.data);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
const extra = tree.extraData(node_datas[switch_node].rhs, ast.Node.SubRange); const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
const case_nodes = tree.extra_data[extra.start..extra.end]; const case_nodes = tree.extra_data[extra.start..extra.end];
for (case_nodes) |case_node| { for (case_nodes) |case_node| {
const case = switch (node_tags[case_node]) { const case = switch (node_tags[case_node]) {
@ -1857,7 +1857,7 @@ pub const SrcLoc = struct {
const node_datas = tree.nodes.items(.data); const node_datas = tree.nodes.items(.data);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
const extra = tree.extraData(node_datas[switch_node].rhs, ast.Node.SubRange); const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
const case_nodes = tree.extra_data[extra.start..extra.end]; const case_nodes = tree.extra_data[extra.start..extra.end];
for (case_nodes) |case_node| { for (case_nodes) |case_node| {
const case = switch (node_tags[case_node]) { const case = switch (node_tags[case_node]) {
@ -1886,7 +1886,7 @@ pub const SrcLoc = struct {
const node_datas = tree.nodes.items(.data); const node_datas = tree.nodes.items(.data);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const node = src_loc.declRelativeToNodeIndex(node_off); const node = src_loc.declRelativeToNodeIndex(node_off);
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
const full = switch (node_tags[node]) { const full = switch (node_tags[node]) {
.fn_proto_simple => tree.fnProtoSimple(&params, node), .fn_proto_simple => tree.fnProtoSimple(&params, node),
.fn_proto_multi => tree.fnProtoMulti(node), .fn_proto_multi => tree.fnProtoMulti(node),
@ -1911,7 +1911,7 @@ pub const SrcLoc = struct {
const tree = try src_loc.file_scope.getTree(gpa); const tree = try src_loc.file_scope.getTree(gpa);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const node = src_loc.declRelativeToNodeIndex(node_off); const node = src_loc.declRelativeToNodeIndex(node_off);
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
const full = switch (node_tags[node]) { const full = switch (node_tags[node]) {
.fn_proto_simple => tree.fnProtoSimple(&params, node), .fn_proto_simple => tree.fnProtoSimple(&params, node),
.fn_proto_multi => tree.fnProtoMulti(node), .fn_proto_multi => tree.fnProtoMulti(node),
@ -1941,7 +1941,7 @@ pub const SrcLoc = struct {
const node_datas = tree.nodes.items(.data); const node_datas = tree.nodes.items(.data);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const parent_node = src_loc.declRelativeToNodeIndex(node_off); const parent_node = src_loc.declRelativeToNodeIndex(node_off);
var params: [1]ast.Node.Index = undefined; var params: [1]Ast.Node.Index = undefined;
const full = switch (node_tags[parent_node]) { const full = switch (node_tags[parent_node]) {
.fn_proto_simple => tree.fnProtoSimple(&params, parent_node), .fn_proto_simple => tree.fnProtoSimple(&params, parent_node),
.fn_proto_multi => tree.fnProtoMulti(parent_node), .fn_proto_multi => tree.fnProtoMulti(parent_node),
@ -3967,7 +3967,7 @@ fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {
decl.analysis = .outdated; decl.analysis = .outdated;
} }
pub fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: ast.Node.Index) !*Decl { pub fn allocateNewDecl(mod: *Module, namespace: *Scope.Namespace, src_node: Ast.Node.Index) !*Decl {
// If we have emit-h then we must allocate a bigger structure to store the emit-h state. // If we have emit-h then we must allocate a bigger structure to store the emit-h state.
const new_decl: *Decl = if (mod.emit_h != null) blk: { const new_decl: *Decl = if (mod.emit_h != null) blk: {
const parent_struct = try mod.gpa.create(DeclPlusEmitH); const parent_struct = try mod.gpa.create(DeclPlusEmitH);
@ -4237,7 +4237,7 @@ pub fn fail(
pub fn failTok( pub fn failTok(
mod: *Module, mod: *Module,
scope: *Scope, scope: *Scope,
token_index: ast.TokenIndex, token_index: Ast.TokenIndex,
comptime format: []const u8, comptime format: []const u8,
args: anytype, args: anytype,
) CompileError { ) CompileError {
@ -4250,7 +4250,7 @@ pub fn failTok(
pub fn failNode( pub fn failNode(
mod: *Module, mod: *Module,
scope: *Scope, scope: *Scope,
node_index: ast.Node.Index, node_index: Ast.Node.Index,
comptime format: []const u8, comptime format: []const u8,
args: anytype, args: anytype,
) CompileError { ) CompileError {
@ -4455,7 +4455,7 @@ pub const SwitchProngSrc = union(enum) {
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
const node_datas = tree.nodes.items(.data); const node_datas = tree.nodes.items(.data);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
const extra = tree.extraData(node_datas[switch_node].rhs, ast.Node.SubRange); const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
const case_nodes = tree.extra_data[extra.start..extra.end]; const case_nodes = tree.extra_data[extra.start..extra.end];
var multi_i: u32 = 0; var multi_i: u32 = 0;

View file

@ -10177,7 +10177,7 @@ fn typeHasOnePossibleValue(
}; };
} }
fn getAstTree(sema: *Sema, block: *Scope.Block) CompileError!*const std.zig.ast.Tree { fn getAstTree(sema: *Sema, block: *Scope.Block) CompileError!*const std.zig.Ast {
return block.src_decl.namespace.file_scope.getTree(sema.gpa) catch |err| { return block.src_decl.namespace.file_scope.getTree(sema.gpa) catch |err| {
log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
return error.AnalysisFail; return error.AnalysisFail;
@ -10186,14 +10186,14 @@ fn getAstTree(sema: *Sema, block: *Scope.Block) CompileError!*const std.zig.ast.
fn enumFieldSrcLoc( fn enumFieldSrcLoc(
decl: *Decl, decl: *Decl,
tree: std.zig.ast.Tree, tree: std.zig.Ast,
node_offset: i32, node_offset: i32,
field_index: usize, field_index: usize,
) LazySrcLoc { ) LazySrcLoc {
@setCold(true); @setCold(true);
const enum_node = decl.relativeToNodeIndex(node_offset); const enum_node = decl.relativeToNodeIndex(node_offset);
const node_tags = tree.nodes.items(.tag); const node_tags = tree.nodes.items(.tag);
var buffer: [2]std.zig.ast.Node.Index = undefined; var buffer: [2]std.zig.Ast.Node.Index = undefined;
const container_decl = switch (node_tags[enum_node]) { const container_decl = switch (node_tags[enum_node]) {
.container_decl, .container_decl,
.container_decl_trailing, .container_decl_trailing,

View file

@ -16,7 +16,7 @@ const Allocator = std.mem.Allocator;
const assert = std.debug.assert; const assert = std.debug.assert;
const BigIntConst = std.math.big.int.Const; const BigIntConst = std.math.big.int.Const;
const BigIntMutable = std.math.big.int.Mutable; const BigIntMutable = std.math.big.int.Mutable;
const ast = std.zig.ast; const Ast = std.zig.Ast;
const Zir = @This(); const Zir = @This();
const Type = @import("type.zig").Type; const Type = @import("type.zig").Type;
@ -2092,7 +2092,7 @@ pub const Inst = struct {
/// Used for unary operators, with a token source location. /// Used for unary operators, with a token source location.
un_tok: struct { un_tok: struct {
/// Offset from Decl AST token index. /// Offset from Decl AST token index.
src_tok: ast.TokenIndex, src_tok: Ast.TokenIndex,
/// The meaning of this operand depends on the corresponding `Tag`. /// The meaning of this operand depends on the corresponding `Tag`.
operand: Ref, operand: Ref,
@ -2114,7 +2114,7 @@ pub const Inst = struct {
}, },
pl_tok: struct { pl_tok: struct {
/// Offset from Decl AST token index. /// Offset from Decl AST token index.
src_tok: ast.TokenIndex, src_tok: Ast.TokenIndex,
/// index into extra. /// index into extra.
/// `Tag` determines what lives there. /// `Tag` determines what lives there.
payload_index: u32, payload_index: u32,
@ -2150,7 +2150,7 @@ pub const Inst = struct {
} }
}, },
/// Offset from Decl AST token index. /// Offset from Decl AST token index.
tok: ast.TokenIndex, tok: Ast.TokenIndex,
/// Offset from Decl AST node index. /// Offset from Decl AST node index.
node: i32, node: i32,
int: u64, int: u64,
@ -2878,9 +2878,9 @@ pub const Inst = struct {
pub const Item = struct { pub const Item = struct {
/// null terminated string index /// null terminated string index
msg: u32, msg: u32,
node: ast.Node.Index, node: Ast.Node.Index,
/// If node is 0 then this will be populated. /// If node is 0 then this will be populated.
token: ast.TokenIndex, token: Ast.TokenIndex,
/// Can be used in combination with `token`. /// Can be used in combination with `token`.
byte_offset: u32, byte_offset: u32,
/// 0 or a payload index of a `Block`, each is a payload /// 0 or a payload index of a `Block`, each is a payload
@ -2897,7 +2897,7 @@ pub const Inst = struct {
/// null terminated string index /// null terminated string index
name: u32, name: u32,
/// points to the import name /// points to the import name
token: ast.TokenIndex, token: Ast.TokenIndex,
}; };
}; };
}; };
@ -2912,8 +2912,8 @@ const Writer = struct {
indent: u32, indent: u32,
parent_decl_node: u32, parent_decl_node: u32,
fn relativeToNodeIndex(self: *Writer, offset: i32) ast.Node.Index { fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {
return @bitCast(ast.Node.Index, offset + @bitCast(i32, self.parent_decl_node)); return @bitCast(Ast.Node.Index, offset + @bitCast(i32, self.parent_decl_node));
} }
fn writeInstToStream( fn writeInstToStream(

View file

@ -6,7 +6,7 @@ const mem = std.mem;
const process = std.process; const process = std.process;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const ArrayList = std.ArrayList; const ArrayList = std.ArrayList;
const ast = std.zig.ast; const Ast = std.zig.Ast;
const warn = std.log.warn; const warn = std.log.warn;
const Compilation = @import("Compilation.zig"); const Compilation = @import("Compilation.zig");
@ -3423,8 +3423,8 @@ fn fmtPathFile(
fn printErrMsgToStdErr( fn printErrMsgToStdErr(
gpa: *mem.Allocator, gpa: *mem.Allocator,
arena: *mem.Allocator, arena: *mem.Allocator,
parse_error: ast.Error, parse_error: Ast.Error,
tree: ast.Tree, tree: Ast,
path: []const u8, path: []const u8,
color: Color, color: Color,
) !void { ) !void {
@ -4029,12 +4029,12 @@ pub fn cmdAstCheck(
} }
{ {
const token_bytes = @sizeOf(std.zig.ast.TokenList) + const token_bytes = @sizeOf(Ast.TokenList) +
file.tree.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(std.zig.ast.ByteOffset)); file.tree.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(Ast.ByteOffset));
const tree_bytes = @sizeOf(std.zig.ast.Tree) + file.tree.nodes.len * const tree_bytes = @sizeOf(Ast) + file.tree.nodes.len *
(@sizeOf(std.zig.ast.Node.Tag) + (@sizeOf(Ast.Node.Tag) +
@sizeOf(std.zig.ast.Node.Data) + @sizeOf(Ast.Node.Data) +
@sizeOf(std.zig.ast.TokenIndex)); @sizeOf(Ast.TokenIndex));
const instruction_bytes = file.zir.instructions.len * const instruction_bytes = file.zir.instructions.len *
// Here we don't use @sizeOf(Zir.Inst.Data) because it would include // Here we don't use @sizeOf(Zir.Inst.Data) because it would include
// the debug safety tag but we want to measure release size. // the debug safety tag but we want to measure release size.

View file

@ -356,7 +356,7 @@ pub fn translate(
args_end: [*]?[*]const u8, args_end: [*]?[*]const u8,
errors: *[]ClangErrMsg, errors: *[]ClangErrMsg,
resources_path: [*:0]const u8, resources_path: [*:0]const u8,
) !std.zig.ast.Tree { ) !std.zig.Ast {
const ast_unit = clang.LoadFromCommandLine( const ast_unit = clang.LoadFromCommandLine(
args_begin, args_begin,
args_end, args_end,
@ -369,7 +369,7 @@ pub fn translate(
}; };
defer ast_unit.delete(); defer ast_unit.delete();
// For memory that has the same lifetime as the Tree that we return // For memory that has the same lifetime as the Ast that we return
// from this function. // from this function.
var arena = std.heap.ArenaAllocator.init(gpa); var arena = std.heap.ArenaAllocator.init(gpa);
errdefer arena.deinit(); errdefer arena.deinit();

View file

@ -714,9 +714,9 @@ pub const Payload = struct {
}; };
}; };
/// Converts the nodes into a Zig ast. /// Converts the nodes into a Zig Ast.
/// Caller must free the source slice. /// Caller must free the source slice.
pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.ast.Tree { pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.Ast {
var ctx = Context{ var ctx = Context{
.gpa = gpa, .gpa = gpa,
.buf = std.ArrayList(u8).init(gpa), .buf = std.ArrayList(u8).init(gpa),
@ -767,7 +767,7 @@ pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.ast.Tree {
.start = @intCast(u32, ctx.buf.items.len), .start = @intCast(u32, ctx.buf.items.len),
}); });
return std.zig.ast.Tree{ return std.zig.Ast{
.source = try ctx.buf.toOwnedSliceSentinel(0), .source = try ctx.buf.toOwnedSliceSentinel(0),
.tokens = ctx.tokens.toOwnedSlice(), .tokens = ctx.tokens.toOwnedSlice(),
.nodes = ctx.nodes.toOwnedSlice(), .nodes = ctx.nodes.toOwnedSlice(),
@ -776,17 +776,17 @@ pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.ast.Tree {
}; };
} }
const NodeIndex = std.zig.ast.Node.Index; const NodeIndex = std.zig.Ast.Node.Index;
const NodeSubRange = std.zig.ast.Node.SubRange; const NodeSubRange = std.zig.Ast.Node.SubRange;
const TokenIndex = std.zig.ast.TokenIndex; const TokenIndex = std.zig.Ast.TokenIndex;
const TokenTag = std.zig.Token.Tag; const TokenTag = std.zig.Token.Tag;
const Context = struct { const Context = struct {
gpa: *Allocator, gpa: *Allocator,
buf: std.ArrayList(u8) = .{}, buf: std.ArrayList(u8) = .{},
nodes: std.zig.ast.NodeList = .{}, nodes: std.zig.Ast.NodeList = .{},
extra_data: std.ArrayListUnmanaged(std.zig.ast.Node.Index) = .{}, extra_data: std.ArrayListUnmanaged(std.zig.Ast.Node.Index) = .{},
tokens: std.zig.ast.TokenList = .{}, tokens: std.zig.Ast.TokenList = .{},
fn addTokenFmt(c: *Context, tag: TokenTag, comptime format: []const u8, args: anytype) Allocator.Error!TokenIndex { fn addTokenFmt(c: *Context, tag: TokenTag, comptime format: []const u8, args: anytype) Allocator.Error!TokenIndex {
const start_index = c.buf.items.len; const start_index = c.buf.items.len;
@ -831,7 +831,7 @@ const Context = struct {
}; };
} }
fn addNode(c: *Context, elem: std.zig.ast.NodeList.Elem) Allocator.Error!NodeIndex { fn addNode(c: *Context, elem: std.zig.Ast.NodeList.Elem) Allocator.Error!NodeIndex {
const result = @intCast(NodeIndex, c.nodes.len); const result = @intCast(NodeIndex, c.nodes.len);
try c.nodes.append(c.gpa, elem); try c.nodes.append(c.gpa, elem);
return result; return result;
@ -1166,7 +1166,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
.main_token = l_bracket, .main_token = l_bracket,
.data = .{ .data = .{
.lhs = string, .lhs = string,
.rhs = try c.addExtra(std.zig.ast.Node.Slice{ .rhs = try c.addExtra(std.zig.Ast.Node.Slice{
.start = start, .start = start,
.end = end, .end = end,
}), }),
@ -1601,7 +1601,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
.main_token = while_tok, .main_token = while_tok,
.data = .{ .data = .{
.lhs = cond, .lhs = cond,
.rhs = try c.addExtra(std.zig.ast.Node.WhileCont{ .rhs = try c.addExtra(std.zig.Ast.Node.WhileCont{
.cont_expr = cont_expr, .cont_expr = cont_expr,
.then_expr = body, .then_expr = body,
}), }),
@ -1654,7 +1654,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
.main_token = if_tok, .main_token = if_tok,
.data = .{ .data = .{
.lhs = cond, .lhs = cond,
.rhs = try c.addExtra(std.zig.ast.Node.If{ .rhs = try c.addExtra(std.zig.Ast.Node.If{
.then_expr = then_expr, .then_expr = then_expr,
.else_expr = else_expr, .else_expr = else_expr,
}), }),
@ -2175,7 +2175,7 @@ fn renderNullSentinelArrayType(c: *Context, len: usize, elem_type: Node) !NodeIn
.main_token = l_bracket, .main_token = l_bracket,
.data = .{ .data = .{
.lhs = len_expr, .lhs = len_expr,
.rhs = try c.addExtra(std.zig.ast.Node.ArrayTypeSentinel{ .rhs = try c.addExtra(std.zig.Ast.Node.ArrayTypeSentinel{
.sentinel = sentinel_expr, .sentinel = sentinel_expr,
.elem_type = elem_type_expr, .elem_type = elem_type_expr,
}), }),
@ -2378,7 +2378,7 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
} }
} }
fn renderPrefixOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex { fn renderPrefixOp(c: *Context, node: Node, tag: std.zig.Ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex {
const payload = @fieldParentPtr(Payload.UnOp, "base", node.ptr_otherwise).data; const payload = @fieldParentPtr(Payload.UnOp, "base", node.ptr_otherwise).data;
return c.addNode(.{ return c.addNode(.{
.tag = tag, .tag = tag,
@ -2390,7 +2390,7 @@ fn renderPrefixOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: T
}); });
} }
fn renderBinOpGrouped(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex { fn renderBinOpGrouped(c: *Context, node: Node, tag: std.zig.Ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex {
const payload = @fieldParentPtr(Payload.BinOp, "base", node.ptr_otherwise).data; const payload = @fieldParentPtr(Payload.BinOp, "base", node.ptr_otherwise).data;
const lhs = try renderNodeGrouped(c, payload.lhs); const lhs = try renderNodeGrouped(c, payload.lhs);
return c.addNode(.{ return c.addNode(.{
@ -2403,7 +2403,7 @@ fn renderBinOpGrouped(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_ta
}); });
} }
fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex { fn renderBinOp(c: *Context, node: Node, tag: std.zig.Ast.Node.Tag, tok_tag: TokenTag, bytes: []const u8) !NodeIndex {
const payload = @fieldParentPtr(Payload.BinOp, "base", node.ptr_otherwise).data; const payload = @fieldParentPtr(Payload.BinOp, "base", node.ptr_otherwise).data;
const lhs = try renderNode(c, payload.lhs); const lhs = try renderNode(c, payload.lhs);
return c.addNode(.{ return c.addNode(.{
@ -2604,7 +2604,7 @@ fn renderVar(c: *Context, node: Node) !NodeIndex {
.tag = .local_var_decl, .tag = .local_var_decl,
.main_token = mut_tok, .main_token = mut_tok,
.data = .{ .data = .{
.lhs = try c.addExtra(std.zig.ast.Node.LocalVarDecl{ .lhs = try c.addExtra(std.zig.Ast.Node.LocalVarDecl{
.type_node = type_node, .type_node = type_node,
.align_node = align_node, .align_node = align_node,
}), }),
@ -2617,7 +2617,7 @@ fn renderVar(c: *Context, node: Node) !NodeIndex {
.tag = .global_var_decl, .tag = .global_var_decl,
.main_token = mut_tok, .main_token = mut_tok,
.data = .{ .data = .{
.lhs = try c.addExtra(std.zig.ast.Node.GlobalVarDecl{ .lhs = try c.addExtra(std.zig.Ast.Node.GlobalVarDecl{
.type_node = type_node, .type_node = type_node,
.align_node = align_node, .align_node = align_node,
.section_node = section_node, .section_node = section_node,
@ -2709,7 +2709,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
.tag = .fn_proto_one, .tag = .fn_proto_one,
.main_token = fn_token, .main_token = fn_token,
.data = .{ .data = .{
.lhs = try c.addExtra(std.zig.ast.Node.FnProtoOne{ .lhs = try c.addExtra(std.zig.Ast.Node.FnProtoOne{
.param = params.items[0], .param = params.items[0],
.align_expr = align_expr, .align_expr = align_expr,
.section_expr = section_expr, .section_expr = section_expr,
@ -2723,7 +2723,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
.tag = .fn_proto, .tag = .fn_proto,
.main_token = fn_token, .main_token = fn_token,
.data = .{ .data = .{
.lhs = try c.addExtra(std.zig.ast.Node.FnProto{ .lhs = try c.addExtra(std.zig.Ast.Node.FnProto{
.params_start = span.start, .params_start = span.start,
.params_end = span.end, .params_end = span.end,
.align_expr = align_expr, .align_expr = align_expr,
@ -2781,7 +2781,7 @@ fn renderMacroFunc(c: *Context, node: Node) !NodeIndex {
.tag = .fn_proto_multi, .tag = .fn_proto_multi,
.main_token = fn_token, .main_token = fn_token,
.data = .{ .data = .{
.lhs = try c.addExtra(std.zig.ast.Node.SubRange{ .lhs = try c.addExtra(std.zig.Ast.Node.SubRange{
.start = span.start, .start = span.start,
.end = span.end, .end = span.end,
}), }),