Make sure that the dynamic lookup table has the right set of members.

Clean up the "can be accessed by dynamic lookup" predicate so that it
checks for a generic context. We no longer need to do the checking in
name lookup, since this means that the dynamic lookup table won't have
anything we can't use (thanks Jordan!). Drop the [objc] allowance for
members of a generic context: it still leaves us with a very weird
case of messaging something when we can't even figure out the type
that we think the object has.

Extend the walk searching for members to include inner classes within
structs, so we get all of the members globally.



Swift SVN r7799
This commit is contained in:
Doug Gregor
2013-08-30 20:43:34 +00:00
parent 8c84806f5b
commit 04d157427d
5 changed files with 65 additions and 62 deletions

View File

@@ -152,14 +152,9 @@ void TUModuleCache::doPopulateCache(ArrayRef<Decl*> decls, bool onlyOperators) {
void TUModuleCache::populateMemberCache(const TranslationUnit &TU) {
for (const Decl *D : TU.Decls) {
if (const NominalTypeDecl *NTD = dyn_cast<NominalTypeDecl>(D)) {
if (isa<ClassDecl>(NTD) || isa<ProtocolDecl>(NTD))
addToMemberCache(NTD->getMembers());
addToMemberCache(NTD->getMembers());
} else if (const ExtensionDecl *ED = dyn_cast<ExtensionDecl>(D)) {
Type baseTy = ED->getExtendedType();
assert(baseTy && "cannot use this before type-checking");
if (auto baseNominal = baseTy->getAnyNominal())
if (isa<ClassDecl>(baseNominal) || isa<ProtocolDecl>(baseNominal))
addToMemberCache(ED->getMembers());
addToMemberCache(ED->getMembers());
}
}
}
@@ -173,9 +168,7 @@ void TUModuleCache::addToMemberCache(ArrayRef<Decl*> decls) {
if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
assert(!VD->canBeAccessedByDynamicLookup() &&
"inner types cannot be accessed by dynamic lookup");
if (isa<ClassDecl>(NTD) || isa<ProtocolDecl>(NTD))
addToMemberCache(NTD->getMembers());
addToMemberCache(NTD->getMembers());
} else if (VD->canBeAccessedByDynamicLookup()) {
ClassMembers[VD->getName()].push_back(VD);
}