remove std.mem.Allocator.construct and other fixups
This commit is contained in:
parent
e891f9cd9d
commit
85f928f8bf
@ -35,7 +35,7 @@ pub fn createFromParseError(
|
|||||||
var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
|
var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
|
||||||
try parse_error.render(&tree.tokens, out_stream);
|
try parse_error.render(&tree.tokens, out_stream);
|
||||||
|
|
||||||
const msg = try allocator.construct(Msg{
|
const msg = try allocator.create(Msg{
|
||||||
.tree = tree,
|
.tree = tree,
|
||||||
.path = path,
|
.path = path,
|
||||||
.text = text_buf.toOwnedSlice(),
|
.text = text_buf.toOwnedSlice(),
|
||||||
|
@ -707,7 +707,7 @@ const Fmt = struct {
|
|||||||
|
|
||||||
// file_path must outlive Fmt
|
// file_path must outlive Fmt
|
||||||
fn addToQueue(self: *Fmt, file_path: []const u8) !void {
|
fn addToQueue(self: *Fmt, file_path: []const u8) !void {
|
||||||
const new_node = try self.seen.allocator.construct(std.LinkedList([]const u8).Node{
|
const new_node = try self.seen.allocator.create(std.LinkedList([]const u8).Node{
|
||||||
.prev = undefined,
|
.prev = undefined,
|
||||||
.next = undefined,
|
.next = undefined,
|
||||||
.data = file_path,
|
.data = file_path,
|
||||||
|
@ -114,7 +114,7 @@ pub const Module = struct {
|
|||||||
.name = name,
|
.name = name,
|
||||||
.path = path,
|
.path = path,
|
||||||
.children = ArrayList(*CliPkg).init(allocator),
|
.children = ArrayList(*CliPkg).init(allocator),
|
||||||
.parent = parent
|
.parent = parent,
|
||||||
});
|
});
|
||||||
return pkg;
|
return pkg;
|
||||||
}
|
}
|
||||||
@ -127,7 +127,16 @@ pub const Module = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn create(allocator: *mem.Allocator, name: []const u8, root_src_path: ?[]const u8, target: *const Target, kind: Kind, build_mode: builtin.Mode, zig_lib_dir: []const u8, cache_dir: []const u8) !*Module {
|
pub fn create(
|
||||||
|
allocator: *mem.Allocator,
|
||||||
|
name: []const u8,
|
||||||
|
root_src_path: ?[]const u8,
|
||||||
|
target: *const Target,
|
||||||
|
kind: Kind,
|
||||||
|
build_mode: builtin.Mode,
|
||||||
|
zig_lib_dir: []const u8,
|
||||||
|
cache_dir: []const u8,
|
||||||
|
) !*Module {
|
||||||
var name_buffer = try Buffer.init(allocator, name);
|
var name_buffer = try Buffer.init(allocator, name);
|
||||||
errdefer name_buffer.deinit();
|
errdefer name_buffer.deinit();
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ fn startPuts(ctx: *Context) u8 {
|
|||||||
std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
|
std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
|
||||||
const x = @bitCast(i32, r.random.scalar(u32));
|
const x = @bitCast(i32, r.random.scalar(u32));
|
||||||
const node = ctx.allocator.create(Queue(i32).Node{
|
const node = ctx.allocator.create(Queue(i32).Node{
|
||||||
.next = null,
|
.next = undefined,
|
||||||
.data = x,
|
.data = x,
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
ctx.queue.put(node);
|
ctx.queue.put(node);
|
||||||
|
@ -118,7 +118,7 @@ fn startPuts(ctx: *Context) u8 {
|
|||||||
std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
|
std.os.time.sleep(0, 1); // let the os scheduler be our fuzz
|
||||||
const x = @bitCast(i32, r.random.scalar(u32));
|
const x = @bitCast(i32, r.random.scalar(u32));
|
||||||
const node = ctx.allocator.create(Stack(i32).Node{
|
const node = ctx.allocator.create(Stack(i32).Node{
|
||||||
.next = null,
|
.next = undefined,
|
||||||
.data = x,
|
.data = x,
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
ctx.stack.push(node);
|
ctx.stack.push(node);
|
||||||
|
@ -407,8 +407,7 @@ fn testAllocator(allocator: *mem.Allocator) !void {
|
|||||||
var slice = try allocator.alloc(*i32, 100);
|
var slice = try allocator.alloc(*i32, 100);
|
||||||
|
|
||||||
for (slice) |*item, i| {
|
for (slice) |*item, i| {
|
||||||
item.* = try allocator.create(i32(0));
|
item.* = try allocator.create(@intCast(i32, i));
|
||||||
item.*.* = @intCast(i32, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (slice) |item, i| {
|
for (slice) |item, i| {
|
||||||
|
@ -193,11 +193,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
|
|||||||
/// A pointer to the new node.
|
/// A pointer to the new node.
|
||||||
pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {
|
pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node {
|
||||||
comptime assert(!isIntrusive());
|
comptime assert(!isIntrusive());
|
||||||
return allocator.create(Node{
|
return allocator.create(Node(undefined));
|
||||||
.prev = null,
|
|
||||||
.next = null,
|
|
||||||
.data = undefined,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deallocate a node.
|
/// Deallocate a node.
|
||||||
|
@ -41,13 +41,7 @@ pub const Allocator = struct {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alias of `create`
|
/// `ptr` should be the return value of `create`
|
||||||
/// Call `destroy` with the result
|
|
||||||
pub fn construct(self: *Allocator, init: var) Error!*@typeOf(init) {
|
|
||||||
return self.create(init);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `ptr` should be the return value of `construct` or `create`
|
|
||||||
pub fn destroy(self: *Allocator, ptr: var) void {
|
pub fn destroy(self: *Allocator, ptr: var) void {
|
||||||
const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
|
const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
|
||||||
self.freeFn(self, non_const_ptr[0..@sizeOf(@typeOf(ptr).Child)]);
|
self.freeFn(self, non_const_ptr[0..@sizeOf(@typeOf(ptr).Child)]);
|
||||||
|
@ -2468,7 +2468,7 @@ pub const Thread = struct {
|
|||||||
data: Data,
|
data: Data,
|
||||||
|
|
||||||
pub const use_pthreads = is_posix and builtin.link_libc;
|
pub const use_pthreads = is_posix and builtin.link_libc;
|
||||||
const Data = if (use_pthreads)
|
pub const Data = if (use_pthreads)
|
||||||
struct {
|
struct {
|
||||||
handle: c.pthread_t,
|
handle: c.pthread_t,
|
||||||
stack_addr: usize,
|
stack_addr: usize,
|
||||||
@ -2583,13 +2583,16 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
|
|||||||
errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
|
errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
|
||||||
const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
|
const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
|
||||||
const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{
|
const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{
|
||||||
.thread = undefined,
|
.thread = Thread{
|
||||||
|
.data = Thread.Data{
|
||||||
|
.heap_handle = heap_handle,
|
||||||
|
.alloc_start = bytes_ptr,
|
||||||
|
.handle = undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
.inner = context,
|
.inner = context,
|
||||||
}) catch unreachable;
|
}) catch unreachable;
|
||||||
|
|
||||||
outer_context.thread.data.heap_handle = heap_handle;
|
|
||||||
outer_context.thread.data.alloc_start = bytes_ptr;
|
|
||||||
|
|
||||||
const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
|
const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
|
||||||
outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse {
|
outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse {
|
||||||
const err = windows.GetLastError();
|
const err = windows.GetLastError();
|
||||||
|
@ -17,7 +17,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
defer stack.deinit();
|
defer stack.deinit();
|
||||||
|
|
||||||
const arena = &tree_arena.allocator;
|
const arena = &tree_arena.allocator;
|
||||||
const root_node = try arena.construct(ast.Node.Root{
|
const root_node = try arena.create(ast.Node.Root{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Root },
|
.base = ast.Node{ .id = ast.Node.Id.Root },
|
||||||
.decls = ast.Node.Root.DeclList.init(arena),
|
.decls = ast.Node.Root.DeclList.init(arena),
|
||||||
.doc_comments = null,
|
.doc_comments = null,
|
||||||
@ -65,14 +65,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
Token.Id.Keyword_test => {
|
Token.Id.Keyword_test => {
|
||||||
stack.append(State.TopLevel) catch unreachable;
|
stack.append(State.TopLevel) catch unreachable;
|
||||||
|
|
||||||
const block = try arena.construct(ast.Node.Block{
|
const block = try arena.create(ast.Node.Block{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Block },
|
.base = ast.Node{ .id = ast.Node.Id.Block },
|
||||||
.label = null,
|
.label = null,
|
||||||
.lbrace = undefined,
|
.lbrace = undefined,
|
||||||
.statements = ast.Node.Block.StatementList.init(arena),
|
.statements = ast.Node.Block.StatementList.init(arena),
|
||||||
.rbrace = undefined,
|
.rbrace = undefined,
|
||||||
});
|
});
|
||||||
const test_node = try arena.construct(ast.Node.TestDecl{
|
const test_node = try arena.create(ast.Node.TestDecl{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.TestDecl },
|
.base = ast.Node{ .id = ast.Node.Id.TestDecl },
|
||||||
.doc_comments = comments,
|
.doc_comments = comments,
|
||||||
.test_token = token_index,
|
.test_token = token_index,
|
||||||
@ -109,14 +109,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_comptime => {
|
Token.Id.Keyword_comptime => {
|
||||||
const block = try arena.construct(ast.Node.Block{
|
const block = try arena.create(ast.Node.Block{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Block },
|
.base = ast.Node{ .id = ast.Node.Id.Block },
|
||||||
.label = null,
|
.label = null,
|
||||||
.lbrace = undefined,
|
.lbrace = undefined,
|
||||||
.statements = ast.Node.Block.StatementList.init(arena),
|
.statements = ast.Node.Block.StatementList.init(arena),
|
||||||
.rbrace = undefined,
|
.rbrace = undefined,
|
||||||
});
|
});
|
||||||
const node = try arena.construct(ast.Node.Comptime{
|
const node = try arena.create(ast.Node.Comptime{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Comptime },
|
.base = ast.Node{ .id = ast.Node.Id.Comptime },
|
||||||
.comptime_token = token_index,
|
.comptime_token = token_index,
|
||||||
.expr = &block.base,
|
.expr = &block.base,
|
||||||
@ -225,7 +225,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.Use{
|
const node = try arena.create(ast.Node.Use{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Use },
|
.base = ast.Node{ .id = ast.Node.Id.Use },
|
||||||
.use_token = token_index,
|
.use_token = token_index,
|
||||||
.visib_token = ctx.visib_token,
|
.visib_token = ctx.visib_token,
|
||||||
@ -266,7 +266,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => {
|
Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => {
|
||||||
const fn_proto = try arena.construct(ast.Node.FnProto{
|
const fn_proto = try arena.create(ast.Node.FnProto{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
||||||
.doc_comments = ctx.comments,
|
.doc_comments = ctx.comments,
|
||||||
.visib_token = ctx.visib_token,
|
.visib_token = ctx.visib_token,
|
||||||
@ -298,7 +298,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_async => {
|
Token.Id.Keyword_async => {
|
||||||
const async_node = try arena.construct(ast.Node.AsyncAttribute{
|
const async_node = try arena.create(ast.Node.AsyncAttribute{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
|
.base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
|
||||||
.async_token = token_index,
|
.async_token = token_index,
|
||||||
.allocator_type = null,
|
.allocator_type = null,
|
||||||
@ -330,7 +330,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
},
|
},
|
||||||
State.TopLevelExternOrField => |ctx| {
|
State.TopLevelExternOrField => |ctx| {
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| {
|
if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| {
|
||||||
const node = try arena.construct(ast.Node.StructField{
|
const node = try arena.create(ast.Node.StructField{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.StructField },
|
.base = ast.Node{ .id = ast.Node.Id.StructField },
|
||||||
.doc_comments = ctx.comments,
|
.doc_comments = ctx.comments,
|
||||||
.visib_token = ctx.visib_token,
|
.visib_token = ctx.visib_token,
|
||||||
@ -375,7 +375,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token = nextToken(&tok_it, &tree);
|
const token = nextToken(&tok_it, &tree);
|
||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
const node = try arena.construct(ast.Node.ContainerDecl{
|
const node = try arena.create(ast.Node.ContainerDecl{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ContainerDecl },
|
.base = ast.Node{ .id = ast.Node.Id.ContainerDecl },
|
||||||
.layout_token = ctx.layout_token,
|
.layout_token = ctx.layout_token,
|
||||||
.kind_token = switch (token_ptr.id) {
|
.kind_token = switch (token_ptr.id) {
|
||||||
@ -448,7 +448,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
Token.Id.Identifier => {
|
Token.Id.Identifier => {
|
||||||
switch (tree.tokens.at(container_decl.kind_token).id) {
|
switch (tree.tokens.at(container_decl.kind_token).id) {
|
||||||
Token.Id.Keyword_struct => {
|
Token.Id.Keyword_struct => {
|
||||||
const node = try arena.construct(ast.Node.StructField{
|
const node = try arena.create(ast.Node.StructField{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.StructField },
|
.base = ast.Node{ .id = ast.Node.Id.StructField },
|
||||||
.doc_comments = comments,
|
.doc_comments = comments,
|
||||||
.visib_token = null,
|
.visib_token = null,
|
||||||
@ -464,7 +464,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_union => {
|
Token.Id.Keyword_union => {
|
||||||
const node = try arena.construct(ast.Node.UnionTag{
|
const node = try arena.create(ast.Node.UnionTag{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.UnionTag },
|
.base = ast.Node{ .id = ast.Node.Id.UnionTag },
|
||||||
.name_token = token_index,
|
.name_token = token_index,
|
||||||
.type_expr = null,
|
.type_expr = null,
|
||||||
@ -480,7 +480,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_enum => {
|
Token.Id.Keyword_enum => {
|
||||||
const node = try arena.construct(ast.Node.EnumTag{
|
const node = try arena.create(ast.Node.EnumTag{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.EnumTag },
|
.base = ast.Node{ .id = ast.Node.Id.EnumTag },
|
||||||
.name_token = token_index,
|
.name_token = token_index,
|
||||||
.value = null,
|
.value = null,
|
||||||
@ -562,7 +562,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
},
|
},
|
||||||
|
|
||||||
State.VarDecl => |ctx| {
|
State.VarDecl => |ctx| {
|
||||||
const var_decl = try arena.construct(ast.Node.VarDecl{
|
const var_decl = try arena.create(ast.Node.VarDecl{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.VarDecl },
|
.base = ast.Node{ .id = ast.Node.Id.VarDecl },
|
||||||
.doc_comments = ctx.comments,
|
.doc_comments = ctx.comments,
|
||||||
.visib_token = ctx.visib_token,
|
.visib_token = ctx.visib_token,
|
||||||
@ -660,7 +660,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
switch (token_ptr.id) {
|
switch (token_ptr.id) {
|
||||||
Token.Id.LBrace => {
|
Token.Id.LBrace => {
|
||||||
const block = try arena.construct(ast.Node.Block{
|
const block = try arena.create(ast.Node.Block{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Block },
|
.base = ast.Node{ .id = ast.Node.Id.Block },
|
||||||
.label = null,
|
.label = null,
|
||||||
.lbrace = token_index,
|
.lbrace = token_index,
|
||||||
@ -712,7 +712,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
// TODO: this is a special case. Remove this when #760 is fixed
|
// TODO: this is a special case. Remove this when #760 is fixed
|
||||||
if (token_ptr.id == Token.Id.Keyword_error) {
|
if (token_ptr.id == Token.Id.Keyword_error) {
|
||||||
if (tok_it.peek().?.id == Token.Id.LBrace) {
|
if (tok_it.peek().?.id == Token.Id.LBrace) {
|
||||||
const error_type_node = try arena.construct(ast.Node.ErrorType{
|
const error_type_node = try arena.create(ast.Node.ErrorType{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ErrorType },
|
.base = ast.Node{ .id = ast.Node.Id.ErrorType },
|
||||||
.token = token_index,
|
.token = token_index,
|
||||||
});
|
});
|
||||||
@ -733,7 +733,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
|
if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const param_decl = try arena.construct(ast.Node.ParamDecl{
|
const param_decl = try arena.create(ast.Node.ParamDecl{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ParamDecl },
|
.base = ast.Node{ .id = ast.Node.Id.ParamDecl },
|
||||||
.comptime_token = null,
|
.comptime_token = null,
|
||||||
.noalias_token = null,
|
.noalias_token = null,
|
||||||
@ -819,7 +819,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
switch (token_ptr.id) {
|
switch (token_ptr.id) {
|
||||||
Token.Id.LBrace => {
|
Token.Id.LBrace => {
|
||||||
const block = try arena.construct(ast.Node.Block{
|
const block = try arena.create(ast.Node.Block{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Block },
|
.base = ast.Node{ .id = ast.Node.Id.Block },
|
||||||
.label = ctx.label,
|
.label = ctx.label,
|
||||||
.lbrace = token_index,
|
.lbrace = token_index,
|
||||||
@ -853,7 +853,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_suspend => {
|
Token.Id.Keyword_suspend => {
|
||||||
const node = try arena.construct(ast.Node.Suspend{
|
const node = try arena.create(ast.Node.Suspend{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Suspend },
|
.base = ast.Node{ .id = ast.Node.Id.Suspend },
|
||||||
.label = ctx.label,
|
.label = ctx.label,
|
||||||
.suspend_token = token_index,
|
.suspend_token = token_index,
|
||||||
@ -925,7 +925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
State.While => |ctx| {
|
State.While => |ctx| {
|
||||||
const node = try arena.construct(ast.Node.While{
|
const node = try arena.create(ast.Node.While{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.While },
|
.base = ast.Node{ .id = ast.Node.Id.While },
|
||||||
.label = ctx.label,
|
.label = ctx.label,
|
||||||
.inline_token = ctx.inline_token,
|
.inline_token = ctx.inline_token,
|
||||||
@ -954,7 +954,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
State.For => |ctx| {
|
State.For => |ctx| {
|
||||||
const node = try arena.construct(ast.Node.For{
|
const node = try arena.create(ast.Node.For{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.For },
|
.base = ast.Node{ .id = ast.Node.Id.For },
|
||||||
.label = ctx.label,
|
.label = ctx.label,
|
||||||
.inline_token = ctx.inline_token,
|
.inline_token = ctx.inline_token,
|
||||||
@ -975,7 +975,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
},
|
},
|
||||||
State.Else => |dest| {
|
State.Else => |dest| {
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
|
||||||
const node = try arena.construct(ast.Node.Else{
|
const node = try arena.create(ast.Node.Else{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Else },
|
.base = ast.Node{ .id = ast.Node.Id.Else },
|
||||||
.else_token = else_token,
|
.else_token = else_token,
|
||||||
.payload = null,
|
.payload = null,
|
||||||
@ -1038,7 +1038,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => {
|
Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => {
|
||||||
const node = try arena.construct(ast.Node.Defer{
|
const node = try arena.create(ast.Node.Defer{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Defer },
|
.base = ast.Node{ .id = ast.Node.Id.Defer },
|
||||||
.defer_token = token_index,
|
.defer_token = token_index,
|
||||||
.kind = switch (token_ptr.id) {
|
.kind = switch (token_ptr.id) {
|
||||||
@ -1056,7 +1056,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.LBrace => {
|
Token.Id.LBrace => {
|
||||||
const inner_block = try arena.construct(ast.Node.Block{
|
const inner_block = try arena.create(ast.Node.Block{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Block },
|
.base = ast.Node{ .id = ast.Node.Id.Block },
|
||||||
.label = null,
|
.label = null,
|
||||||
.lbrace = token_index,
|
.lbrace = token_index,
|
||||||
@ -1124,7 +1124,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.AsmOutput{
|
const node = try arena.create(ast.Node.AsmOutput{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.AsmOutput },
|
.base = ast.Node{ .id = ast.Node.Id.AsmOutput },
|
||||||
.lbracket = lbracket_index,
|
.lbracket = lbracket_index,
|
||||||
.symbolic_name = undefined,
|
.symbolic_name = undefined,
|
||||||
@ -1178,7 +1178,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.AsmInput{
|
const node = try arena.create(ast.Node.AsmInput{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.AsmInput },
|
.base = ast.Node{ .id = ast.Node.Id.AsmInput },
|
||||||
.lbracket = lbracket_index,
|
.lbracket = lbracket_index,
|
||||||
.symbolic_name = undefined,
|
.symbolic_name = undefined,
|
||||||
@ -1243,7 +1243,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.FieldInitializer{
|
const node = try arena.create(ast.Node.FieldInitializer{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.FieldInitializer },
|
.base = ast.Node{ .id = ast.Node.Id.FieldInitializer },
|
||||||
.period_token = undefined,
|
.period_token = undefined,
|
||||||
.name_token = undefined,
|
.name_token = undefined,
|
||||||
@ -1332,7 +1332,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const comments = try eatDocComments(arena, &tok_it, &tree);
|
const comments = try eatDocComments(arena, &tok_it, &tree);
|
||||||
const node = try arena.construct(ast.Node.SwitchCase{
|
const node = try arena.create(ast.Node.SwitchCase{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SwitchCase },
|
.base = ast.Node{ .id = ast.Node.Id.SwitchCase },
|
||||||
.items = ast.Node.SwitchCase.ItemList.init(arena),
|
.items = ast.Node.SwitchCase.ItemList.init(arena),
|
||||||
.payload = null,
|
.payload = null,
|
||||||
@ -1369,7 +1369,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (token_ptr.id == Token.Id.Keyword_else) {
|
if (token_ptr.id == Token.Id.Keyword_else) {
|
||||||
const else_node = try arena.construct(ast.Node.SwitchElse{
|
const else_node = try arena.create(ast.Node.SwitchElse{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SwitchElse },
|
.base = ast.Node{ .id = ast.Node.Id.SwitchElse },
|
||||||
.token = token_index,
|
.token = token_index,
|
||||||
});
|
});
|
||||||
@ -1468,7 +1468,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
|
|
||||||
State.ExternType => |ctx| {
|
State.ExternType => |ctx| {
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| {
|
||||||
const fn_proto = try arena.construct(ast.Node.FnProto{
|
const fn_proto = try arena.create(ast.Node.FnProto{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
||||||
.doc_comments = ctx.comments,
|
.doc_comments = ctx.comments,
|
||||||
.visib_token = null,
|
.visib_token = null,
|
||||||
@ -1641,7 +1641,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.Payload{
|
const node = try arena.create(ast.Node.Payload{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Payload },
|
.base = ast.Node{ .id = ast.Node.Id.Payload },
|
||||||
.lpipe = token_index,
|
.lpipe = token_index,
|
||||||
.error_symbol = undefined,
|
.error_symbol = undefined,
|
||||||
@ -1677,7 +1677,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.PointerPayload{
|
const node = try arena.create(ast.Node.PointerPayload{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PointerPayload },
|
.base = ast.Node{ .id = ast.Node.Id.PointerPayload },
|
||||||
.lpipe = token_index,
|
.lpipe = token_index,
|
||||||
.ptr_token = null,
|
.ptr_token = null,
|
||||||
@ -1720,7 +1720,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.PointerIndexPayload{
|
const node = try arena.create(ast.Node.PointerIndexPayload{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload },
|
.base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload },
|
||||||
.lpipe = token_index,
|
.lpipe = token_index,
|
||||||
.ptr_token = null,
|
.ptr_token = null,
|
||||||
@ -1754,7 +1754,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
switch (token_ptr.id) {
|
switch (token_ptr.id) {
|
||||||
Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => {
|
Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => {
|
||||||
const node = try arena.construct(ast.Node.ControlFlowExpression{
|
const node = try arena.create(ast.Node.ControlFlowExpression{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },
|
.base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },
|
||||||
.ltoken = token_index,
|
.ltoken = token_index,
|
||||||
.kind = undefined,
|
.kind = undefined,
|
||||||
@ -1783,7 +1783,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => {
|
Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => {
|
||||||
const node = try arena.construct(ast.Node.PrefixOp{
|
const node = try arena.create(ast.Node.PrefixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
.op = switch (token_ptr.id) {
|
.op = switch (token_ptr.id) {
|
||||||
@ -1817,7 +1817,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
|
if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = ellipsis3,
|
.op_token = ellipsis3,
|
||||||
@ -1842,7 +1842,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToAssignment(token_ptr.id)) |ass_id| {
|
if (tokenIdToAssignment(token_ptr.id)) |ass_id| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -1872,7 +1872,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| {
|
if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -1904,7 +1904,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = or_token,
|
.op_token = or_token,
|
||||||
@ -1928,7 +1928,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = and_token,
|
.op_token = and_token,
|
||||||
@ -1955,7 +1955,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToComparison(token_ptr.id)) |comp_id| {
|
if (tokenIdToComparison(token_ptr.id)) |comp_id| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -1982,7 +1982,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {
|
if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = pipe,
|
.op_token = pipe,
|
||||||
@ -2006,7 +2006,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {
|
if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = caret,
|
.op_token = caret,
|
||||||
@ -2030,7 +2030,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {
|
if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = ampersand,
|
.op_token = ampersand,
|
||||||
@ -2057,7 +2057,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| {
|
if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -2087,7 +2087,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToAddition(token_ptr.id)) |add_id| {
|
if (tokenIdToAddition(token_ptr.id)) |add_id| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -2117,7 +2117,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToMultiply(token_ptr.id)) |mult_id| {
|
if (tokenIdToMultiply(token_ptr.id)) |mult_id| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -2145,7 +2145,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (tok_it.peek().?.id == Token.Id.Period) {
|
if (tok_it.peek().?.id == Token.Id.Period) {
|
||||||
const node = try arena.construct(ast.Node.SuffixOp{
|
const node = try arena.create(ast.Node.SuffixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
|
.op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
|
||||||
@ -2164,7 +2164,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.SuffixOp{
|
const node = try arena.create(ast.Node.SuffixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
|
.op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
|
||||||
@ -2193,7 +2193,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const lhs = opt_ctx.get() orelse continue;
|
const lhs = opt_ctx.get() orelse continue;
|
||||||
|
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {
|
if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = bang,
|
.op_token = bang,
|
||||||
@ -2212,7 +2212,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_index = token.index;
|
const token_index = token.index;
|
||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| {
|
if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| {
|
||||||
var node = try arena.construct(ast.Node.PrefixOp{
|
var node = try arena.create(ast.Node.PrefixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
.op = prefix_id,
|
.op = prefix_id,
|
||||||
@ -2222,7 +2222,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
|
|
||||||
// Treat '**' token as two pointer types
|
// Treat '**' token as two pointer types
|
||||||
if (token_ptr.id == Token.Id.AsteriskAsterisk) {
|
if (token_ptr.id == Token.Id.AsteriskAsterisk) {
|
||||||
const child = try arena.construct(ast.Node.PrefixOp{
|
const child = try arena.create(ast.Node.PrefixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
.op = prefix_id,
|
.op = prefix_id,
|
||||||
@ -2246,7 +2246,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
|
|
||||||
State.SuffixOpExpressionBegin => |opt_ctx| {
|
State.SuffixOpExpressionBegin => |opt_ctx| {
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| {
|
||||||
const async_node = try arena.construct(ast.Node.AsyncAttribute{
|
const async_node = try arena.create(ast.Node.AsyncAttribute{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
|
.base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
|
||||||
.async_token = async_token,
|
.async_token = async_token,
|
||||||
.allocator_type = null,
|
.allocator_type = null,
|
||||||
@ -2277,7 +2277,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
const token_ptr = token.ptr;
|
const token_ptr = token.ptr;
|
||||||
switch (token_ptr.id) {
|
switch (token_ptr.id) {
|
||||||
Token.Id.LParen => {
|
Token.Id.LParen => {
|
||||||
const node = try arena.construct(ast.Node.SuffixOp{
|
const node = try arena.create(ast.Node.SuffixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op = ast.Node.SuffixOp.Op{
|
.op = ast.Node.SuffixOp.Op{
|
||||||
@ -2301,7 +2301,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.LBracket => {
|
Token.Id.LBracket => {
|
||||||
const node = try arena.construct(ast.Node.SuffixOp{
|
const node = try arena.create(ast.Node.SuffixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined },
|
.op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined },
|
||||||
@ -2316,7 +2316,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
},
|
},
|
||||||
Token.Id.Period => {
|
Token.Id.Period => {
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.Asterisk)) |asterisk_token| {
|
||||||
const node = try arena.construct(ast.Node.SuffixOp{
|
const node = try arena.create(ast.Node.SuffixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op = ast.Node.SuffixOp.Op.Deref,
|
.op = ast.Node.SuffixOp.Op.Deref,
|
||||||
@ -2327,7 +2327,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| {
|
if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| {
|
||||||
const node = try arena.construct(ast.Node.SuffixOp{
|
const node = try arena.create(ast.Node.SuffixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
.base = ast.Node{ .id = ast.Node.Id.SuffixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op = ast.Node.SuffixOp.Op.UnwrapOptional,
|
.op = ast.Node.SuffixOp.Op.UnwrapOptional,
|
||||||
@ -2337,7 +2337,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
|
stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const node = try arena.construct(ast.Node.InfixOp{
|
const node = try arena.create(ast.Node.InfixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
.base = ast.Node{ .id = ast.Node.Id.InfixOp },
|
||||||
.lhs = lhs,
|
.lhs = lhs,
|
||||||
.op_token = token_index,
|
.op_token = token_index,
|
||||||
@ -2397,7 +2397,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_promise => {
|
Token.Id.Keyword_promise => {
|
||||||
const node = try arena.construct(ast.Node.PromiseType{
|
const node = try arena.create(ast.Node.PromiseType{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PromiseType },
|
.base = ast.Node{ .id = ast.Node.Id.PromiseType },
|
||||||
.promise_token = token.index,
|
.promise_token = token.index,
|
||||||
.result = null,
|
.result = null,
|
||||||
@ -2423,7 +2423,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.LParen => {
|
Token.Id.LParen => {
|
||||||
const node = try arena.construct(ast.Node.GroupedExpression{
|
const node = try arena.create(ast.Node.GroupedExpression{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.GroupedExpression },
|
.base = ast.Node{ .id = ast.Node.Id.GroupedExpression },
|
||||||
.lparen = token.index,
|
.lparen = token.index,
|
||||||
.expr = undefined,
|
.expr = undefined,
|
||||||
@ -2441,7 +2441,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Builtin => {
|
Token.Id.Builtin => {
|
||||||
const node = try arena.construct(ast.Node.BuiltinCall{
|
const node = try arena.create(ast.Node.BuiltinCall{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.BuiltinCall },
|
.base = ast.Node{ .id = ast.Node.Id.BuiltinCall },
|
||||||
.builtin_token = token.index,
|
.builtin_token = token.index,
|
||||||
.params = ast.Node.BuiltinCall.ParamList.init(arena),
|
.params = ast.Node.BuiltinCall.ParamList.init(arena),
|
||||||
@ -2460,7 +2460,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.LBracket => {
|
Token.Id.LBracket => {
|
||||||
const node = try arena.construct(ast.Node.PrefixOp{
|
const node = try arena.create(ast.Node.PrefixOp{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
.base = ast.Node{ .id = ast.Node.Id.PrefixOp },
|
||||||
.op_token = token.index,
|
.op_token = token.index,
|
||||||
.op = undefined,
|
.op = undefined,
|
||||||
@ -2519,7 +2519,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_fn => {
|
Token.Id.Keyword_fn => {
|
||||||
const fn_proto = try arena.construct(ast.Node.FnProto{
|
const fn_proto = try arena.create(ast.Node.FnProto{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
||||||
.doc_comments = null,
|
.doc_comments = null,
|
||||||
.visib_token = null,
|
.visib_token = null,
|
||||||
@ -2540,7 +2540,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
|
Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
|
||||||
const fn_proto = try arena.construct(ast.Node.FnProto{
|
const fn_proto = try arena.create(ast.Node.FnProto{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
.base = ast.Node{ .id = ast.Node.Id.FnProto },
|
||||||
.doc_comments = null,
|
.doc_comments = null,
|
||||||
.visib_token = null,
|
.visib_token = null,
|
||||||
@ -2567,7 +2567,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_asm => {
|
Token.Id.Keyword_asm => {
|
||||||
const node = try arena.construct(ast.Node.Asm{
|
const node = try arena.create(ast.Node.Asm{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Asm },
|
.base = ast.Node{ .id = ast.Node.Id.Asm },
|
||||||
.asm_token = token.index,
|
.asm_token = token.index,
|
||||||
.volatile_token = null,
|
.volatile_token = null,
|
||||||
@ -2629,7 +2629,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.ErrorSetDecl{
|
const node = try arena.create(ast.Node.ErrorSetDecl{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl },
|
.base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl },
|
||||||
.error_token = ctx.error_token,
|
.error_token = ctx.error_token,
|
||||||
.decls = ast.Node.ErrorSetDecl.DeclList.init(arena),
|
.decls = ast.Node.ErrorSetDecl.DeclList.init(arena),
|
||||||
@ -2695,7 +2695,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = try arena.construct(ast.Node.ErrorTag{
|
const node = try arena.create(ast.Node.ErrorTag{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ErrorTag },
|
.base = ast.Node{ .id = ast.Node.Id.ErrorTag },
|
||||||
.doc_comments = comments,
|
.doc_comments = comments,
|
||||||
.name_token = ident_token_index,
|
.name_token = ident_token_index,
|
||||||
@ -3032,7 +3032,7 @@ fn pushDocComment(arena: *mem.Allocator, line_comment: TokenIndex, result: *?*as
|
|||||||
if (result.*) |comment_node| {
|
if (result.*) |comment_node| {
|
||||||
break :blk comment_node;
|
break :blk comment_node;
|
||||||
} else {
|
} else {
|
||||||
const comment_node = try arena.construct(ast.Node.DocComment{
|
const comment_node = try arena.create(ast.Node.DocComment{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.DocComment },
|
.base = ast.Node{ .id = ast.Node.Id.DocComment },
|
||||||
.lines = ast.Node.DocComment.LineList.init(arena),
|
.lines = ast.Node.DocComment.LineList.init(arena),
|
||||||
});
|
});
|
||||||
@ -3061,7 +3061,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
|
|||||||
return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
|
return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
|
||||||
},
|
},
|
||||||
Token.Id.MultilineStringLiteralLine => {
|
Token.Id.MultilineStringLiteralLine => {
|
||||||
const node = try arena.construct(ast.Node.MultilineStringLiteral{
|
const node = try arena.create(ast.Node.MultilineStringLiteral{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral },
|
.base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral },
|
||||||
.lines = ast.Node.MultilineStringLiteral.LineList.init(arena),
|
.lines = ast.Node.MultilineStringLiteral.LineList.init(arena),
|
||||||
});
|
});
|
||||||
@ -3089,7 +3089,7 @@ fn parseStringLiteral(arena: *mem.Allocator, tok_it: *ast.Tree.TokenList.Iterato
|
|||||||
fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {
|
fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *const OptionalCtx, token_ptr: *const Token, token_index: TokenIndex) !bool {
|
||||||
switch (token_ptr.id) {
|
switch (token_ptr.id) {
|
||||||
Token.Id.Keyword_suspend => {
|
Token.Id.Keyword_suspend => {
|
||||||
const node = try arena.construct(ast.Node.Suspend{
|
const node = try arena.create(ast.Node.Suspend{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Suspend },
|
.base = ast.Node{ .id = ast.Node.Id.Suspend },
|
||||||
.label = null,
|
.label = null,
|
||||||
.suspend_token = token_index,
|
.suspend_token = token_index,
|
||||||
@ -3103,7 +3103,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_if => {
|
Token.Id.Keyword_if => {
|
||||||
const node = try arena.construct(ast.Node.If{
|
const node = try arena.create(ast.Node.If{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.If },
|
.base = ast.Node{ .id = ast.Node.Id.If },
|
||||||
.if_token = token_index,
|
.if_token = token_index,
|
||||||
.condition = undefined,
|
.condition = undefined,
|
||||||
@ -3144,7 +3144,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_switch => {
|
Token.Id.Keyword_switch => {
|
||||||
const node = try arena.construct(ast.Node.Switch{
|
const node = try arena.create(ast.Node.Switch{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Switch },
|
.base = ast.Node{ .id = ast.Node.Id.Switch },
|
||||||
.switch_token = token_index,
|
.switch_token = token_index,
|
||||||
.expr = undefined,
|
.expr = undefined,
|
||||||
@ -3166,7 +3166,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Token.Id.Keyword_comptime => {
|
Token.Id.Keyword_comptime => {
|
||||||
const node = try arena.construct(ast.Node.Comptime{
|
const node = try arena.create(ast.Node.Comptime{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Comptime },
|
.base = ast.Node{ .id = ast.Node.Id.Comptime },
|
||||||
.comptime_token = token_index,
|
.comptime_token = token_index,
|
||||||
.expr = undefined,
|
.expr = undefined,
|
||||||
@ -3178,7 +3178,7 @@ fn parseBlockExpr(stack: *std.ArrayList(State), arena: *mem.Allocator, ctx: *con
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Token.Id.LBrace => {
|
Token.Id.LBrace => {
|
||||||
const block = try arena.construct(ast.Node.Block{
|
const block = try arena.create(ast.Node.Block{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.Block },
|
.base = ast.Node{ .id = ast.Node.Id.Block },
|
||||||
.label = null,
|
.label = null,
|
||||||
.lbrace = token_index,
|
.lbrace = token_index,
|
||||||
@ -3318,7 +3318,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {
|
fn createLiteral(arena: *mem.Allocator, comptime T: type, token_index: TokenIndex) !*T {
|
||||||
return arena.construct(T{
|
return arena.create(T{
|
||||||
.base = ast.Node{ .id = ast.Node.typeToId(T) },
|
.base = ast.Node{ .id = ast.Node.typeToId(T) },
|
||||||
.token = token_index,
|
.token = token_index,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user