Respect access control in visible decl lookup (and code completion).

<rdar://problem/17648922>

Swift SVN r19963
This commit is contained in:
Jordan Rose
2014-07-14 23:02:41 +00:00
parent 820e8e0a49
commit 67536dbb8a
9 changed files with 138 additions and 88 deletions

View File

@@ -1933,7 +1933,9 @@ public:
: LookupKind::ValueInDeclContext;
NeedLeadingDot = false;
Module *M = CurrDeclContext->getParentModule();
M->lookupVisibleDecls({}, *this, NLKind::QualifiedLookup);
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
TypeResolver.get());
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::QualifiedLookup);
}
void getVisibleDeclsOfModule(const Module *TheModule,
@@ -1947,39 +1949,11 @@ public:
LookupAccessPath.push_back(
std::make_pair(Ctx.getIdentifier(Piece), SourceLoc()));
}
TheModule->lookupVisibleDecls(LookupAccessPath, *this,
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
TypeResolver.get());
TheModule->lookupVisibleDecls(LookupAccessPath, FilteringConsumer,
NLKind::QualifiedLookup);
}
void getModuleImportCompletions(StringRef ModuleName,
const std::vector<std::string> &AccessPath,
bool ResultsHaveLeadingDot) {
Kind = LookupKind::ImportFromModule;
NeedLeadingDot = ResultsHaveLeadingDot;
auto ModulePath =
std::make_pair(Ctx.getIdentifier(ModuleName), SourceLoc());
Module *M = Ctx.getModule(llvm::makeArrayRef(ModulePath));
if (!M)
return;
llvm::SmallVector<std::pair<Identifier, SourceLoc>, 1> LookupAccessPath;
for (auto Piece : AccessPath) {
LookupAccessPath.push_back(
std::make_pair(Ctx.getIdentifier(Piece), SourceLoc()));
}
using namespace swift::namelookup;
SmallVector<ValueDecl *, 1> Decls;
lookupVisibleDeclsInModule(M, LookupAccessPath, Decls,
NLKind::QualifiedLookup,
ResolutionKind::Exact,
TypeResolver.get());
for (auto *VD : Decls) {
foundDecl(VD, DeclVisibilityKind::VisibleAtTopLevel);
}
}
};
class CompletionOverrideLookup : public swift::VisibleDeclConsumer {