[llvm] 7789a68 - [llvm] Convert OptTable::parseOneArgGrouped() to std::unique_ptr<>
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 27 08:19:43 PDT 2021
Author: Nico Weber
Date: 2021-09-27T11:19:15-04:00
New Revision: 7789a68e5ab999e39248469482c3c40d440131c1
URL: https://github.com/llvm/llvm-project/commit/7789a68e5ab999e39248469482c3c40d440131c1
DIFF: https://github.com/llvm/llvm-project/commit/7789a68e5ab999e39248469482c3c40d440131c1.diff
LOG: [llvm] Convert OptTable::parseOneArgGrouped() to std::unique_ptr<>
Added:
Modified:
llvm/include/llvm/Option/OptTable.h
llvm/lib/Option/OptTable.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Option/OptTable.h b/llvm/include/llvm/Option/OptTable.h
index ca2013ee6f04..30c39471e2aa 100644
--- a/llvm/include/llvm/Option/OptTable.h
+++ b/llvm/include/llvm/Option/OptTable.h
@@ -83,7 +83,8 @@ class OptTable {
return OptionInfos[id - 1];
}
- Arg *parseOneArgGrouped(InputArgList &Args, unsigned &Index) const;
+ std::unique_ptr<Arg> parseOneArgGrouped(InputArgList &Args,
+ unsigned &Index) const;
protected:
OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase = false);
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index b3198004f3bf..fb83a2b73e78 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -337,13 +337,15 @@ bool OptTable::addValues(const char *Option, const char *Values) {
// GroupedShortOptions is true, -a matches "-abc" and the argument in Args will
// be updated to "-bc". This overload does not support
// FlagsToInclude/FlagsToExclude or case insensitive options.
-Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
+std::unique_ptr<Arg> OptTable::parseOneArgGrouped(InputArgList &Args,
+ unsigned &Index) const {
// Anything that doesn't start with PrefixesUnion is an input, as is '-'
// itself.
const char *CStr = Args.getArgString(Index);
StringRef Str(CStr);
if (isInput(PrefixesUnion, Str))
- return new Arg(getOption(TheInputOptionID), Str, Index++, CStr);
+ return std::make_unique<Arg>(getOption(TheInputOptionID), Str, Index++,
+ CStr);
const Info *End = OptionInfos.data() + OptionInfos.size();
StringRef Name = Str.ltrim(PrefixChars);
@@ -361,7 +363,7 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
Option Opt(Start, this);
if (std::unique_ptr<Arg> A = Opt.accept(
Args, StringRef(Args.getArgString(Index), ArgSize), false, Index))
- return A.release();
+ return A;
// If Opt is a Flag of length 2 (e.g. "-a"), we know it is a prefix of
// 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 {
Option Opt(Fallback, this);
// Check that the last option isn't a flag wrongly given an argument.
if (Str[2] == '=')
- return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
+ return std::make_unique<Arg>(getOption(TheUnknownOptionID), Str, Index++,
+ CStr);
if (std::unique_ptr<Arg> A =
Opt.accept(Args, Str.substr(0, 2), true, Index)) {
Args.replaceArgString(Index, Twine('-') + Str.substr(2));
- return A.release();
+ return A;
}
}
@@ -391,10 +394,12 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
if (Str[1] != '-') {
CStr = Args.MakeArgString(Str.substr(0, 2));
Args.replaceArgString(Index, Twine('-') + Str.substr(2));
- return new Arg(getOption(TheUnknownOptionID), CStr, Index, CStr);
+ return std::make_unique<Arg>(getOption(TheUnknownOptionID), CStr, Index,
+ CStr);
}
- return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
+ return std::make_unique<Arg>(getOption(TheUnknownOptionID), Str, Index++,
+ CStr);
}
Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
@@ -483,7 +488,7 @@ InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr,
unsigned Prev = Index;
Arg *A = GroupedShortOptions
- ? parseOneArgGrouped(Args, Index)
+ ? parseOneArgGrouped(Args, Index).release()
: ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude);
assert((Index > Prev || GroupedShortOptions) &&
"Parser failed to consume argument.");
More information about the llvm-commits
mailing list