Initial implementation of member operators. Known limitations: currently only works for operators on structs/classes, the lookup rules aren't completely settled,

and we don't actually check whether it's reasonable to declare a given operator as a member.



Swift SVN r2277
This commit is contained in:
Eli Friedman
2012-06-29 00:47:33 +00:00
parent ce77e792cf
commit a1a182e3d9
6 changed files with 42 additions and 42 deletions

View File

@@ -83,6 +83,7 @@ namespace {
/// Module::LookupCachePimpl.
class TUModuleCache {
llvm::DenseMap<Identifier, TinyPtrVector<ValueDecl*>> TopLevelValues;
void doPopulateCache(ArrayRef<Decl*> decls, bool onlyOperators);
public:
typedef Module::AccessPathTy AccessPathTy;
@@ -107,14 +108,21 @@ static void freeTUCachePimpl(void *&Ptr) {
Ptr = 0;
}
void TUModuleCache::doPopulateCache(ArrayRef<Decl*> decls, bool onlyOperators) {
for (Decl *D : decls) {
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
if (onlyOperators ? VD->getName().isOperator() : !VD->getName().empty())
TopLevelValues[VD->getName()].push_back(VD);
if (NominalTypeDecl *NTD = dyn_cast<NominalTypeDecl>(D))
doPopulateCache(NTD->getMembers(), true);
if (ExtensionDecl *ED = dyn_cast<ExtensionDecl>(D))
doPopulateCache(ED->getMembers(), true);
}
}
/// Populate our cache on the first name lookup.
TUModuleCache::TUModuleCache(TranslationUnit &TU) {
for (Decl *D : TU.Decls) {
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
if (!VD->getName().empty())
TopLevelValues[VD->getName()].push_back(VD);
}
doPopulateCache(TU.Decls, false);
}