|
|
|
@@ -181,7 +181,7 @@ pub fn getFunctionSnippet(allocator: std.mem.Allocator, tree: Ast, func: Ast.ful
|
|
|
|
return buffer.toOwnedSlice(allocator);
|
|
|
|
return buffer.toOwnedSlice(allocator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn hasSelfParam(arena: *std.heap.ArenaAllocator, document_store: *const DocumentStore, handle: *const DocumentStore.Handle, func: Ast.full.FnProto) !bool {
|
|
|
|
pub fn hasSelfParam(arena: *std.heap.ArenaAllocator, document_store: *DocumentStore, handle: *const DocumentStore.Handle, func: Ast.full.FnProto) !bool {
|
|
|
|
// Non-decl prototypes cannot have a self parameter.
|
|
|
|
// Non-decl prototypes cannot have a self parameter.
|
|
|
|
if (func.name_token == null) return false;
|
|
|
|
if (func.name_token == null) return false;
|
|
|
|
if (func.ast.params.len == 0) return false;
|
|
|
|
if (func.ast.params.len == 0) return false;
|
|
|
|
@@ -314,7 +314,7 @@ fn getDeclName(tree: Ast, node: Ast.Node.Index) ?[]const u8 {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn resolveVarDeclAliasInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, root: bool) error{OutOfMemory}!?DeclWithHandle {
|
|
|
|
fn resolveVarDeclAliasInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, root: bool) error{OutOfMemory}!?DeclWithHandle {
|
|
|
|
_ = root;
|
|
|
|
_ = root;
|
|
|
|
const handle = node_handle.handle;
|
|
|
|
const handle = node_handle.handle;
|
|
|
|
const tree = handle.tree;
|
|
|
|
const tree = handle.tree;
|
|
|
|
@@ -367,7 +367,7 @@ fn resolveVarDeclAliasInternal(store: *const DocumentStore, arena: *std.heap.Are
|
|
|
|
/// const decl = @import("decl-file.zig").decl;
|
|
|
|
/// const decl = @import("decl-file.zig").decl;
|
|
|
|
/// const other = decl.middle.other;
|
|
|
|
/// const other = decl.middle.other;
|
|
|
|
///```
|
|
|
|
///```
|
|
|
|
pub fn resolveVarDeclAlias(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, decl_handle: NodeWithHandle) !?DeclWithHandle {
|
|
|
|
pub fn resolveVarDeclAlias(store: *DocumentStore, arena: *std.heap.ArenaAllocator, decl_handle: NodeWithHandle) !?DeclWithHandle {
|
|
|
|
const decl = decl_handle.node;
|
|
|
|
const decl = decl_handle.node;
|
|
|
|
const handle = decl_handle.handle;
|
|
|
|
const handle = decl_handle.handle;
|
|
|
|
const tree = handle.tree;
|
|
|
|
const tree = handle.tree;
|
|
|
|
@@ -431,7 +431,7 @@ fn findReturnStatement(tree: Ast, fn_decl: Ast.full.FnProto, body: Ast.Node.Inde
|
|
|
|
return findReturnStatementInternal(tree, fn_decl, body, &already_found);
|
|
|
|
return findReturnStatementInternal(tree, fn_decl, body, &already_found);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn resolveReturnType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, fn_decl: Ast.full.FnProto, handle: *const DocumentStore.Handle, bound_type_params: *BoundTypeParams, fn_body: ?Ast.Node.Index) !?TypeWithHandle {
|
|
|
|
pub fn resolveReturnType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, fn_decl: Ast.full.FnProto, handle: *const DocumentStore.Handle, bound_type_params: *BoundTypeParams, fn_body: ?Ast.Node.Index) !?TypeWithHandle {
|
|
|
|
const tree = handle.tree;
|
|
|
|
const tree = handle.tree;
|
|
|
|
if (isTypeFunction(tree, fn_decl) and fn_body != null) {
|
|
|
|
if (isTypeFunction(tree, fn_decl) and fn_body != null) {
|
|
|
|
// If this is a type function and it only contains a single return statement that returns
|
|
|
|
// If this is a type function and it only contains a single return statement that returns
|
|
|
|
@@ -468,7 +468,7 @@ pub fn resolveReturnType(store: *const DocumentStore, arena: *std.heap.ArenaAllo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Resolves the child type of an optional type
|
|
|
|
/// Resolves the child type of an optional type
|
|
|
|
fn resolveUnwrapOptionalType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, opt: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
fn resolveUnwrapOptionalType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, opt: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
const opt_node = switch (opt.type.data) {
|
|
|
|
const opt_node = switch (opt.type.data) {
|
|
|
|
.other => |n| n,
|
|
|
|
.other => |n| n,
|
|
|
|
else => return null,
|
|
|
|
else => return null,
|
|
|
|
@@ -484,7 +484,7 @@ fn resolveUnwrapOptionalType(store: *const DocumentStore, arena: *std.heap.Arena
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn resolveUnwrapErrorType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, rhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
fn resolveUnwrapErrorType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, rhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
const rhs_node = switch (rhs.type.data) {
|
|
|
|
const rhs_node = switch (rhs.type.data) {
|
|
|
|
.other => |n| n,
|
|
|
|
.other => |n| n,
|
|
|
|
.error_union => |n| return TypeWithHandle{
|
|
|
|
.error_union => |n| return TypeWithHandle{
|
|
|
|
@@ -505,7 +505,7 @@ fn resolveUnwrapErrorType(store: *const DocumentStore, arena: *std.heap.ArenaAll
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Resolves the child type of a deref type
|
|
|
|
/// Resolves the child type of a deref type
|
|
|
|
fn resolveDerefType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, deref: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
fn resolveDerefType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, deref: TypeWithHandle, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
const deref_node = switch (deref.type.data) {
|
|
|
|
const deref_node = switch (deref.type.data) {
|
|
|
|
.other => |n| n,
|
|
|
|
.other => |n| n,
|
|
|
|
.pointer => |n| return TypeWithHandle{
|
|
|
|
.pointer => |n| return TypeWithHandle{
|
|
|
|
@@ -538,7 +538,7 @@ fn resolveDerefType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Resolves slicing and array access
|
|
|
|
/// Resolves slicing and array access
|
|
|
|
fn resolveBracketAccessType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, rhs: enum { Single, Range }, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
fn resolveBracketAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, rhs: enum { Single, Range }, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
const lhs_node = switch (lhs.type.data) {
|
|
|
|
const lhs_node = switch (lhs.type.data) {
|
|
|
|
.other => |n| n,
|
|
|
|
.other => |n| n,
|
|
|
|
else => return null,
|
|
|
|
else => return null,
|
|
|
|
@@ -575,7 +575,7 @@ fn resolveBracketAccessType(store: *const DocumentStore, arena: *std.heap.ArenaA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Called to remove one level of pointerness before a field access
|
|
|
|
/// Called to remove one level of pointerness before a field access
|
|
|
|
pub fn resolveFieldAccessLhsType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !TypeWithHandle {
|
|
|
|
pub fn resolveFieldAccessLhsType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, lhs: TypeWithHandle, bound_type_params: *BoundTypeParams) !TypeWithHandle {
|
|
|
|
return (try resolveDerefType(store, arena, lhs, bound_type_params)) orelse lhs;
|
|
|
|
return (try resolveDerefType(store, arena, lhs, bound_type_params)) orelse lhs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -614,7 +614,7 @@ pub fn isTypeIdent(text: []const u8) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Resolves the type of a node
|
|
|
|
/// Resolves the type of a node
|
|
|
|
pub fn resolveTypeOfNodeInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, bound_type_params: *BoundTypeParams) error{OutOfMemory}!?TypeWithHandle {
|
|
|
|
pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle, bound_type_params: *BoundTypeParams) error{OutOfMemory}!?TypeWithHandle {
|
|
|
|
// If we were asked to resolve this node before,
|
|
|
|
// If we were asked to resolve this node before,
|
|
|
|
// it is self-referential and we cannot resolve it.
|
|
|
|
// it is self-referential and we cannot resolve it.
|
|
|
|
for (resolve_trail.items) |i| {
|
|
|
|
for (resolve_trail.items) |i| {
|
|
|
|
@@ -1080,7 +1080,7 @@ pub const TypeWithHandle = struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
pub fn resolveTypeOfNode(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle) error{OutOfMemory}!?TypeWithHandle {
|
|
|
|
pub fn resolveTypeOfNode(store: *DocumentStore, arena: *std.heap.ArenaAllocator, node_handle: NodeWithHandle) error{OutOfMemory}!?TypeWithHandle {
|
|
|
|
var bound_type_params = BoundTypeParams{};
|
|
|
|
var bound_type_params = BoundTypeParams{};
|
|
|
|
return resolveTypeOfNodeInternal(store, arena, node_handle, &bound_type_params);
|
|
|
|
return resolveTypeOfNodeInternal(store, arena, node_handle, &bound_type_params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -1153,7 +1153,7 @@ pub const FieldAccessReturn = struct {
|
|
|
|
unwrapped: ?TypeWithHandle = null,
|
|
|
|
unwrapped: ?TypeWithHandle = null,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
pub fn getFieldAccessType(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, tokenizer: *std.zig.Tokenizer) !?FieldAccessReturn {
|
|
|
|
pub fn getFieldAccessType(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, tokenizer: *std.zig.Tokenizer) !?FieldAccessReturn {
|
|
|
|
var current_type = TypeWithHandle.typeVal(.{
|
|
|
|
var current_type = TypeWithHandle.typeVal(.{
|
|
|
|
.node = undefined,
|
|
|
|
.node = undefined,
|
|
|
|
.handle = handle,
|
|
|
|
.handle = handle,
|
|
|
|
@@ -1887,7 +1887,7 @@ pub const DeclWithHandle = struct {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn resolveType(self: DeclWithHandle, store: *const DocumentStore, arena: *std.heap.ArenaAllocator, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
pub fn resolveType(self: DeclWithHandle, store: *DocumentStore, arena: *std.heap.ArenaAllocator, bound_type_params: *BoundTypeParams) !?TypeWithHandle {
|
|
|
|
const tree = self.handle.tree;
|
|
|
|
const tree = self.handle.tree;
|
|
|
|
const node_tags = tree.nodes.items(.tag);
|
|
|
|
const node_tags = tree.nodes.items(.tag);
|
|
|
|
const main_tokens = tree.nodes.items(.main_token);
|
|
|
|
const main_tokens = tree.nodes.items(.main_token);
|
|
|
|
@@ -1997,7 +1997,7 @@ fn findContainerScope(container_handle: NodeWithHandle) ?*Scope {
|
|
|
|
} else null;
|
|
|
|
} else null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn iterateSymbolsContainerInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *const DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void {
|
|
|
|
fn iterateSymbolsContainerInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *const DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void {
|
|
|
|
const container = container_handle.node;
|
|
|
|
const container = container_handle.node;
|
|
|
|
const handle = container_handle.handle;
|
|
|
|
const handle = container_handle.handle;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2064,7 +2064,7 @@ fn iterateSymbolsContainerInternal(store: *const DocumentStore, arena: *std.heap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn iterateSymbolsContainer(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *const DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool) error{OutOfMemory}!void {
|
|
|
|
pub fn iterateSymbolsContainer(store: *DocumentStore, arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *const DocumentStore.Handle, comptime callback: anytype, context: anytype, instance_access: bool) error{OutOfMemory}!void {
|
|
|
|
var use_trail = std.ArrayList(Ast.Node.Index).init(arena.allocator());
|
|
|
|
var use_trail = std.ArrayList(Ast.Node.Index).init(arena.allocator());
|
|
|
|
return try iterateSymbolsContainerInternal(store, arena, container_handle, orig_handle, callback, context, instance_access, &use_trail);
|
|
|
|
return try iterateSymbolsContainerInternal(store, arena, container_handle, orig_handle, callback, context, instance_access, &use_trail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -2085,7 +2085,7 @@ pub fn iterateLabels(handle: *const DocumentStore.Handle, source_index: usize, c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn iterateSymbolsGlobalInternal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void {
|
|
|
|
fn iterateSymbolsGlobalInternal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype, use_trail: *std.ArrayList(Ast.Node.Index)) error{OutOfMemory}!void {
|
|
|
|
for (handle.document_scope.scopes.items) |scope| {
|
|
|
|
for (handle.document_scope.scopes.items) |scope| {
|
|
|
|
if (source_index >= scope.loc.start and source_index <= scope.loc.end) {
|
|
|
|
if (source_index >= scope.loc.start and source_index <= scope.loc.end) {
|
|
|
|
var decl_it = scope.decls.iterator();
|
|
|
|
var decl_it = scope.decls.iterator();
|
|
|
|
@@ -2126,7 +2126,7 @@ fn iterateSymbolsGlobalInternal(store: *const DocumentStore, arena: *std.heap.Ar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn iterateSymbolsGlobal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void {
|
|
|
|
pub fn iterateSymbolsGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, source_index: usize, comptime callback: anytype, context: anytype) error{OutOfMemory}!void {
|
|
|
|
var use_trail = std.ArrayList(Ast.Node.Index).init(arena.allocator());
|
|
|
|
var use_trail = std.ArrayList(Ast.Node.Index).init(arena.allocator());
|
|
|
|
return try iterateSymbolsGlobalInternal(store, arena, handle, source_index, callback, context, &use_trail);
|
|
|
|
return try iterateSymbolsGlobalInternal(store, arena, handle, source_index, callback, context, &use_trail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -2167,7 +2167,7 @@ pub fn innermostContainer(handle: *const DocumentStore.Handle, source_index: usi
|
|
|
|
return TypeWithHandle.typeVal(.{ .node = current, .handle = handle });
|
|
|
|
return TypeWithHandle.typeVal(.{ .node = current, .handle = handle });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn resolveUse(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, uses: []const Ast.Node.Index, symbol: []const u8, handle: *const DocumentStore.Handle) error{OutOfMemory}!?DeclWithHandle {
|
|
|
|
fn resolveUse(store: *DocumentStore, arena: *std.heap.ArenaAllocator, uses: []const Ast.Node.Index, symbol: []const u8, handle: *const DocumentStore.Handle) error{OutOfMemory}!?DeclWithHandle {
|
|
|
|
// If we were asked to resolve this symbol before,
|
|
|
|
// If we were asked to resolve this symbol before,
|
|
|
|
// it is self-referential and we cannot resolve it.
|
|
|
|
// it is self-referential and we cannot resolve it.
|
|
|
|
if (std.mem.indexOfScalar([*]const u8, using_trail.items, symbol.ptr) != null)
|
|
|
|
if (std.mem.indexOfScalar([*]const u8, using_trail.items, symbol.ptr) != null)
|
|
|
|
@@ -2218,7 +2218,7 @@ pub fn lookupLabel(handle: *const DocumentStore.Handle, symbol: []const u8, sour
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn lookupSymbolGlobal(store: *const DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle {
|
|
|
|
pub fn lookupSymbolGlobal(store: *DocumentStore, arena: *std.heap.ArenaAllocator, handle: *const DocumentStore.Handle, symbol: []const u8, source_index: usize) error{OutOfMemory}!?DeclWithHandle {
|
|
|
|
const innermost_scope_idx = innermostBlockScopeIndex(handle.*, source_index);
|
|
|
|
const innermost_scope_idx = innermostBlockScopeIndex(handle.*, source_index);
|
|
|
|
|
|
|
|
|
|
|
|
var curr = innermost_scope_idx;
|
|
|
|
var curr = innermost_scope_idx;
|
|
|
|
@@ -2246,7 +2246,7 @@ pub fn lookupSymbolGlobal(store: *const DocumentStore, arena: *std.heap.ArenaAll
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn lookupSymbolContainer(
|
|
|
|
pub fn lookupSymbolContainer(
|
|
|
|
store: *const DocumentStore,
|
|
|
|
store: *DocumentStore,
|
|
|
|
arena: *std.heap.ArenaAllocator,
|
|
|
|
arena: *std.heap.ArenaAllocator,
|
|
|
|
container_handle: NodeWithHandle,
|
|
|
|
container_handle: NodeWithHandle,
|
|
|
|
symbol: []const u8,
|
|
|
|
symbol: []const u8,
|
|
|
|
|