Skip to content

Commit c11bf80

Browse files
committed
unique_ptrify JobList::Jobs
llvm-svn: 217168
1 parent ba97c37 commit c11bf80

File tree

9 files changed

+74
-78
lines changed

9 files changed

+74
-78
lines changed

clang/examples/clang-interpreter/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,22 @@ int main(int argc, const char **argv, char * const *envp) {
111111
// We expect to get back exactly one command job, if we didn't something
112112
// failed. Extract that job from the compilation.
113113
const driver::JobList &Jobs = C->getJobs();
114-
if (Jobs.size() != 1 || !isa<driver::Command>(*Jobs.begin())) {
114+
if (Jobs.size() != 1 || !isa<driver::Command>(**Jobs.begin())) {
115115
SmallString<256> Msg;
116116
llvm::raw_svector_ostream OS(Msg);
117117
Jobs.Print(OS, "; ", true);
118118
Diags.Report(diag::err_fe_expected_compiler_job) << OS.str();
119119
return 1;
120120
}
121121

122-
const driver::Command *Cmd = cast<driver::Command>(*Jobs.begin());
123-
if (llvm::StringRef(Cmd->getCreator().getName()) != "clang") {
122+
const driver::Command &Cmd = cast<driver::Command>(**Jobs.begin());
123+
if (llvm::StringRef(Cmd.getCreator().getName()) != "clang") {
124124
Diags.Report(diag::err_fe_expected_clang_command);
125125
return 1;
126126
}
127127

128128
// Initialize a compiler invocation object from the clang (-cc1) arguments.
129-
const driver::ArgStringList &CCArgs = Cmd->getArguments();
129+
const driver::ArgStringList &CCArgs = Cmd.getArguments();
130130
std::unique_ptr<CompilerInvocation> CI(new CompilerInvocation);
131131
CompilerInvocation::CreateFromArgs(*CI,
132132
const_cast<const char **>(CCArgs.data()),

clang/include/clang/Driver/Compilation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Compilation {
9494
JobList &getJobs() { return Jobs; }
9595
const JobList &getJobs() const { return Jobs; }
9696

97-
void addCommand(Command *C) { Jobs.addJob(C); }
97+
void addCommand(std::unique_ptr<Command> C) { Jobs.addJob(std::move(C)); }
9898

9999
const llvm::opt::ArgStringList &getTempFiles() const { return TempFiles; }
100100

clang/include/clang/Driver/Job.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class FallbackCommand : public Command {
104104
public:
105105
FallbackCommand(const Action &Source_, const Tool &Creator_,
106106
const char *Executable_, const ArgStringList &Arguments_,
107-
Command *Fallback_);
107+
std::unique_ptr<Command> Fallback_);
108108

109109
void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
110110
bool CrashReport = false) const override;
@@ -123,7 +123,7 @@ class FallbackCommand : public Command {
123123
/// JobList - A sequence of jobs to perform.
124124
class JobList : public Job {
125125
public:
126-
typedef SmallVector<Job*, 4> list_type;
126+
typedef SmallVector<std::unique_ptr<Job>, 4> list_type;
127127
typedef list_type::size_type size_type;
128128
typedef list_type::iterator iterator;
129129
typedef list_type::const_iterator const_iterator;
@@ -133,13 +133,13 @@ class JobList : public Job {
133133

134134
public:
135135
JobList();
136-
virtual ~JobList();
136+
virtual ~JobList() {}
137137

138138
void Print(llvm::raw_ostream &OS, const char *Terminator,
139139
bool Quote, bool CrashReport = false) const override;
140140

141141
/// Add a job to the list (taking ownership).
142-
void addJob(Job *J) { Jobs.push_back(J); }
142+
void addJob(std::unique_ptr<Job> J) { Jobs.push_back(std::move(J)); }
143143

144144
/// Clear the job list.
145145
void clear();

clang/lib/Driver/Job.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ int Command::Execute(const StringRef **Redirects, std::string *ErrMsg,
136136
FallbackCommand::FallbackCommand(const Action &Source_, const Tool &Creator_,
137137
const char *Executable_,
138138
const ArgStringList &Arguments_,
139-
Command *Fallback_)
140-
: Command(Source_, Creator_, Executable_, Arguments_), Fallback(Fallback_) {
141-
}
139+
std::unique_ptr<Command> Fallback_)
140+
: Command(Source_, Creator_, Executable_, Arguments_),
141+
Fallback(std::move(Fallback_)) {}
142142

143143
void FallbackCommand::Print(raw_ostream &OS, const char *Terminator,
144144
bool Quote, bool CrashReport) const {
@@ -175,17 +175,10 @@ int FallbackCommand::Execute(const StringRef **Redirects, std::string *ErrMsg,
175175

176176
JobList::JobList() : Job(JobListClass) {}
177177

178-
JobList::~JobList() {
179-
for (iterator it = begin(), ie = end(); it != ie; ++it)
180-
delete *it;
181-
}
182-
183178
void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote,
184179
bool CrashReport) const {
185180
for (const_iterator it = begin(), ie = end(); it != ie; ++it)
186181
(*it)->Print(OS, Terminator, Quote, CrashReport);
187182
}
188183

189-
void JobList::clear() {
190-
DeleteContainerPointers(Jobs);
191-
}
184+
void JobList::clear() { Jobs.clear(); }

0 commit comments

Comments
 (0)