Add lookupClassMembers for use in id-style dynamic lookup.

With this, we can now get a list of all class members* available in the
current translation unit, which will be necessary for doing id-style
dynamic lookup (inferring which method you're referring to when the base
type is some magic "dynamic lookup" type).

* Including members of protocols, since a class we don't know about could
have implemented the protocol.

Since there is no code currently using this, I've added a new mode to
swift-ide-test to just dump all class members -- what will eventually
happen when you code complete on a dynamic lookup type. This mode will
go away once the other pieces of id-style lookup are in place.

Swift SVN r7287
This commit is contained in:
Jordan Rose
2013-08-16 20:22:14 +00:00
parent cf6bb91b20
commit 2241086363
10 changed files with 236 additions and 11 deletions

View File

@@ -858,6 +858,9 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
getterID, setterID, overriddenID);
auto DC = ForcedContext ? *ForcedContext : getDeclContext(contextID);
if (declOrOffset.isComplete())
break;
auto var = new (ctx) VarDecl(SourceLoc(), getIdentifier(nameID),
getType(typeID), DC);
@@ -2418,3 +2421,30 @@ void ModuleFile::loadDeclsConformingTo(KnownProtocolKind kind) {
}
}
void ModuleFile::lookupClassMembers(Module::AccessPathTy accessPath,
VisibleDeclConsumer &consumer) {
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
if (!ClassMembersByName)
return;
if (!accessPath.empty()) {
for (const auto &list : make_range(ClassMembersByName->data_begin(),
ClassMembersByName->data_end())) {
for (auto item : list) {
auto vd = cast<ValueDecl>(getDecl(item.second));
Type ty = vd->getDeclContext()->getDeclaredTypeOfContext();
if (auto nominal = ty->getAnyNominal())
if (nominal->getName() == accessPath.front().first)
consumer.foundDecl(vd);
}
}
return;
}
for (const auto &list : make_range(ClassMembersByName->data_begin(),
ClassMembersByName->data_end())) {
for (auto item : list)
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)));
}
}