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. llvm-svn: 218938
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include "clang/Basic/LLVM.h"
|
#include "clang/Basic/LLVM.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Option/Option.h"
|
#include "llvm/Option/Option.h"
|
||||||
|
#include "llvm/ADT/iterator.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@@ -158,8 +159,8 @@ class JobList : public Job {
|
|||||||
public:
|
public:
|
||||||
typedef SmallVector<std::unique_ptr<Job>, 4> list_type;
|
typedef SmallVector<std::unique_ptr<Job>, 4> list_type;
|
||||||
typedef list_type::size_type size_type;
|
typedef list_type::size_type size_type;
|
||||||
typedef list_type::iterator iterator;
|
typedef llvm::pointee_iterator<list_type::iterator> iterator;
|
||||||
typedef list_type::const_iterator const_iterator;
|
typedef llvm::pointee_iterator<list_type::const_iterator> const_iterator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
list_type Jobs;
|
list_type Jobs;
|
||||||
|
|||||||
@@ -202,9 +202,8 @@ void Compilation::ExecuteJob(const Job &J,
|
|||||||
FailingCommands.push_back(std::make_pair(Res, FailingCommand));
|
FailingCommands.push_back(std::make_pair(Res, FailingCommand));
|
||||||
} else {
|
} else {
|
||||||
const JobList *Jobs = cast<JobList>(&J);
|
const JobList *Jobs = cast<JobList>(&J);
|
||||||
for (JobList::const_iterator it = Jobs->begin(), ie = Jobs->end();
|
for (const auto &Job : *Jobs)
|
||||||
it != ie; ++it)
|
ExecuteJob(Job, FailingCommands);
|
||||||
ExecuteJob(**it, FailingCommands);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -578,8 +578,8 @@ void Driver::generateCompilationDiagnostics(Compilation &C,
|
|||||||
|
|
||||||
void Driver::setUpResponseFiles(Compilation &C, Job &J) {
|
void Driver::setUpResponseFiles(Compilation &C, Job &J) {
|
||||||
if (JobList *Jobs = dyn_cast<JobList>(&J)) {
|
if (JobList *Jobs = dyn_cast<JobList>(&J)) {
|
||||||
for (JobList::iterator I = Jobs->begin(), E = Jobs->end(); I != E; ++I)
|
for (auto &Job : *Jobs)
|
||||||
setUpResponseFiles(C, **I);
|
setUpResponseFiles(C, Job);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -287,8 +287,8 @@ JobList::JobList() : Job(JobListClass) {}
|
|||||||
|
|
||||||
void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
|
void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
|
||||||
bool CrashReport) const {
|
bool CrashReport) const {
|
||||||
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
|
for (const auto &Job : *this)
|
||||||
(*it)->Print(OS, Terminator, Quote, CrashReport);
|
Job.Print(OS, Terminator, Quote, CrashReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JobList::clear() { Jobs.clear(); }
|
void JobList::clear() { Jobs.clear(); }
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList,
|
|||||||
// We expect to get back exactly one command job, if we didn't something
|
// We expect to get back exactly one command job, if we didn't something
|
||||||
// failed.
|
// failed.
|
||||||
const driver::JobList &Jobs = C->getJobs();
|
const driver::JobList &Jobs = C->getJobs();
|
||||||
if (Jobs.size() != 1 || !isa<driver::Command>(**Jobs.begin())) {
|
if (Jobs.size() != 1 || !isa<driver::Command>(*Jobs.begin())) {
|
||||||
SmallString<256> Msg;
|
SmallString<256> Msg;
|
||||||
llvm::raw_svector_ostream OS(Msg);
|
llvm::raw_svector_ostream OS(Msg);
|
||||||
Jobs.Print(OS, "; ", true);
|
Jobs.Print(OS, "; ", true);
|
||||||
@@ -71,7 +71,7 @@ clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const driver::Command &Cmd = cast<driver::Command>(**Jobs.begin());
|
const driver::Command &Cmd = cast<driver::Command>(*Jobs.begin());
|
||||||
if (StringRef(Cmd.getCreator().getName()) != "clang") {
|
if (StringRef(Cmd.getCreator().getName()) != "clang") {
|
||||||
Diags->Report(diag::err_fe_expected_clang_command);
|
Diags->Report(diag::err_fe_expected_clang_command);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -249,10 +249,9 @@ static bool stripPositionalArgs(std::vector<const char *> Args,
|
|||||||
|
|
||||||
CompileJobAnalyzer CompileAnalyzer;
|
CompileJobAnalyzer CompileAnalyzer;
|
||||||
|
|
||||||
for (driver::JobList::const_iterator I = Jobs.begin(), E = Jobs.end(); I != E;
|
for (const auto &Job : Jobs) {
|
||||||
++I) {
|
if (Job.getKind() == driver::Job::CommandClass) {
|
||||||
if ((*I)->getKind() == driver::Job::CommandClass) {
|
const driver::Command &Cmd = cast<driver::Command>(Job);
|
||||||
const driver::Command &Cmd = cast<driver::Command>(**I);
|
|
||||||
// Collect only for Assemble jobs. If we do all jobs we get duplicates
|
// Collect only for Assemble jobs. If we do all jobs we get duplicates
|
||||||
// since Link jobs point to Assemble jobs as inputs.
|
// since Link jobs point to Assemble jobs as inputs.
|
||||||
if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
|
if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ static const llvm::opt::ArgStringList *getCC1Arguments(
|
|||||||
// We expect to get back exactly one Command job, if we didn't something
|
// We expect to get back exactly one Command job, if we didn't something
|
||||||
// failed. Extract that job from the Compilation.
|
// failed. Extract that job from the Compilation.
|
||||||
const clang::driver::JobList &Jobs = Compilation->getJobs();
|
const clang::driver::JobList &Jobs = Compilation->getJobs();
|
||||||
if (Jobs.size() != 1 || !isa<clang::driver::Command>(**Jobs.begin())) {
|
if (Jobs.size() != 1 || !isa<clang::driver::Command>(*Jobs.begin())) {
|
||||||
SmallString<256> error_msg;
|
SmallString<256> error_msg;
|
||||||
llvm::raw_svector_ostream error_stream(error_msg);
|
llvm::raw_svector_ostream error_stream(error_msg);
|
||||||
Jobs.Print(error_stream, "; ", true);
|
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.
|
// The one job we find should be to invoke clang again.
|
||||||
const clang::driver::Command &Cmd =
|
const clang::driver::Command &Cmd =
|
||||||
cast<clang::driver::Command>(**Jobs.begin());
|
cast<clang::driver::Command>(*Jobs.begin());
|
||||||
if (StringRef(Cmd.getCreator().getName()) != "clang") {
|
if (StringRef(Cmd.getCreator().getName()) != "clang") {
|
||||||
Diagnostics->Report(clang::diag::err_fe_expected_clang_command);
|
Diagnostics->Report(clang::diag::err_fe_expected_clang_command);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user