Fix namespaces in containers
This commit is contained in:
parent
85937d48ca
commit
094b31be48
108
src/analysis.zig
108
src/analysis.zig
@ -2117,62 +2117,55 @@ fn iterateSymbolsContainerInternal(
|
|||||||
const token_tags = tree.tokens.items(.tag);
|
const token_tags = tree.tokens.items(.tag);
|
||||||
const main_token = tree.nodes.items(.main_token)[container];
|
const main_token = tree.nodes.items(.main_token)[container];
|
||||||
|
|
||||||
const is_enum = if (isContainer(node_tags[container]) and node_tags[container] != .root)
|
const is_enum = token_tags[main_token] == .keyword_enum;
|
||||||
token_tags[main_token] == .keyword_enum
|
|
||||||
else
|
|
||||||
false;
|
|
||||||
|
|
||||||
if (findContainerScope(container_handle)) |container_scope| {
|
const container_scope = findContainerScope(container_handle) orelse return;
|
||||||
var decl_it = container_scope.decls.iterator();
|
|
||||||
while (decl_it.next()) |entry| {
|
|
||||||
switch (entry.value) {
|
|
||||||
.ast_node => |node| {
|
|
||||||
if (node_tags[node].isContainerField()) {
|
|
||||||
if (!instance_access and !is_enum) continue;
|
|
||||||
if (instance_access and is_enum) continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.label_decl => continue,
|
|
||||||
else => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
const decl = DeclWithHandle{ .decl = &entry.value, .handle = handle };
|
var decl_it = container_scope.decls.iterator();
|
||||||
if (handle != orig_handle and !decl.isPublic()) continue;
|
while (decl_it.next()) |entry| {
|
||||||
try callback(context, decl);
|
switch (entry.value) {
|
||||||
|
.ast_node => |node| {
|
||||||
|
if (node_tags[node].isContainerField()) {
|
||||||
|
if (!instance_access and !is_enum) continue;
|
||||||
|
if (instance_access and is_enum) continue;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.label_decl => continue,
|
||||||
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
for (container_scope.uses) |use| {
|
const decl = DeclWithHandle{ .decl = &entry.value, .handle = handle };
|
||||||
const use_token = tree.nodes.items(.main_token)[use];
|
if (handle != orig_handle and !decl.isPublic()) continue;
|
||||||
const is_pub = use_token > 0 and token_tags[use_token - 1] == .keyword_pub;
|
try callback(context, decl);
|
||||||
if (handle != orig_handle and !is_pub) continue;
|
}
|
||||||
if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue;
|
|
||||||
try use_trail.append(use);
|
|
||||||
|
|
||||||
const rhs = tree.nodes.items(.data)[use].rhs;
|
for (container_scope.uses) |use| {
|
||||||
// rhs can be invalid so apply the following check to ensure
|
const use_token = tree.nodes.items(.main_token)[use];
|
||||||
// we do not go out of bounds when resolving the type
|
const is_pub = use_token > 0 and token_tags[use_token - 1] == .keyword_pub;
|
||||||
if (rhs == 0 or rhs > tree.nodes.len) continue;
|
if (handle != orig_handle and !is_pub) continue;
|
||||||
const use_expr = (try resolveTypeOfNode(store, arena, .{
|
if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue;
|
||||||
.node = tree.nodes.items(.data)[use].rhs,
|
try use_trail.append(use);
|
||||||
.handle = orig_handle,
|
|
||||||
})) orelse continue;
|
|
||||||
|
|
||||||
const use_expr_node = switch (use_expr.type.data) {
|
const lhs = tree.nodes.items(.data)[use].lhs;
|
||||||
.other => |n| n,
|
const use_expr = (try resolveTypeOfNode(store, arena, .{
|
||||||
else => continue,
|
.node = lhs,
|
||||||
};
|
.handle = handle,
|
||||||
|
})) orelse continue;
|
||||||
|
|
||||||
try iterateSymbolsContainerInternal(
|
const use_expr_node = switch (use_expr.type.data) {
|
||||||
store,
|
.other => |n| n,
|
||||||
arena,
|
else => continue,
|
||||||
.{ .node = use_expr_node, .handle = use_expr.handle },
|
};
|
||||||
orig_handle,
|
try iterateSymbolsContainerInternal(
|
||||||
callback,
|
store,
|
||||||
context,
|
arena,
|
||||||
false,
|
.{ .node = use_expr_node, .handle = use_expr.handle },
|
||||||
use_trail,
|
orig_handle,
|
||||||
);
|
callback,
|
||||||
}
|
context,
|
||||||
|
false,
|
||||||
|
use_trail,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2232,12 +2225,25 @@ fn iterateSymbolsGlobalInternal(
|
|||||||
if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue;
|
if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue;
|
||||||
try use_trail.append(use);
|
try use_trail.append(use);
|
||||||
|
|
||||||
const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = handle.tree.nodes.items(.data)[use].lhs, .handle = handle })) orelse continue;
|
const use_expr = (try resolveTypeOfNode(
|
||||||
|
store,
|
||||||
|
arena,
|
||||||
|
.{ .node = handle.tree.nodes.items(.data)[use].lhs, .handle = handle },
|
||||||
|
)) orelse continue;
|
||||||
const use_expr_node = switch (use_expr.type.data) {
|
const use_expr_node = switch (use_expr.type.data) {
|
||||||
.other => |n| n,
|
.other => |n| n,
|
||||||
else => continue,
|
else => continue,
|
||||||
};
|
};
|
||||||
try iterateSymbolsContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, handle, callback, context, false, use_trail);
|
try iterateSymbolsContainerInternal(
|
||||||
|
store,
|
||||||
|
arena,
|
||||||
|
.{ .node = use_expr_node, .handle = use_expr.handle },
|
||||||
|
handle,
|
||||||
|
callback,
|
||||||
|
context,
|
||||||
|
false,
|
||||||
|
use_trail,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user