mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user