llvm.org GIT mirror llvm / 7117d73
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206724 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 6 years ago
2 changed file(s) with 30 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
1414 #include "llvm/Option/OptSpecifier.h"
1515 #include "llvm/Option/Option.h"
1616 #include
17 #include
1718 #include
1819 #include
1920
333334 const InputArgList &BaseArgs;
334335
335336 /// The list of arguments we synthesized.
336 mutable arglist_type SynthesizedArgs;
337 mutable SmallVector, 16> SynthesizedArgs;
337338
338339 public:
339340 /// Construct a new derived arg list from \p BaseArgs.
357358
358359 /// AddSynthesizedArg - Add a argument to the list of synthesized arguments
359360 /// (to be freed).
360 void AddSynthesizedArg(Arg *A) {
361 SynthesizedArgs.push_back(A);
362 }
361 void AddSynthesizedArg(Arg *A);
363362
364363 const char *MakeArgString(StringRef Str) const override;
365364
88
99 #include "llvm/Option/ArgList.h"
1010 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/STLExtras.h"
1112 #include "llvm/ADT/Twine.h"
1213 #include "llvm/Option/Arg.h"
1314 #include "llvm/Option/Option.h"
347348 : BaseArgs(_BaseArgs) {
348349 }
349350
350 DerivedArgList::~DerivedArgList() {
351 // We only own the arguments we explicitly synthesized.
352 for (iterator it = SynthesizedArgs.begin(), ie = SynthesizedArgs.end();
353 it != ie; ++it)
354 delete *it;
355 }
351 DerivedArgList::~DerivedArgList() {}
356352
357353 const char *DerivedArgList::MakeArgString(StringRef Str) const {
358354 return BaseArgs.MakeArgString(Str);
359355 }
360356
357 void DerivedArgList::AddSynthesizedArg(Arg *A) {
358 SynthesizedArgs.push_back(std::unique_ptr(A));
359 }
360
361361 Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option Opt) const {
362 Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
363 Twine(Opt.getName())),
364 BaseArgs.MakeIndex(Opt.getName()), BaseArg);
365 SynthesizedArgs.push_back(A);
366 return A;
362 SynthesizedArgs.push_back(make_unique(
363 Opt,
364 ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
365 BaseArgs.MakeIndex(Opt.getName()), BaseArg));
366 return SynthesizedArgs.back().get();
367367 }
368368
369369 Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option Opt,
370370 StringRef Value) const {
371371 unsigned Index = BaseArgs.MakeIndex(Value);
372 Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
373 Twine(Opt.getName())),
374 Index, BaseArgs.getArgString(Index), BaseArg);
375 SynthesizedArgs.push_back(A);
376 return A;
372 SynthesizedArgs.push_back(make_unique(
373 Opt,
374 ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
375 Index, BaseArgs.getArgString(Index), BaseArg));
376 return SynthesizedArgs.back().get();
377377 }
378378
379379 Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option Opt,
380380 StringRef Value) const {
381381 unsigned Index = BaseArgs.MakeIndex(Opt.getName(), Value);
382 Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
383 Twine(Opt.getName())),
384 Index, BaseArgs.getArgString(Index + 1), BaseArg);
385 SynthesizedArgs.push_back(A);
386 return A;
382 SynthesizedArgs.push_back(make_unique(
383 Opt,
384 ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
385 Index, BaseArgs.getArgString(Index + 1), BaseArg));
386 return SynthesizedArgs.back().get();
387387 }
388388
389389 Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option Opt,
390390 StringRef Value) const {
391391 unsigned Index = BaseArgs.MakeIndex(Opt.getName().str() + Value.str());
392 Arg *A = new Arg(Opt, ArgList::MakeArgString(Twine(Opt.getPrefix()) +
393 Twine(Opt.getName())), Index,
394 BaseArgs.getArgString(Index) + Opt.getName().size(),
395 BaseArg);
396 SynthesizedArgs.push_back(A);
397 return A;
398 }
392 SynthesizedArgs.push_back(make_unique(
393 Opt,
394 ArgList::MakeArgString(Twine(Opt.getPrefix()) + Twine(Opt.getName())),
395 Index, BaseArgs.getArgString(Index) + Opt.getName().size(), BaseArg));
396 return SynthesizedArgs.back().get();
397 }