Skip to content

Commit 7789a68

Browse files
committed
[llvm] Convert OptTable::parseOneArgGrouped() to std::unique_ptr<>
1 parent 2f95542 commit 7789a68

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎llvm/include/llvm/Option/OptTable.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class OptTable {
8383
return OptionInfos[id - 1];
8484
}
8585

86-
Arg *parseOneArgGrouped(InputArgList &Args, unsigned &Index) const;
86+
std::unique_ptr<Arg> parseOneArgGrouped(InputArgList &Args,
87+
unsigned &Index) const;
8788

8889
protected:
8990
OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase = false);

‎llvm/lib/Option/OptTable.cpp‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,15 @@ bool OptTable::addValues(const char *Option, const char *Values) {
337337
// GroupedShortOptions is true, -a matches "-abc" and the argument in Args will
338338
// be updated to "-bc". This overload does not support
339339
// FlagsToInclude/FlagsToExclude or case insensitive options.
340-
Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
340+
std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args,
341+
unsigned &Index) const {
341342
// Anything that doesn't start with PrefixesUnion is an input, as is '-'
342343
// itself.
343344
const char *CStr = Args.getArgString(Index);
344345
StringRef Str(CStr);
345346
if (isInput(PrefixesUnion, Str))
346-
return new Arg(getOption(TheInputOptionID), Str, Index++, CStr);
347+
return std::make_unique<Arg>(getOption(TheInputOptionID), Str, Index++,
348+
CStr);
347349

348350
const Info *End = OptionInfos.data() + OptionInfos.size();
349351
StringRef Name = Str.ltrim(PrefixChars);
@@ -361,7 +363,7 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
361363
Option Opt(Start, this);
362364
if (std::unique_ptr<Arg> A = Opt.accept(
363365
Args, StringRef(Args.getArgString(Index), ArgSize), false, Index))
364-
return A.release();
366+
return A;
365367

366368
// If Opt is a Flag of length 2 (e.g. "-a"), we know it is a prefix of
367369
// the current argument (e.g. "-abc"). Match it as a fallback if no longer
@@ -377,12 +379,13 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
377379
Option Opt(Fallback, this);
378380
// Check that the last option isn't a flag wrongly given an argument.
379381
if (Str[2] == '=')
380-
return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
382+
return std::make_unique<Arg>(getOption(TheUnknownOptionID), Str, Index++,
383+
CStr);
381384

382385
if (std::unique_ptr<Arg> A =
383386
Opt.accept(Args, Str.substr(0, 2), true, Index)) {
384387
Args.replaceArgString(Index, Twine('-') + Str.substr(2));
385-
return A.release();
388+
return A;
386389
}
387390
}
388391

@@ -391,10 +394,12 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
391394
if (Str[1] != '-') {
392395
CStr = Args.MakeArgString(Str.substr(0, 2));
393396
Args.replaceArgString(Index, Twine('-') + Str.substr(2));
394-
return new Arg(getOption(TheUnknownOptionID), CStr, Index, CStr);
397+
return std::make_unique<Arg>(getOption(TheUnknownOptionID), CStr, Index,
398+
CStr);
395399
}
396400

397-
return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
401+
return std::make_unique<Arg>(getOption(TheUnknownOptionID), Str, Index++,
402+
CStr);
398403
}
399404

400405
Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
@@ -483,7 +488,7 @@ InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr,
483488

484489
unsigned Prev = Index;
485490
Arg *A = GroupedShortOptions
486-
? parseOneArgGrouped(Args, Index)
491+
? parseOneArgGrouped(Args, Index).release()
487492
: ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude);
488493
assert((Index > Prev || GroupedShortOptions) &&
489494
"Parser failed to consume argument.");

0 commit comments

Comments
 (0)