Make semantic_tokens use @asyncCall instead of a stack again.

This commit is contained in:
Alexandros Naskos 2021-04-19 17:17:46 +03:00
parent 8f868dfec6
commit 23454e111c
No known key found for this signature in database
GPG Key ID: 02BF2E72B0EA32D2

View File

@ -327,7 +327,7 @@ fn writeNodeTokens(
store: *DocumentStore, store: *DocumentStore,
maybe_node: ?ast.Node.Index, maybe_node: ?ast.Node.Index,
) error{OutOfMemory}!void { ) error{OutOfMemory}!void {
const start_node = maybe_node orelse return; const node = maybe_node orelse return;
const handle = builder.handle; const handle = builder.handle;
const tree = handle.tree; const tree = handle.tree;
@ -335,24 +335,21 @@ fn writeNodeTokens(
const token_tags = tree.tokens.items(.tag); const token_tags = tree.tokens.items(.tag);
const node_data = tree.nodes.items(.data); const node_data = tree.nodes.items(.data);
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
if (start_node > node_data.len) return; if (node == 0 or node > node_data.len) return;
var stack = std.ArrayList(ast.Node.Index).init(arena.child_allocator); const FrameSize = @sizeOf(@Frame(writeNodeTokens));
defer stack.deinit(); var child_frame = try arena.child_allocator.alignedAlloc(u8, std.Target.stack_align, FrameSize);
defer arena.child_allocator.free(child_frame);
try stack.append(start_node);
while (stack.popOrNull()) |node| {
if (node == 0 or node > node_data.len) continue;
const tag = node_tags[node]; const tag = node_tags[node];
const main_token = main_tokens[node]; const main_token = main_tokens[node];
switch (tag) { switch (tag) {
.root => unreachable, .root => unreachable,
.container_field, .container_field,
.container_field_align, .container_field_align,
.container_field_init, .container_field_init,
=> try writeContainerField(builder, arena, store, node, .field, &stack), => try writeContainerField(builder, arena, store, node, .field, child_frame),
.@"errdefer" => { .@"errdefer" => {
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
@ -363,7 +360,7 @@ fn writeNodeTokens(
try writeToken(builder, payload_tok + 1, .operator); try writeToken(builder, payload_tok + 1, .operator);
} }
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.block, .block,
.block_semicolon, .block_semicolon,
@ -394,9 +391,9 @@ fn writeNodeTokens(
for (statements) |child| { for (statements) |child| {
try gap_highlighter.next(child); try gap_highlighter.next(child);
if (node_tags[child].isContainerField()) { if (node_tags[child].isContainerField()) {
try writeContainerField(builder, arena, store, child, .field, &stack); try writeContainerField(builder, arena, store, child, .field, child_frame);
} else { } else {
try stack.append(child); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, child });
} }
} }
@ -424,14 +421,14 @@ fn writeNodeTokens(
} }
if (var_decl.ast.type_node != 0) if (var_decl.ast.type_node != 0)
try stack.append(var_decl.ast.type_node); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, var_decl.ast.type_node });
if (var_decl.ast.align_node != 0) if (var_decl.ast.align_node != 0)
try stack.append(var_decl.ast.align_node); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, var_decl.ast.align_node });
if (var_decl.ast.section_node != 0) if (var_decl.ast.section_node != 0)
try stack.append(var_decl.ast.section_node); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, var_decl.ast.section_node });
try writeToken(builder, var_decl.ast.mut_token + 2, .operator); try writeToken(builder, var_decl.ast.mut_token + 2, .operator);
try stack.append(var_decl.ast.init_node); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, var_decl.ast.init_node });
}, },
.@"usingnamespace" => { .@"usingnamespace" => {
const first_tok = tree.firstToken(node); const first_tok = tree.firstToken(node);
@ -439,7 +436,7 @@ fn writeNodeTokens(
try writeDocComments(builder, tree, first_tok - 1); try writeDocComments(builder, tree, first_tok - 1);
try writeToken(builder, if (token_tags[first_tok] == .keyword_pub) first_tok else null, .keyword); try writeToken(builder, if (token_tags[first_tok] == .keyword_pub) first_tok else null, .keyword);
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
}, },
.container_decl, .container_decl,
.container_decl_trailing, .container_decl_trailing,
@ -469,19 +466,19 @@ fn writeNodeTokens(
try writeToken(builder, decl.ast.main_token, .keyword); try writeToken(builder, decl.ast.main_token, .keyword);
if (decl.ast.enum_token) |enum_token| { if (decl.ast.enum_token) |enum_token| {
if (decl.ast.arg != 0) if (decl.ast.arg != 0)
try stack.append(decl.ast.arg) try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, decl.ast.arg })
else else
try writeToken(builder, enum_token, .keyword); try writeToken(builder, enum_token, .keyword);
} else if (decl.ast.arg != 0) try stack.append(decl.ast.arg); } else if (decl.ast.arg != 0) try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, decl.ast.arg });
var gap_highlighter = GapHighlighter.init(builder, main_token + 1); var gap_highlighter = GapHighlighter.init(builder, main_token + 1);
const field_token_type = fieldTokenType(node, handle); const field_token_type = fieldTokenType(node, handle);
for (decl.ast.members) |child| { for (decl.ast.members) |child| {
try gap_highlighter.next(child); try gap_highlighter.next(child);
if (node_tags[child].isContainerField()) { if (node_tags[child].isContainerField()) {
try writeContainerField(builder, arena, store, child, field_token_type, &stack); try writeContainerField(builder, arena, store, child, field_token_type, child_frame);
} else { } else {
try stack.append(child); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, child });
} }
} }
try gap_highlighter.end(lastToken(tree, node)); try gap_highlighter.end(lastToken(tree, node));
@ -551,32 +548,32 @@ fn writeNodeTokens(
try writeTokenMod(builder, param_decl.name_token, .parameter, .{ .declaration = true }); try writeTokenMod(builder, param_decl.name_token, .parameter, .{ .declaration = true });
if (param_decl.anytype_ellipsis3) |any_token| { if (param_decl.anytype_ellipsis3) |any_token| {
try writeToken(builder, any_token, .type); try writeToken(builder, any_token, .type);
} else if (param_decl.type_expr != 0) try stack.append(param_decl.type_expr); } else if (param_decl.type_expr != 0) try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, param_decl.type_expr });
} }
if (fn_proto.ast.align_expr != 0) if (fn_proto.ast.align_expr != 0)
try stack.append(fn_proto.ast.align_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, fn_proto.ast.align_expr });
if (fn_proto.ast.section_expr != 0) if (fn_proto.ast.section_expr != 0)
try stack.append(fn_proto.ast.section_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, fn_proto.ast.section_expr });
if (fn_proto.ast.callconv_expr != 0) if (fn_proto.ast.callconv_expr != 0)
try stack.append(fn_proto.ast.callconv_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, fn_proto.ast.callconv_expr });
if (fn_proto.ast.return_type != 0) if (fn_proto.ast.return_type != 0)
try stack.append(fn_proto.ast.return_type); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, fn_proto.ast.return_type });
if (tag == .fn_decl) if (tag == .fn_decl)
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.anyframe_type => { .anyframe_type => {
try writeToken(builder, main_token, .type); try writeToken(builder, main_token, .type);
if (node_data[node].rhs != 0) { if (node_data[node].rhs != 0) {
try writeToken(builder, node_data[node].lhs, .type); try writeToken(builder, node_data[node].lhs, .type);
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
} }
}, },
.@"defer" => { .@"defer" => {
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.@"comptime", .@"comptime",
.@"nosuspend", .@"nosuspend",
@ -584,20 +581,20 @@ fn writeNodeTokens(
if (analysis.getDocCommentTokenIndex(token_tags, main_token)) |doc| if (analysis.getDocCommentTokenIndex(token_tags, main_token)) |doc|
try writeDocComments(builder, tree, doc); try writeDocComments(builder, tree, doc);
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
}, },
.@"switch", .@"switch",
.switch_comma, .switch_comma,
=> { => {
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
const extra = tree.extraData(node_data[node].rhs, ast.Node.SubRange); const extra = tree.extraData(node_data[node].rhs, ast.Node.SubRange);
const cases = tree.extra_data[extra.start..extra.end]; const cases = tree.extra_data[extra.start..extra.end];
var gap_highlighter = GapHighlighter.init(builder, lastToken(tree, node_data[node].lhs) + 1); var gap_highlighter = GapHighlighter.init(builder, lastToken(tree, node_data[node].lhs) + 1);
for (cases) |case_node| { for (cases) |case_node| {
try gap_highlighter.next(case_node); try gap_highlighter.next(case_node);
try stack.append(case_node); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, case_node });
} }
try gap_highlighter.end(lastToken(tree, node)); try gap_highlighter.end(lastToken(tree, node));
}, },
@ -605,7 +602,7 @@ fn writeNodeTokens(
.switch_case, .switch_case,
=> { => {
const switch_case = if (tag == .switch_case) tree.switchCase(node) else tree.switchCaseOne(node); const switch_case = if (tag == .switch_case) tree.switchCase(node) else tree.switchCaseOne(node);
for (switch_case.ast.values) |item_node| try stack.append(item_node); for (switch_case.ast.values) |item_node| try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, item_node });
// check it it's 'else' // check it it's 'else'
if (switch_case.ast.values.len == 0) try writeToken(builder, switch_case.ast.arrow_token - 1, .keyword); if (switch_case.ast.values.len == 0) try writeToken(builder, switch_case.ast.arrow_token - 1, .keyword);
try writeToken(builder, switch_case.ast.arrow_token, .operator); try writeToken(builder, switch_case.ast.arrow_token, .operator);
@ -613,7 +610,7 @@ fn writeNodeTokens(
const p_token = @boolToInt(token_tags[payload_token] == .asterisk); const p_token = @boolToInt(token_tags[payload_token] == .asterisk);
try writeToken(builder, p_token, .variable); try writeToken(builder, p_token, .variable);
} }
try stack.append(switch_case.ast.target_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, switch_case.ast.target_expr });
}, },
.@"while", .@"while",
.while_simple, .while_simple,
@ -625,7 +622,7 @@ fn writeNodeTokens(
try writeToken(builder, while_node.label_token, .label); try writeToken(builder, while_node.label_token, .label);
try writeToken(builder, while_node.inline_token, .keyword); try writeToken(builder, while_node.inline_token, .keyword);
try writeToken(builder, while_node.ast.while_token, .keyword); try writeToken(builder, while_node.ast.while_token, .keyword);
try stack.append(while_node.ast.cond_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, while_node.ast.cond_expr });
if (while_node.payload_token) |payload| { if (while_node.payload_token) |payload| {
try writeToken(builder, payload - 1, .operator); try writeToken(builder, payload - 1, .operator);
try writeToken(builder, payload, .variable); try writeToken(builder, payload, .variable);
@ -638,9 +635,9 @@ fn writeNodeTokens(
try writeToken(builder, r_pipe, .operator); try writeToken(builder, r_pipe, .operator);
} }
if (while_node.ast.cont_expr != 0) if (while_node.ast.cont_expr != 0)
try stack.append(while_node.ast.cont_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, while_node.ast.cont_expr });
try stack.append(while_node.ast.then_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, while_node.ast.then_expr });
if (while_node.ast.else_expr != 0) { if (while_node.ast.else_expr != 0) {
try writeToken(builder, while_node.else_token, .keyword); try writeToken(builder, while_node.else_token, .keyword);
@ -650,7 +647,7 @@ fn writeNodeTokens(
try writeToken(builder, err_token, .variable); try writeToken(builder, err_token, .variable);
try writeToken(builder, err_token + 1, .operator); try writeToken(builder, err_token + 1, .operator);
} }
try stack.append(while_node.ast.else_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, while_node.ast.else_expr });
} }
}, },
.@"if", .@"if",
@ -659,7 +656,7 @@ fn writeNodeTokens(
const if_node = ifFull(tree, node); const if_node = ifFull(tree, node);
try writeToken(builder, if_node.ast.if_token, .keyword); try writeToken(builder, if_node.ast.if_token, .keyword);
try stack.append(if_node.ast.cond_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, if_node.ast.cond_expr });
if (if_node.payload_token) |payload| { if (if_node.payload_token) |payload| {
// if (?x) |x| // if (?x) |x|
@ -667,7 +664,7 @@ fn writeNodeTokens(
try writeToken(builder, payload, .variable); // x try writeToken(builder, payload, .variable); // x
try writeToken(builder, payload + 1, .operator); // | try writeToken(builder, payload + 1, .operator); // |
} }
try stack.append(if_node.ast.then_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, if_node.ast.then_expr });
if (if_node.ast.else_expr != 0) { if (if_node.ast.else_expr != 0) {
try writeToken(builder, if_node.else_token, .keyword); try writeToken(builder, if_node.else_token, .keyword);
@ -677,7 +674,7 @@ fn writeNodeTokens(
try writeToken(builder, err_token, .variable); // err try writeToken(builder, err_token, .variable); // err
try writeToken(builder, err_token + 1, .operator); // | try writeToken(builder, err_token + 1, .operator); // |
} }
try stack.append(if_node.ast.else_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, if_node.ast.else_expr });
} }
}, },
.array_init, .array_init,
@ -699,8 +696,8 @@ fn writeNodeTokens(
}; };
if (array_init.ast.type_expr != 0) if (array_init.ast.type_expr != 0)
try stack.append(array_init.ast.type_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, array_init.ast.type_expr });
for (array_init.ast.elements) |elem| try stack.append(elem); for (array_init.ast.elements) |elem| try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, elem });
}, },
.struct_init, .struct_init,
.struct_init_comma, .struct_init_comma,
@ -723,7 +720,7 @@ fn writeNodeTokens(
var field_token_type: ?TokenType = null; var field_token_type: ?TokenType = null;
if (struct_init.ast.type_expr != 0) { if (struct_init.ast.type_expr != 0) {
try stack.append(struct_init.ast.type_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, struct_init.ast.type_expr });
field_token_type = if (try analysis.resolveTypeOfNode(store, arena, .{ field_token_type = if (try analysis.resolveTypeOfNode(store, arena, .{
.node = struct_init.ast.type_expr, .node = struct_init.ast.type_expr,
@ -745,7 +742,7 @@ fn writeNodeTokens(
try writeToken(builder, init_token - 3, field_token_type orelse .field); // '.' try writeToken(builder, init_token - 3, field_token_type orelse .field); // '.'
try writeToken(builder, init_token - 2, field_token_type orelse .field); // name try writeToken(builder, init_token - 2, field_token_type orelse .field); // name
try writeToken(builder, init_token - 1, .operator); // '=' try writeToken(builder, init_token - 1, .operator); // '='
try stack.append(field_init); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, field_init });
} }
try gap_highlighter.end(lastToken(tree, node)); try gap_highlighter.end(lastToken(tree, node));
}, },
@ -766,14 +763,14 @@ fn writeNodeTokens(
}; };
try writeToken(builder, call.async_token, .keyword); try writeToken(builder, call.async_token, .keyword);
try stack.append(call.ast.fn_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, call.ast.fn_expr });
if (builder.current_token) |curr_tok| { if (builder.current_token) |curr_tok| {
if (curr_tok != lastToken(tree, call.ast.fn_expr) and token_tags[lastToken(tree, call.ast.fn_expr)] == .identifier) { if (curr_tok != lastToken(tree, call.ast.fn_expr) and token_tags[lastToken(tree, call.ast.fn_expr)] == .identifier) {
try writeToken(builder, lastToken(tree, call.ast.fn_expr), .function); try writeToken(builder, lastToken(tree, call.ast.fn_expr), .function);
} }
} }
for (call.ast.params) |param| try stack.append(param); for (call.ast.params) |param| try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, param });
}, },
.slice, .slice,
.slice_open, .slice_open,
@ -786,29 +783,29 @@ fn writeNodeTokens(
else => unreachable, else => unreachable,
}; };
try stack.append(slice.ast.sliced); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.ast.sliced });
try stack.append(slice.ast.start); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.ast.start });
try writeToken(builder, lastToken(tree, slice.ast.start) + 1, .operator); try writeToken(builder, lastToken(tree, slice.ast.start) + 1, .operator);
if (slice.ast.end != 0) if (slice.ast.end != 0)
try stack.append(slice.ast.end); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.ast.end });
if (slice.ast.sentinel != 0) if (slice.ast.sentinel != 0)
try stack.append(slice.ast.sentinel); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.ast.sentinel });
}, },
.array_access => { .array_access => {
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.deref => { .deref => {
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
try writeToken(builder, main_token, .operator); try writeToken(builder, main_token, .operator);
}, },
.unwrap_optional => { .unwrap_optional => {
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
try writeToken(builder, main_token + 1, .operator); try writeToken(builder, main_token + 1, .operator);
}, },
.grouped_expression => { .grouped_expression => {
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
}, },
.@"break", .@"break",
.@"continue", .@"continue",
@ -817,12 +814,12 @@ fn writeNodeTokens(
if (node_data[node].lhs != 0) if (node_data[node].lhs != 0)
try writeToken(builder, node_data[node].lhs, .label); try writeToken(builder, node_data[node].lhs, .label);
if (node_data[node].rhs != 0) if (node_data[node].rhs != 0)
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.@"suspend", .@"return" => { .@"suspend", .@"return" => {
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
if (node_data[node].lhs != 0) if (node_data[node].lhs != 0)
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
}, },
.integer_literal, .integer_literal,
.float_literal, .float_literal,
@ -852,7 +849,7 @@ fn writeNodeTokens(
try writeToken(builder, main_token, .builtin); try writeToken(builder, main_token, .builtin);
for (params) |param| for (params) |param|
try stack.append(param); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, param });
}, },
.string_literal, .string_literal,
.char_literal, .char_literal,
@ -889,7 +886,7 @@ fn writeNodeTokens(
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
try writeToken(builder, asm_node.volatile_token, .keyword); try writeToken(builder, asm_node.volatile_token, .keyword);
try stack.append(asm_node.ast.template); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, asm_node.ast.template });
// TODO Inputs, outputs. // TODO Inputs, outputs.
}, },
.@"anytype" => { .@"anytype" => {
@ -903,14 +900,14 @@ fn writeNodeTokens(
if (token_tags[main_token + 1] == .string_literal) if (token_tags[main_token + 1] == .string_literal)
try writeToken(builder, main_token + 1, .string); try writeToken(builder, main_token + 1, .string);
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.@"catch" => { .@"catch" => {
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
if (token_tags[main_token + 1] == .pipe) if (token_tags[main_token + 1] == .pipe)
try writeToken(builder, main_token + 1, .variable); try writeToken(builder, main_token + 1, .variable);
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.add, .add,
.add_wrap, .add_wrap,
@ -954,7 +951,7 @@ fn writeNodeTokens(
.sub_wrap, .sub_wrap,
.@"orelse", .@"orelse",
=> { => {
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
const token_type: TokenType = switch (tag) { const token_type: TokenType = switch (tag) {
.bool_and, .bool_or => .keyword, .bool_and, .bool_or => .keyword,
else => .operator, else => .operator,
@ -962,14 +959,14 @@ fn writeNodeTokens(
try writeToken(builder, main_token, token_type); try writeToken(builder, main_token, token_type);
if (node_data[node].rhs != 0) if (node_data[node].rhs != 0)
try stack.append(node_data[node].rhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].rhs });
}, },
.field_access => { .field_access => {
const data = node_data[node]; const data = node_data[node];
if (data.rhs == 0) return; if (data.rhs == 0) return;
const rhs_str = tree.tokenSlice(data.rhs); const rhs_str = tree.tokenSlice(data.rhs);
try stack.append(data.lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, data.lhs });
// TODO This is basically exactly the same as what is done in analysis.resolveTypeOfNode, with the added // TODO This is basically exactly the same as what is done in analysis.resolveTypeOfNode, with the added
// writeToken code. // writeToken code.
@ -1026,12 +1023,12 @@ fn writeNodeTokens(
if (ptr_type.size == .One and token_tags[main_token] == .asterisk_asterisk and if (ptr_type.size == .One and token_tags[main_token] == .asterisk_asterisk and
main_token == main_tokens[ptr_type.ast.child_type]) main_token == main_tokens[ptr_type.ast.child_type])
{ {
return try stack.append(ptr_type.ast.child_type); return try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, ptr_type.ast.child_type });
} }
if (ptr_type.size == .One) try writeToken(builder, main_token, .operator); if (ptr_type.size == .One) try writeToken(builder, main_token, .operator);
if (ptr_type.ast.sentinel != 0) { if (ptr_type.ast.sentinel != 0) {
return try stack.append(ptr_type.ast.sentinel); return try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, ptr_type.ast.sentinel });
} }
try writeToken(builder, ptr_type.allowzero_token, .keyword); try writeToken(builder, ptr_type.allowzero_token, .keyword);
@ -1039,19 +1036,19 @@ fn writeNodeTokens(
if (ptr_type.ast.align_node != 0) { if (ptr_type.ast.align_node != 0) {
const first_tok = tree.firstToken(ptr_type.ast.align_node); const first_tok = tree.firstToken(ptr_type.ast.align_node);
try writeToken(builder, first_tok - 2, .keyword); try writeToken(builder, first_tok - 2, .keyword);
try stack.append(ptr_type.ast.align_node); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, ptr_type.ast.align_node });
if (ptr_type.ast.bit_range_start != 0) { if (ptr_type.ast.bit_range_start != 0) {
try stack.append(ptr_type.ast.bit_range_start); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, ptr_type.ast.bit_range_start });
try writeToken(builder, tree.firstToken(ptr_type.ast.bit_range_end - 1), .operator); try writeToken(builder, tree.firstToken(ptr_type.ast.bit_range_end - 1), .operator);
try stack.append(ptr_type.ast.bit_range_end); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, ptr_type.ast.bit_range_end });
} }
} }
try writeToken(builder, ptr_type.const_token, .keyword); try writeToken(builder, ptr_type.const_token, .keyword);
try writeToken(builder, ptr_type.volatile_token, .keyword); try writeToken(builder, ptr_type.volatile_token, .keyword);
try stack.append(ptr_type.ast.child_type); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, ptr_type.ast.child_type });
}, },
.array_type, .array_type,
.array_type_sentinel, .array_type_sentinel,
@ -1061,11 +1058,11 @@ fn writeNodeTokens(
else else
tree.arrayTypeSentinel(node); tree.arrayTypeSentinel(node);
try stack.append(array_type.ast.elem_count); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, array_type.ast.elem_count });
if (array_type.ast.sentinel != 0) if (array_type.ast.sentinel != 0)
try stack.append(array_type.ast.sentinel); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, array_type.ast.sentinel });
try stack.append(array_type.ast.elem_type); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, array_type.ast.elem_type });
}, },
.address_of, .address_of,
.bit_not, .bit_not,
@ -1075,18 +1072,17 @@ fn writeNodeTokens(
.negation_wrap, .negation_wrap,
=> { => {
try writeToken(builder, main_token, .operator); try writeToken(builder, main_token, .operator);
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
}, },
.@"try", .@"try",
.@"resume", .@"resume",
.@"await", .@"await",
=> { => {
try writeToken(builder, main_token, .keyword); try writeToken(builder, main_token, .keyword);
try stack.append(node_data[node].lhs); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, node_data[node].lhs });
}, },
.anyframe_literal => try writeToken(builder, main_token, .keyword), .anyframe_literal => try writeToken(builder, main_token, .keyword),
} }
}
} }
fn writeContainerField( fn writeContainerField(
@ -1095,7 +1091,7 @@ fn writeContainerField(
store: *DocumentStore, store: *DocumentStore,
node: ast.Node.Index, node: ast.Node.Index,
field_token_type: ?TokenType, field_token_type: ?TokenType,
stack: *std.ArrayList(ast.Node.Index), child_frame: anytype,
) !void { ) !void {
const tree = builder.handle.tree; const tree = builder.handle.tree;
const container_field = containerField(tree, node).?; const container_field = containerField(tree, node).?;
@ -1111,9 +1107,9 @@ fn writeContainerField(
if (container_field.ast.type_expr != 0) { if (container_field.ast.type_expr != 0) {
if (container_field.ast.align_expr != 0) { if (container_field.ast.align_expr != 0) {
try writeToken(builder, tree.firstToken(container_field.ast.align_expr) - 2, .keyword); try writeToken(builder, tree.firstToken(container_field.ast.align_expr) - 2, .keyword);
try stack.append(container_field.ast.align_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, container_field.ast.align_expr });
} }
try stack.append(container_field.ast.type_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, container_field.ast.type_expr });
} }
if (container_field.ast.value_expr != 0) block: { if (container_field.ast.value_expr != 0) block: {
@ -1125,7 +1121,7 @@ fn writeContainerField(
break :block; // Check this, I believe it is correct. break :block; // Check this, I believe it is correct.
try writeToken(builder, eq_tok, .operator); try writeToken(builder, eq_tok, .operator);
try stack.append(container_field.ast.value_expr); try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, container_field.ast.value_expr });
} }
} }