mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Simplify ModuleDecl::forAllVisibleModules()
This commit is contained in:
@@ -400,46 +400,14 @@ public:
|
||||
///
|
||||
/// \param topLevelAccessPath If present, include the top-level module in the
|
||||
/// results, with the given access path.
|
||||
/// \param includePrivateTopLevelImports If true, imports listed in all
|
||||
/// file units within this module are traversed. Otherwise (the
|
||||
/// default), only re-exported imports are traversed.
|
||||
/// \param fn A callback of type bool(ImportedModule) or void(ImportedModule).
|
||||
/// Return \c false to abort iteration.
|
||||
///
|
||||
/// \return True if the traversal ran to completion, false if it ended early
|
||||
/// due to the callback.
|
||||
bool forAllVisibleModules(AccessPathTy topLevelAccessPath,
|
||||
bool includePrivateTopLevelImports,
|
||||
llvm::function_ref<bool(ImportedModule)> fn);
|
||||
|
||||
bool forAllVisibleModules(AccessPathTy topLevelAccessPath,
|
||||
bool includePrivateTopLevelImports,
|
||||
llvm::function_ref<void(ImportedModule)> fn) {
|
||||
return forAllVisibleModules(topLevelAccessPath,
|
||||
includePrivateTopLevelImports,
|
||||
[=](const ImportedModule &import) -> bool {
|
||||
fn(import);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
bool forAllVisibleModules(AccessPathTy topLevelAccessPath,
|
||||
bool includePrivateTopLevelImports,
|
||||
Fn &&fn) {
|
||||
using RetTy = typename std::result_of<Fn(ImportedModule)>::type;
|
||||
llvm::function_ref<RetTy(ImportedModule)> wrapped{std::forward<Fn>(fn)};
|
||||
return forAllVisibleModules(topLevelAccessPath,
|
||||
includePrivateTopLevelImports,
|
||||
wrapped);
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
bool forAllVisibleModules(AccessPathTy topLevelAccessPath, Fn &&fn) {
|
||||
return forAllVisibleModules(topLevelAccessPath, false,
|
||||
std::forward<Fn>(fn));
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
using LinkLibraryCallback = llvm::function_ref<void(LinkLibrary)>;
|
||||
@@ -687,23 +655,6 @@ public:
|
||||
bool
|
||||
forAllVisibleModules(llvm::function_ref<bool(ModuleDecl::ImportedModule)> fn);
|
||||
|
||||
bool
|
||||
forAllVisibleModules(llvm::function_ref<void(ModuleDecl::ImportedModule)> fn) {
|
||||
return forAllVisibleModules([=](ModuleDecl::ImportedModule import) -> bool {
|
||||
fn(import);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
bool forAllVisibleModules(Fn &&fn) {
|
||||
using RetTy = typename std::result_of<Fn(ModuleDecl::ImportedModule)>::type;
|
||||
llvm::function_ref<RetTy(ModuleDecl::ImportedModule)> wrapped{
|
||||
std::forward<Fn>(fn)
|
||||
};
|
||||
return forAllVisibleModules(wrapped);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
/// True if this file contains the main class for the module.
|
||||
|
||||
Reference in New Issue
Block a user