9 #ifndef LLVM_OPTION_ARGLIST_H 10 #define LLVM_OPTION_ARGLIST_H 24 #include <initializer_list> 39 template<
typename BaseIter,
unsigned NumOptSpecifiers = 0>
42 BaseIter Current, End;
46 OptSpecifier Ids[NumOptSpecifiers ? NumOptSpecifiers : 1];
48 void SkipToNextArg() {
49 for (; Current != End; ++Current) {
55 if (!NumOptSpecifiers)
59 const Option &
O = (*Current)->getOption();
69 using Traits = std::iterator_traits<BaseIter>;
79 BaseIter Current, BaseIter End,
80 const OptSpecifier (&Ids)[NumOptSpecifiers ? NumOptSpecifiers : 1] = {})
81 : Current(Current), End(End) {
82 for (
unsigned I = 0;
I != NumOptSpecifiers; ++
I)
83 this->Ids[
I] = Ids[
I];
103 return LHS.Current == RHS.Current;
106 return !(LHS == RHS);
134 using OptRange = std::pair<unsigned, unsigned>;
135 static OptRange emptyRange() {
return {-1u, 0u}; }
142 OptRange getRange(std::initializer_list<OptSpecifier> Ids)
const;
156 : Args(
std::move(RHS.Args)), OptRanges(
std::move(RHS.OptRanges)) {
158 RHS.OptRanges.clear();
162 Args = std::move(RHS.Args);
164 OptRanges = std::move(RHS.OptRanges);
165 RHS.OptRanges.clear();
203 template<
typename ...OptSpecifiers>
206 OptRange Range = getRange({toOptSpecifier(Ids)...});
207 auto B = Args.
begin() + Range.first;
208 auto E = Args.
begin() + Range.second;
209 using Iterator = filtered_iterator<
sizeof...(OptSpecifiers)>;
210 return make_range(Iterator(B,
E, {toOptSpecifier(Ids)...}),
211 Iterator(
E,
E, {toOptSpecifier(Ids)...}));
214 template<
typename ...OptSpecifiers>
215 iterator_range<filtered_reverse_iterator<
sizeof...(OptSpecifiers)>>
217 OptRange Range = getRange({toOptSpecifier(Ids)...});
218 auto B = Args.
rend() - Range.second;
219 auto E = Args.
rend() - Range.first;
220 using Iterator = filtered_reverse_iterator<
sizeof...(OptSpecifiers)>;
221 return make_range(Iterator(B,
E, {toOptSpecifier(Ids)...}),
222 Iterator(
E,
E, {toOptSpecifier(Ids)...}));
239 template<
typename ...OptSpecifiers>
241 return getLastArgNoClaim(Ids...) !=
nullptr;
243 template<
typename ...OptSpecifiers>
244 bool hasArg(OptSpecifiers ...Ids)
const {
245 return getLastArg(Ids...) !=
nullptr;
249 template<
typename ...OptSpecifiers>
252 for (
Arg *A : filtered(Ids...)) {
261 template<
typename ...OptSpecifiers>
263 for (
Arg *A : filtered_reverse(Ids...))
269 virtual const char *getArgString(
unsigned Index)
const = 0;
274 virtual unsigned getNumInputArgStrings()
const = 0;
285 std::vector<std::string> getAllArgValues(
OptSpecifier Id)
const;
302 bool Default =
true)
const;
305 template<
typename ...OptSpecifiers>
307 if (
Arg *A = getLastArg(Ids...))
334 const char *Translation,
335 bool Joined =
false)
const;
343 void ClaimAllArgs()
const;
351 virtual const char *MakeArgStringRef(
StringRef Str)
const = 0;
359 const char *GetOrMakeJoinedArgString(
unsigned Index,
StringRef LHS,
382 mutable std::list<std::string> SynthesizedStrings;
385 unsigned NumInputArgStrings;
388 void releaseMemory();
393 InputArgList(
const char*
const *ArgBegin,
const char*
const *ArgEnd);
396 :
ArgList(
std::move(RHS)), ArgStrings(
std::move(RHS.ArgStrings)),
397 SynthesizedStrings(
std::move(RHS.SynthesizedStrings)),
398 NumInputArgStrings(RHS.NumInputArgStrings) {}
403 ArgStrings = std::move(RHS.ArgStrings);
404 SynthesizedStrings = std::move(RHS.SynthesizedStrings);
405 NumInputArgStrings = RHS.NumInputArgStrings;
412 return ArgStrings[
Index];
416 return NumInputArgStrings;
424 unsigned MakeIndex(
StringRef String0)
const;
428 const char *MakeArgStringRef(
StringRef Str)
const override;
462 void AddSynthesizedArg(
Arg *A);
465 const char *MakeArgStringRef(
StringRef Str)
const override;
470 append(MakeFlagArg(BaseArg, Opt));
478 append(MakePositionalArg(BaseArg, Opt, Value));
486 append(MakeSeparateArg(BaseArg, Opt, Value));
493 append(MakeJoinedArg(BaseArg, Opt, Value));
497 Arg *MakeFlagArg(
const Arg *BaseArg,
const Option Opt)
const;
501 Arg *MakePositionalArg(
const Arg *BaseArg,
const Option Opt,
506 Arg *MakeSeparateArg(
const Arg *BaseArg,
const Option Opt,
511 Arg *MakeJoinedArg(
const Arg *BaseArg,
const Option Opt,
521 #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
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")
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...
void AddLastArg(ArgStringList &Output, OptSpecifiers ...Ids) const
Render only the last argument match Id0, if present.
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)
OptSpecifier - Wrapper class for abstracting references to option IDs.
static OptSpecifier toOptSpecifier(OptSpecifier S)
typename Traits::value_type value_type
void render(const ArgList &Args, ArgStringList &Output) const
Append the argument onto the given array as strings.
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