Move lookupQualified from Module to DeclContext.

Qualified lookup depends not only on the current module but actually the
current file, since imports are file-scoped by default. Currently this only
affects lookup into other modules (e.g. "Foundation.NSString"), but this
could also be used for extension filtering.

This breaks one name resolution test, but the refactoring in the next
commit changes everything anyway and will restore the test.

Swift SVN r10831
This commit is contained in:
Jordan Rose
2013-12-05 01:51:07 +00:00
parent eede5ec4f9
commit d0d661164d
8 changed files with 88 additions and 50 deletions

View File

@@ -167,32 +167,6 @@ public:
VisibleDeclConsumer &Consumer,
NLKind LookupKind) const;
/// Look for the set of declarations with the given name within a type,
/// its extensions and, optionally, its supertypes.
///
/// This routine performs name lookup within a given type, its extensions
/// and, optionally, its supertypes and their extensions. It can eliminate
/// non-visible, hidden, and overridden declarations from the result set.
/// It does not, however, perform any filtering based on the semantic
/// usefulness of the results.
///
/// \param type The type to look into.
///
/// \param name The name to search for.
///
/// \param options Options that control name lookup, based on the
/// \c NL_* constants in \c NameLookupOptions.
///
/// \param typeResolver Used to resolve types, usually for overload purposes.
///
/// \param[out] decls Will be populated with the declarations found by name
/// lookup.
///
/// \returns true if anything was found.
bool lookupQualified(Type type, Identifier name, unsigned options,
LazyResolver *typeResolver,
SmallVectorImpl<ValueDecl *> &decls);
/// @{
/// Look up the given operator in this module.
@@ -368,6 +342,22 @@ public:
/// This does a simple local lookup, not recursively looking through imports.
void getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const;
void forAllVisibleModules(std::function<bool(Module::ImportedModule)> fn);
void forAllVisibleModules(std::function<void(Module::ImportedModule)> fn) {
forAllVisibleModules([=](const Module::ImportedModule &import) -> bool {
fn(import);
return true;
});
}
template <typename Fn>
void forAllVisibleModules(const Fn &fn) {
using RetTy = typename as_function<Fn>::type::result_type;
std::function<RetTy(Module::ImportedModule)> wrapped = std::cref(fn);
forAllVisibleModules(wrapped);
}
Module *getParentModule() const {
return const_cast<Module *>(cast<Module>(getParent()));
}