Merge branch 'master' into intern-pool

This commit is contained in:
Techarix
2023-02-14 23:48:57 +01:00
26 changed files with 484 additions and 535 deletions

View File

@@ -1457,47 +1457,11 @@ fn nodeContainsSourceIndex(tree: Ast, node: Ast.Node.Index, source_index: usize)
return source_index >= loc.start and source_index <= loc.end;
}
pub fn getImportStr(tree: Ast, node: Ast.Node.Index, source_index: usize) ?[]const u8 {
const node_tags = tree.nodes.items(.tag);
var buf: [2]Ast.Node.Index = undefined;
if (tree.fullContainerDecl(&buf, node)) |container_decl| {
for (container_decl.ast.members) |decl_idx| {
if (getImportStr(tree, decl_idx, source_index)) |name| {
return name;
}
}
return null;
} else if (tree.fullVarDecl(node)) |var_decl| {
return getImportStr(tree, var_decl.ast.init_node, source_index);
} else if (node_tags[node] == .@"usingnamespace") {
return getImportStr(tree, tree.nodes.items(.data)[node].lhs, source_index);
}
if (!nodeContainsSourceIndex(tree, node, source_index)) return null;
if (!ast.isBuiltinCall(tree, node)) return null;
const builtin_token = tree.nodes.items(.main_token)[node];
const call_name = tree.tokenSlice(builtin_token);
if (!std.mem.eql(u8, call_name, "@import")) return null;
var buffer: [2]Ast.Node.Index = undefined;
const params = ast.builtinCallParams(tree, node, &buffer).?;
if (params.len != 1) return null;
if (node_tags[params[0]] != .string_literal) return null;
const import_str = tree.tokenSlice(tree.nodes.items(.main_token)[params[0]]);
return import_str[1 .. import_str.len - 1];
}
pub const PositionContext = union(enum) {
builtin: offsets.Loc,
comment,
import_string_literal: offsets.Loc,
cinclude_string_literal: offsets.Loc,
embedfile_string_literal: offsets.Loc,
string_literal: offsets.Loc,
field_access: offsets.Loc,
@@ -1514,6 +1478,7 @@ pub const PositionContext = union(enum) {
.builtin => |r| r,
.comment => null,
.import_string_literal => |r| r,
.cinclude_string_literal => |r| r,
.embedfile_string_literal => |r| r,
.string_literal => |r| r,
.field_access => |r| r,
@@ -1591,7 +1556,7 @@ pub fn getPositionContext(
};
while (true) {
const tok = tokenizer.next();
var tok = tokenizer.next();
// Early exits.
if (tok.loc.start > new_index) break;
if (tok.loc.start == new_index) {
@@ -1610,7 +1575,12 @@ pub fn getPositionContext(
},
};
}
return .other;
const q = std.mem.lastIndexOf(u8, held_line, "\"") orelse return .other;
if (held_line[q -| 1] == '@') {
tok.tag = .identifier;
} else {
tok.tag = .string_literal;
}
},
.doc_comment, .container_doc_comment => return .comment,
.eof => break,
@@ -1630,8 +1600,10 @@ pub fn getPositionContext(
if (std.mem.eql(u8, builtin_name, "@import")) {
curr_ctx.ctx = .{ .import_string_literal = tok.loc };
break :string_lit_block;
}
if (std.mem.eql(u8, builtin_name, "@embedFile")) {
} else if (std.mem.eql(u8, builtin_name, "@cInclude")) {
curr_ctx.ctx = .{ .cinclude_string_literal = tok.loc };
break :string_lit_block;
} else if (std.mem.eql(u8, builtin_name, "@embedFile")) {
curr_ctx.ctx = .{ .embedfile_string_literal = tok.loc };
break :string_lit_block;
}
@@ -1850,6 +1822,7 @@ fn addOutlineNodes(allocator: std.mem.Allocator, tree: Ast, child: Ast.Node.Inde
.error_set_decl,
=> return,
.container_decl,
.container_decl_trailing,
.container_decl_arg,
.container_decl_arg_trailing,
.container_decl_two,