AST: Change lookupInModule() to take a DeclContext instead of a module and extra imports

Also get rid of the 'accessPath' parameter.
This commit is contained in:
Slava Pestov
2019-08-26 21:32:53 -04:00
parent 61a4a48e21
commit 37f308b8d3
6 changed files with 52 additions and 47 deletions

View File

@@ -444,14 +444,15 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
cache.try_emplace(cacheKey, lookupResults);
}
void namelookup::lookupInModule(ModuleDecl *startModule,
ModuleDecl::AccessPathTy topAccessPath,
void namelookup::lookupInModule(const DeclContext *moduleOrFile,
DeclName name,
SmallVectorImpl<ValueDecl *> &decls,
NLKind lookupKind,
ResolutionKind resolutionKind,
const DeclContext *moduleScopeContext,
ArrayRef<ModuleDecl::ImportedModule> extraImports) {
const DeclContext *moduleScopeContext) {
assert(moduleScopeContext->isModuleScopeContext());
auto *startModule = moduleOrFile->getParentModule();
auto &ctx = startModule->getASTContext();
auto *stats = ctx.Stats;
if (stats)
@@ -459,23 +460,43 @@ void namelookup::lookupInModule(ModuleDecl *startModule,
FrontendStatsTracer tracer(stats, "lookup-in-module");
assert(moduleScopeContext && moduleScopeContext->isModuleScopeContext());
// Add private imports to the extra search list.
SmallVector<ModuleDecl::ImportedModule, 8> extraImports;
if (auto *file = dyn_cast<FileUnit>(moduleOrFile)) {
ModuleDecl::ImportFilter importFilter;
importFilter |= ModuleDecl::ImportFilterKind::Private;
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
file->getImportedModules(extraImports, importFilter);
}
LookupByName lookup(ctx, resolutionKind, name, lookupKind);
lookup.lookupInModule(decls, startModule, topAccessPath, moduleScopeContext,
lookup.lookupInModule(decls, startModule, {}, moduleScopeContext,
extraImports);
}
void namelookup::lookupVisibleDeclsInModule(
ModuleDecl *M,
const DeclContext *moduleOrFile,
ModuleDecl::AccessPathTy accessPath,
SmallVectorImpl<ValueDecl *> &decls,
NLKind lookupKind,
ResolutionKind resolutionKind,
const DeclContext *moduleScopeContext,
ArrayRef<ModuleDecl::ImportedModule> extraImports) {
auto &ctx = M->getASTContext();
assert(moduleScopeContext && moduleScopeContext->isModuleScopeContext());
const DeclContext *moduleScopeContext) {
assert(moduleScopeContext->isModuleScopeContext());
auto *startModule = moduleOrFile->getParentModule();
auto &ctx = startModule->getASTContext();
// Add private imports to the extra search list.
SmallVector<ModuleDecl::ImportedModule, 8> extraImports;
if (auto *file = dyn_cast<FileUnit>(moduleOrFile)) {
ModuleDecl::ImportFilter importFilter;
importFilter |= ModuleDecl::ImportFilterKind::Private;
importFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
file->getImportedModules(extraImports, importFilter);
}
LookupVisibleDecls lookup(ctx, resolutionKind, lookupKind);
lookup.lookupInModule(decls, M, accessPath, moduleScopeContext, extraImports);
lookup.lookupInModule(decls, startModule, accessPath, moduleScopeContext,
extraImports);
}