From 6597883c1eb44eb00acf9dc0afde4ea9ae709e87 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 3 Oct 2014 01:04:53 +0000 Subject: [PATCH] Driver: Use pointee_iterator rather than iterating over unique_ptrs There's probably never a good reason to iterate over unique_ptrs. This lets us use range-for and say Job.foo instead of (*it)->foo in a few places. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218938 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Job.h | 5 +++-- lib/Driver/Compilation.cpp | 5 ++--- lib/Driver/Driver.cpp | 4 ++-- lib/Driver/Job.cpp | 4 ++-- lib/Frontend/CreateInvocationFromCommandLine.cpp | 4 ++-- lib/Tooling/CompilationDatabase.cpp | 7 +++---- lib/Tooling/Tooling.cpp | 4 ++-- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/clang/Driver/Job.h b/include/clang/Driver/Job.h index 032e831251..2695f9eadb 100644 --- a/include/clang/Driver/Job.h +++ b/include/clang/Driver/Job.h @@ -13,6 +13,7 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Option/Option.h" +#include "llvm/ADT/iterator.h" #include namespace llvm { @@ -158,8 +159,8 @@ class JobList : public Job { public: typedef SmallVector, 4> list_type; typedef list_type::size_type size_type; - typedef list_type::iterator iterator; - typedef list_type::const_iterator const_iterator; + typedef llvm::pointee_iterator iterator; + typedef llvm::pointee_iterator const_iterator; private: list_type Jobs; diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 124ecca4d3..2bcbd5cf94 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -202,9 +202,8 @@ void Compilation::ExecuteJob(const Job &J, FailingCommands.push_back(std::make_pair(Res, FailingCommand)); } else { const JobList *Jobs = cast(&J); - for (JobList::const_iterator it = Jobs->begin(), ie = Jobs->end(); - it != ie; ++it) - ExecuteJob(**it, FailingCommands); + for (const auto &Job : *Jobs) + ExecuteJob(Job, FailingCommands); } } diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 6cf6c01dca..8b09775506 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -578,8 +578,8 @@ void Driver::generateCompilationDiagnostics(Compilation &C, void Driver::setUpResponseFiles(Compilation &C, Job &J) { if (JobList *Jobs = dyn_cast(&J)) { - for (JobList::iterator I = Jobs->begin(), E = Jobs->end(); I != E; ++I) - setUpResponseFiles(C, **I); + for (auto &Job : *Jobs) + setUpResponseFiles(C, Job); return; } diff --git a/lib/Driver/Job.cpp b/lib/Driver/Job.cpp index 1202c997b5..c13b56e1be 100644 --- a/lib/Driver/Job.cpp +++ b/lib/Driver/Job.cpp @@ -287,8 +287,8 @@ JobList::JobList() : Job(JobListClass) {} void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote, bool CrashReport) const { - for (const_iterator it = begin(), ie = end(); it != ie; ++it) - (*it)->Print(OS, Terminator, Quote, CrashReport); + for (const auto &Job : *this) + Job.Print(OS, Terminator, Quote, CrashReport); } void JobList::clear() { Jobs.clear(); } diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp index 24f9adf5ba..4a8a8a029e 100644 --- a/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -63,7 +63,7 @@ clang::createInvocationFromCommandLine(ArrayRef ArgList, // We expect to get back exactly one command job, if we didn't something // failed. const driver::JobList &Jobs = C->getJobs(); - if (Jobs.size() != 1 || !isa(**Jobs.begin())) { + if (Jobs.size() != 1 || !isa(*Jobs.begin())) { SmallString<256> Msg; llvm::raw_svector_ostream OS(Msg); Jobs.Print(OS, "; ", true); @@ -71,7 +71,7 @@ clang::createInvocationFromCommandLine(ArrayRef ArgList, return nullptr; } - const driver::Command &Cmd = cast(**Jobs.begin()); + const driver::Command &Cmd = cast(*Jobs.begin()); if (StringRef(Cmd.getCreator().getName()) != "clang") { Diags->Report(diag::err_fe_expected_clang_command); return nullptr; diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index f16f64744e..7613988c96 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -249,10 +249,9 @@ static bool stripPositionalArgs(std::vector Args, CompileJobAnalyzer CompileAnalyzer; - for (driver::JobList::const_iterator I = Jobs.begin(), E = Jobs.end(); I != E; - ++I) { - if ((*I)->getKind() == driver::Job::CommandClass) { - const driver::Command &Cmd = cast(**I); + for (const auto &Job : Jobs) { + if (Job.getKind() == driver::Job::CommandClass) { + const driver::Command &Cmd = cast(Job); // Collect only for Assemble jobs. If we do all jobs we get duplicates // since Link jobs point to Assemble jobs as inputs. if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass) diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index aa72f630ff..7109584f53 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -69,7 +69,7 @@ static const llvm::opt::ArgStringList *getCC1Arguments( // We expect to get back exactly one Command job, if we didn't something // failed. Extract that job from the Compilation. const clang::driver::JobList &Jobs = Compilation->getJobs(); - if (Jobs.size() != 1 || !isa(**Jobs.begin())) { + if (Jobs.size() != 1 || !isa(*Jobs.begin())) { SmallString<256> error_msg; llvm::raw_svector_ostream error_stream(error_msg); Jobs.Print(error_stream, "; ", true); @@ -80,7 +80,7 @@ static const llvm::opt::ArgStringList *getCC1Arguments( // The one job we find should be to invoke clang again. const clang::driver::Command &Cmd = - cast(**Jobs.begin()); + cast(*Jobs.begin()); if (StringRef(Cmd.getCreator().getName()) != "clang") { Diagnostics->Report(clang::diag::err_fe_expected_clang_command); return nullptr; -- 2.40.0