@@ -106,23 +106,24 @@ bool Option::matches(OptSpecifier Opt) const {
106
106
return false ;
107
107
}
108
108
109
- Arg *Option::acceptInternal (const ArgList &Args, StringRef Spelling,
110
- unsigned &Index) const {
109
+ std::unique_ptr<Arg> Option::acceptInternal (const ArgList &Args,
110
+ StringRef Spelling,
111
+ unsigned &Index) const {
111
112
size_t ArgSize = Spelling.size ();
112
113
switch (getKind ()) {
113
114
case FlagClass: {
114
115
if (ArgSize != strlen (Args.getArgString (Index)))
115
116
return nullptr ;
116
- return new Arg (*this , Spelling, Index++);
117
+ return std::make_unique< Arg> (*this , Spelling, Index++);
117
118
}
118
119
case JoinedClass: {
119
120
const char *Value = Args.getArgString (Index) + ArgSize;
120
- return new Arg (*this , Spelling, Index++, Value);
121
+ return std::make_unique< Arg> (*this , Spelling, Index++, Value);
121
122
}
122
123
case CommaJoinedClass: {
123
124
// Always matches.
124
125
const char *Str = Args.getArgString (Index) + ArgSize;
125
- Arg * A = new Arg (*this , Spelling, Index++);
126
+ auto A = std::make_unique< Arg> (*this , Spelling, Index++);
126
127
127
128
// Parse out the comma separated values.
128
129
const char *Prev = Str;
@@ -158,7 +159,8 @@ Arg *Option::acceptInternal(const ArgList &Args, StringRef Spelling,
158
159
Args.getArgString (Index - 1 ) == nullptr )
159
160
return nullptr ;
160
161
161
- return new Arg (*this , Spelling, Index - 2 , Args.getArgString (Index - 1 ));
162
+ return std::make_unique<Arg>(*this , Spelling, Index - 2 ,
163
+ Args.getArgString (Index - 1 ));
162
164
case MultiArgClass: {
163
165
// Matches iff this is an exact match.
164
166
// FIXME: Avoid strlen.
@@ -169,8 +171,8 @@ Arg *Option::acceptInternal(const ArgList &Args, StringRef Spelling,
169
171
if (Index > Args.getNumInputArgStrings ())
170
172
return nullptr ;
171
173
172
- Arg * A = new Arg (*this , Spelling, Index - 1 - getNumArgs (),
173
- Args.getArgString (Index - getNumArgs ()));
174
+ auto A = std::make_unique< Arg> (*this , Spelling, Index - 1 - getNumArgs (),
175
+ Args.getArgString (Index - getNumArgs ()));
174
176
for (unsigned i = 1 ; i != getNumArgs (); ++i)
175
177
A->getValues ().push_back (Args.getArgString (Index - getNumArgs () + i));
176
178
return A;
@@ -180,7 +182,7 @@ Arg *Option::acceptInternal(const ArgList &Args, StringRef Spelling,
180
182
// FIXME: Avoid strlen.
181
183
if (ArgSize != strlen (Args.getArgString (Index))) {
182
184
const char *Value = Args.getArgString (Index) + ArgSize;
183
- return new Arg (*this , Spelling, Index++, Value);
185
+ return std::make_unique< Arg> (*this , Spelling, Index++, Value);
184
186
}
185
187
186
188
// Otherwise it must be separate.
@@ -189,7 +191,8 @@ Arg *Option::acceptInternal(const ArgList &Args, StringRef Spelling,
189
191
Args.getArgString (Index - 1 ) == nullptr )
190
192
return nullptr ;
191
193
192
- return new Arg (*this , Spelling, Index - 2 , Args.getArgString (Index - 1 ));
194
+ return std::make_unique<Arg>(*this , Spelling, Index - 2 ,
195
+ Args.getArgString (Index - 1 ));
193
196
}
194
197
case JoinedAndSeparateClass:
195
198
// Always matches.
@@ -198,22 +201,22 @@ Arg *Option::acceptInternal(const ArgList &Args, StringRef Spelling,
198
201
Args.getArgString (Index - 1 ) == nullptr )
199
202
return nullptr ;
200
203
201
- return new Arg (*this , Spelling, Index - 2 ,
202
- Args.getArgString (Index - 2 ) + ArgSize,
203
- Args.getArgString (Index - 1 ));
204
+ return std::make_unique< Arg> (*this , Spelling, Index - 2 ,
205
+ Args.getArgString (Index - 2 ) + ArgSize,
206
+ Args.getArgString (Index - 1 ));
204
207
case RemainingArgsClass: {
205
208
// Matches iff this is an exact match.
206
209
// FIXME: Avoid strlen.
207
210
if (ArgSize != strlen (Args.getArgString (Index)))
208
211
return nullptr ;
209
- Arg * A = new Arg (*this , Spelling, Index++);
212
+ auto A = std::make_unique< Arg> (*this , Spelling, Index++);
210
213
while (Index < Args.getNumInputArgStrings () &&
211
214
Args.getArgString (Index) != nullptr )
212
215
A->getValues ().push_back (Args.getArgString (Index++));
213
216
return A;
214
217
}
215
218
case RemainingArgsJoinedClass: {
216
- Arg * A = new Arg (*this , Spelling, Index);
219
+ auto A = std::make_unique< Arg> (*this , Spelling, Index);
217
220
if (ArgSize != strlen (Args.getArgString (Index))) {
218
221
// An inexact match means there is a joined arg.
219
222
A->getValues ().push_back (Args.getArgString (Index) + ArgSize);
@@ -230,17 +233,18 @@ Arg *Option::acceptInternal(const ArgList &Args, StringRef Spelling,
230
233
}
231
234
}
232
235
233
- Arg *Option::accept (const ArgList &Args, StringRef CurArg,
234
- bool GroupedShortOption, unsigned &Index) const {
235
- std::unique_ptr<Arg> A (GroupedShortOption && getKind () == FlagClass
236
- ? new Arg (*this , CurArg, Index)
236
+ std::unique_ptr<Arg> Option::accept (const ArgList &Args, StringRef CurArg,
237
+ bool GroupedShortOption,
238
+ unsigned &Index) const {
239
+ auto A (GroupedShortOption && getKind () == FlagClass
240
+ ? std::make_unique<Arg>(*this , CurArg, Index)
237
241
: acceptInternal (Args, CurArg, Index));
238
242
if (!A)
239
243
return nullptr ;
240
244
241
245
const Option &UnaliasedOption = getUnaliasedOption ();
242
246
if (getID () == UnaliasedOption.getID ())
243
- return A. release () ;
247
+ return A;
244
248
245
249
// "A" is an alias for a different flag. For most clients it's more convenient
246
250
// if this function returns unaliased Args, so create an unaliased arg for
@@ -259,7 +263,8 @@ Arg *Option::accept(const ArgList &Args, StringRef CurArg,
259
263
// Due to this, ArgList::getArgString(A->getIndex()) will return the spelling
260
264
// of the aliased arg always, while A->getSpelling() returns either the
261
265
// unaliased or the aliased arg, depending on which Arg object it's called on.
262
- Arg *UnaliasedA = new Arg (UnaliasedOption, UnaliasedSpelling, A->getIndex ());
266
+ auto UnaliasedA =
267
+ std::make_unique<Arg>(UnaliasedOption, UnaliasedSpelling, A->getIndex ());
263
268
Arg *RawA = A.get ();
264
269
UnaliasedA->setAlias (std::move (A));
265
270
0 commit comments