10 #ifndef LLVM_OPTION_ARGLIST_H 11 #define LLVM_OPTION_ARGLIST_H 25 #include <initializer_list> 40 template<
typename BaseIter,
unsigned NumOptSpecifiers = 0>
43 BaseIter Current, End;
47 OptSpecifier Ids[NumOptSpecifiers ? NumOptSpecifiers : 1];
49 void SkipToNextArg() {
50 for (; Current != End; ++Current) {
56 if (!NumOptSpecifiers)
60 const Option &
O = (*Current)->getOption();
70 using Traits = std::iterator_traits<BaseIter>;
80 BaseIter Current, BaseIter End,
81 const OptSpecifier (&Ids)[NumOptSpecifiers ? NumOptSpecifiers : 1] = {})
82 : Current(Current), End(End) {
83 for (
unsigned I = 0;
I != NumOptSpecifiers; ++
I)
84 this->Ids[
I] = Ids[
I];
104 return LHS.Current == RHS.Current;
107 return !(LHS == RHS);
135 using OptRange = std::pair<unsigned, unsigned>;
136 static OptRange emptyRange() {
return {-1u, 0u}; }
143 OptRange getRange(std::initializer_list<OptSpecifier> Ids)
const;
157 : Args(
std::move(RHS.Args)), OptRanges(
std::move(RHS.OptRanges)) {
159 RHS.OptRanges.clear();
163 Args = std::move(RHS.Args);
165 OptRanges = std::move(RHS.OptRanges);
166 RHS.OptRanges.clear();
204 template<
typename ...OptSpecifiers>
207 OptRange Range = getRange({toOptSpecifier(Ids)...});
208 auto B = Args.
begin() + Range.first;
209 auto E = Args.
begin() + Range.second;
210 using Iterator = filtered_iterator<
sizeof...(OptSpecifiers)>;
211 return make_range(Iterator(B,
E, {toOptSpecifier(Ids)...}),
212 Iterator(
E,
E, {toOptSpecifier(Ids)...}));
215 template<
typename ...OptSpecifiers>
216 iterator_range<filtered_reverse_iterator<
sizeof...(OptSpecifiers)>>
218 OptRange Range = getRange({toOptSpecifier(Ids)...});
219 auto B = Args.
rend() - Range.second;
220 auto E = Args.
rend() - Range.first;
221 using Iterator = filtered_reverse_iterator<
sizeof...(OptSpecifiers)>;
222 return make_range(Iterator(B,
E, {toOptSpecifier(Ids)...}),
223 Iterator(
E,
E, {toOptSpecifier(Ids)...}));
240 template<
typename ...OptSpecifiers>
242 return getLastArgNoClaim(Ids...) !=
nullptr;
244 template<
typename ...OptSpecifiers>
245 bool hasArg(OptSpecifiers ...Ids)
const {
246 return getLastArg(Ids...) !=
nullptr;
250 template<
typename ...OptSpecifiers>
253 for (
Arg *A : filtered(Ids...)) {
262 template<
typename ...OptSpecifiers>
264 for (
Arg *A : filtered_reverse(Ids...))
270 virtual const char *getArgString(
unsigned Index)
const = 0;
275 virtual unsigned getNumInputArgStrings()
const = 0;
286 std::vector<std::string> getAllArgValues(
OptSpecifier Id)
const;
303 bool Default =
true)
const;
333 const char *Translation,
334 bool Joined =
false)
const;
342 void ClaimAllArgs()
const;
350 virtual const char *MakeArgStringRef(
StringRef Str)
const = 0;
358 const char *GetOrMakeJoinedArgString(
unsigned Index,
StringRef LHS,
381 mutable std::list<std::string> SynthesizedStrings;
384 unsigned NumInputArgStrings;
387 void releaseMemory();
392 InputArgList(
const char*
const *ArgBegin,
const char*
const *ArgEnd);
395 :
ArgList(
std::move(RHS)), ArgStrings(
std::move(RHS.ArgStrings)),
396 SynthesizedStrings(
std::move(RHS.SynthesizedStrings)),
397 NumInputArgStrings(RHS.NumInputArgStrings) {}
402 ArgStrings = std::move(RHS.ArgStrings);
403 SynthesizedStrings = std::move(RHS.SynthesizedStrings);
404 NumInputArgStrings = RHS.NumInputArgStrings;
411 return ArgStrings[
Index];
415 return NumInputArgStrings;
423 unsigned MakeIndex(
StringRef String0)
const;
427 const char *MakeArgStringRef(
StringRef Str)
const override;
461 void AddSynthesizedArg(
Arg *A);
464 const char *MakeArgStringRef(
StringRef Str)
const override;
469 append(MakeFlagArg(BaseArg, Opt));
477 append(MakePositionalArg(BaseArg, Opt, Value));
485 append(MakeSeparateArg(BaseArg, Opt, Value));
492 append(MakeJoinedArg(BaseArg, Opt, Value));
496 Arg *MakeFlagArg(
const Arg *BaseArg,
const Option Opt)
const;
500 Arg *MakePositionalArg(
const Arg *BaseArg,
const Option Opt,
505 Arg *MakeSeparateArg(
const Arg *BaseArg,
const Option Opt,
510 Arg *MakeJoinedArg(
const Arg *BaseArg,
const Option Opt,
520 #endif // LLVM_OPTION_ARGLIST_H
This class represents lattice values for constants.
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 ...
const InputArgList & getBaseArgs() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
const_iterator begin() const
iterator_range< filtered_iterator< sizeof...(OptSpecifiers)> > filtered(OptSpecifiers ...Ids) const
iterator_range< filtered_reverse_iterator< sizeof...(OptSpecifiers)> > filtered_reverse(OptSpecifiers ...Ids) const
reverse_iterator rbegin()
const char * getArgString(unsigned Index) const override
getArgString - Return the input argument string at Index.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
unsigned getNumInputArgStrings() const override
getNumInputArgStrings - Return the number of original argument strings, which are guaranteed to be th...
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...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
arg_iterator - Iterates through arguments stored inside an ArgList.
bool hasArg(OptSpecifiers ...Ids) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
arg_iterator operator++(int)
std::ptrdiff_t difference_type
const_reverse_iterator rbegin() const
static bool hasFlag(StringRef Feature)
Determine if a feature has a flag; '+' or '-'.
bool hasArgNoClaim(OptSpecifiers ...Ids) const
hasArg - Does the arg list contain any option matching Id.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Option - Abstract representation for a single form of driver argument.
bool matches(OptSpecifier ID) const
matches - Predicate for whether this option is part of the given option (which may be a group)...
A concrete instance of a particular driver option.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
const char * MakeArgString(const Twine &Str) const
arg_iterator & operator++()
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Arg * getLastArgNoClaim(OptSpecifiers ...Ids) const
Return the last argument matching Id, or null.
Arg * getLastArg(OptSpecifiers ...Ids) const
Return the last argument matching Id, or null.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
typename Traits::pointer pointer
const_reverse_iterator rend() const
ArgList & operator=(ArgList &&RHS)
void claim() const
Set the Arg claimed bit.
const arglist_type & getArgs() const
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...
const_iterator end() const
A range adaptor for a pair of iterators.
Defines the llvm::Arg class for parsed arguments.
friend bool operator!=(arg_iterator LHS, arg_iterator RHS)
friend bool operator==(arg_iterator LHS, arg_iterator RHS)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
OptSpecifier - Wrapper class for abstracting references to option IDs.
static OptSpecifier toOptSpecifier(OptSpecifier S)
typename Traits::value_type value_type
std::forward_iterator_tag iterator_category
arg_iterator(BaseIter Current, BaseIter End, const OptSpecifier(&Ids)[NumOptSpecifiers ? NumOptSpecifiers :1]={})
reverse_iterator rbegin()
pointer operator->() const
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
DerivedArgList - An ordered collection of driver arguments, whose storage may be in another argument ...
StringRef - Represent a constant reference to a string, i.e.
ArgList - Ordered collection of driver arguments.
reference operator*() const
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...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
typename Traits::reference reference