mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
rename std.zig.ast to std.zig.Ast; use top-level fields
This commit is contained in:
parent
e41e75a486
commit
3940a1be18
15 changed files with 3396 additions and 3396 deletions
|
|
@ -529,7 +529,7 @@ set(ZIG_STAGE2_SOURCES
|
|||
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/unicode.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/parse.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub const fmtEscapes = fmt.fmtEscapes;
|
|||
pub const isValidId = fmt.isValidId;
|
||||
pub const parse = @import("zig/parse.zig").parse;
|
||||
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 CrossTarget = @import("zig/cross_target.zig").CrossTarget;
|
||||
|
||||
|
|
|
|||
2979
lib/std/zig/Ast.zig
Normal file
2979
lib/std/zig/Ast.zig
Normal file
File diff suppressed because it is too large
Load diff
2978
lib/std/zig/ast.zig
2978
lib/std/zig/ast.zig
File diff suppressed because it is too large
Load diff
|
|
@ -1,19 +1,18 @@
|
|||
const std = @import("../std.zig");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ast = std.zig.ast;
|
||||
const Node = ast.Node;
|
||||
const Tree = ast.Tree;
|
||||
const AstError = ast.Error;
|
||||
const TokenIndex = ast.TokenIndex;
|
||||
const Ast = std.zig.Ast;
|
||||
const Node = Ast.Node;
|
||||
const AstError = Ast.Error;
|
||||
const TokenIndex = Ast.TokenIndex;
|
||||
const Token = std.zig.Token;
|
||||
|
||||
pub const Error = error{ParseError} || Allocator.Error;
|
||||
|
||||
/// Result should be freed with tree.deinit() when there are
|
||||
/// no more references to any of the tokens or nodes.
|
||||
pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Tree {
|
||||
var tokens = ast.TokenList{};
|
||||
pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast {
|
||||
var tokens = Ast.TokenList{};
|
||||
defer tokens.deinit(gpa);
|
||||
|
||||
// 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
|
||||
return Tree{
|
||||
return Ast{
|
||||
.source = source,
|
||||
.tokens = tokens.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;
|
||||
|
||||
/// 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 {
|
||||
gpa: *Allocator,
|
||||
source: []const u8,
|
||||
token_tags: []const Token.Tag,
|
||||
token_starts: []const ast.ByteOffset,
|
||||
token_starts: []const Ast.ByteOffset,
|
||||
tok_i: TokenIndex,
|
||||
errors: std.ArrayListUnmanaged(AstError),
|
||||
nodes: ast.NodeList,
|
||||
nodes: Ast.NodeList,
|
||||
extra_data: 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);
|
||||
try p.nodes.append(p.gpa, elem);
|
||||
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);
|
||||
return @intCast(Node.Index, i);
|
||||
}
|
||||
|
|
@ -148,7 +147,7 @@ const Parser = struct {
|
|||
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);
|
||||
try p.warnMsg(.{ .tag = tag, .token = p.tok_i });
|
||||
}
|
||||
|
|
@ -161,12 +160,12 @@ const Parser = struct {
|
|||
.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);
|
||||
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);
|
||||
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);
|
||||
try p.warnMsg(msg);
|
||||
return error.ParseError;
|
||||
|
|
|
|||
|
|
@ -5308,7 +5308,7 @@ fn testCanonical(source: [:0]const u8) !void {
|
|||
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 {
|
||||
var tree = try std.zig.parse(std.testing.allocator, source);
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@ const assert = std.debug.assert;
|
|||
const mem = std.mem;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const meta = std.meta;
|
||||
const ast = std.zig.ast;
|
||||
const Ast = std.zig.Ast;
|
||||
const Token = std.zig.Token;
|
||||
|
||||
const indent_delta = 4;
|
||||
const asm_indent_delta = 2;
|
||||
|
||||
pub const Error = ast.Tree.RenderError;
|
||||
pub const Error = Ast.RenderError;
|
||||
|
||||
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.
|
||||
var auto_indenting_stream = Ais{
|
||||
.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
|
||||
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;
|
||||
try renderMember(gpa, ais, tree, members[0], .newline);
|
||||
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 main_tokens = tree.nodes.items(.main_token);
|
||||
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]) {
|
||||
.fn_proto_one, .fn_proto => {
|
||||
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
|
||||
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 (mem.eql(u8, "Inline", tree.tokenSlice(main_tokens[callconv_expr]))) {
|
||||
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
|
||||
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;
|
||||
try renderExpression(gpa, ais, tree, expressions[0], space);
|
||||
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 main_tokens = tree.nodes.items(.main_token);
|
||||
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_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) {
|
||||
return renderBlock(gpa, ais, tree, node, statements[0..0], space);
|
||||
} 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),
|
||||
|
||||
.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);
|
||||
},
|
||||
.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);
|
||||
},
|
||||
.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),
|
||||
|
||||
.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);
|
||||
},
|
||||
.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);
|
||||
},
|
||||
.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),
|
||||
|
||||
.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(¶ms, 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),
|
||||
|
||||
.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);
|
||||
},
|
||||
.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),
|
||||
|
||||
.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);
|
||||
},
|
||||
.tagged_union_enum_tag,
|
||||
|
|
@ -619,12 +619,12 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
|
|||
},
|
||||
|
||||
.fn_proto_simple => {
|
||||
var params: [1]ast.Node.Index = undefined;
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
return renderFnProto(gpa, ais, tree, tree.fnProtoSimple(¶ms, node), space);
|
||||
},
|
||||
.fn_proto_multi => return renderFnProto(gpa, ais, tree, tree.fnProtoMulti(node), space),
|
||||
.fn_proto_one => {
|
||||
var params: [1]ast.Node.Index = undefined;
|
||||
var params: [1]Ast.Node.Index = undefined;
|
||||
return renderFnProto(gpa, ais, tree, tree.fnProtoOne(¶ms, 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 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 rparen = tree.lastToken(condition) + 1;
|
||||
|
||||
|
|
@ -704,8 +704,8 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I
|
|||
fn renderArrayType(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
array_type: ast.full.ArrayType,
|
||||
tree: Ast,
|
||||
array_type: Ast.full.ArrayType,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const rbracket = tree.firstToken(array_type.ast.elem_type) - 1;
|
||||
|
|
@ -726,8 +726,8 @@ fn renderArrayType(
|
|||
fn renderPtrType(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
ptr_type: ast.full.PtrType,
|
||||
tree: Ast,
|
||||
ptr_type: Ast.full.PtrType,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
switch (ptr_type.size) {
|
||||
|
|
@ -811,9 +811,9 @@ fn renderPtrType(
|
|||
fn renderSlice(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
slice_node: ast.Node.Index,
|
||||
slice: ast.full.Slice,
|
||||
tree: Ast,
|
||||
slice_node: Ast.Node.Index,
|
||||
slice: Ast.full.Slice,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
|
|
@ -847,8 +847,8 @@ fn renderSlice(
|
|||
fn renderAsmOutput(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
asm_output: ast.Node.Index,
|
||||
tree: Ast,
|
||||
asm_output: Ast.Node.Index,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -877,8 +877,8 @@ fn renderAsmOutput(
|
|||
fn renderAsmInput(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
asm_input: ast.Node.Index,
|
||||
tree: Ast,
|
||||
asm_input: Ast.Node.Index,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
|
|
@ -896,7 +896,7 @@ fn renderAsmInput(
|
|||
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| {
|
||||
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); // ;
|
||||
}
|
||||
|
||||
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, .{
|
||||
.ast = .{
|
||||
.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
|
||||
/// 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 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(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
field: ast.full.ContainerField,
|
||||
tree: Ast,
|
||||
field: Ast.full.ContainerField,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
if (field.comptime_token) |t| {
|
||||
|
|
@ -1183,9 +1183,9 @@ fn renderContainerField(
|
|||
fn renderBuiltinCall(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
builtin_token: ast.TokenIndex,
|
||||
params: []const ast.Node.Index,
|
||||
tree: Ast,
|
||||
builtin_token: Ast.TokenIndex,
|
||||
params: []const Ast.Node.Index,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
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_starts = tree.tokens.items(.start);
|
||||
|
||||
|
|
@ -1438,8 +1438,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full.
|
|||
fn renderSwitchCase(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
switch_case: ast.full.SwitchCase,
|
||||
tree: Ast,
|
||||
switch_case: Ast.full.SwitchCase,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
|
|
@ -1491,9 +1491,9 @@ fn renderSwitchCase(
|
|||
fn renderBlock(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
block_node: ast.Node.Index,
|
||||
statements: []const ast.Node.Index,
|
||||
tree: Ast,
|
||||
block_node: Ast.Node.Index,
|
||||
statements: []const Ast.Node.Index,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -1531,9 +1531,9 @@ fn renderBlock(
|
|||
fn renderStructInit(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
struct_node: ast.Node.Index,
|
||||
struct_init: ast.full.StructInit,
|
||||
tree: Ast,
|
||||
struct_node: Ast.Node.Index,
|
||||
struct_init: Ast.full.StructInit,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -1590,8 +1590,8 @@ fn renderStructInit(
|
|||
fn renderArrayInit(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
array_init: ast.full.ArrayInit,
|
||||
tree: Ast,
|
||||
array_init: Ast.full.ArrayInit,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -1787,9 +1787,9 @@ fn renderArrayInit(
|
|||
fn renderContainerDecl(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
container_decl_node: ast.Node.Index,
|
||||
container_decl: ast.full.ContainerDecl,
|
||||
tree: Ast,
|
||||
container_decl_node: Ast.Node.Index,
|
||||
container_decl: Ast.full.ContainerDecl,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -1799,7 +1799,7 @@ fn renderContainerDecl(
|
|||
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| {
|
||||
try renderToken(ais, tree, container_decl.ast.main_token, .none); // union
|
||||
try renderToken(ais, tree, enum_token - 1, .none); // lparen
|
||||
|
|
@ -1869,8 +1869,8 @@ fn renderContainerDecl(
|
|||
fn renderAsm(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
asm_node: ast.full.Asm,
|
||||
tree: Ast,
|
||||
asm_node: Ast.full.Asm,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -2018,8 +2018,8 @@ fn renderAsm(
|
|||
fn renderCall(
|
||||
gpa: *Allocator,
|
||||
ais: *Ais,
|
||||
tree: ast.Tree,
|
||||
call: ast.full.Call,
|
||||
tree: Ast,
|
||||
call: Ast.full.Call,
|
||||
space: Space,
|
||||
) Error!void {
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
|
|
@ -2091,7 +2091,7 @@ fn renderCall(
|
|||
|
||||
/// Renders the given expression indented, popping the indent before rendering
|
||||
/// 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_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.
|
||||
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 maybe_comma = tree.lastToken(node) + 1;
|
||||
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 maybe_comma = token + 1;
|
||||
if (token_tags[maybe_comma] == .comma) {
|
||||
|
|
@ -2191,7 +2191,7 @@ const Space = enum {
|
|||
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_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
|
||||
/// fn_proto should be wrapped and have a trailing comma inserted even if
|
||||
/// 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);
|
||||
|
||||
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
|
||||
/// 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);
|
||||
|
||||
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
|
||||
/// 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;
|
||||
while (mem.indexOf(u8, tree.source[index..end], "//")) |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;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/// 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_start = token_starts[token_index];
|
||||
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
|
||||
/// 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.
|
||||
const token_tags = tree.tokens.items(.tag);
|
||||
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.
|
||||
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);
|
||||
var tok = start_token;
|
||||
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);
|
||||
if (tree.tokens.items(.tag)[token_index] == .multiline_string_literal_line) {
|
||||
assert(ret[ret.len - 1] == '\n');
|
||||
|
|
@ -2399,7 +2399,7 @@ fn tokenSliceForRender(tree: ast.Tree, token_index: ast.TokenIndex) []const u8 {
|
|||
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 between_source = tree.source[token_starts[token_index]..token_starts[token_index + 1]];
|
||||
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
|
||||
/// 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;
|
||||
const token_starts = tree.tokens.items(.start);
|
||||
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) {
|
||||
.block,
|
||||
.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) {
|
||||
.@"if",
|
||||
.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) {
|
||||
.@"catch",
|
||||
.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`.
|
||||
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 first_token = tree.firstToken(exprs[0]);
|
||||
|
|
|
|||
504
src/AstGen.zig
504
src/AstGen.zig
File diff suppressed because it is too large
Load diff
|
|
@ -2408,7 +2408,7 @@ const AstGenSrc = union(enum) {
|
|||
root,
|
||||
import: struct {
|
||||
importing_file: *Module.Scope.File,
|
||||
import_tok: std.zig.ast.TokenIndex,
|
||||
import_tok: std.zig.Ast.TokenIndex,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const log = std.log.scoped(.module);
|
|||
const BigIntConst = std.math.big.int.Const;
|
||||
const BigIntMutable = std.math.big.int.Mutable;
|
||||
const Target = std.Target;
|
||||
const ast = std.zig.ast;
|
||||
const Ast = std.zig.Ast;
|
||||
|
||||
const Module = @This();
|
||||
const Compilation = @import("Compilation.zig");
|
||||
|
|
@ -291,7 +291,7 @@ pub const Decl = struct {
|
|||
generation: u32,
|
||||
/// The AST node index of this declaration.
|
||||
/// 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
|
||||
/// do not need to be loaded into memory in order to compute debug line numbers.
|
||||
src_line: u32,
|
||||
|
|
@ -499,19 +499,19 @@ pub const Decl = struct {
|
|||
return decl.src_line + offset;
|
||||
}
|
||||
|
||||
pub fn relativeToNodeIndex(decl: Decl, offset: i32) ast.Node.Index {
|
||||
return @bitCast(ast.Node.Index, offset + @bitCast(i32, decl.src_node));
|
||||
pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {
|
||||
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);
|
||||
}
|
||||
|
||||
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() };
|
||||
}
|
||||
|
||||
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) };
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
return tree.firstToken(decl.src_node);
|
||||
}
|
||||
|
|
@ -1121,7 +1121,7 @@ pub const Scope = struct {
|
|||
/// Whether this is populated depends on `status`.
|
||||
stat_mtime: i128,
|
||||
/// 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`.
|
||||
zir: Zir,
|
||||
/// Package that this file is a part of, managed externally.
|
||||
|
|
@ -1220,7 +1220,7 @@ pub const Scope = struct {
|
|||
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;
|
||||
|
||||
const source = try file.getSource(gpa);
|
||||
|
|
@ -1565,17 +1565,17 @@ pub const ErrorMsg = struct {
|
|||
pub const SrcLoc = struct {
|
||||
file_scope: *Scope.File,
|
||||
/// 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`.
|
||||
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;
|
||||
return tree.firstToken(src_loc.parent_decl_node);
|
||||
}
|
||||
|
||||
pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) ast.TokenIndex {
|
||||
return @bitCast(ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node));
|
||||
pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.TokenIndex {
|
||||
return @bitCast(Ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node));
|
||||
}
|
||||
|
||||
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 node_tags = tree.nodes.items(.tag);
|
||||
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]) {
|
||||
.call_one,
|
||||
.call_one_comma,
|
||||
|
|
@ -1831,7 +1831,7 @@ pub const SrcLoc = struct {
|
|||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
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];
|
||||
for (case_nodes) |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_tags = tree.nodes.items(.tag);
|
||||
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];
|
||||
for (case_nodes) |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_tags = tree.nodes.items(.tag);
|
||||
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]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, 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 node_tags = tree.nodes.items(.tag);
|
||||
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]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(node),
|
||||
|
|
@ -1941,7 +1941,7 @@ pub const SrcLoc = struct {
|
|||
const node_datas = tree.nodes.items(.data);
|
||||
const node_tags = tree.nodes.items(.tag);
|
||||
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]) {
|
||||
.fn_proto_simple => tree.fnProtoSimple(¶ms, parent_node),
|
||||
.fn_proto_multi => tree.fnProtoMulti(parent_node),
|
||||
|
|
@ -3967,7 +3967,7 @@ fn markOutdatedDecl(mod: *Module, decl: *Decl) !void {
|
|||
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.
|
||||
const new_decl: *Decl = if (mod.emit_h != null) blk: {
|
||||
const parent_struct = try mod.gpa.create(DeclPlusEmitH);
|
||||
|
|
@ -4237,7 +4237,7 @@ pub fn fail(
|
|||
pub fn failTok(
|
||||
mod: *Module,
|
||||
scope: *Scope,
|
||||
token_index: ast.TokenIndex,
|
||||
token_index: Ast.TokenIndex,
|
||||
comptime format: []const u8,
|
||||
args: anytype,
|
||||
) CompileError {
|
||||
|
|
@ -4250,7 +4250,7 @@ pub fn failTok(
|
|||
pub fn failNode(
|
||||
mod: *Module,
|
||||
scope: *Scope,
|
||||
node_index: ast.Node.Index,
|
||||
node_index: Ast.Node.Index,
|
||||
comptime format: []const u8,
|
||||
args: anytype,
|
||||
) CompileError {
|
||||
|
|
@ -4455,7 +4455,7 @@ pub const SwitchProngSrc = union(enum) {
|
|||
const main_tokens = tree.nodes.items(.main_token);
|
||||
const node_datas = tree.nodes.items(.data);
|
||||
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];
|
||||
|
||||
var multi_i: u32 = 0;
|
||||
|
|
|
|||
|
|
@ -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| {
|
||||
log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
|
||||
return error.AnalysisFail;
|
||||
|
|
@ -10186,14 +10186,14 @@ fn getAstTree(sema: *Sema, block: *Scope.Block) CompileError!*const std.zig.ast.
|
|||
|
||||
fn enumFieldSrcLoc(
|
||||
decl: *Decl,
|
||||
tree: std.zig.ast.Tree,
|
||||
tree: std.zig.Ast,
|
||||
node_offset: i32,
|
||||
field_index: usize,
|
||||
) LazySrcLoc {
|
||||
@setCold(true);
|
||||
const enum_node = decl.relativeToNodeIndex(node_offset);
|
||||
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]) {
|
||||
.container_decl,
|
||||
.container_decl_trailing,
|
||||
|
|
|
|||
18
src/Zir.zig
18
src/Zir.zig
|
|
@ -16,7 +16,7 @@ const Allocator = std.mem.Allocator;
|
|||
const assert = std.debug.assert;
|
||||
const BigIntConst = std.math.big.int.Const;
|
||||
const BigIntMutable = std.math.big.int.Mutable;
|
||||
const ast = std.zig.ast;
|
||||
const Ast = std.zig.Ast;
|
||||
|
||||
const Zir = @This();
|
||||
const Type = @import("type.zig").Type;
|
||||
|
|
@ -2092,7 +2092,7 @@ pub const Inst = struct {
|
|||
/// Used for unary operators, with a token source location.
|
||||
un_tok: struct {
|
||||
/// Offset from Decl AST token index.
|
||||
src_tok: ast.TokenIndex,
|
||||
src_tok: Ast.TokenIndex,
|
||||
/// The meaning of this operand depends on the corresponding `Tag`.
|
||||
operand: Ref,
|
||||
|
||||
|
|
@ -2114,7 +2114,7 @@ pub const Inst = struct {
|
|||
},
|
||||
pl_tok: struct {
|
||||
/// Offset from Decl AST token index.
|
||||
src_tok: ast.TokenIndex,
|
||||
src_tok: Ast.TokenIndex,
|
||||
/// index into extra.
|
||||
/// `Tag` determines what lives there.
|
||||
payload_index: u32,
|
||||
|
|
@ -2150,7 +2150,7 @@ pub const Inst = struct {
|
|||
}
|
||||
},
|
||||
/// Offset from Decl AST token index.
|
||||
tok: ast.TokenIndex,
|
||||
tok: Ast.TokenIndex,
|
||||
/// Offset from Decl AST node index.
|
||||
node: i32,
|
||||
int: u64,
|
||||
|
|
@ -2878,9 +2878,9 @@ pub const Inst = struct {
|
|||
pub const Item = struct {
|
||||
/// null terminated string index
|
||||
msg: u32,
|
||||
node: ast.Node.Index,
|
||||
node: Ast.Node.Index,
|
||||
/// If node is 0 then this will be populated.
|
||||
token: ast.TokenIndex,
|
||||
token: Ast.TokenIndex,
|
||||
/// Can be used in combination with `token`.
|
||||
byte_offset: u32,
|
||||
/// 0 or a payload index of a `Block`, each is a payload
|
||||
|
|
@ -2897,7 +2897,7 @@ pub const Inst = struct {
|
|||
/// null terminated string index
|
||||
name: u32,
|
||||
/// points to the import name
|
||||
token: ast.TokenIndex,
|
||||
token: Ast.TokenIndex,
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -2912,8 +2912,8 @@ const Writer = struct {
|
|||
indent: u32,
|
||||
parent_decl_node: u32,
|
||||
|
||||
fn relativeToNodeIndex(self: *Writer, offset: i32) ast.Node.Index {
|
||||
return @bitCast(ast.Node.Index, offset + @bitCast(i32, self.parent_decl_node));
|
||||
fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {
|
||||
return @bitCast(Ast.Node.Index, offset + @bitCast(i32, self.parent_decl_node));
|
||||
}
|
||||
|
||||
fn writeInstToStream(
|
||||
|
|
|
|||
18
src/main.zig
18
src/main.zig
|
|
@ -6,7 +6,7 @@ const mem = std.mem;
|
|||
const process = std.process;
|
||||
const Allocator = mem.Allocator;
|
||||
const ArrayList = std.ArrayList;
|
||||
const ast = std.zig.ast;
|
||||
const Ast = std.zig.Ast;
|
||||
const warn = std.log.warn;
|
||||
|
||||
const Compilation = @import("Compilation.zig");
|
||||
|
|
@ -3423,8 +3423,8 @@ fn fmtPathFile(
|
|||
fn printErrMsgToStdErr(
|
||||
gpa: *mem.Allocator,
|
||||
arena: *mem.Allocator,
|
||||
parse_error: ast.Error,
|
||||
tree: ast.Tree,
|
||||
parse_error: Ast.Error,
|
||||
tree: Ast,
|
||||
path: []const u8,
|
||||
color: Color,
|
||||
) !void {
|
||||
|
|
@ -4029,12 +4029,12 @@ pub fn cmdAstCheck(
|
|||
}
|
||||
|
||||
{
|
||||
const token_bytes = @sizeOf(std.zig.ast.TokenList) +
|
||||
file.tree.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(std.zig.ast.ByteOffset));
|
||||
const tree_bytes = @sizeOf(std.zig.ast.Tree) + file.tree.nodes.len *
|
||||
(@sizeOf(std.zig.ast.Node.Tag) +
|
||||
@sizeOf(std.zig.ast.Node.Data) +
|
||||
@sizeOf(std.zig.ast.TokenIndex));
|
||||
const token_bytes = @sizeOf(Ast.TokenList) +
|
||||
file.tree.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(Ast.ByteOffset));
|
||||
const tree_bytes = @sizeOf(Ast) + file.tree.nodes.len *
|
||||
(@sizeOf(Ast.Node.Tag) +
|
||||
@sizeOf(Ast.Node.Data) +
|
||||
@sizeOf(Ast.TokenIndex));
|
||||
const instruction_bytes = file.zir.instructions.len *
|
||||
// Here we don't use @sizeOf(Zir.Inst.Data) because it would include
|
||||
// the debug safety tag but we want to measure release size.
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ pub fn translate(
|
|||
args_end: [*]?[*]const u8,
|
||||
errors: *[]ClangErrMsg,
|
||||
resources_path: [*:0]const u8,
|
||||
) !std.zig.ast.Tree {
|
||||
) !std.zig.Ast {
|
||||
const ast_unit = clang.LoadFromCommandLine(
|
||||
args_begin,
|
||||
args_end,
|
||||
|
|
@ -369,7 +369,7 @@ pub fn translate(
|
|||
};
|
||||
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.
|
||||
var arena = std.heap.ArenaAllocator.init(gpa);
|
||||
errdefer arena.deinit();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
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{
|
||||
.gpa = 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),
|
||||
});
|
||||
|
||||
return std.zig.ast.Tree{
|
||||
return std.zig.Ast{
|
||||
.source = try ctx.buf.toOwnedSliceSentinel(0),
|
||||
.tokens = ctx.tokens.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 NodeSubRange = std.zig.ast.Node.SubRange;
|
||||
const TokenIndex = std.zig.ast.TokenIndex;
|
||||
const NodeIndex = std.zig.Ast.Node.Index;
|
||||
const NodeSubRange = std.zig.Ast.Node.SubRange;
|
||||
const TokenIndex = std.zig.Ast.TokenIndex;
|
||||
const TokenTag = std.zig.Token.Tag;
|
||||
|
||||
const Context = struct {
|
||||
gpa: *Allocator,
|
||||
buf: std.ArrayList(u8) = .{},
|
||||
nodes: std.zig.ast.NodeList = .{},
|
||||
extra_data: std.ArrayListUnmanaged(std.zig.ast.Node.Index) = .{},
|
||||
tokens: std.zig.ast.TokenList = .{},
|
||||
nodes: std.zig.Ast.NodeList = .{},
|
||||
extra_data: std.ArrayListUnmanaged(std.zig.Ast.Node.Index) = .{},
|
||||
tokens: std.zig.Ast.TokenList = .{},
|
||||
|
||||
fn addTokenFmt(c: *Context, tag: TokenTag, comptime format: []const u8, args: anytype) Allocator.Error!TokenIndex {
|
||||
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);
|
||||
try c.nodes.append(c.gpa, elem);
|
||||
return result;
|
||||
|
|
@ -1166,7 +1166,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
|
|||
.main_token = l_bracket,
|
||||
.data = .{
|
||||
.lhs = string,
|
||||
.rhs = try c.addExtra(std.zig.ast.Node.Slice{
|
||||
.rhs = try c.addExtra(std.zig.Ast.Node.Slice{
|
||||
.start = start,
|
||||
.end = end,
|
||||
}),
|
||||
|
|
@ -1601,7 +1601,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
|
|||
.main_token = while_tok,
|
||||
.data = .{
|
||||
.lhs = cond,
|
||||
.rhs = try c.addExtra(std.zig.ast.Node.WhileCont{
|
||||
.rhs = try c.addExtra(std.zig.Ast.Node.WhileCont{
|
||||
.cont_expr = cont_expr,
|
||||
.then_expr = body,
|
||||
}),
|
||||
|
|
@ -1654,7 +1654,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
|
|||
.main_token = if_tok,
|
||||
.data = .{
|
||||
.lhs = cond,
|
||||
.rhs = try c.addExtra(std.zig.ast.Node.If{
|
||||
.rhs = try c.addExtra(std.zig.Ast.Node.If{
|
||||
.then_expr = then_expr,
|
||||
.else_expr = else_expr,
|
||||
}),
|
||||
|
|
@ -2175,7 +2175,7 @@ fn renderNullSentinelArrayType(c: *Context, len: usize, elem_type: Node) !NodeIn
|
|||
.main_token = l_bracket,
|
||||
.data = .{
|
||||
.lhs = len_expr,
|
||||
.rhs = try c.addExtra(std.zig.ast.Node.ArrayTypeSentinel{
|
||||
.rhs = try c.addExtra(std.zig.Ast.Node.ArrayTypeSentinel{
|
||||
.sentinel = sentinel_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;
|
||||
return c.addNode(.{
|
||||
.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 lhs = try renderNodeGrouped(c, payload.lhs);
|
||||
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 lhs = try renderNode(c, payload.lhs);
|
||||
return c.addNode(.{
|
||||
|
|
@ -2604,7 +2604,7 @@ fn renderVar(c: *Context, node: Node) !NodeIndex {
|
|||
.tag = .local_var_decl,
|
||||
.main_token = mut_tok,
|
||||
.data = .{
|
||||
.lhs = try c.addExtra(std.zig.ast.Node.LocalVarDecl{
|
||||
.lhs = try c.addExtra(std.zig.Ast.Node.LocalVarDecl{
|
||||
.type_node = type_node,
|
||||
.align_node = align_node,
|
||||
}),
|
||||
|
|
@ -2617,7 +2617,7 @@ fn renderVar(c: *Context, node: Node) !NodeIndex {
|
|||
.tag = .global_var_decl,
|
||||
.main_token = mut_tok,
|
||||
.data = .{
|
||||
.lhs = try c.addExtra(std.zig.ast.Node.GlobalVarDecl{
|
||||
.lhs = try c.addExtra(std.zig.Ast.Node.GlobalVarDecl{
|
||||
.type_node = type_node,
|
||||
.align_node = align_node,
|
||||
.section_node = section_node,
|
||||
|
|
@ -2709,7 +2709,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
|
|||
.tag = .fn_proto_one,
|
||||
.main_token = fn_token,
|
||||
.data = .{
|
||||
.lhs = try c.addExtra(std.zig.ast.Node.FnProtoOne{
|
||||
.lhs = try c.addExtra(std.zig.Ast.Node.FnProtoOne{
|
||||
.param = params.items[0],
|
||||
.align_expr = align_expr,
|
||||
.section_expr = section_expr,
|
||||
|
|
@ -2723,7 +2723,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex {
|
|||
.tag = .fn_proto,
|
||||
.main_token = fn_token,
|
||||
.data = .{
|
||||
.lhs = try c.addExtra(std.zig.ast.Node.FnProto{
|
||||
.lhs = try c.addExtra(std.zig.Ast.Node.FnProto{
|
||||
.params_start = span.start,
|
||||
.params_end = span.end,
|
||||
.align_expr = align_expr,
|
||||
|
|
@ -2781,7 +2781,7 @@ fn renderMacroFunc(c: *Context, node: Node) !NodeIndex {
|
|||
.tag = .fn_proto_multi,
|
||||
.main_token = fn_token,
|
||||
.data = .{
|
||||
.lhs = try c.addExtra(std.zig.ast.Node.SubRange{
|
||||
.lhs = try c.addExtra(std.zig.Ast.Node.SubRange{
|
||||
.start = span.start,
|
||||
.end = span.end,
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue