LLVM: include/llvm/Option/ArgList.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_OPTION_ARGLIST_H
10#define LLVM_OPTION_ARGLIST_H
11
24#include
25#include
26#include <initializer_list>
27#include
28#include
29#include
30#include
31#include
32#include
33
34namespace llvm {
35
37
38namespace opt {
39
40
41template<typename BaseIter, unsigned NumOptSpecifiers = 0>
43
44 BaseIter Current, End;
45
46
47
48 OptSpecifier Ids[NumOptSpecifiers ? NumOptSpecifiers : 1];
49
50 void SkipToNextArg() {
51 for (; Current != End; ++Current) {
52
53 if (!*Current)
54 continue;
55
56
57 if (!NumOptSpecifiers)
58 return;
59
60
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;
72
73public:
74 using value_type = typename Traits::value_type;
75 using reference = typename Traits::reference;
76 using pointer = typename Traits::pointer;
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)
86 SkipToNextArg();
87 }
88
91
93 ++Current;
94 SkipToNextArg();
95 return *this;
96 }
97
100 ++(*this);
101 return tmp;
102 }
103
105 return LHS.Current == RHS.Current;
106 }
109 }
110};
111
112
113
114
115
116
117
119public:
126
131
132private:
133
135
136 using OptRange = std::pair<unsigned, unsigned>;
137 static OptRange emptyRange() { return {-1u, 0u}; }
138
139
141
142
143
144 LLVM_ABI OptRange getRange(std::initializer_list Ids) const;
145
146protected:
147
148
149
151
152
153
154
155
156
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
173
174
175
177
178public:
179
180
181
182
184
186
187 unsigned size() const { return Args.size(); }
188
189
190
191
192
195
198
201
204
205 template<typename ...OptSpecifiers>
209 auto B = Args.begin() + Range.first;
210 auto E = Args.begin() + Range.second;
214 }
215
216 template<typename ...OptSpecifiers>
220 auto B = Args.rend() - Range.second;
221 auto E = Args.rend() - Range.first;
225 }
226
227
228
229
230
231
233
234
235
236
237
238
239
240
241 template<typename ...OptSpecifiers>
245 template<typename ...OptSpecifiers>
249
250
253 return (Args.begin() != Args.end()) && (++Args.begin()) != Args.end();
254 }
255
256
257 template <typename... OptSpecifiers>
259 Arg *Res = nullptr;
261 Res = A;
263 }
264 return Res;
265 }
266
267
268
269 template <typename... OptSpecifiers>
272 return A;
273 return nullptr;
274 }
275
276
277 virtual const char *getArgString(unsigned Index) const = 0;
278
279
280
281
283
284
285
286
287
288
289
290
291
292
293
294
299
300
301
302
303
304
307
308
309
311
312
313
314
315
316
317
318
319
323
324
325
326
327
330
331
332
335
340
341
342 template <typename... OptSpecifiers>
347 template <typename... OptSpecifiers>
351
352
353
357
360
361
363
364
365
369
370
371
372
373
374
375
377 const char *Translation,
378 bool Joined = false) const;
379
380
381
383
384 template <typename... OptSpecifiers>
389
390
391
393
394
395
396
397
398
404
405
406
409
412
413
414};
415
417private:
418
419
420
421
422
424
425
426
427
428
429
430 mutable std::liststd::string SynthesizedStrings;
431
432
433 unsigned NumInputArgStrings;
434
435
436 void releaseMemory();
437
438public:
440
441 InputArgList(const char* const *ArgBegin, const char* const *ArgEnd);
442
445 SynthesizedStrings(std::move(RHS.SynthesizedStrings)),
446 NumInputArgStrings(RHS.NumInputArgStrings) {}
447
449 if (this == &RHS)
450 return *this;
451 releaseMemory();
453 ArgStrings = std::move(RHS.ArgStrings);
454 SynthesizedStrings = std::move(RHS.SynthesizedStrings);
455 NumInputArgStrings = RHS.NumInputArgStrings;
456 return *this;
457 }
458
460
461 const char *getArgString(unsigned Index) const override {
462 return ArgStrings[Index];
463 }
464
468
470 return NumInputArgStrings;
471 }
472
473
474
475
476public:
477
478 unsigned MakeIndex(StringRef String0) const;
480
482 const char *MakeArgStringRef(StringRef Str) const override;
483
484
485};
486
487
488
491
492
494
495public:
496
498
499 const char *getArgString(unsigned Index) const override {
500 return BaseArgs.getArgString(Index);
501 }
502
504 return BaseArgs.getNumInputArgStrings();
505 }
506
508 return BaseArgs;
509 }
510
511
512
513
514
515
516 void AddSynthesizedArg(Arg *A);
517
519 const char *MakeArgStringRef(StringRef Str) const override;
520
521
522
526
527
528
529
534
535
536
537
542
543
544
549
550
551 Arg *MakeFlagArg(const Arg *BaseArg, const Option Opt) const;
552
553
554
555 Arg *MakePositionalArg(const Arg *BaseArg, const Option Opt,
557
558
559
560 Arg *MakeSeparateArg(const Arg *BaseArg, const Option Opt,
562
563
564
565 Arg *MakeJoinedArg(const Arg *BaseArg, const Option Opt,
567
568
569};
570
571}
572
573}
574
575#endif
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_FOR_TEST
#define LLVM_ATTRIBUTE_NOINLINE
LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, mark a method "not for inl...
This file defines the DenseMap class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallString class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
A range adaptor for a pair of iterators.
LLVM_ABI void eraseArg(OptSpecifier Id)
eraseArg - Remove any option matching Id.
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.
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
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.
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.
LLVM_ABI bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg, bool Default) const
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...
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.
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
LLVM_ABI_FOR_TEST 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.
LLVM_ABI void append(Arg *A)
append - Append A to the arg list.
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.
LLVM_ABI void ClaimAllArgs() const
ClaimAllArgs - Claim all arguments.
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
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...
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.
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.
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,...
SmallVector< Arg *, 16 > arglist_type
Definition ArgList.h:120
A concrete instance of a particular driver option.
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.
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.
DerivedArgList(const InputArgList &BaseArgs)
Construct a new derived arg list from BaseArgs.
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.
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.
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
~InputArgList()
Definition ArgList.h:459
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
InputArgList()
Definition ArgList.h:439
OptSpecifier - Wrapper class for abstracting references to option IDs.
Option - Abstract representation for a single form of driver argument.
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.
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.
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.
@ Default
The result values are uniform if and only if all operands are uniform.
Implement std::hash so that hash_code can be used in STL containers.