llvm::Expected<std::unique_ptr<Generator>>
findGeneratorByName(llvm::StringRef Format) {
- for (auto I = GeneratorRegistry::begin(), E = GeneratorRegistry::end();
- I != E; ++I) {
- if (I->getName() != Format)
+ for (const auto &Generator : GeneratorRegistry::entries()) {
+ if (Generator.getName() != Format)
continue;
- return I->instantiate();
+ return Generator.instantiate();
}
return createStringError(llvm::inconvertibleErrorCode(),
"can't find generator: " + Format);
Options.FormatStyle = "none";
Options.User = llvm::None;
unsigned Priority = 0;
- for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(),
- E = ClangTidyModuleRegistry::end();
- I != E; ++I)
+ for (const ClangTidyModuleRegistry::entry &Module :
+ ClangTidyModuleRegistry::entries())
Options =
- Options.mergeWith(I->instantiate()->getModuleOptions(), ++Priority);
+ Options.mergeWith(Module.instantiate()->getModuleOptions(), ++Priority);
return Options;
}
if (Scheme == "file")
return std::make_unique<FileSystemScheme>();
- for (auto I = URISchemeRegistry::begin(), E = URISchemeRegistry::end();
- I != E; ++I) {
- if (I->getName() != Scheme)
+ for (const auto &URIScheme : URISchemeRegistry::entries()) {
+ if (URIScheme.getName() != Scheme)
continue;
- return I->instantiate();
+ return URIScheme.instantiate();
}
return make_string_error("Can't find scheme: " + Scheme);
}
bool FoundAllPlugins = true;
for (const std::string &Arg : CI.getFrontendOpts().AddPluginActions) {
bool Found = false;
- for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
- ie = FrontendPluginRegistry::end();
- it != ie; ++it) {
- if (it->getName() == Arg)
+ for (const FrontendPluginRegistry::entry &Plugin :
+ FrontendPluginRegistry::entries()) {
+ if (Plugin.getName() == Arg)
Found = true;
}
if (!Found) {
// or after it (in AfterConsumers)
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers;
- for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
- ie = FrontendPluginRegistry::end();
- it != ie; ++it) {
- std::unique_ptr<PluginASTAction> P = it->instantiate();
+ for (const FrontendPluginRegistry::entry &Plugin :
+ FrontendPluginRegistry::entries()) {
+ std::unique_ptr<PluginASTAction> P = Plugin.instantiate();
PluginASTAction::ActionType ActionType = P->getActionType();
if (ActionType == PluginASTAction::Cmdline) {
// This is O(|plugins| * |add_plugins|), but since both numbers are
// way below 50 in practice, that's ok.
- for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size();
- i != e; ++i) {
- if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) {
- ActionType = PluginASTAction::AddAfterMainAction;
- break;
- }
- }
+ if (llvm::any_of(CI.getFrontendOpts().AddPluginActions,
+ [&](const std::string &PluginAction) {
+ return PluginAction == Plugin.getName();
+ }))
+ ActionType = PluginASTAction::AddAfterMainAction;
}
if ((ActionType == PluginASTAction::AddBeforeMainAction ||
ActionType == PluginASTAction::AddAfterMainAction) &&
P->ParseArgs(
- CI, CI.getFrontendOpts().PluginArgs[std::string(it->getName())])) {
+ CI,
+ CI.getFrontendOpts().PluginArgs[std::string(Plugin.getName())])) {
std::unique_ptr<ASTConsumer> PluginConsumer = P->CreateASTConsumer(CI, InFile);
if (ActionType == PluginASTAction::AddBeforeMainAction) {
Consumers.push_back(std::move(PluginConsumer));
case TemplightDump: return std::make_unique<TemplightDumpAction>();
case PluginAction: {
- for (FrontendPluginRegistry::iterator it =
- FrontendPluginRegistry::begin(), ie = FrontendPluginRegistry::end();
- it != ie; ++it) {
- if (it->getName() == CI.getFrontendOpts().ActionName) {
- std::unique_ptr<PluginASTAction> P(it->instantiate());
+ for (const FrontendPluginRegistry::entry &Plugin :
+ FrontendPluginRegistry::entries()) {
+ if (Plugin.getName() == CI.getFrontendOpts().ActionName) {
+ std::unique_ptr<PluginASTAction> P(Plugin.instantiate());
if ((P->getActionType() != PluginASTAction::ReplaceAction &&
P->getActionType() != PluginASTAction::Cmdline) ||
!P->ParseArgs(
CI,
- CI.getFrontendOpts().PluginArgs[std::string(it->getName())]))
+ CI.getFrontendOpts().PluginArgs[std::string(Plugin.getName())]))
return nullptr;
return std::move(P);
}
}
// Load any requested plugins.
- for (unsigned i = 0,
- e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
- const std::string &Path = Clang->getFrontendOpts().Plugins[i];
+ for (const std::string &Path : Clang->getFrontendOpts().Plugins) {
std::string Error;
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
}
// Check if any of the loaded plugins replaces the main AST action
- for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
- ie = FrontendPluginRegistry::end();
- it != ie; ++it) {
- std::unique_ptr<PluginASTAction> P(it->instantiate());
+ for (const FrontendPluginRegistry::entry &Plugin :
+ FrontendPluginRegistry::entries()) {
+ std::unique_ptr<PluginASTAction> P(Plugin.instantiate());
if (P->getActionType() == PluginASTAction::ReplaceAction) {
Clang->getFrontendOpts().ProgramAction = clang::frontend::PluginAction;
- Clang->getFrontendOpts().ActionName = std::string(it->getName());
+ Clang->getFrontendOpts().ActionName = Plugin.getName().str();
break;
}
}
}
// Pragmas added by plugins
- for (PragmaHandlerRegistry::iterator it = PragmaHandlerRegistry::begin(),
- ie = PragmaHandlerRegistry::end();
- it != ie; ++it) {
- AddPragmaHandler(it->instantiate().release());
+ for (const PragmaHandlerRegistry::entry &handler :
+ PragmaHandlerRegistry::entries()) {
+ AddPragmaHandler(handler.instantiate().release());
}
}
CompilationDatabase::loadFromDirectory(StringRef BuildDirectory,
std::string &ErrorMessage) {
llvm::raw_string_ostream ErrorStream(ErrorMessage);
- for (CompilationDatabasePluginRegistry::iterator
- It = CompilationDatabasePluginRegistry::begin(),
- Ie = CompilationDatabasePluginRegistry::end();
- It != Ie; ++It) {
+ for (const CompilationDatabasePluginRegistry::entry &Database :
+ CompilationDatabasePluginRegistry::entries()) {
std::string DatabaseErrorMessage;
- std::unique_ptr<CompilationDatabasePlugin> Plugin(It->instantiate());
+ std::unique_ptr<CompilationDatabasePlugin> Plugin(Database.instantiate());
if (std::unique_ptr<CompilationDatabase> DB =
Plugin->loadFromDirectory(BuildDirectory, DatabaseErrorMessage))
return DB;
- ErrorStream << It->getName() << ": " << DatabaseErrorMessage << "\n";
+ ErrorStream << Database.getName() << ": " << DatabaseErrorMessage << "\n";
}
return nullptr;
}
/*Overview=*/Overview);
if (!OptionsParser)
return OptionsParser.takeError();
- for (auto I = ToolExecutorPluginRegistry::begin(),
- E = ToolExecutorPluginRegistry::end();
- I != E; ++I) {
- if (I->getName() != ExecutorName) {
+ for (const auto &TEPlugin : ToolExecutorPluginRegistry::entries()) {
+ if (TEPlugin.getName() != ExecutorName) {
continue;
}
- std::unique_ptr<ToolExecutorPlugin> Plugin(I->instantiate());
+ std::unique_ptr<ToolExecutorPlugin> Plugin(TEPlugin.instantiate());
llvm::Expected<std::unique_ptr<ToolExecutor>> Executor =
Plugin->create(*OptionsParser);
if (!Executor) {
return llvm::make_error<llvm::StringError>(
- llvm::Twine("Failed to create '") + I->getName() +
+ llvm::Twine("Failed to create '") + TEPlugin.getName() +
"': " + llvm::toString(Executor.takeError()) + "\n",
llvm::inconvertibleErrorCode());
}
auto Name = S.getName();
- for (GCMetadataPrinterRegistry::iterator
- I = GCMetadataPrinterRegistry::begin(),
- E = GCMetadataPrinterRegistry::end(); I != E; ++I)
- if (Name == I->getName()) {
- std::unique_ptr<GCMetadataPrinter> GMP = I->instantiate();
+ for (const GCMetadataPrinterRegistry::entry &GCMetaPrinter :
+ GCMetadataPrinterRegistry::entries())
+ if (Name == GCMetaPrinter.getName()) {
+ std::unique_ptr<GCMetadataPrinter> GMP = GCMetaPrinter.instantiate();
GMP->S = &S;
auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP)));
return IterBool.first->second.get();