astgen: update a handful of expression types to new mem layout

break, continue, blocks, bit_not, negation, identifiers, string
literals, integer literals, inline assembly

also gave multiline string literals a different node tag from regular
string literals, for code clarity and to avoid an unnecessary load from
token_tags array.
This commit is contained in:
Andrew Kelley
2021-02-13 21:40:12 -07:00
parent 24798b84ad
commit c2b4d51749
4 changed files with 274 additions and 190 deletions

View File

@@ -283,6 +283,7 @@ pub const Tree = struct {
.undefined_literal,
.unreachable_literal,
.string_literal,
.multiline_string_literal,
.grouped_expression,
.builtin_call_two,
.builtin_call_two_comma,
@@ -593,7 +594,7 @@ pub const Tree = struct {
.field_access,
.unwrap_optional,
.grouped_expression,
.string_literal,
.multiline_string_literal,
.error_set_decl,
.asm_simple,
.asm_output,
@@ -614,6 +615,7 @@ pub const Tree = struct {
.identifier,
.deref,
.enum_literal,
.string_literal,
=> return main_tokens[n] + end_offset,
.@"return" => if (datas[n].lhs != 0) {
@@ -2826,11 +2828,14 @@ pub const Node = struct {
identifier,
/// lhs is the dot token index, rhs unused, main_token is the identifier.
enum_literal,
/// main_token is the string literal token
/// Both lhs and rhs unused.
string_literal,
/// main_token is the first token index (redundant with lhs)
/// lhs is the first token index; rhs is the last token index.
/// Could be a series of multiline_string_literal_line tokens, or a single
/// string_literal token.
string_literal,
multiline_string_literal,
/// `(lhs)`. main_token is the `(`; rhs is the token index of the `)`.
grouped_expression,
/// `@a(lhs, rhs)`. lhs and rhs may be omitted.

View File

@@ -2595,8 +2595,8 @@ const Parser = struct {
.tag = .string_literal,
.main_token = main_token,
.data = .{
.lhs = main_token,
.rhs = main_token,
.lhs = undefined,
.rhs = undefined,
},
});
},
@@ -2633,7 +2633,7 @@ const Parser = struct {
p.tok_i += 1;
}
return p.addNode(.{
.tag = .string_literal,
.tag = .multiline_string_literal,
.main_token = first_line,
.data = .{
.lhs = first_line,
@@ -3996,8 +3996,8 @@ const Parser = struct {
.tag = .string_literal,
.main_token = main_token,
.data = .{
.lhs = main_token,
.rhs = main_token,
.lhs = undefined,
.rhs = undefined,
},
});
},
@@ -4007,7 +4007,7 @@ const Parser = struct {
p.tok_i += 1;
}
return p.addNode(.{
.tag = .string_literal,
.tag = .multiline_string_literal,
.main_token = first_line,
.data = .{
.lhs = first_line,

View File

@@ -153,29 +153,25 @@ fn renderExpression(ais: *Ais, tree: ast.Tree, node: ast.Node.Index, space: Spac
.unreachable_literal,
.undefined_literal,
.anyframe_literal,
.string_literal,
=> return renderToken(ais, tree, main_tokens[node], space),
.string_literal => switch (token_tags[main_tokens[node]]) {
.string_literal => try renderToken(ais, tree, main_tokens[node], space),
.multiline_string_literal => {
var locked_indents = ais.lockOneShotIndent();
try ais.maybeInsertNewline();
.multiline_string_literal_line => {
var locked_indents = ais.lockOneShotIndent();
try ais.maybeInsertNewline();
var i = datas[node].lhs;
while (i <= datas[node].rhs) : (i += 1) try renderToken(ais, tree, i, .newline);
var i = datas[node].lhs;
while (i <= datas[node].rhs) : (i += 1) try renderToken(ais, tree, i, .newline);
while (locked_indents > 0) : (locked_indents -= 1) ais.popIndent();
while (locked_indents > 0) : (locked_indents -= 1) ais.popIndent();
switch (space) {
.none => {},
.semicolon => if (token_tags[i] == .semicolon) try renderToken(ais, tree, i, .newline),
.comma => if (token_tags[i] == .comma) try renderToken(ais, tree, i, .newline),
.comma_space => if (token_tags[i] == .comma) try renderToken(ais, tree, i, .space),
else => unreachable,
}
},
else => unreachable,
switch (space) {
.none => {},
.semicolon => if (token_tags[i] == .semicolon) try renderToken(ais, tree, i, .newline),
.comma => if (token_tags[i] == .comma) try renderToken(ais, tree, i, .newline),
.comma_space => if (token_tags[i] == .comma) try renderToken(ais, tree, i, .space),
else => unreachable,
}
},
.error_value => {
@@ -1850,8 +1846,7 @@ fn renderCall(
try renderExpression(ais, tree, param_node, Space.none);
// Unindent the comma for multiline string literals
const is_multiline_string = node_tags[param_node] == .string_literal and
token_tags[main_tokens[param_node]] == .multiline_string_literal_line;
const is_multiline_string = node_tags[param_node] == .multiline_string_literal;
if (is_multiline_string) ais.popIndent();
const comma = tree.lastToken(param_node) + 1;

File diff suppressed because it is too large Load Diff