LLVM 22.0.0git
ArgList.h
Go to the documentation of this file.
1//===- ArgList.h - Argument List Management ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_OPTION_ARGLIST_H
10#define LLVM_OPTION_ARGLIST_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/Twine.h"
19#include "llvm/Option/Arg.h"
21#include "llvm/Option/Option.h"
23#include "llvm/Support/Error.h"
24#include <algorithm>
25#include <cstddef>
26#include <initializer_list>
27#include <iterator>
28#include <list>
29#include <memory>
30#include <string>
31#include <utility>
32#include <vector>
33
34namespace llvm {
35
36class raw_ostream;
37
38namespace opt {
39
40/// arg_iterator - Iterates through arguments stored inside an ArgList.
41template<typename BaseIter, unsigned NumOptSpecifiers = 0>
43 /// The current argument and the end of the sequence we're iterating.
44 BaseIter Current, End;
45
46 /// Optional filters on the arguments which will be match. To avoid a
47 /// zero-sized array, we store one specifier even if we're asked for none.
48 OptSpecifier Ids[NumOptSpecifiers ? NumOptSpecifiers : 1];
49
50 void SkipToNextArg() {
51 for (; Current != End; ++Current) {
52 // Skip erased elements.
53 if (!*Current)
54 continue;
55
56 // Done if there are no filters.
57 if (!NumOptSpecifiers)
58 return;
59
60 // Otherwise require a match.
61 const Option &O = (*Current)->getOption();
62 for (auto Id : Ids) {
63 if (!Id.isValid())
64 break;
65 if (O.matches(Id))
66 return;
67 }
68 }
69 }
70
71 using Traits = std::iterator_traits<BaseIter>;
72
73public:
74 using value_type = typename Traits::value_type;
75 using reference = typename Traits::reference;
76 using pointer = typename Traits::pointer;
77 using iterator_category = std::forward_iterator_tag;
78 using difference_type = std::ptrdiff_t;
79
81 BaseIter Current, BaseIter End,
82 const OptSpecifier (&Ids)[NumOptSpecifiers ? NumOptSpecifiers : 1] = {})
83 : Current(Current), End(End) {
84 for (unsigned I = 0; I != NumOptSpecifiers; ++I)
85 this->Ids[I] = Ids[I];
86 SkipToNextArg();
87 }
88
89 reference operator*() const { return *Current; }
90 pointer operator->() const { return Current; }
91
93 ++Current;
94 SkipToNextArg();
95 return *this;
96 }
97
99 arg_iterator tmp(*this);
100 ++(*this);
101 return tmp;
102 }
103
105 return LHS.Current == RHS.Current;
106 }
108 return !(LHS == RHS);
109 }
110};
111
112/// ArgList - Ordered collection of driver arguments.
113///
114/// The ArgList class manages a list of Arg instances as well as
115/// auxiliary data and convenience methods to allow Tools to quickly
116/// check for the presence of Arg instances for a particular Option
117/// and to iterate over groups of arguments.
118class ArgList {
119public:
126
127 template<unsigned N> using filtered_iterator =
129 template<unsigned N> using filtered_reverse_iterator =
131
132private:
133 /// The internal list of arguments.
134 arglist_type Args;
135
136 using OptRange = std::pair<unsigned, unsigned>;
137 static OptRange emptyRange() { return {-1u, 0u}; }
138
139 /// The first and last index of each different OptSpecifier ID.
141
142 /// Get the range of indexes in which options with the specified IDs might
143 /// reside, or (0, 0) if there are no such options.
144 LLVM_ABI OptRange getRange(std::initializer_list<OptSpecifier> Ids) const;
145
146protected:
147 // Make the default special members protected so they won't be used to slice
148 // derived objects, but can still be used by derived objects to implement
149 // their own special members.
150 ArgList() = default;
151
152 // Explicit move operations to ensure the container is cleared post-move
153 // otherwise it could lead to a double-delete in the case of moving of an
154 // InputArgList which deletes the contents of the container. If we could fix
155 // up the ownership here (delegate storage/ownership to the derived class so
156 // it can be a container of unique_ptr) this would be simpler.
158 : Args(std::move(RHS.Args)), OptRanges(std::move(RHS.OptRanges)) {
159 RHS.Args.clear();
160 RHS.OptRanges.clear();
161 }
162
164 Args = std::move(RHS.Args);
165 RHS.Args.clear();
166 OptRanges = std::move(RHS.OptRanges);
167 RHS.OptRanges.clear();
168 return *this;
169 }
170
171 // Protect the dtor to ensure this type is never destroyed polymorphically.
172 ~ArgList() = default;
173
174 // Implicitly convert a value to an OptSpecifier. Used to work around a bug
175 // in MSVC's implementation of narrowing conversion checking.
177
178public:
179 /// @name Arg Access
180 /// @{
181
182 /// append - Append \p A to the arg list.
183 LLVM_ABI void append(Arg *A);
184
185 const arglist_type &getArgs() const { return Args; }
186
187 unsigned size() const { return Args.size(); }
188
189 /// @}
190 /// @name Arg Iteration
191 /// @{
192
193 iterator begin() { return {Args.begin(), Args.end()}; }
194 iterator end() { return {Args.end(), Args.end()}; }
195
196 reverse_iterator rbegin() { return {Args.rbegin(), Args.rend()}; }
197 reverse_iterator rend() { return {Args.rend(), Args.rend()}; }
198
199 const_iterator begin() const { return {Args.begin(), Args.end()}; }
200 const_iterator end() const { return {Args.end(), Args.end()}; }
201
202 const_reverse_iterator rbegin() const { return {Args.rbegin(), Args.rend()}; }
203 const_reverse_iterator rend() const { return {Args.rend(), Args.rend()}; }
204
205 template<typename ...OptSpecifiers>
206 iterator_range<filtered_iterator<sizeof...(OptSpecifiers)>>
207 filtered(OptSpecifiers ...Ids) const {
208 OptRange Range = getRange({toOptSpecifier(Ids)...});
209 auto B = Args.begin() + Range.first;
210 auto E = Args.begin() + Range.second;
211 using Iterator = filtered_iterator<sizeof...(OptSpecifiers)>;
212 return make_range(Iterator(B, E, {toOptSpecifier(Ids)...}),
213 Iterator(E, E, {toOptSpecifier(Ids)...}));
214 }
215
216 template<typename ...OptSpecifiers>
217 iterator_range<filtered_reverse_iterator<sizeof...(OptSpecifiers)>>
218 filtered_reverse(OptSpecifiers ...Ids) const {
219 OptRange Range = getRange({toOptSpecifier(Ids)...});
220 auto B = Args.rend() - Range.second;
221 auto E = Args.rend() - Range.first;
222 using Iterator = filtered_reverse_iterator<sizeof...(OptSpecifiers)>;
223 return make_range(Iterator(B, E, {toOptSpecifier(Ids)...}),
224 Iterator(E, E, {toOptSpecifier(Ids)...}));
225 }
226
227 /// @}
228 /// @name Arg Removal
229 /// @{
230
231 /// eraseArg - Remove any option matching \p Id.
233
234 /// @}
235 /// @name Arg Access
236 /// @{
237
238 /// hasArg - Does the arg list contain any option matching \p Id.
239 ///
240 /// \p Claim Whether the argument should be claimed, if it exists.
241 template<typename ...OptSpecifiers>
242 bool hasArgNoClaim(OptSpecifiers ...Ids) const {
243 return getLastArgNoClaim(Ids...) != nullptr;
244 }
245 template<typename ...OptSpecifiers>
246 bool hasArg(OptSpecifiers ...Ids) const {
247 return getLastArg(Ids...) != nullptr;
248 }
249
250 /// Return true if the arg list contains multiple arguments matching \p Id.
252 auto Args = filtered(Id);
253 return (Args.begin() != Args.end()) && (++Args.begin()) != Args.end();
254 }
255
256 /// Return the last argument matching \p Id, or null.
257 template <typename... OptSpecifiers>
258 LLVM_ATTRIBUTE_NOINLINE Arg *getLastArg(OptSpecifiers... Ids) const {
259 Arg *Res = nullptr;
260 for (Arg *A : filtered(Ids...)) {
261 Res = A;
262 Res->claim();
263 }
264 return Res;
265 }
266
267 /// Return the last argument matching \p Id, or null. Do not "claim" the
268 /// option (don't mark it as having been used).
269 template <typename... OptSpecifiers>
270 LLVM_ATTRIBUTE_NOINLINE Arg *getLastArgNoClaim(OptSpecifiers... Ids) const {
271 for (Arg *A : filtered_reverse(Ids...))
272 return A;
273 return nullptr;
274 }
275
276 /// getArgString - Return the input argument string at \p Index.
277 virtual const char *getArgString(unsigned Index) const = 0;
278
279 /// getNumInputArgStrings - Return the number of original argument strings,
280 /// which are guaranteed to be the first strings in the argument string
281 /// list.
282 virtual unsigned getNumInputArgStrings() const = 0;
283
284 /// getSubCommand - Find subcommand from the arguments if the usage is valid.
285 ///
286 /// \param AllSubCommands - A list of all valid subcommands.
287 /// \param HandleMultipleSubcommands - A callback for the case where multiple
288 /// subcommands are present in the arguments. It gets a list of all found
289 /// subcommands.
290 /// \param HandleOtherPositionals - A callback for the case where positional
291 /// arguments that are not subcommands are present.
292 /// \return The name of the subcommand found. If no subcommand is found,
293 /// this returns an empty StringRef. If multiple subcommands are found, the
294 /// first one is returned.
297 std::function<void(ArrayRef<StringRef>)> HandleMultipleSubcommands,
298 std::function<void(ArrayRef<StringRef>)> HandleOtherPositionals) const;
299
300 /// @}
301 /// @name Argument Lookup Utilities
302 /// @{
303
304 /// getLastArgValue - Return the value of the last argument, or a default.
306 StringRef Default = "") const;
307
308 /// getAllArgValues - Get the values of all instances of the given argument
309 /// as strings.
310 LLVM_ABI std::vector<std::string> getAllArgValues(OptSpecifier Id) const;
311
312 /// @}
313 /// @name Translation Utilities
314 /// @{
315
316 /// hasFlag - Given an option \p Pos and its negative form \p Neg, return
317 /// true if the option is present, false if the negation is present, and
318 /// \p Default if neither option is given. If both the option and its
319 /// negation are present, the last one wins.
320 LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
322 bool Default) const;
323
324 /// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
325 /// form \p Neg, return true if the option or its alias is present, false if
326 /// the negation is present, and \p Default if none of the options are
327 /// given. If multiple options are present, the last one wins.
328 LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias,
329 OptSpecifier Neg, bool Default) const;
330
331 /// Given an option Pos and its negative form Neg, render the option if Pos is
332 /// present.
334 OptSpecifier Neg) const;
335 /// Render the option if Neg is present.
337 OptSpecifier Neg) const {
338 addOptInFlag(Output, Neg, Pos);
339 }
340
341 /// Render only the last argument match \p Id0, if present.
342 template <typename... OptSpecifiers>
343 void addLastArg(ArgStringList &Output, OptSpecifiers... Ids) const {
344 if (Arg *A = getLastArg(Ids...)) // Calls claim() on all Ids's Args.
345 A->render(*this, Output);
346 }
347 template <typename... OptSpecifiers>
348 void AddLastArg(ArgStringList &Output, OptSpecifiers... Ids) const {
349 addLastArg(Output, Ids...);
350 }
351
352 /// AddAllArgsExcept - Render all arguments matching any of the given ids
353 /// and not matching any of the excluded ids.
356 ArrayRef<OptSpecifier> ExcludeIds) const;
357 /// Render all arguments matching any of the given ids.
358 LLVM_ABI void addAllArgs(ArgStringList &Output,
359 ArrayRef<OptSpecifier> Ids) const;
360
361 /// AddAllArgs - Render all arguments matching the given ids.
362 LLVM_ABI void AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const;
363
364 /// AddAllArgValues - Render the argument values of all arguments
365 /// matching the given ids.
367 OptSpecifier Id1 = 0U,
368 OptSpecifier Id2 = 0U) const;
369
370 /// AddAllArgsTranslated - Render all the arguments matching the
371 /// given ids, but forced to separate args and using the provided
372 /// name instead of the first option value.
373 ///
374 /// \param Joined - If true, render the argument as joined with
375 /// the option specifier.
377 const char *Translation,
378 bool Joined = false) const;
379
380 /// ClaimAllArgs - Claim all arguments which match the given
381 /// option id.
382 LLVM_ABI void ClaimAllArgs(OptSpecifier Id0) const;
383
384 template <typename... OptSpecifiers>
385 void claimAllArgs(OptSpecifiers... Ids) const {
386 for (Arg *A : filtered(Ids...))
387 A->claim();
388 }
389
390 /// ClaimAllArgs - Claim all arguments.
391 ///
392 LLVM_ABI void ClaimAllArgs() const;
393 /// @}
394 /// @name Arg Synthesis
395 /// @{
396
397 /// Construct a constant string pointer whose
398 /// lifetime will match that of the ArgList.
399 virtual const char *MakeArgStringRef(StringRef Str) const = 0;
400 const char *MakeArgString(const Twine &Str) const {
402 return MakeArgStringRef(Str.toStringRef(Buf));
403 }
404
405 /// Create an arg string for (\p LHS + \p RHS), reusing the
406 /// string at \p Index if possible.
407 LLVM_ABI const char *GetOrMakeJoinedArgString(unsigned Index, StringRef LHS,
408 StringRef RHS) const;
409
410 LLVM_ABI void print(raw_ostream &O) const;
411 LLVM_ABI void dump() const;
412
413 /// @}
414};
415
416class LLVM_ABI InputArgList final : public ArgList {
417private:
418 /// List of argument strings used by the contained Args.
419 ///
420 /// This is mutable since we treat the ArgList as being the list
421 /// of Args, and allow routines to add new strings (to have a
422 /// convenient place to store the memory) via MakeIndex.
423 mutable ArgStringList ArgStrings;
424
425 /// Strings for synthesized arguments.
426 ///
427 /// This is mutable since we treat the ArgList as being the list
428 /// of Args, and allow routines to add new strings (to have a
429 /// convenient place to store the memory) via MakeIndex.
430 mutable std::list<std::string> SynthesizedStrings;
431
432 /// The number of original input argument strings.
433 unsigned NumInputArgStrings;
434
435 /// Release allocated arguments.
436 void releaseMemory();
437
438public:
439 InputArgList() : NumInputArgStrings(0) {}
440
441 InputArgList(const char* const *ArgBegin, const char* const *ArgEnd);
442
444 : ArgList(std::move(RHS)), ArgStrings(std::move(RHS.ArgStrings)),
445 SynthesizedStrings(std::move(RHS.SynthesizedStrings)),
446 NumInputArgStrings(RHS.NumInputArgStrings) {}
447
449 if (this == &RHS)
450 return *this;
451 releaseMemory();
452 ArgList::operator=(std::move(RHS));
453 ArgStrings = std::move(RHS.ArgStrings);
454 SynthesizedStrings = std::move(RHS.SynthesizedStrings);
455 NumInputArgStrings = RHS.NumInputArgStrings;
456 return *this;
457 }
458
459 ~InputArgList() { releaseMemory(); }
460
461 const char *getArgString(unsigned Index) const override {
462 return ArgStrings[Index];
463 }
464
465 void replaceArgString(unsigned Index, const Twine &S) {
466 ArgStrings[Index] = MakeArgString(S);
467 }
468
469 unsigned getNumInputArgStrings() const override {
470 return NumInputArgStrings;
471 }
472
473 /// @name Arg Synthesis
474 /// @{
475
476public:
477 /// MakeIndex - Get an index for the given string(s).
478 unsigned MakeIndex(StringRef String0) const;
479 unsigned MakeIndex(StringRef String0, StringRef String1) const;
480
482 const char *MakeArgStringRef(StringRef Str) const override;
483
484 /// @}
485};
486
487/// DerivedArgList - An ordered collection of driver arguments,
488/// whose storage may be in another argument list.
489class LLVM_ABI DerivedArgList final : public ArgList {
490 const InputArgList &BaseArgs;
491
492 /// The list of arguments we synthesized.
493 mutable SmallVector<std::unique_ptr<Arg>, 16> SynthesizedArgs;
494
495public:
496 /// Construct a new derived arg list from \p BaseArgs.
497 DerivedArgList(const InputArgList &BaseArgs);
498
499 const char *getArgString(unsigned Index) const override {
500 return BaseArgs.getArgString(Index);
501 }
502
503 unsigned getNumInputArgStrings() const override {
504 return BaseArgs.getNumInputArgStrings();
505 }
506
507 const InputArgList &getBaseArgs() const {
508 return BaseArgs;
509 }
510
511 /// @name Arg Synthesis
512 /// @{
513
514 /// AddSynthesizedArg - Add a argument to the list of synthesized arguments
515 /// (to be freed).
516 void AddSynthesizedArg(Arg *A);
517
519 const char *MakeArgStringRef(StringRef Str) const override;
520
521 /// AddFlagArg - Construct a new FlagArg for the given option \p Id and
522 /// append it to the argument list.
523 void AddFlagArg(const Arg *BaseArg, const Option Opt) {
524 append(MakeFlagArg(BaseArg, Opt));
525 }
526
527 /// AddPositionalArg - Construct a new Positional arg for the given option
528 /// \p Id, with the provided \p Value and append it to the argument
529 /// list.
530 void AddPositionalArg(const Arg *BaseArg, const Option Opt,
532 append(MakePositionalArg(BaseArg, Opt, Value));
533 }
534
535 /// AddSeparateArg - Construct a new Positional arg for the given option
536 /// \p Id, with the provided \p Value and append it to the argument
537 /// list.
538 void AddSeparateArg(const Arg *BaseArg, const Option Opt,
540 append(MakeSeparateArg(BaseArg, Opt, Value));
541 }
542
543 /// AddJoinedArg - Construct a new Positional arg for the given option
544 /// \p Id, with the provided \p Value and append it to the argument list.
545 void AddJoinedArg(const Arg *BaseArg, const Option Opt,
547 append(MakeJoinedArg(BaseArg, Opt, Value));
548 }
549
550 /// MakeFlagArg - Construct a new FlagArg for the given option \p Id.
551 Arg *MakeFlagArg(const Arg *BaseArg, const Option Opt) const;
552
553 /// MakePositionalArg - Construct a new Positional arg for the
554 /// given option \p Id, with the provided \p Value.
555 Arg *MakePositionalArg(const Arg *BaseArg, const Option Opt,
556 StringRef Value) const;
557
558 /// MakeSeparateArg - Construct a new Positional arg for the
559 /// given option \p Id, with the provided \p Value.
560 Arg *MakeSeparateArg(const Arg *BaseArg, const Option Opt,
561 StringRef Value) const;
562
563 /// MakeJoinedArg - Construct a new Positional arg for the
564 /// given option \p Id, with the provided \p Value.
565 Arg *MakeJoinedArg(const Arg *BaseArg, const Option Opt,
566 StringRef Value) const;
567
568 /// @}
569};
570
571} // end namespace opt
572
573} // end namespace llvm
574
575#endif // LLVM_OPTION_ARGLIST_H
Defines the llvm::Arg class for parsed arguments.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static ManagedStatic< SubCommand > AllSubCommands
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_ATTRIBUTE_NOINLINE
LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, mark a method "not for inl...
Definition Compiler.h:346
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:58
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallString class.
This file defines the SmallVector class.
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
A range adaptor for a pair of iterators.
LLVM_ABI void eraseArg(OptSpecifier Id)
eraseArg - Remove any option matching Id.
Definition ArgList.cpp:46
arg_iterator< arglist_type::const_reverse_iterator, N > filtered_reverse_iterator
Definition ArgList.h:129
virtual const char * getArgString(unsigned Index) const =0
getArgString - Return the input argument string at Index.
LLVM_ABI void AddAllArgValues(ArgStringList &Output, OptSpecifier Id0, OptSpecifier Id1=0U, OptSpecifier Id2=0U) const
AddAllArgValues - Render the argument values of all arguments matching the given ids.
Definition ArgList.cpp:149
virtual unsigned getNumInputArgStrings() const =0
getNumInputArgStrings - Return the number of original argument strings, which are guaranteed to be th...
LLVM_ABI void print(raw_ostream &O) const
Definition ArgList.cpp:196
LLVM_ABI const char * GetOrMakeJoinedArgString(unsigned Index, StringRef LHS, StringRef RHS) const
Create an arg string for (LHS + RHS), reusing the string at Index if possible.
Definition ArgList.cpp:185
LLVM_ABI void addOptInFlag(ArgStringList &Output, OptSpecifier Pos, OptSpecifier Neg) const
Given an option Pos and its negative form Neg, render the option if Pos is present.
Definition ArgList.cpp:105
LLVM_ABI bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg, bool Default) const
Definition ArgList.cpp:79
unsigned size() const
Definition ArgList.h:187
LLVM_ABI void AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0, const char *Translation, bool Joined=false) const
AddAllArgsTranslated - Render all the arguments matching the given ids, but forced to separate args a...
Definition ArgList.cpp:158
static OptSpecifier toOptSpecifier(OptSpecifier S)
Definition ArgList.h:176
const_iterator end() const
Definition ArgList.h:200
arg_iterator< arglist_type::const_iterator > const_iterator
Definition ArgList.h:122
iterator_range< filtered_reverse_iterator< sizeof...(OptSpecifiers)> > filtered_reverse(OptSpecifiers ...Ids) const
Definition ArgList.h:218
bool hasMultipleArgs(OptSpecifier Id) const
Return true if the arg list contains multiple arguments matching Id.
Definition ArgList.h:251
LLVM_ABI void AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const
AddAllArgs - Render all arguments matching the given ids.
Definition ArgList.cpp:142
arg_iterator< arglist_type::const_iterator, N > filtered_iterator
Definition ArgList.h:127
const char * MakeArgString(const Twine &Str) const
Definition ArgList.h:400
const_reverse_iterator rend() const
Definition ArgList.h:203
bool hasArgNoClaim(OptSpecifiers ...Ids) const
hasArg - Does the arg list contain any option matching Id.
Definition ArgList.h:242
void AddLastArg(ArgStringList &Output, OptSpecifiers... Ids) const
Definition ArgList.h:348
iterator begin()
Definition ArgList.h:193
arg_iterator< arglist_type::const_reverse_iterator > const_reverse_iterator
Definition ArgList.h:124
StringRef getSubCommand(ArrayRef< OptTable::SubCommand > AllSubCommands, std::function< void(ArrayRef< StringRef >)> HandleMultipleSubcommands, std::function< void(ArrayRef< StringRef >)> HandleOtherPositionals) const
getSubCommand - Find subcommand from the arguments if the usage is valid.
Definition ArgList.cpp:207
LLVM_ABI void append(Arg *A)
append - Append A to the arg list.
Definition ArgList.cpp:33
void addLastArg(ArgStringList &Output, OptSpecifiers... Ids) const
Render only the last argument match Id0, if present.
Definition ArgList.h:343
const arglist_type & getArgs() const
Definition ArgList.h:185
LLVM_ABI void addAllArgs(ArgStringList &Output, ArrayRef< OptSpecifier > Ids) const
Render all arguments matching any of the given ids.
Definition ArgList.cpp:136
LLVM_ABI void ClaimAllArgs() const
ClaimAllArgs - Claim all arguments.
Definition ArgList.cpp:179
const_iterator begin() const
Definition ArgList.h:199
const_reverse_iterator rbegin() const
Definition ArgList.h:202
LLVM_ATTRIBUTE_NOINLINE Arg * getLastArgNoClaim(OptSpecifiers... Ids) const
Return the last argument matching Id, or null.
Definition ArgList.h:270
reverse_iterator rbegin()
Definition ArgList.h:196
void claimAllArgs(OptSpecifiers... Ids) const
Definition ArgList.h:385
LLVM_ABI void dump() const
Definition ArgList.cpp:204
reverse_iterator rend()
Definition ArgList.h:197
LLVM_ABI void AddAllArgsExcept(ArgStringList &Output, ArrayRef< OptSpecifier > Ids, ArrayRef< OptSpecifier > ExcludeIds) const
AddAllArgsExcept - Render all arguments matching any of the given ids and not matching any of the exc...
Definition ArgList.cpp:112
LLVM_ATTRIBUTE_NOINLINE Arg * getLastArg(OptSpecifiers... Ids) const
Return the last argument matching Id, or null.
Definition ArgList.h:258
arg_iterator< arglist_type::reverse_iterator > reverse_iterator
Definition ArgList.h:123
LLVM_ABI std::vector< std::string > getAllArgValues(OptSpecifier Id) const
getAllArgValues - Get the values of all instances of the given argument as strings.
Definition ArgList.cpp:99
void addOptOutFlag(ArgStringList &Output, OptSpecifier Pos, OptSpecifier Neg) const
Render the option if Neg is present.
Definition ArgList.h:336
arg_iterator< arglist_type::iterator > iterator
Definition ArgList.h:121
bool hasArg(OptSpecifiers ...Ids) const
Definition ArgList.h:246
LLVM_ABI StringRef getLastArgValue(OptSpecifier Id, StringRef Default="") const
getLastArgValue - Return the value of the last argument, or a default.
Definition ArgList.cpp:93
iterator end()
Definition ArgList.h:194
virtual const char * MakeArgStringRef(StringRef Str) const =0
Construct a constant string pointer whose lifetime will match that of the ArgList.
iterator_range< filtered_iterator< sizeof...(OptSpecifiers)> > filtered(OptSpecifiers ...Ids) const
Definition ArgList.h:207
ArgList & operator=(ArgList &&RHS)
Definition ArgList.h:163
ArgList(ArgList &&RHS)
Definition ArgList.h:157
LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const
hasFlag - Given an option Pos and its negative form Neg, return true if the option is present,...
Definition ArgList.cpp:73
SmallVector< Arg *, 16 > arglist_type
Definition ArgList.h:120
A concrete instance of a particular driver option.
Definition Arg.h:35
void claim() const
Definition Arg.h:116
void AddJoinedArg(const Arg *BaseArg, const Option Opt, StringRef Value)
AddJoinedArg - Construct a new Positional arg for the given option Id, with the provided Value and ap...
Definition ArgList.h:545
Arg * MakeSeparateArg(const Arg *BaseArg, const Option Opt, StringRef Value) const
MakeSeparateArg - Construct a new Positional arg for the given option Id, with the provided Value.
Definition ArgList.cpp:305
void AddFlagArg(const Arg *BaseArg, const Option Opt)
AddFlagArg - Construct a new FlagArg for the given option Id and append it to the argument list.
Definition ArgList.h:523
Arg * MakeJoinedArg(const Arg *BaseArg, const Option Opt, StringRef Value) const
MakeJoinedArg - Construct a new Positional arg for the given option Id, with the provided Value.
Definition ArgList.cpp:314
DerivedArgList(const InputArgList &BaseArgs)
Construct a new derived arg list from BaseArgs.
Definition ArgList.cpp:278
unsigned getNumInputArgStrings() const override
getNumInputArgStrings - Return the number of original argument strings, which are guaranteed to be th...
Definition ArgList.h:503
const InputArgList & getBaseArgs() const
Definition ArgList.h:507
const char * getArgString(unsigned Index) const override
getArgString - Return the input argument string at Index.
Definition ArgList.h:499
Arg * MakePositionalArg(const Arg *BaseArg, const Option Opt, StringRef Value) const
MakePositionalArg - Construct a new Positional arg for the given option Id, with the provided Value.
Definition ArgList.cpp:296
void AddPositionalArg(const Arg *BaseArg, const Option Opt, StringRef Value)
AddPositionalArg - Construct a new Positional arg for the given option Id, with the provided Value an...
Definition ArgList.h:530
void AddSeparateArg(const Arg *BaseArg, const Option Opt, StringRef Value)
AddSeparateArg - Construct a new Positional arg for the given option Id, with the provided Value and ...
Definition ArgList.h:538
Arg * MakeFlagArg(const Arg *BaseArg, const Option Opt) const
MakeFlagArg - Construct a new FlagArg for the given option Id.
Definition ArgList.cpp:289
InputArgList(InputArgList &&RHS)
Definition ArgList.h:443
InputArgList & operator=(InputArgList &&RHS)
Definition ArgList.h:448
const char * getArgString(unsigned Index) const override
getArgString - Return the input argument string at Index.
Definition ArgList.h:461
const char * MakeArgString(const Twine &Str) const
Definition ArgList.h:400
void replaceArgString(unsigned Index, const Twine &S)
Definition ArgList.h:465
unsigned getNumInputArgStrings() const override
getNumInputArgStrings - Return the number of original argument strings, which are guaranteed to be th...
Definition ArgList.h:469
OptSpecifier - Wrapper class for abstracting references to option IDs.
Option - Abstract representation for a single form of driver argument.
Definition Option.h:55
arg_iterator - Iterates through arguments stored inside an ArgList.
Definition ArgList.h:42
friend bool operator==(arg_iterator LHS, arg_iterator RHS)
Definition ArgList.h:104
arg_iterator(BaseIter Current, BaseIter End, const OptSpecifier(&Ids)[NumOptSpecifiers ? NumOptSpecifiers :1]={})
Definition ArgList.h:80
std::ptrdiff_t difference_type
Definition ArgList.h:78
reference operator*() const
Definition ArgList.h:89
typename Traits::value_type value_type
Definition ArgList.h:74
arg_iterator & operator++()
Definition ArgList.h:92
typename Traits::pointer pointer
Definition ArgList.h:76
std::forward_iterator_tag iterator_category
Definition ArgList.h:77
pointer operator->() const
Definition ArgList.h:90
arg_iterator operator++(int)
Definition ArgList.h:98
friend bool operator!=(arg_iterator LHS, arg_iterator RHS)
Definition ArgList.h:107
typename Traits::reference reference
Definition ArgList.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
SmallVector< const char *, 16 > ArgStringList
ArgStringList - Type used for constructing argv lists for subprocesses.
Definition Option.h:30
This is an optimization pass for GlobalISel generic memory operations.
static ConstantRange getRange(Value *Op, SCCPSolver &Solver, const SmallPtrSetImpl< Value * > &InsertedValues)
Helper for getting ranges from Solver.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1869
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867