mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add an entry point for id-style lookup of a known name.
This will be used to resolve properties and method calls on objects with
dynamic-lookup ("id") type. For now, this is tested in swift-ide-test
by using the -dynamic-lookup-completion option and providing a
-code-completion-token value.
Caveats/TODOs:
- As before, since we're using the global method pool, this isn't scoped by
module. We could do a per-module filter, but I don't know if that will
actually buy us much.
- Again, Clang's method pool does not include methods from protocols.
- Lookup by selector name cannot find properties with a customized getter
name. <rdar://problem/14776565>
- The Clang-side method pool is keyed by selector, but Swift wants to look
things up by method name, which maps to the first selector piece, so we
end up having to do a scan of all the selectors in the pool.
Swift SVN r7330
This commit is contained in:
@@ -2423,6 +2423,35 @@ void ModuleFile::loadDeclsConformingTo(KnownProtocolKind kind) {
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleFile::lookupClassMember(Module::AccessPathTy accessPath,
|
||||
Identifier name,
|
||||
SmallVectorImpl<ValueDecl*> &results) {
|
||||
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
|
||||
|
||||
if (!ClassMembersByName)
|
||||
return;
|
||||
|
||||
auto iter = ClassMembersByName->find(name);
|
||||
if (iter == ClassMembersByName->end())
|
||||
return;
|
||||
|
||||
if (!accessPath.empty()) {
|
||||
for (auto item : *iter) {
|
||||
auto vd = cast<ValueDecl>(getDecl(item.second));
|
||||
Type ty = vd->getDeclContext()->getDeclaredTypeOfContext();
|
||||
if (auto nominal = ty->getAnyNominal())
|
||||
if (nominal->getName() == accessPath.front().first)
|
||||
results.push_back(vd);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto item : *iter) {
|
||||
auto vd = cast<ValueDecl>(getDecl(item.second));
|
||||
results.push_back(vd);
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleFile::lookupClassMembers(Module::AccessPathTy accessPath,
|
||||
VisibleDeclConsumer &consumer) {
|
||||
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
|
||||
|
||||
Reference in New Issue
Block a user