summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Option/ArgList.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-20 22:37:46 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-20 22:37:46 +0000
commitf70b21a4b810972b2f8cceb4e3a1638381ec5e91 (patch)
tree7f7d842e8086cfa3a79a2752ae2000af1b2d068d /llvm/lib/Option/ArgList.cpp
parent5d506103063fc8afabacd87a5c505b0e07ad5eac (diff)
downloadbcm5719-llvm-f70b21a4b810972b2f8cceb4e3a1638381ec5e91.tar.gz
bcm5719-llvm-f70b21a4b810972b2f8cceb4e3a1638381ec5e91.zip
Use unique_ptr to handle ownership of synthesized args in DerivedArgList
This might be able to be simplified further by using Arg as a value type in a linked list (to maintain pointer validity), but here's something simple to start with. llvm-svn: 206724
Diffstat (limited to 'llvm/lib/Option/ArgList.cpp')
-rw-r--r--llvm/lib/Option/ArgList.cpp53
1 files changed, 26 insertions, 27 deletions
diff --git a/llvm/lib/Option/ArgList.cpp b/llvm/lib/Option/ArgList.cpp
index 1b013f2c02a..2d65c5ac870 100644
--- a/llvm/lib/Option/ArgList.cpp
+++ b/llvm/lib/Option/ArgList.cpp
@@ -9,6 +9,7 @@
#include "llvm/Option/ArgList.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/Option.h"
@@ -348,52 +349,50 @@ DerivedArgList::DerivedArgList(const InputArgList &_BaseArgs)
: BaseArgs(_BaseArgs) {
}
-DerivedArgList::~DerivedArgList() {
- // We only own the arguments we explicitly synthesized.
- for (iterator it = SynthesizedArgs.begin(), ie = SynthesizedArgs.end();
- it != ie; ++it)
- delete *it;
-}
+DerivedArgList::~DerivedArgList() {}
const char *DerivedArgList::MakeArgString(StringRef Str) const {
return BaseArgs.MakeArgString(Str);
}
+void DerivedArgList::AddSynthesizedArg(Arg *A) {
+ SynthesizedArgs.push_back(std::unique_ptr<Arg>(A));
+}
+
Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option Opt) const {
- Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
- Twine(Opt.getName())),
- BaseArgs.MakeIndex(Opt.getName()), BaseArg);
- SynthesizedArgs.push_back(A);
- return A;
+ SynthesizedArgs.push_back(make_unique<Arg>(
+ Opt,
+ ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
+ BaseArgs.MakeIndex(Opt.getName()), BaseArg));
+ return SynthesizedArgs.back().get();
}
Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Value);
- Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
- Twine(Opt.getName())),
- Index, BaseArgs.getArgString(Index), BaseArg);
- SynthesizedArgs.push_back(A);
- return A;
+ SynthesizedArgs.push_back(make_unique<Arg>(
+ Opt,
+ ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
+ Index, BaseArgs.getArgString(Index), BaseArg));
+ return SynthesizedArgs.back().get();
}
Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Opt.getName(), Value);
- Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
- Twine(Opt.getName())),
- Index, BaseArgs.getArgString(Index + 1), BaseArg);
- SynthesizedArgs.push_back(A);
- return A;
+ SynthesizedArgs.push_back(make_unique<Arg>(
+ Opt,
+ ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
+ Index, BaseArgs.getArgString(Index + 1), BaseArg));
+ return SynthesizedArgs.back().get();
}
Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option Opt,
StringRef Value) const {
unsigned Index = BaseArgs.MakeIndex(Opt.getName().str() + Value.str());
- Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
- Twine(Opt.getName())), Index,
- BaseArgs.getArgString(Index) + Opt.getName().size(),
- BaseArg);
- SynthesizedArgs.push_back(A);
- return A;
+ SynthesizedArgs.push_back(make_unique<Arg>(
+ Opt,
+ ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
+ Index, BaseArgs.getArgString(Index) + Opt.getName().size(), BaseArg));
+ return SynthesizedArgs.back().get();
}
OpenPOWER on IntegriCloud