Looks up a direct child of decl by name.
pub fn get_child(decl: *const Decl, name: []const u8) ?Decl.Index
pub fn get_child(decl: *const Decl, name: []const u8) ?Decl.Index {
switch (decl.categorize()) {
.alias => |aliasee| return aliasee.get().get_child(name),
.namespace, .container => |node| {
const file = decl.file.get();
const scope = file.scopes.get(node) orelse return null;
const child_node = scope.get_child(name) orelse return null;
return file.node_decls.get(child_node);
},
.type_function => {
// Find a decl with this function as the parent, with a name matching `name`
for (Walk.decls.items, 0..) |*candidate, i| {
if (candidate.parent != .none and candidate.parent.get() == decl and std.mem.eql(u8, candidate.extra_info().name, name)) {
return @fromBackingInt(@intCast(i));
}
}
return null;
},
else => return null,
}
}