[llvm] r225817 - Running clang-format on CommandLine.h and CommandLine.cpp.
Chris Bieneman
beanz at apple.com
Tue Jan 13 11:14:20 PST 2015
Author: cbieneman
Date: Tue Jan 13 13:14:20 2015
New Revision: 225817
URL: http://llvm.org/viewvc/llvm-project?rev=225817&view=rev
Log:
Running clang-format on CommandLine.h and CommandLine.cpp.
No functional changes, I'm just going to be doing a lot of work in these files and it would be helpful if they had more current LLVM style.
Modified:
llvm/trunk/include/llvm/Support/CommandLine.h
llvm/trunk/lib/Support/CommandLine.cpp
Modified: llvm/trunk/include/llvm/Support/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=225817&r1=225816&r2=225817&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CommandLine.h (original)
+++ llvm/trunk/include/llvm/Support/CommandLine.h Tue Jan 13 13:14:20 2015
@@ -40,7 +40,7 @@ namespace cl {
//===----------------------------------------------------------------------===//
// ParseCommandLineOptions - Command line option processing entry point.
//
-void ParseCommandLineOptions(int argc, const char * const *argv,
+void ParseCommandLineOptions(int argc, const char *const *argv,
const char *Overview = nullptr);
//===----------------------------------------------------------------------===//
@@ -66,7 +66,6 @@ void SetVersionPrinter(void (*func)());
/// information specific to the tool.
void AddExtraVersionPrinter(void (*func)());
-
// PrintOptionValues - Print option values.
// With -print-options print the difference between option values and defaults.
// With -print-all-options print all option values.
@@ -80,11 +79,11 @@ void MarkOptionsChanged();
// Flags permitted to be passed to command line arguments
//
-enum NumOccurrencesFlag { // Flags for the number of occurrences allowed
- Optional = 0x00, // Zero or One occurrence
- ZeroOrMore = 0x01, // Zero or more occurrences allowed
- Required = 0x02, // One occurrence required
- OneOrMore = 0x03, // One or more occurrences required
+enum NumOccurrencesFlag { // Flags for the number of occurrences allowed
+ Optional = 0x00, // Zero or One occurrence
+ ZeroOrMore = 0x01, // Zero or more occurrences allowed
+ Required = 0x02, // One occurrence required
+ OneOrMore = 0x03, // One or more occurrences required
// ConsumeAfter - Indicates that this option is fed anything that follows the
// last positional argument required by the application (it is an error if
@@ -93,20 +92,20 @@ enum NumOccurrencesFlag { // Flags
// found. Once a filename is found, all of the succeeding arguments are
// passed, unprocessed, to the ConsumeAfter option.
//
- ConsumeAfter = 0x04
+ ConsumeAfter = 0x04
};
-enum ValueExpected { // Is a value required for the option?
+enum ValueExpected { // Is a value required for the option?
// zero reserved for the unspecified value
- ValueOptional = 0x01, // The value can appear... or not
- ValueRequired = 0x02, // The value is required to appear!
- ValueDisallowed = 0x03 // A value may not be specified (for flags)
+ ValueOptional = 0x01, // The value can appear... or not
+ ValueRequired = 0x02, // The value is required to appear!
+ ValueDisallowed = 0x03 // A value may not be specified (for flags)
};
-enum OptionHidden { // Control whether -help shows this option
- NotHidden = 0x00, // Option included in -help & -help-hidden
- Hidden = 0x01, // -help doesn't, but -help-hidden does
- ReallyHidden = 0x02 // Neither -help nor -help-hidden show this arg
+enum OptionHidden { // Control whether -help shows this option
+ NotHidden = 0x00, // Option included in -help & -help-hidden
+ Hidden = 0x01, // -help doesn't, but -help-hidden does
+ ReallyHidden = 0x02 // Neither -help nor -help-hidden show this arg
};
// Formatting flags - This controls special features that the option might have
@@ -125,16 +124,16 @@ enum OptionHidden { // Contro
//
enum FormattingFlags {
- NormalFormatting = 0x00, // Nothing special
- Positional = 0x01, // Is a positional argument, no '-' required
- Prefix = 0x02, // Can this option directly prefix its value?
- Grouping = 0x03 // Can this option group with other options?
+ NormalFormatting = 0x00, // Nothing special
+ Positional = 0x01, // Is a positional argument, no '-' required
+ Prefix = 0x02, // Can this option directly prefix its value?
+ Grouping = 0x03 // Can this option group with other options?
};
-enum MiscFlags { // Miscellaneous flags to adjust argument
- CommaSeparated = 0x01, // Should this cl::list split between commas?
- PositionalEatsArgs = 0x02, // Should this positional cl::list eat -args?
- Sink = 0x04 // Should this cl::list eat all unknown options?
+enum MiscFlags { // Miscellaneous flags to adjust argument
+ CommaSeparated = 0x01, // Should this cl::list split between commas?
+ PositionalEatsArgs = 0x02, // Should this positional cl::list eat -args?
+ Sink = 0x04 // Should this cl::list eat all unknown options?
};
//===----------------------------------------------------------------------===//
@@ -145,9 +144,13 @@ private:
const char *const Name;
const char *const Description;
void registerCategory();
+
public:
- OptionCategory(const char *const Name, const char *const Description = nullptr)
- : Name(Name), Description(Description) { registerCategory(); }
+ OptionCategory(const char *const Name,
+ const char *const Description = nullptr)
+ : Name(Name), Description(Description) {
+ registerCategory();
+ }
const char *getName() const { return Name; }
const char *getDescription() const { return Description; }
};
@@ -176,7 +179,7 @@ class Option {
// Out of line virtual function to provide home for the class.
virtual void anchor();
- int NumOccurrences; // The number of times specified
+ int NumOccurrences; // The number of times specified
// Occurrences, HiddenFlag, and Formatting are all enum types but to avoid
// problems with signed enums in bitfields.
unsigned Occurrences : 3; // enum NumOccurrencesFlag
@@ -186,9 +189,9 @@ class Option {
unsigned HiddenFlag : 2; // enum OptionHidden
unsigned Formatting : 2; // enum FormattingFlags
unsigned Misc : 3;
- unsigned Position; // Position of last occurrence of the option
- unsigned AdditionalVals;// Greater than 0 for multi-valued option.
- Option *NextRegistered; // Singly linked list of registered options.
+ unsigned Position; // Position of last occurrence of the option
+ unsigned AdditionalVals; // Greater than 0 for multi-valued option.
+ Option *NextRegistered; // Singly linked list of registered options.
public:
const char *ArgStr; // The argument string itself (ex: "help", "o")
@@ -200,8 +203,7 @@ public:
return (enum NumOccurrencesFlag)Occurrences;
}
inline enum ValueExpected getValueExpectedFlag() const {
- return Value ? ((enum ValueExpected)Value)
- : getValueExpectedFlagDefault();
+ return Value ? ((enum ValueExpected)Value) : getValueExpectedFlagDefault();
}
inline enum OptionHidden getOptionHiddenFlag() const {
return (enum OptionHidden)HiddenFlag;
@@ -209,9 +211,7 @@ public:
inline enum FormattingFlags getFormattingFlag() const {
return (enum FormattingFlags)Formatting;
}
- inline unsigned getMiscFlags() const {
- return Misc;
- }
+ inline unsigned getMiscFlags() const { return Misc; }
inline unsigned getPosition() const { return Position; }
inline unsigned getNumAdditionalVals() const { return AdditionalVals; }
@@ -224,25 +224,24 @@ public:
void setArgStr(const char *S) { ArgStr = S; }
void setDescription(const char *S) { HelpStr = S; }
void setValueStr(const char *S) { ValueStr = S; }
- void setNumOccurrencesFlag(enum NumOccurrencesFlag Val) {
- Occurrences = Val;
- }
+ void setNumOccurrencesFlag(enum NumOccurrencesFlag Val) { Occurrences = Val; }
void setValueExpectedFlag(enum ValueExpected Val) { Value = Val; }
void setHiddenFlag(enum OptionHidden Val) { HiddenFlag = Val; }
void setFormattingFlag(enum FormattingFlags V) { Formatting = V; }
void setMiscFlag(enum MiscFlags M) { Misc |= M; }
void setPosition(unsigned pos) { Position = pos; }
void setCategory(OptionCategory &C) { Category = &C; }
+
protected:
explicit Option(enum NumOccurrencesFlag OccurrencesFlag,
enum OptionHidden Hidden)
- : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
- HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0),
- Position(0), AdditionalVals(0), NextRegistered(nullptr),
- ArgStr(""), HelpStr(""), ValueStr(""), Category(&GeneralCategory) {
- }
+ : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
+ HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0), Position(0),
+ AdditionalVals(0), NextRegistered(nullptr), ArgStr(""), HelpStr(""),
+ ValueStr(""), Category(&GeneralCategory) {}
inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; }
+
public:
// addArgument - Register this argument with the commandline system.
//
@@ -266,12 +265,12 @@ public:
virtual void printOptionValue(size_t GlobalWidth, bool Force) const = 0;
- virtual void getExtraOptionNames(SmallVectorImpl<const char*> &) {}
+ virtual void getExtraOptionNames(SmallVectorImpl<const char *> &) {}
// addOccurrence - Wrapper around handleOccurrence that enforces Flags.
//
- virtual bool addOccurrence(unsigned pos, StringRef ArgName,
- StringRef Value, bool MultiArg = false);
+ virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value,
+ bool MultiArg = false);
// Prints option name followed by message. Always returns true.
bool error(const Twine &Message, StringRef ArgName = StringRef());
@@ -281,7 +280,6 @@ public:
virtual ~Option() {}
};
-
//===----------------------------------------------------------------------===//
// Command line option modifiers that can be used to modify the behavior of
// command line option parsers...
@@ -306,36 +304,31 @@ struct value_desc {
// the default constructor for the argument type does not give you what you
// want. This is only valid on "opt" arguments, not on "list" arguments.
//
-template<class Ty>
-struct initializer {
+template <class Ty> struct initializer {
const Ty &Init;
initializer(const Ty &Val) : Init(Val) {}
- template<class Opt>
- void apply(Opt &O) const { O.setInitialValue(Init); }
+ template <class Opt> void apply(Opt &O) const { O.setInitialValue(Init); }
};
-template<class Ty>
-initializer<Ty> init(const Ty &Val) {
+template <class Ty> initializer<Ty> init(const Ty &Val) {
return initializer<Ty>(Val);
}
-
// location - Allow the user to specify which external variable they want to
// store the results of the command line argument processing into, if they don't
// want to store it in the option itself.
//
-template<class Ty>
-struct LocationClass {
+template <class Ty> struct LocationClass {
Ty &Loc;
LocationClass(Ty &L) : Loc(L) {}
- template<class Opt>
- void apply(Opt &O) const { O.setLocation(O, Loc); }
+ template <class Opt> void apply(Opt &O) const { O.setLocation(O, Loc); }
};
-template<class Ty>
-LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
+template <class Ty> LocationClass<Ty> location(Ty &L) {
+ return LocationClass<Ty>(L);
+}
// cat - Specifiy the Option category for the command line argument to belong
// to.
@@ -343,11 +336,9 @@ struct cat {
OptionCategory &Category;
cat(OptionCategory &c) : Category(c) {}
- template<class Opt>
- void apply(Opt &O) const { O.setCategory(Category); }
+ template <class Opt> void apply(Opt &O) const { O.setCategory(Category); }
};
-
//===----------------------------------------------------------------------===//
// OptionValue class
@@ -360,11 +351,11 @@ private:
virtual void anchor();
};
-template<class DataType> struct OptionValue;
+template <class DataType> struct OptionValue;
// The default value safely does nothing. Option value printing is only
// best-effort.
-template<class DataType, bool isClass>
+template <class DataType, bool isClass>
struct OptionValueBase : public GenericOptionValue {
// Temporary storage for argument passing.
typedef OptionValue<DataType> WrapperType;
@@ -374,21 +365,20 @@ struct OptionValueBase : public GenericO
const DataType &getValue() const { llvm_unreachable("no default value"); }
// Some options may take their value from a different data type.
- template<class DT>
- void setValue(const DT& /*V*/) {}
+ template <class DT> void setValue(const DT & /*V*/) {}
- bool compare(const DataType &/*V*/) const { return false; }
+ bool compare(const DataType & /*V*/) const { return false; }
- bool compare(const GenericOptionValue& /*V*/) const override {
+ bool compare(const GenericOptionValue & /*V*/) const override {
return false;
}
};
// Simple copy of the option value.
-template<class DataType>
-class OptionValueCopy : public GenericOptionValue {
+template <class DataType> class OptionValueCopy : public GenericOptionValue {
DataType Value;
bool Valid;
+
public:
OptionValueCopy() : Valid(false) {}
@@ -399,37 +389,36 @@ public:
return Value;
}
- void setValue(const DataType &V) { Valid = true; Value = V; }
-
- bool compare(const DataType &V) const {
- return Valid && (Value != V);
+ void setValue(const DataType &V) {
+ Valid = true;
+ Value = V;
}
+ bool compare(const DataType &V) const { return Valid && (Value != V); }
+
bool compare(const GenericOptionValue &V) const override {
const OptionValueCopy<DataType> &VC =
- static_cast< const OptionValueCopy<DataType>& >(V);
- if (!VC.hasValue()) return false;
+ static_cast<const OptionValueCopy<DataType> &>(V);
+ if (!VC.hasValue())
+ return false;
return compare(VC.getValue());
}
};
// Non-class option values.
-template<class DataType>
+template <class DataType>
struct OptionValueBase<DataType, false> : OptionValueCopy<DataType> {
typedef DataType WrapperType;
};
// Top-level option class.
-template<class DataType>
+template <class DataType>
struct OptionValue : OptionValueBase<DataType, std::is_class<DataType>::value> {
OptionValue() {}
- OptionValue(const DataType& V) {
- this->setValue(V);
- }
+ OptionValue(const DataType &V) { this->setValue(V); }
// Some options may take their value from a different data type.
- template<class DT>
- OptionValue<DataType> &operator=(const DT& V) {
+ template <class DT> OptionValue<DataType> &operator=(const DT &V) {
this->setValue(V);
return *this;
}
@@ -437,36 +426,33 @@ struct OptionValue : OptionValueBase<Dat
// Other safe-to-copy-by-value common option types.
enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE };
-template<>
+template <>
struct OptionValue<cl::boolOrDefault> : OptionValueCopy<cl::boolOrDefault> {
typedef cl::boolOrDefault WrapperType;
OptionValue() {}
- OptionValue(const cl::boolOrDefault& V) {
- this->setValue(V);
- }
- OptionValue<cl::boolOrDefault> &operator=(const cl::boolOrDefault& V) {
+ OptionValue(const cl::boolOrDefault &V) { this->setValue(V); }
+ OptionValue<cl::boolOrDefault> &operator=(const cl::boolOrDefault &V) {
setValue(V);
return *this;
}
+
private:
void anchor() override;
};
-template<>
-struct OptionValue<std::string> : OptionValueCopy<std::string> {
+template <> struct OptionValue<std::string> : OptionValueCopy<std::string> {
typedef StringRef WrapperType;
OptionValue() {}
- OptionValue(const std::string& V) {
- this->setValue(V);
- }
- OptionValue<std::string> &operator=(const std::string& V) {
+ OptionValue(const std::string &V) { this->setValue(V); }
+ OptionValue<std::string> &operator=(const std::string &V) {
setValue(V);
return *this;
}
+
private:
void anchor() override;
};
@@ -476,20 +462,20 @@ private:
//
#define clEnumVal(ENUMVAL, DESC) #ENUMVAL, int(ENUMVAL), DESC
#define clEnumValN(ENUMVAL, FLAGNAME, DESC) FLAGNAME, int(ENUMVAL), DESC
-#define clEnumValEnd (reinterpret_cast<void*>(0))
+#define clEnumValEnd (reinterpret_cast<void *>(0))
// values - For custom data types, allow specifying a group of values together
// as the values that go into the mapping that the option handler uses. Note
// that the values list must always have a 0 at the end of the list to indicate
// that the list has ended.
//
-template<class DataType>
-class ValuesClass {
+template <class DataType> class ValuesClass {
// Use a vector instead of a map, because the lists should be short,
// the overhead is less, and most importantly, it keeps them in the order
// inserted so we can print our option out nicely.
- SmallVector<std::pair<const char *, std::pair<int, const char *> >,4> Values;
+ SmallVector<std::pair<const char *, std::pair<int, const char *>>, 4> Values;
void processValues(va_list Vals);
+
public:
ValuesClass(const char *EnumName, DataType Val, const char *Desc,
va_list ValueArgs) {
@@ -500,13 +486,12 @@ public:
while (const char *enumName = va_arg(ValueArgs, const char *)) {
DataType EnumVal = static_cast<DataType>(va_arg(ValueArgs, int));
const char *EnumDesc = va_arg(ValueArgs, const char *);
- Values.push_back(std::make_pair(enumName, // Add value to value map
+ Values.push_back(std::make_pair(enumName, // Add value to value map
std::make_pair(EnumVal, EnumDesc)));
}
}
- template<class Opt>
- void apply(Opt &O) const {
+ template <class Opt> void apply(Opt &O) const {
for (size_t i = 0, e = Values.size(); i != e; ++i)
O.getParser().addLiteralOption(Values[i].first, Values[i].second.first,
Values[i].second.second);
@@ -516,11 +501,11 @@ public:
template <class DataType>
ValuesClass<DataType> LLVM_END_WITH_NULL
values(const char *Arg, DataType Val, const char *Desc, ...) {
- va_list ValueArgs;
- va_start(ValueArgs, Desc);
- ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
- va_end(ValueArgs);
- return Vals;
+ va_list ValueArgs;
+ va_start(ValueArgs, Desc);
+ ValuesClass<DataType> Vals(Arg, Val, Desc, ValueArgs);
+ va_end(ValueArgs);
+ return Vals;
}
//===----------------------------------------------------------------------===//
@@ -539,13 +524,14 @@ class generic_parser_base {
protected:
class GenericOptionInfo {
public:
- GenericOptionInfo(const char *name, const char *helpStr) :
- Name(name), HelpStr(helpStr) {}
+ GenericOptionInfo(const char *name, const char *helpStr)
+ : Name(name), HelpStr(helpStr) {}
const char *Name;
const char *HelpStr;
};
+
public:
- virtual ~generic_parser_base() {} // Base class should have virtual-dtor
+ virtual ~generic_parser_base() {} // Base class should have virtual-dtor
// getNumOptions - Virtual function implemented by generic subclass to
// indicate how many entries are in Values.
@@ -576,7 +562,7 @@ public:
//
// Template definition ensures that the option and default have the same
// DataType (via the same AnyOptionValue).
- template<class AnyOptionValue>
+ template <class AnyOptionValue>
void printOptionDiff(const Option &O, const AnyOptionValue &V,
const AnyOptionValue &Default,
size_t GlobalWidth) const {
@@ -590,7 +576,7 @@ public:
hasArgStr = O.hasArgStr();
}
- void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
+ void getExtraOptionNames(SmallVectorImpl<const char *> &OptionNames) {
// If there has been no argstr specified, that means that we need to add an
// argument for every possible option. This ensures that our options are
// vectored to us.
@@ -599,7 +585,6 @@ public:
OptionNames.push_back(getOption(i));
}
-
enum ValueExpected getValueExpectedFlagDefault() const {
// If there is an ArgStr specified, then we are of the form:
//
@@ -633,16 +618,16 @@ protected:
// command line option for -help. Because this is a simple mapping parser, the
// data type can be any unsupported type.
//
-template <class DataType>
-class parser : public generic_parser_base {
+template <class DataType> class parser : public generic_parser_base {
protected:
class OptionInfo : public GenericOptionInfo {
public:
- OptionInfo(const char *name, DataType v, const char *helpStr) :
- GenericOptionInfo(name, helpStr), V(v) {}
+ OptionInfo(const char *name, DataType v, const char *helpStr)
+ : GenericOptionInfo(name, helpStr), V(v) {}
OptionValue<DataType> V;
};
SmallVector<OptionInfo, 8> Values;
+
public:
typedef DataType parser_data_type;
@@ -690,14 +675,14 @@ public:
void removeLiteralOption(const char *Name) {
unsigned N = findOption(Name);
assert(N != Values.size() && "Option not found!");
- Values.erase(Values.begin()+N);
+ Values.erase(Values.begin() + N);
}
};
//--------------------------------------------------
// basic_parser - Super class of parsers to provide boilerplate code
//
-class basic_parser_impl { // non-template implementation of basic_parser<t>
+class basic_parser_impl { // non-template implementation of basic_parser<t>
public:
virtual ~basic_parser_impl() {}
@@ -705,7 +690,7 @@ public:
return ValueRequired;
}
- void getExtraOptionNames(SmallVectorImpl<const char*> &) {}
+ void getExtraOptionNames(SmallVectorImpl<const char *> &) {}
void initialize(Option &) {}
@@ -735,8 +720,7 @@ protected:
// basic_parser - The real basic parser is just a template wrapper that provides
// a typedef for the provided data type.
//
-template<class DataType>
-class basic_parser : public basic_parser_impl {
+template <class DataType> class basic_parser : public basic_parser_impl {
public:
typedef DataType parser_data_type;
typedef OptionValue<DataType> OptVal;
@@ -745,18 +729,14 @@ public:
//--------------------------------------------------
// parser<bool>
//
-template<>
-class parser<bool> : public basic_parser<bool> {
+template <> class parser<bool> : public basic_parser<bool> {
const char *ArgStr;
-public:
+public:
// parse - Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val);
- template <class Opt>
- void initialize(Opt &O) {
- ArgStr = O.ArgStr;
- }
+ template <class Opt> void initialize(Opt &O) { ArgStr = O.ArgStr; }
enum ValueExpected getValueExpectedFlagDefault() const {
return ValueOptional;
@@ -776,8 +756,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<boolOrDefault>
-template<>
-class parser<boolOrDefault> : public basic_parser<boolOrDefault> {
+template <> class parser<boolOrDefault> : public basic_parser<boolOrDefault> {
public:
// parse - Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val);
@@ -801,8 +780,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<int>
//
-template<>
-class parser<int> : public basic_parser<int> {
+template <> class parser<int> : public basic_parser<int> {
public:
// parse - Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val);
@@ -819,12 +797,10 @@ public:
EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<int>);
-
//--------------------------------------------------
// parser<unsigned>
//
-template<>
-class parser<unsigned> : public basic_parser<unsigned> {
+template <> class parser<unsigned> : public basic_parser<unsigned> {
public:
// parse - Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val);
@@ -844,7 +820,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<unsigned long long>
//
-template<>
+template <>
class parser<unsigned long long> : public basic_parser<unsigned long long> {
public:
// parse - Return true on error.
@@ -866,8 +842,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<double>
//
-template<>
-class parser<double> : public basic_parser<double> {
+template <> class parser<double> : public basic_parser<double> {
public:
// parse - Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val);
@@ -887,8 +862,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<float>
//
-template<>
-class parser<float> : public basic_parser<float> {
+template <> class parser<float> : public basic_parser<float> {
public:
// parse - Return true on error.
bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val);
@@ -908,8 +882,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<std::string>
//
-template<>
-class parser<std::string> : public basic_parser<std::string> {
+template <> class parser<std::string> : public basic_parser<std::string> {
public:
// parse - Return true on error.
bool parse(Option &, StringRef, StringRef Arg, std::string &Value) {
@@ -932,8 +905,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
//--------------------------------------------------
// parser<char>
//
-template<>
-class parser<char> : public basic_parser<char> {
+template <> class parser<char> : public basic_parser<char> {
public:
// parse - Return true on error.
bool parse(Option &, StringRef, StringRef Arg, char &Value) {
@@ -960,7 +932,7 @@ EXTERN_TEMPLATE_INSTANTIATION(class basi
// parser to handle all the template nastiness.
// This overloaded function is selected by the generic parser.
-template<class ParserClass, class DT>
+template <class ParserClass, class DT>
void printOptionDiff(const Option &O, const generic_parser_base &P, const DT &V,
const OptionValue<DT> &Default, size_t GlobalWidth) {
OptionValue<DT> OV = V;
@@ -969,18 +941,16 @@ void printOptionDiff(const Option &O, co
// This is instantiated for basic parsers when the parsed value has a different
// type than the option value. e.g. HelpPrinter.
-template<class ParserDT, class ValDT>
-struct OptionDiffPrinter {
- void print(const Option &O, const parser<ParserDT> P, const ValDT &/*V*/,
- const OptionValue<ValDT> &/*Default*/, size_t GlobalWidth) {
+template <class ParserDT, class ValDT> struct OptionDiffPrinter {
+ void print(const Option &O, const parser<ParserDT> P, const ValDT & /*V*/,
+ const OptionValue<ValDT> & /*Default*/, size_t GlobalWidth) {
P.printOptionNoValue(O, GlobalWidth);
}
};
// This is instantiated for basic parsers when the parsed value has the same
// type as the option value.
-template<class DT>
-struct OptionDiffPrinter<DT, DT> {
+template <class DT> struct OptionDiffPrinter<DT, DT> {
void print(const Option &O, const parser<DT> P, const DT &V,
const OptionValue<DT> &Default, size_t GlobalWidth) {
P.printOptionDiff(O, V, Default, GlobalWidth);
@@ -989,15 +959,14 @@ struct OptionDiffPrinter<DT, DT> {
// This overloaded function is selected by the basic parser, which may parse a
// different type than the option type.
-template<class ParserClass, class ValDT>
+template <class ParserClass, class ValDT>
void printOptionDiff(
- const Option &O,
- const basic_parser<typename ParserClass::parser_data_type> &P,
- const ValDT &V, const OptionValue<ValDT> &Default,
- size_t GlobalWidth) {
+ const Option &O,
+ const basic_parser<typename ParserClass::parser_data_type> &P,
+ const ValDT &V, const OptionValue<ValDT> &Default, size_t GlobalWidth) {
OptionDiffPrinter<typename ParserClass::parser_data_type, ValDT> printer;
- printer.print(O, static_cast<const ParserClass&>(P), V, Default,
+ printer.print(O, static_cast<const ParserClass &>(P), V, Default,
GlobalWidth);
}
@@ -1007,46 +976,47 @@ void printOptionDiff(
// not correctly respond to the apply method). Because the syntax to use this
// is a pain, we have the 'apply' method below to handle the nastiness...
//
-template<class Mod> struct applicator {
- template<class Opt>
- static void opt(const Mod &M, Opt &O) { M.apply(O); }
+template <class Mod> struct applicator {
+ template <class Opt> static void opt(const Mod &M, Opt &O) { M.apply(O); }
};
// Handle const char* as a special case...
-template<unsigned n> struct applicator<char[n]> {
- template<class Opt>
- static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
+template <unsigned n> struct applicator<char[n]> {
+ template <class Opt> static void opt(const char *Str, Opt &O) {
+ O.setArgStr(Str);
+ }
};
-template<unsigned n> struct applicator<const char[n]> {
- template<class Opt>
- static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
+template <unsigned n> struct applicator<const char[n]> {
+ template <class Opt> static void opt(const char *Str, Opt &O) {
+ O.setArgStr(Str);
+ }
};
-template<> struct applicator<const char*> {
- template<class Opt>
- static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
+template <> struct applicator<const char *> {
+ template <class Opt> static void opt(const char *Str, Opt &O) {
+ O.setArgStr(Str);
+ }
};
-template<> struct applicator<NumOccurrencesFlag> {
+template <> struct applicator<NumOccurrencesFlag> {
static void opt(NumOccurrencesFlag N, Option &O) {
O.setNumOccurrencesFlag(N);
}
};
-template<> struct applicator<ValueExpected> {
+template <> struct applicator<ValueExpected> {
static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
};
-template<> struct applicator<OptionHidden> {
+template <> struct applicator<OptionHidden> {
static void opt(OptionHidden OH, Option &O) { O.setHiddenFlag(OH); }
};
-template<> struct applicator<FormattingFlags> {
+template <> struct applicator<FormattingFlags> {
static void opt(FormattingFlags FF, Option &O) { O.setFormattingFlag(FF); }
};
-template<> struct applicator<MiscFlags> {
+template <> struct applicator<MiscFlags> {
static void opt(MiscFlags MF, Option &O) { O.setMiscFlag(MF); }
};
// apply method - Apply a modifier to an option in a type safe way.
-template<class Mod, class Opt>
-void apply(const Mod &M, Opt *O) {
+template <class Mod, class Opt> void apply(const Mod &M, Opt *O) {
applicator<Mod>::opt(M, *O);
}
@@ -1057,16 +1027,17 @@ void apply(const Mod &M, Opt *O) {
// assumes the user will specify a variable to store the data into with the
// cl::location(x) modifier.
//
-template<class DataType, bool ExternalStorage, bool isClass>
+template <class DataType, bool ExternalStorage, bool isClass>
class opt_storage {
- DataType *Location; // Where to store the object...
+ DataType *Location; // Where to store the object...
OptionValue<DataType> Default;
void check_location() const {
assert(Location && "cl::location(...) not specified for a command "
- "line option with external storage, "
- "or cl::init specified before cl::location()!!");
+ "line option with external storage, "
+ "or cl::init specified before cl::location()!!");
}
+
public:
opt_storage() : Location(nullptr) {}
@@ -1078,16 +1049,21 @@ public:
return false;
}
- template<class T>
- void setValue(const T &V, bool initial = false) {
+ template <class T> void setValue(const T &V, bool initial = false) {
check_location();
*Location = V;
if (initial)
Default = V;
}
- DataType &getValue() { check_location(); return *Location; }
- const DataType &getValue() const { check_location(); return *Location; }
+ DataType &getValue() {
+ check_location();
+ return *Location;
+ }
+ const DataType &getValue() const {
+ check_location();
+ return *Location;
+ }
operator DataType() const { return this->getValue(); }
@@ -1098,13 +1074,12 @@ public:
// inherit from a class, we do so. This makes us exactly compatible with the
// object in all cases that it is used.
//
-template<class DataType>
-class opt_storage<DataType,false,true> : public DataType {
+template <class DataType>
+class opt_storage<DataType, false, true> : public DataType {
public:
OptionValue<DataType> Default;
- template<class T>
- void setValue(const T &V, bool initial = false) {
+ template <class T> void setValue(const T &V, bool initial = false) {
DataType::operator=(V);
if (initial)
Default = V;
@@ -1120,8 +1095,7 @@ public:
// this case, we store an instance through containment, and overload operators
// to get at the value.
//
-template<class DataType>
-class opt_storage<DataType, false, false> {
+template <class DataType> class opt_storage<DataType, false, false> {
public:
DataType Value;
OptionValue<DataType> Default;
@@ -1130,8 +1104,7 @@ public:
// type.
opt_storage() : Value(DataType()), Default(DataType()) {}
- template<class T>
- void setValue(const T &V, bool initial = false) {
+ template <class T> void setValue(const T &V, bool initial = false) {
Value = V;
if (initial)
Default = V;
@@ -1147,12 +1120,11 @@ public:
DataType operator->() const { return Value; }
};
-
//===----------------------------------------------------------------------===//
// opt - A scalar command line option.
//
template <class DataType, bool ExternalStorage = false,
- class ParserClass = parser<DataType> >
+ class ParserClass = parser<DataType>>
class opt : public Option,
public opt_storage<DataType, ExternalStorage,
std::is_class<DataType>::value> {
@@ -1161,9 +1133,9 @@ class opt : public Option,
bool handleOccurrence(unsigned pos, StringRef ArgName,
StringRef Arg) override {
typename ParserClass::parser_data_type Val =
- typename ParserClass::parser_data_type();
+ typename ParserClass::parser_data_type();
if (Parser.parse(*this, ArgName, Arg, Val))
- return true; // Parse error!
+ return true; // Parse error!
this->setValue(Val);
this->setPosition(pos);
return false;
@@ -1172,20 +1144,23 @@ class opt : public Option,
enum ValueExpected getValueExpectedFlagDefault() const override {
return Parser.getValueExpectedFlagDefault();
}
- void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) override {
+ void
+ getExtraOptionNames(SmallVectorImpl<const char *> &OptionNames) override {
return Parser.getExtraOptionNames(OptionNames);
}
// Forward printing stuff to the parser...
- size_t getOptionWidth() const override {return Parser.getOptionWidth(*this);}
+ size_t getOptionWidth() const override {
+ return Parser.getOptionWidth(*this);
+ }
void printOptionInfo(size_t GlobalWidth) const override {
Parser.printOptionInfo(*this, GlobalWidth);
}
void printOptionValue(size_t GlobalWidth, bool Force) const override {
if (Force || this->getDefault().compare(this->getValue())) {
- cl::printOptionDiff<ParserClass>(
- *this, Parser, this->getValue(), this->getDefault(), GlobalWidth);
+ cl::printOptionDiff<ParserClass>(*this, Parser, this->getValue(),
+ this->getDefault(), GlobalWidth);
}
}
@@ -1193,81 +1168,107 @@ class opt : public Option,
addArgument();
Parser.initialize(*this);
}
+
public:
// setInitialValue - Used by the cl::init modifier...
void setInitialValue(const DataType &V) { this->setValue(V, true); }
ParserClass &getParser() { return Parser; }
- template<class T>
- DataType &operator=(const T &Val) {
+ template <class T> DataType &operator=(const T &Val) {
this->setValue(Val);
return this->getValue();
}
// One option...
- template<class M0t>
- explicit opt(const M0t &M0) : Option(Optional, NotHidden) {
+ template <class M0t>
+ explicit opt(const M0t &M0)
+ : Option(Optional, NotHidden) {
apply(M0, this);
done();
}
// Two options...
- template<class M0t, class M1t>
- opt(const M0t &M0, const M1t &M1) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this);
+ template <class M0t, class M1t>
+ opt(const M0t &M0, const M1t &M1)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
done();
}
// Three options...
- template<class M0t, class M1t, class M2t>
- opt(const M0t &M0, const M1t &M1,
- const M2t &M2) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this);
+ template <class M0t, class M1t, class M2t>
+ opt(const M0t &M0, const M1t &M1, const M2t &M2)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
done();
}
// Four options...
- template<class M0t, class M1t, class M2t, class M3t>
- opt(const M0t &M0, const M1t &M1, const M2t &M2,
- const M3t &M3) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ template <class M0t, class M1t, class M2t, class M3t>
+ opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
done();
}
// Five options...
- template<class M0t, class M1t, class M2t, class M3t, class M4t>
- opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ template <class M0t, class M1t, class M2t, class M3t, class M4t>
+ opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
apply(M4, this);
done();
}
// Six options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t>
- opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this);
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t>
+ opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4,
+ const M5t &M5)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
done();
}
// Seven options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t, class M6t>
- opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5,
- const M6t &M6) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this); apply(M6, this);
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t,
+ class M6t>
+ opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4,
+ const M5t &M5, const M6t &M6)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
+ apply(M6, this);
done();
}
// Eight options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t, class M6t, class M7t>
- opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5, const M6t &M6,
- const M7t &M7) : Option(Optional, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t,
+ class M6t, class M7t>
+ opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4,
+ const M5t &M5, const M6t &M6, const M7t &M7)
+ : Option(Optional, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
+ apply(M6, this);
+ apply(M7, this);
done();
}
};
@@ -1285,9 +1286,8 @@ EXTERN_TEMPLATE_INSTANTIATION(class opt<
// assumes the user will specify a variable to store the data into with the
// cl::location(x) modifier.
//
-template<class DataType, class StorageClass>
-class list_storage {
- StorageClass *Location; // Where to store the object...
+template <class DataType, class StorageClass> class list_storage {
+ StorageClass *Location; // Where to store the object...
public:
list_storage() : Location(0) {}
@@ -1299,32 +1299,30 @@ public:
return false;
}
- template<class T>
- void addValue(const T &V) {
+ template <class T> void addValue(const T &V) {
assert(Location != 0 && "cl::location(...) not specified for a command "
- "line option with external storage!");
+ "line option with external storage!");
Location->push_back(V);
}
};
-
// Define how to hold a class type object, such as a string. Since we can
// inherit from a class, we do so. This makes us exactly compatible with the
// object in all cases that it is used.
//
-template<class DataType>
+template <class DataType>
class list_storage<DataType, bool> : public std::vector<DataType> {
public:
- template<class T>
- void addValue(const T &V) { std::vector<DataType>::push_back(V); }
+ template <class T> void addValue(const T &V) {
+ std::vector<DataType>::push_back(V);
+ }
};
-
//===----------------------------------------------------------------------===//
// list - A list of command line options.
//
template <class DataType, class Storage = bool,
- class ParserClass = parser<DataType> >
+ class ParserClass = parser<DataType>>
class list : public Option, public list_storage<DataType, Storage> {
std::vector<unsigned> Positions;
ParserClass Parser;
@@ -1332,16 +1330,17 @@ class list : public Option, public list_
enum ValueExpected getValueExpectedFlagDefault() const override {
return Parser.getValueExpectedFlagDefault();
}
- void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) override {
+ void
+ getExtraOptionNames(SmallVectorImpl<const char *> &OptionNames) override {
return Parser.getExtraOptionNames(OptionNames);
}
bool handleOccurrence(unsigned pos, StringRef ArgName,
StringRef Arg) override {
typename ParserClass::parser_data_type Val =
- typename ParserClass::parser_data_type();
+ typename ParserClass::parser_data_type();
if (Parser.parse(*this, ArgName, Arg, Val))
- return true; // Parse Error!
+ return true; // Parse Error!
list_storage<DataType, Storage>::addValue(Val);
setPosition(pos);
Positions.push_back(pos);
@@ -1349,19 +1348,22 @@ class list : public Option, public list_
}
// Forward printing stuff to the parser...
- size_t getOptionWidth() const override {return Parser.getOptionWidth(*this);}
+ size_t getOptionWidth() const override {
+ return Parser.getOptionWidth(*this);
+ }
void printOptionInfo(size_t GlobalWidth) const override {
Parser.printOptionInfo(*this, GlobalWidth);
}
// Unimplemented: list options don't currently store their default value.
- void printOptionValue(size_t /*GlobalWidth*/,
- bool /*Force*/) const override {}
+ void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
+ }
void done() {
addArgument();
Parser.initialize(*this);
}
+
public:
ParserClass &getParser() { return Parser; }
@@ -1370,71 +1372,96 @@ public:
return Positions[optnum];
}
- void setNumAdditionalVals(unsigned n) {
- Option::setNumAdditionalVals(n);
- }
+ void setNumAdditionalVals(unsigned n) { Option::setNumAdditionalVals(n); }
// One option...
- template<class M0t>
- explicit list(const M0t &M0) : Option(ZeroOrMore, NotHidden) {
+ template <class M0t>
+ explicit list(const M0t &M0)
+ : Option(ZeroOrMore, NotHidden) {
apply(M0, this);
done();
}
// Two options...
- template<class M0t, class M1t>
- list(const M0t &M0, const M1t &M1) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this);
+ template <class M0t, class M1t>
+ list(const M0t &M0, const M1t &M1)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
done();
}
// Three options...
- template<class M0t, class M1t, class M2t>
+ template <class M0t, class M1t, class M2t>
list(const M0t &M0, const M1t &M1, const M2t &M2)
- : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this);
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
done();
}
// Four options...
- template<class M0t, class M1t, class M2t, class M3t>
+ template <class M0t, class M1t, class M2t, class M3t>
list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
- : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
done();
}
// Five options...
- template<class M0t, class M1t, class M2t, class M3t, class M4t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t>
list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ const M4t &M4)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
apply(M4, this);
done();
}
// Six options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t>
list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this);
+ const M4t &M4, const M5t &M5)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
done();
}
// Seven options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t, class M6t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t,
+ class M6t>
list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
const M4t &M4, const M5t &M5, const M6t &M6)
- : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this); apply(M6, this);
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
+ apply(M6, this);
done();
}
// Eight options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t, class M6t, class M7t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t,
+ class M6t, class M7t>
list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5, const M6t &M6,
- const M7t &M7) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
+ const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
+ apply(M6, this);
+ apply(M7, this);
done();
}
};
@@ -1445,10 +1472,11 @@ struct multi_val {
explicit multi_val(unsigned N) : AdditionalVals(N) {}
template <typename D, typename S, typename P>
- void apply(list<D, S, P> &L) const { L.setNumAdditionalVals(AdditionalVals); }
+ void apply(list<D, S, P> &L) const {
+ L.setNumAdditionalVals(AdditionalVals);
+ }
};
-
//===----------------------------------------------------------------------===//
// bits_storage class
@@ -1456,15 +1484,13 @@ struct multi_val {
// assumes the user will specify a variable to store the data into with the
// cl::location(x) modifier.
//
-template<class DataType, class StorageClass>
-class bits_storage {
- unsigned *Location; // Where to store the bits...
+template <class DataType, class StorageClass> class bits_storage {
+ unsigned *Location; // Where to store the bits...
- template<class T>
- static unsigned Bit(const T &V) {
+ template <class T> static unsigned Bit(const T &V) {
unsigned BitPos = reinterpret_cast<unsigned>(V);
assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
- "enum exceeds width of bit vector!");
+ "enum exceeds width of bit vector!");
return 1 << BitPos;
}
@@ -1478,57 +1504,45 @@ public:
return false;
}
- template<class T>
- void addValue(const T &V) {
+ template <class T> void addValue(const T &V) {
assert(Location != 0 && "cl::location(...) not specified for a command "
- "line option with external storage!");
+ "line option with external storage!");
*Location |= Bit(V);
}
unsigned getBits() { return *Location; }
- template<class T>
- bool isSet(const T &V) {
+ template <class T> bool isSet(const T &V) {
return (*Location & Bit(V)) != 0;
}
};
-
// Define how to hold bits. Since we can inherit from a class, we do so.
// This makes us exactly compatible with the bits in all cases that it is used.
//
-template<class DataType>
-class bits_storage<DataType, bool> {
- unsigned Bits; // Where to store the bits...
+template <class DataType> class bits_storage<DataType, bool> {
+ unsigned Bits; // Where to store the bits...
- template<class T>
- static unsigned Bit(const T &V) {
+ template <class T> static unsigned Bit(const T &V) {
unsigned BitPos = (unsigned)V;
assert(BitPos < sizeof(unsigned) * CHAR_BIT &&
- "enum exceeds width of bit vector!");
+ "enum exceeds width of bit vector!");
return 1 << BitPos;
}
public:
- template<class T>
- void addValue(const T &V) {
- Bits |= Bit(V);
- }
+ template <class T> void addValue(const T &V) { Bits |= Bit(V); }
unsigned getBits() { return Bits; }
- template<class T>
- bool isSet(const T &V) {
- return (Bits & Bit(V)) != 0;
- }
+ template <class T> bool isSet(const T &V) { return (Bits & Bit(V)) != 0; }
};
-
//===----------------------------------------------------------------------===//
// bits - A bit vector of command options.
//
template <class DataType, class Storage = bool,
- class ParserClass = parser<DataType> >
+ class ParserClass = parser<DataType>>
class bits : public Option, public bits_storage<DataType, Storage> {
std::vector<unsigned> Positions;
ParserClass Parser;
@@ -1536,16 +1550,17 @@ class bits : public Option, public bits_
enum ValueExpected getValueExpectedFlagDefault() const override {
return Parser.getValueExpectedFlagDefault();
}
- void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) override {
+ void
+ getExtraOptionNames(SmallVectorImpl<const char *> &OptionNames) override {
return Parser.getExtraOptionNames(OptionNames);
}
bool handleOccurrence(unsigned pos, StringRef ArgName,
StringRef Arg) override {
typename ParserClass::parser_data_type Val =
- typename ParserClass::parser_data_type();
+ typename ParserClass::parser_data_type();
if (Parser.parse(*this, ArgName, Arg, Val))
- return true; // Parse Error!
+ return true; // Parse Error!
this->addValue(Val);
setPosition(pos);
Positions.push_back(pos);
@@ -1553,19 +1568,22 @@ class bits : public Option, public bits_
}
// Forward printing stuff to the parser...
- size_t getOptionWidth() const override {return Parser.getOptionWidth(*this);}
+ size_t getOptionWidth() const override {
+ return Parser.getOptionWidth(*this);
+ }
void printOptionInfo(size_t GlobalWidth) const override {
Parser.printOptionInfo(*this, GlobalWidth);
}
// Unimplemented: bits options don't currently store their default values.
- void printOptionValue(size_t /*GlobalWidth*/,
- bool /*Force*/) const override {}
+ void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
+ }
void done() {
addArgument();
Parser.initialize(*this);
}
+
public:
ParserClass &getParser() { return Parser; }
@@ -1575,66 +1593,93 @@ public:
}
// One option...
- template<class M0t>
- explicit bits(const M0t &M0) : Option(ZeroOrMore, NotHidden) {
+ template <class M0t>
+ explicit bits(const M0t &M0)
+ : Option(ZeroOrMore, NotHidden) {
apply(M0, this);
done();
}
// Two options...
- template<class M0t, class M1t>
- bits(const M0t &M0, const M1t &M1) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this);
+ template <class M0t, class M1t>
+ bits(const M0t &M0, const M1t &M1)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
done();
}
// Three options...
- template<class M0t, class M1t, class M2t>
+ template <class M0t, class M1t, class M2t>
bits(const M0t &M0, const M1t &M1, const M2t &M2)
- : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this);
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
done();
}
// Four options...
- template<class M0t, class M1t, class M2t, class M3t>
+ template <class M0t, class M1t, class M2t, class M3t>
bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
- : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
done();
}
// Five options...
- template<class M0t, class M1t, class M2t, class M3t, class M4t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t>
bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ const M4t &M4)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
apply(M4, this);
done();
}
// Six options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t>
bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this);
+ const M4t &M4, const M5t &M5)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
done();
}
// Seven options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t, class M6t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t,
+ class M6t>
bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
const M4t &M4, const M5t &M5, const M6t &M6)
- : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this); apply(M6, this);
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
+ apply(M6, this);
done();
}
// Eight options...
- template<class M0t, class M1t, class M2t, class M3t,
- class M4t, class M5t, class M6t, class M7t>
+ template <class M0t, class M1t, class M2t, class M3t, class M4t, class M5t,
+ class M6t, class M7t>
bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3,
- const M4t &M4, const M5t &M5, const M6t &M6,
- const M7t &M7) : Option(ZeroOrMore, NotHidden) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
- apply(M4, this); apply(M5, this); apply(M6, this); apply(M7, this);
+ const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7)
+ : Option(ZeroOrMore, NotHidden) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
+ apply(M4, this);
+ apply(M5, this);
+ apply(M6, this);
+ apply(M7, this);
done();
}
};
@@ -1646,11 +1691,11 @@ public:
class alias : public Option {
Option *AliasFor;
bool handleOccurrence(unsigned pos, StringRef /*ArgName*/,
- StringRef Arg) override {
+ StringRef Arg) override {
return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
}
- bool addOccurrence(unsigned pos, StringRef /*ArgName*/,
- StringRef Value, bool MultiArg = false) override {
+ bool addOccurrence(unsigned pos, StringRef /*ArgName*/, StringRef Value,
+ bool MultiArg = false) override {
return AliasFor->addOccurrence(pos, AliasFor->ArgStr, Value, MultiArg);
}
// Handle printing stuff...
@@ -1658,8 +1703,8 @@ class alias : public Option {
void printOptionInfo(size_t GlobalWidth) const override;
// Aliases do not need to print their values.
- void printOptionValue(size_t /*GlobalWidth*/,
- bool /*Force*/) const override {}
+ void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const override {
+ }
ValueExpected getValueExpectedFlagDefault() const override {
return AliasFor->getValueExpectedFlag();
@@ -1670,8 +1715,9 @@ class alias : public Option {
error("cl::alias must have argument name specified!");
if (!AliasFor)
error("cl::alias must have an cl::aliasopt(option) specified!");
- addArgument();
+ addArgument();
}
+
public:
void setAliasFor(Option &O) {
if (AliasFor)
@@ -1680,30 +1726,37 @@ public:
}
// One option...
- template<class M0t>
- explicit alias(const M0t &M0) : Option(Optional, Hidden), AliasFor(nullptr) {
+ template <class M0t>
+ explicit alias(const M0t &M0)
+ : Option(Optional, Hidden), AliasFor(nullptr) {
apply(M0, this);
done();
}
// Two options...
- template<class M0t, class M1t>
+ template <class M0t, class M1t>
alias(const M0t &M0, const M1t &M1)
- : Option(Optional, Hidden), AliasFor(nullptr) {
- apply(M0, this); apply(M1, this);
+ : Option(Optional, Hidden), AliasFor(nullptr) {
+ apply(M0, this);
+ apply(M1, this);
done();
}
// Three options...
- template<class M0t, class M1t, class M2t>
+ template <class M0t, class M1t, class M2t>
alias(const M0t &M0, const M1t &M1, const M2t &M2)
- : Option(Optional, Hidden), AliasFor(nullptr) {
- apply(M0, this); apply(M1, this); apply(M2, this);
+ : Option(Optional, Hidden), AliasFor(nullptr) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
done();
}
// Four options...
- template<class M0t, class M1t, class M2t, class M3t>
+ template <class M0t, class M1t, class M2t, class M3t>
alias(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3)
- : Option(Optional, Hidden), AliasFor(nullptr) {
- apply(M0, this); apply(M1, this); apply(M2, this); apply(M3, this);
+ : Option(Optional, Hidden), AliasFor(nullptr) {
+ apply(M0, this);
+ apply(M1, this);
+ apply(M2, this);
+ apply(M3, this);
done();
}
};
@@ -1720,8 +1773,8 @@ struct aliasopt {
// printed to stderr at the end of the regular help, just before
// exit is called.
struct extrahelp {
- const char * morehelp;
- explicit extrahelp(const char* help);
+ const char *morehelp;
+ explicit extrahelp(const char *help);
};
void PrintVersionMessage();
@@ -1733,8 +1786,7 @@ void PrintVersionMessage();
///
/// \param Hidden if true will print hidden options
/// \param Categorized if true print options in categories
-void PrintHelpMessage(bool Hidden=false, bool Categorized=false);
-
+void PrintHelpMessage(bool Hidden = false, bool Categorized = false);
//===----------------------------------------------------------------------===//
// Public interface for accessing registered options.
@@ -1766,7 +1818,7 @@ void PrintHelpMessage(bool Hidden=false,
/// This interface is useful for modifying options in libraries that are out of
/// the control of the client. The options should be modified before calling
/// llvm::cl::ParseCommandLineOptions().
-void getRegisteredOptions(StringMap<Option*> &Map);
+void getRegisteredOptions(StringMap<Option *> &Map);
//===----------------------------------------------------------------------===//
// Standalone command line processing utilities.
@@ -1776,9 +1828,10 @@ void getRegisteredOptions(StringMap<Opti
/// raw character pointer.
class StringSaver {
virtual void anchor();
+
public:
virtual const char *SaveString(const char *Str) = 0;
- virtual ~StringSaver() {}; // Pacify -Wnon-virtual-dtor.
+ virtual ~StringSaver(){}; // Pacify -Wnon-virtual-dtor.
};
/// \brief Tokenizes a command line that can contain escapes and quotes.
Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=225817&r1=225816&r2=225817&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Tue Jan 13 13:14:20 2015
@@ -44,7 +44,8 @@ using namespace cl;
//===----------------------------------------------------------------------===//
// Template instantiations and anchors.
//
-namespace llvm { namespace cl {
+namespace llvm {
+namespace cl {
TEMPLATE_INSTANTIATION(class basic_parser<bool>);
TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
TEMPLATE_INSTANTIATION(class basic_parser<int>);
@@ -60,7 +61,8 @@ TEMPLATE_INSTANTIATION(class opt<int>);
TEMPLATE_INSTANTIATION(class opt<std::string>);
TEMPLATE_INSTANTIATION(class opt<char>);
TEMPLATE_INSTANTIATION(class opt<bool>);
-} } // end namespace llvm::cl
+}
+} // end namespace llvm::cl
// Pin the vtables to this file.
void GenericOptionValue::anchor() {}
@@ -87,19 +89,16 @@ static char ProgramName[80] = "<premain>
static const char *ProgramOverview = nullptr;
// This collects additional help to be printed.
-static ManagedStatic<std::vector<const char*> > MoreHelp;
+static ManagedStatic<std::vector<const char *>> MoreHelp;
-extrahelp::extrahelp(const char *Help)
- : morehelp(Help) {
+extrahelp::extrahelp(const char *Help) : morehelp(Help) {
MoreHelp->push_back(Help);
}
static bool OptionListChanged = false;
// MarkOptionsChanged - Internal helper function.
-void cl::MarkOptionsChanged() {
- OptionListChanged = true;
-}
+void cl::MarkOptionsChanged() { OptionListChanged = true; }
/// RegisteredOptionList - This is the list of the command line options that
/// have statically constructed themselves.
@@ -127,7 +126,7 @@ void Option::removeArgument() {
}
// This collects the different option categories that have been registered.
-typedef SmallPtrSet<OptionCategory*,16> OptionCatSet;
+typedef SmallPtrSet<OptionCategory *, 16> OptionCatSet;
static ManagedStatic<OptionCatSet> RegisteredOptionCategories;
// Initialise the general option category.
@@ -138,7 +137,8 @@ void OptionCategory::registerCategory()
RegisteredOptionCategories->end(),
[this](const OptionCategory *Category) {
return getName() == Category->getName();
- }) == 0 && "Duplicate option categories");
+ }) == 0 &&
+ "Duplicate option categories");
RegisteredOptionCategories->insert(this);
}
@@ -149,12 +149,12 @@ void OptionCategory::registerCategory()
/// GetOptionInfo - Scan the list of registered options, turning them into data
/// structures that are easier to handle.
-static void GetOptionInfo(SmallVectorImpl<Option*> &PositionalOpts,
- SmallVectorImpl<Option*> &SinkOpts,
- StringMap<Option*> &OptionsMap) {
+static void GetOptionInfo(SmallVectorImpl<Option *> &PositionalOpts,
+ SmallVectorImpl<Option *> &SinkOpts,
+ StringMap<Option *> &OptionsMap) {
bool HadErrors = false;
- SmallVector<const char*, 16> OptionNames;
- Option *CAOpt = nullptr; // The ConsumeAfter option if it exists.
+ SmallVector<const char *, 16> OptionNames;
+ Option *CAOpt = nullptr; // The ConsumeAfter option if it exists.
for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) {
// If this option wants to handle multiple option names, get the full set.
// This handles enum options like "-O1 -O2" etc.
@@ -201,31 +201,32 @@ static void GetOptionInfo(SmallVectorImp
report_fatal_error("inconsistency in registered CommandLine options");
}
-
/// LookupOption - Lookup the option specified by the specified option on the
/// command line. If there is a value specified (after an equal sign) return
/// that as well. This assumes that leading dashes have already been stripped.
static Option *LookupOption(StringRef &Arg, StringRef &Value,
- const StringMap<Option*> &OptionsMap) {
+ const StringMap<Option *> &OptionsMap) {
// Reject all dashes.
- if (Arg.empty()) return nullptr;
+ if (Arg.empty())
+ return nullptr;
size_t EqualPos = Arg.find('=');
// If we have an equals sign, remember the value.
if (EqualPos == StringRef::npos) {
// Look up the option.
- StringMap<Option*>::const_iterator I = OptionsMap.find(Arg);
+ StringMap<Option *>::const_iterator I = OptionsMap.find(Arg);
return I != OptionsMap.end() ? I->second : nullptr;
}
// If the argument before the = is a valid option name, we match. If not,
// return Arg unmolested.
- StringMap<Option*>::const_iterator I =
- OptionsMap.find(Arg.substr(0, EqualPos));
- if (I == OptionsMap.end()) return nullptr;
+ StringMap<Option *>::const_iterator I =
+ OptionsMap.find(Arg.substr(0, EqualPos));
+ if (I == OptionsMap.end())
+ return nullptr;
- Value = Arg.substr(EqualPos+1);
+ Value = Arg.substr(EqualPos + 1);
Arg = Arg.substr(0, EqualPos);
return I->second;
}
@@ -235,23 +236,25 @@ static Option *LookupOption(StringRef &A
/// (after an equal sign) return that as well. This assumes that leading dashes
/// have already been stripped.
static Option *LookupNearestOption(StringRef Arg,
- const StringMap<Option*> &OptionsMap,
+ const StringMap<Option *> &OptionsMap,
std::string &NearestString) {
// Reject all dashes.
- if (Arg.empty()) return nullptr;
+ if (Arg.empty())
+ return nullptr;
// Split on any equal sign.
std::pair<StringRef, StringRef> SplitArg = Arg.split('=');
- StringRef &LHS = SplitArg.first; // LHS == Arg when no '=' is present.
+ StringRef &LHS = SplitArg.first; // LHS == Arg when no '=' is present.
StringRef &RHS = SplitArg.second;
// Find the closest match.
Option *Best = nullptr;
unsigned BestDistance = 0;
- for (StringMap<Option*>::const_iterator it = OptionsMap.begin(),
- ie = OptionsMap.end(); it != ie; ++it) {
+ for (StringMap<Option *>::const_iterator it = OptionsMap.begin(),
+ ie = OptionsMap.end();
+ it != ie; ++it) {
Option *O = it->second;
- SmallVector<const char*, 16> OptionNames;
+ SmallVector<const char *, 16> OptionNames;
O->getExtraOptionNames(OptionNames);
if (O->ArgStr[0])
OptionNames.push_back(O->ArgStr);
@@ -261,7 +264,7 @@ static Option *LookupNearestOption(Strin
for (size_t i = 0, e = OptionNames.size(); i != e; ++i) {
StringRef Name = OptionNames[i];
unsigned Distance = StringRef(Name).edit_distance(
- Flag, /*AllowReplacements=*/true, /*MaxEditDistance=*/BestDistance);
+ Flag, /*AllowReplacements=*/true, /*MaxEditDistance=*/BestDistance);
if (!Best || Distance < BestDistance) {
Best = O;
BestDistance = Distance;
@@ -292,8 +295,8 @@ static bool CommaSeparateAndAddOccurrenc
if (Handler->addOccurrence(pos, ArgName, Val.substr(0, Pos), MultiArg))
return true;
// Erase the portion before the comma, AND the comma.
- Val = Val.substr(Pos+1);
- Value.substr(Pos+1); // Increment the original value pointer as well.
+ Val = Val.substr(Pos + 1);
+ Value.substr(Pos + 1); // Increment the original value pointer as well.
// Check for another comma.
Pos = Val.find(',');
}
@@ -320,7 +323,7 @@ static inline bool ProvideOption(Option
switch (Handler->getValueExpectedFlag()) {
case ValueRequired:
if (!Value.data()) { // No value specified?
- if (i+1 >= argc)
+ if (i + 1 >= argc)
return Handler->error("requires a value!");
// Steal the next argument, like for '-o filename'
assert(argv && "null check");
@@ -333,8 +336,8 @@ static inline bool ProvideOption(Option
" with ValueDisallowed modifier!");
if (Value.data())
- return Handler->error("does not allow a value! '" +
- Twine(Value) + "' specified.");
+ return Handler->error("does not allow a value! '" + Twine(Value) +
+ "' specified.");
break;
case ValueOptional:
break;
@@ -355,7 +358,7 @@ static inline bool ProvideOption(Option
}
while (NumAdditionalVals > 0) {
- if (i+1 >= argc)
+ if (i + 1 >= argc)
return Handler->error("not enough values!");
assert(argv && "null check");
Value = argv[++i];
@@ -373,7 +376,6 @@ static bool ProvidePositionalOption(Opti
return ProvideOption(Handler, Handler->ArgStr, Arg, 0, nullptr, Dummy);
}
-
// Option predicates...
static inline bool isGrouping(const Option *O) {
return O->getFormattingFlag() == cl::Grouping;
@@ -389,39 +391,42 @@ static inline bool isPrefixedOrGrouping(
// otherwise return null.
//
static Option *getOptionPred(StringRef Name, size_t &Length,
- bool (*Pred)(const Option*),
- const StringMap<Option*> &OptionsMap) {
+ bool (*Pred)(const Option *),
+ const StringMap<Option *> &OptionsMap) {
- StringMap<Option*>::const_iterator OMI = OptionsMap.find(Name);
+ StringMap<Option *>::const_iterator OMI = OptionsMap.find(Name);
// Loop while we haven't found an option and Name still has at least two
// characters in it (so that the next iteration will not be the empty
// string.
while (OMI == OptionsMap.end() && Name.size() > 1) {
- Name = Name.substr(0, Name.size()-1); // Chop off the last character.
+ Name = Name.substr(0, Name.size() - 1); // Chop off the last character.
OMI = OptionsMap.find(Name);
}
if (OMI != OptionsMap.end() && Pred(OMI->second)) {
Length = Name.size();
- return OMI->second; // Found one!
+ return OMI->second; // Found one!
}
- return nullptr; // No option found!
+ return nullptr; // No option found!
}
/// HandlePrefixedOrGroupedOption - The specified argument string (which started
/// with at least one '-') does not fully match an available option. Check to
/// see if this is a prefix or grouped option. If so, split arg into output an
/// Arg/Value pair and return the Option to parse it with.
-static Option *HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value,
- bool &ErrorParsing,
- const StringMap<Option*> &OptionsMap) {
- if (Arg.size() == 1) return nullptr;
+static Option *
+HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value,
+ bool &ErrorParsing,
+ const StringMap<Option *> &OptionsMap) {
+ if (Arg.size() == 1)
+ return nullptr;
// Do the lookup!
size_t Length = 0;
Option *PGOpt = getOptionPred(Arg, Length, isPrefixedOrGrouping, OptionsMap);
- if (!PGOpt) return nullptr;
+ if (!PGOpt)
+ return nullptr;
// If the option is a prefixed option, then the value is simply the
// rest of the name... so fall through to later processing, by
@@ -447,8 +452,8 @@ static Option *HandlePrefixedOrGroupedOp
assert(PGOpt->getValueExpectedFlag() != cl::ValueRequired &&
"Option can not be cl::Grouping AND cl::ValueRequired!");
int Dummy = 0;
- ErrorParsing |= ProvideOption(PGOpt, OneArgName,
- StringRef(), 0, nullptr, Dummy);
+ ErrorParsing |=
+ ProvideOption(PGOpt, OneArgName, StringRef(), 0, nullptr, Dummy);
// Get the next grouping option.
PGOpt = getOptionPred(Arg, Length, isGrouping, OptionsMap);
@@ -458,8 +463,6 @@ static Option *HandlePrefixedOrGroupedOp
return PGOpt;
}
-
-
static bool RequiresValue(const Option *O) {
return O->getNumOccurrencesFlag() == cl::Required ||
O->getNumOccurrencesFlag() == cl::OneOrMore;
@@ -470,17 +473,11 @@ static bool EatsUnboundedNumberOfValues(
O->getNumOccurrencesFlag() == cl::OneOrMore;
}
-static bool isWhitespace(char C) {
- return strchr(" \t\n\r\f\v", C);
-}
+static bool isWhitespace(char C) { return strchr(" \t\n\r\f\v", C); }
-static bool isQuote(char C) {
- return C == '\"' || C == '\'';
-}
+static bool isQuote(char C) { return C == '\"' || C == '\''; }
-static bool isGNUSpecial(char C) {
- return strchr("\\\"\' ", C);
-}
+static bool isGNUSpecial(char C) { return strchr("\\\"\' ", C); }
void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver,
SmallVectorImpl<const char *> &NewArgv,
@@ -495,13 +492,14 @@ void cl::TokenizeGNUCommandLine(StringRe
NewArgv.push_back(nullptr);
++I;
}
- if (I == E) break;
+ if (I == E)
+ break;
}
// Backslashes can escape backslashes, spaces, and other quotes. Otherwise
// they are literal. This makes it much easier to read Windows file paths.
if (I + 1 < E && Src[I] == '\\' && isGNUSpecial(Src[I + 1])) {
- ++I; // Skip the escape.
+ ++I; // Skip the escape.
Token.push_back(Src[I]);
continue;
}
@@ -516,7 +514,8 @@ void cl::TokenizeGNUCommandLine(StringRe
Token.push_back(Src[I]);
++I;
}
- if (I == E) break;
+ if (I == E)
+ break;
continue;
}
@@ -691,7 +690,7 @@ bool cl::ExpandResponseFiles(StringSaver
bool AllExpanded = true;
// Don't cache Argv.size() because it can change.
- for (unsigned I = 0; I != Argv.size(); ) {
+ for (unsigned I = 0; I != Argv.size();) {
const char *Arg = Argv[I];
// Check if it is an EOL marker
if (Arg == nullptr) {
@@ -728,22 +727,23 @@ bool cl::ExpandResponseFiles(StringSaver
}
namespace {
- class StrDupSaver : public StringSaver {
- std::vector<char*> Dups;
- public:
- ~StrDupSaver() {
- for (std::vector<char *>::iterator I = Dups.begin(), E = Dups.end();
- I != E; ++I) {
- char *Dup = *I;
- free(Dup);
- }
- }
- const char *SaveString(const char *Str) override {
- char *Dup = strdup(Str);
- Dups.push_back(Dup);
- return Dup;
+class StrDupSaver : public StringSaver {
+ std::vector<char *> Dups;
+
+public:
+ ~StrDupSaver() {
+ for (std::vector<char *>::iterator I = Dups.begin(), E = Dups.end(); I != E;
+ ++I) {
+ char *Dup = *I;
+ free(Dup);
}
- };
+ }
+ const char *SaveString(const char *Str) override {
+ char *Dup = strdup(Str);
+ Dups.push_back(Dup);
+ return Dup;
+ }
+};
}
/// ParseEnvironmentOptions - An alternative entry point to the
@@ -775,16 +775,15 @@ void cl::ParseEnvironmentOptions(const c
ParseCommandLineOptions(newArgc, &newArgv[0], Overview);
}
-void cl::ParseCommandLineOptions(int argc, const char * const *argv,
+void cl::ParseCommandLineOptions(int argc, const char *const *argv,
const char *Overview) {
// Process all registered options.
- SmallVector<Option*, 4> PositionalOpts;
- SmallVector<Option*, 4> SinkOpts;
- StringMap<Option*> Opts;
+ SmallVector<Option *, 4> PositionalOpts;
+ SmallVector<Option *, 4> SinkOpts;
+ StringMap<Option *> Opts;
GetOptionInfo(PositionalOpts, SinkOpts, Opts);
- assert((!Opts.empty() || !PositionalOpts.empty()) &&
- "No options specified!");
+ assert((!Opts.empty() || !PositionalOpts.empty()) && "No options specified!");
// Expand response files.
SmallVector<const char *, 20> newArgv;
@@ -820,8 +819,8 @@ void cl::ParseCommandLineOptions(int arg
// Calculate how many positional values are _required_.
bool UnboundedFound = false;
- for (size_t i = ConsumeAfterOpt ? 1 : 0, e = PositionalOpts.size();
- i != e; ++i) {
+ for (size_t i = ConsumeAfterOpt ? 1 : 0, e = PositionalOpts.size(); i != e;
+ ++i) {
Option *Opt = PositionalOpts[i];
if (RequiresValue(Opt))
++NumPositionalRequired;
@@ -829,10 +828,10 @@ void cl::ParseCommandLineOptions(int arg
// ConsumeAfter cannot be combined with "optional" positional options
// unless there is only one positional argument...
if (PositionalOpts.size() > 2)
- ErrorParsing |=
- Opt->error("error - this positional option will never be matched, "
- "because it does not Require a value, and a "
- "cl::ConsumeAfter option is active!");
+ ErrorParsing |= Opt->error(
+ "error - this positional option will never be matched, "
+ "because it does not Require a value, and a "
+ "cl::ConsumeAfter option is active!");
} else if (UnboundedFound && !Opt->ArgStr[0]) {
// This option does not "require" a value... Make sure this option is
// not specified after an option that eats all extra arguments, or this
@@ -851,7 +850,7 @@ void cl::ParseCommandLineOptions(int arg
// PositionalVals - A vector of "positional" arguments we accumulate into
// the process at the end.
//
- SmallVector<std::pair<StringRef,unsigned>, 4> PositionalVals;
+ SmallVector<std::pair<StringRef, unsigned>, 4> PositionalVals;
// If the program has named positional arguments, and the name has been run
// across, keep track of which positional argument was named. Otherwise put
@@ -859,7 +858,7 @@ void cl::ParseCommandLineOptions(int arg
Option *ActivePositionalArg = nullptr;
// Loop over all of the arguments... processing them.
- bool DashDashFound = false; // Have we read '--'?
+ bool DashDashFound = false; // Have we read '--'?
for (int i = 1; i < argc; ++i) {
Option *Handler = nullptr;
Option *NearestHandler = nullptr;
@@ -886,19 +885,19 @@ void cl::ParseCommandLineOptions(int arg
// Positional argument!
if (ActivePositionalArg) {
ProvidePositionalOption(ActivePositionalArg, argv[i], i);
- continue; // We are done!
+ continue; // We are done!
}
if (!PositionalOpts.empty()) {
- PositionalVals.push_back(std::make_pair(argv[i],i));
+ PositionalVals.push_back(std::make_pair(argv[i], i));
// All of the positional arguments have been fulfulled, give the rest to
// the consume after option... if it's specified...
//
if (PositionalVals.size() >= NumPositionalRequired && ConsumeAfterOpt) {
for (++i; i < argc; ++i)
- PositionalVals.push_back(std::make_pair(argv[i],i));
- break; // Handle outside of the argument processing loop...
+ PositionalVals.push_back(std::make_pair(argv[i], i));
+ break; // Handle outside of the argument processing loop...
}
// Delay processing positional arguments until the end...
@@ -906,14 +905,14 @@ void cl::ParseCommandLineOptions(int arg
}
} else if (argv[i][0] == '-' && argv[i][1] == '-' && argv[i][2] == 0 &&
!DashDashFound) {
- DashDashFound = true; // This is the mythical "--"?
- continue; // Don't try to process it as an argument itself.
+ DashDashFound = true; // This is the mythical "--"?
+ continue; // Don't try to process it as an argument itself.
} else if (ActivePositionalArg &&
(ActivePositionalArg->getMiscFlags() & PositionalEatsArgs)) {
// If there is a positional argument eating options, check to see if this
// option is another positional argument. If so, treat it as an argument,
// otherwise feed it to the eating positional.
- ArgName = argv[i]+1;
+ ArgName = argv[i] + 1;
// Eat leading dashes.
while (!ArgName.empty() && ArgName[0] == '-')
ArgName = ArgName.substr(1);
@@ -921,11 +920,11 @@ void cl::ParseCommandLineOptions(int arg
Handler = LookupOption(ArgName, Value, Opts);
if (!Handler || Handler->getFormattingFlag() != cl::Positional) {
ProvidePositionalOption(ActivePositionalArg, argv[i], i);
- continue; // We are done!
+ continue; // We are done!
}
- } else { // We start with a '-', must be an argument.
- ArgName = argv[i]+1;
+ } else { // We start with a '-', must be an argument.
+ ArgName = argv[i] + 1;
// Eat leading dashes.
while (!ArgName.empty() && ArgName[0] == '-')
ArgName = ArgName.substr(1);
@@ -934,31 +933,32 @@ void cl::ParseCommandLineOptions(int arg
// Check to see if this "option" is really a prefixed or grouped argument.
if (!Handler)
- Handler = HandlePrefixedOrGroupedOption(ArgName, Value,
- ErrorParsing, Opts);
+ Handler =
+ HandlePrefixedOrGroupedOption(ArgName, Value, ErrorParsing, Opts);
// Otherwise, look for the closest available option to report to the user
// in the upcoming error.
if (!Handler && SinkOpts.empty())
- NearestHandler = LookupNearestOption(ArgName, Opts,
- NearestHandlerString);
+ NearestHandler =
+ LookupNearestOption(ArgName, Opts, NearestHandlerString);
}
if (!Handler) {
if (SinkOpts.empty()) {
- errs() << ProgramName << ": Unknown command line argument '"
- << argv[i] << "'. Try: '" << argv[0] << " -help'\n";
+ errs() << ProgramName << ": Unknown command line argument '" << argv[i]
+ << "'. Try: '" << argv[0] << " -help'\n";
if (NearestHandler) {
// If we know a near match, report it as well.
- errs() << ProgramName << ": Did you mean '-"
- << NearestHandlerString << "'?\n";
+ errs() << ProgramName << ": Did you mean '-" << NearestHandlerString
+ << "'?\n";
}
ErrorParsing = true;
} else {
- for (SmallVectorImpl<Option*>::iterator I = SinkOpts.begin(),
- E = SinkOpts.end(); I != E ; ++I)
+ for (SmallVectorImpl<Option *>::iterator I = SinkOpts.begin(),
+ E = SinkOpts.end();
+ I != E; ++I)
(*I)->addOccurrence(i, "", argv[i]);
}
continue;
@@ -975,17 +975,16 @@ void cl::ParseCommandLineOptions(int arg
// Check and handle positional arguments now...
if (NumPositionalRequired > PositionalVals.size()) {
errs() << ProgramName
- << ": Not enough positional command line arguments specified!\n"
- << "Must specify at least " << NumPositionalRequired
- << " positional arguments: See: " << argv[0] << " -help\n";
+ << ": Not enough positional command line arguments specified!\n"
+ << "Must specify at least " << NumPositionalRequired
+ << " positional arguments: See: " << argv[0] << " -help\n";
ErrorParsing = true;
} else if (!HasUnlimitedPositionals &&
PositionalVals.size() > PositionalOpts.size()) {
- errs() << ProgramName
- << ": Too many positional arguments specified!\n"
- << "Can specify at most " << PositionalOpts.size()
- << " positional arguments: See: " << argv[0] << " -help\n";
+ errs() << ProgramName << ": Too many positional arguments specified!\n"
+ << "Can specify at most " << PositionalOpts.size()
+ << " positional arguments: See: " << argv[0] << " -help\n";
ErrorParsing = true;
} else if (!ConsumeAfterOpt) {
@@ -996,7 +995,7 @@ void cl::ParseCommandLineOptions(int arg
ProvidePositionalOption(PositionalOpts[i], PositionalVals[ValNo].first,
PositionalVals[ValNo].second);
ValNo++;
- --NumPositionalRequired; // We fulfilled our duty...
+ --NumPositionalRequired; // We fulfilled our duty...
}
// If we _can_ give this option more arguments, do so now, as long as we
@@ -1004,13 +1003,13 @@ void cl::ParseCommandLineOptions(int arg
// option even _WANTS_ any more.
//
bool Done = PositionalOpts[i]->getNumOccurrencesFlag() == cl::Required;
- while (NumVals-ValNo > NumPositionalRequired && !Done) {
+ while (NumVals - ValNo > NumPositionalRequired && !Done) {
switch (PositionalOpts[i]->getNumOccurrencesFlag()) {
case cl::Optional:
- Done = true; // Optional arguments want _at most_ one value
- // FALL THROUGH
- case cl::ZeroOrMore: // Zero or more will take all they can get...
- case cl::OneOrMore: // One or more will take all they can get...
+ Done = true; // Optional arguments want _at most_ one value
+ // FALL THROUGH
+ case cl::ZeroOrMore: // Zero or more will take all they can get...
+ case cl::OneOrMore: // One or more will take all they can get...
ProvidePositionalOption(PositionalOpts[i],
PositionalVals[ValNo].first,
PositionalVals[ValNo].second);
@@ -1018,7 +1017,7 @@ void cl::ParseCommandLineOptions(int arg
break;
default:
llvm_unreachable("Internal error, unexpected NumOccurrences flag in "
- "positional argument processing!");
+ "positional argument processing!");
}
}
}
@@ -1048,9 +1047,9 @@ void cl::ParseCommandLineOptions(int arg
// Handle over all of the rest of the arguments to the
// cl::ConsumeAfter command line option...
for (; ValNo != PositionalVals.size(); ++ValNo)
- ErrorParsing |= ProvidePositionalOption(ConsumeAfterOpt,
- PositionalVals[ValNo].first,
- PositionalVals[ValNo].second);
+ ErrorParsing |=
+ ProvidePositionalOption(ConsumeAfterOpt, PositionalVals[ValNo].first,
+ PositionalVals[ValNo].second);
}
// Loop over args and make sure all required args are specified!
@@ -1062,7 +1061,7 @@ void cl::ParseCommandLineOptions(int arg
Opt.second->error("must be specified at least once!");
ErrorParsing = true;
}
- // Fall through
+ // Fall through
default:
break;
}
@@ -1072,10 +1071,8 @@ void cl::ParseCommandLineOptions(int arg
// Note that if ReadResponseFiles == true, this must be done before the
// memory allocated for the expanded command line is free()d below.
DEBUG(dbgs() << "Args: ";
- for (int i = 0; i < argc; ++i)
- dbgs() << argv[i] << ' ';
- dbgs() << '\n';
- );
+ for (int i = 0; i < argc; ++i) dbgs() << argv[i] << ' ';
+ dbgs() << '\n';);
// Free all of the memory allocated to the map. Command line options may only
// be processed once!
@@ -1084,7 +1081,8 @@ void cl::ParseCommandLineOptions(int arg
MoreHelp->clear();
// If we had an error processing our arguments, don't let the program execute
- if (ErrorParsing) exit(1);
+ if (ErrorParsing)
+ exit(1);
}
//===----------------------------------------------------------------------===//
@@ -1092,9 +1090,10 @@ void cl::ParseCommandLineOptions(int arg
//
bool Option::error(const Twine &Message, StringRef ArgName) {
- if (!ArgName.data()) ArgName = ArgStr;
+ if (!ArgName.data())
+ ArgName = ArgStr;
if (ArgName.empty())
- errs() << HelpStr; // Be nice for positional arguments
+ errs() << HelpStr; // Be nice for positional arguments
else
errs() << ProgramName << ": for the -" << ArgName;
@@ -1102,10 +1101,10 @@ bool Option::error(const Twine &Message,
return true;
}
-bool Option::addOccurrence(unsigned pos, StringRef ArgName,
- StringRef Value, bool MultiArg) {
+bool Option::addOccurrence(unsigned pos, StringRef ArgName, StringRef Value,
+ bool MultiArg) {
if (!MultiArg)
- NumOccurrences++; // Increment the number of times we have been seen
+ NumOccurrences++; // Increment the number of times we have been seen
switch (getNumOccurrencesFlag()) {
case Optional:
@@ -1115,21 +1114,22 @@ bool Option::addOccurrence(unsigned pos,
case Required:
if (NumOccurrences > 1)
return error("must occur exactly one time!", ArgName);
- // Fall through
+ // Fall through
case OneOrMore:
case ZeroOrMore:
- case ConsumeAfter: break;
+ case ConsumeAfter:
+ break;
}
return handleOccurrence(pos, ArgName, Value);
}
-
// getValueStr - Get the value description string, using "DefaultMsg" if nothing
// has been specified yet.
//
static const char *getValueStr(const Option &O, const char *DefaultMsg) {
- if (O.ValueStr[0] == 0) return DefaultMsg;
+ if (O.ValueStr[0] == 0)
+ return DefaultMsg;
return O.ValueStr;
}
@@ -1138,9 +1138,7 @@ static const char *getValueStr(const Opt
//
// Return the width of the option tag for printing...
-size_t alias::getOptionWidth() const {
- return std::strlen(ArgStr)+6;
-}
+size_t alias::getOptionWidth() const { return std::strlen(ArgStr) + 6; }
static void printHelpStr(StringRef HelpStr, size_t Indent,
size_t FirstLineIndentedBy) {
@@ -1169,7 +1167,7 @@ void alias::printOptionInfo(size_t Globa
size_t basic_parser_impl::getOptionWidth(const Option &O) const {
size_t Len = std::strlen(O.ArgStr);
if (const char *ValName = getValueName())
- Len += std::strlen(getValueStr(O, ValName))+3;
+ Len += std::strlen(getValueStr(O, ValName)) + 3;
return Len + 6;
}
@@ -1190,14 +1188,13 @@ void basic_parser_impl::printOptionInfo(
void basic_parser_impl::printOptionName(const Option &O,
size_t GlobalWidth) const {
outs() << " -" << O.ArgStr;
- outs().indent(GlobalWidth-std::strlen(O.ArgStr));
+ outs().indent(GlobalWidth - std::strlen(O.ArgStr));
}
-
// parser<bool> implementation
//
-bool parser<bool>::parse(Option &O, StringRef ArgName,
- StringRef Arg, bool &Value) {
+bool parser<bool>::parse(Option &O, StringRef ArgName, StringRef Arg,
+ bool &Value) {
if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
Arg == "1") {
Value = true;
@@ -1214,8 +1211,8 @@ bool parser<bool>::parse(Option &O, Stri
// parser<boolOrDefault> implementation
//
-bool parser<boolOrDefault>::parse(Option &O, StringRef ArgName,
- StringRef Arg, boolOrDefault &Value) {
+bool parser<boolOrDefault>::parse(Option &O, StringRef ArgName, StringRef Arg,
+ boolOrDefault &Value) {
if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
Arg == "1") {
Value = BOU_TRUE;
@@ -1232,8 +1229,8 @@ bool parser<boolOrDefault>::parse(Option
// parser<int> implementation
//
-bool parser<int>::parse(Option &O, StringRef ArgName,
- StringRef Arg, int &Value) {
+bool parser<int>::parse(Option &O, StringRef ArgName, StringRef Arg,
+ int &Value) {
if (Arg.getAsInteger(0, Value))
return O.error("'" + Arg + "' value invalid for integer argument!");
return false;
@@ -1241,8 +1238,8 @@ bool parser<int>::parse(Option &O, Strin
// parser<unsigned> implementation
//
-bool parser<unsigned>::parse(Option &O, StringRef ArgName,
- StringRef Arg, unsigned &Value) {
+bool parser<unsigned>::parse(Option &O, StringRef ArgName, StringRef Arg,
+ unsigned &Value) {
if (Arg.getAsInteger(0, Value))
return O.error("'" + Arg + "' value invalid for uint argument!");
@@ -1252,7 +1249,8 @@ bool parser<unsigned>::parse(Option &O,
// parser<unsigned long long> implementation
//
bool parser<unsigned long long>::parse(Option &O, StringRef ArgName,
- StringRef Arg, unsigned long long &Value){
+ StringRef Arg,
+ unsigned long long &Value) {
if (Arg.getAsInteger(0, Value))
return O.error("'" + Arg + "' value invalid for uint argument!");
@@ -1271,13 +1269,13 @@ static bool parseDouble(Option &O, Strin
return false;
}
-bool parser<double>::parse(Option &O, StringRef ArgName,
- StringRef Arg, double &Val) {
+bool parser<double>::parse(Option &O, StringRef ArgName, StringRef Arg,
+ double &Val) {
return parseDouble(O, Arg, Val);
}
-bool parser<float>::parse(Option &O, StringRef ArgName,
- StringRef Arg, float &Val) {
+bool parser<float>::parse(Option &O, StringRef ArgName, StringRef Arg,
+ float &Val) {
double dVal;
if (parseDouble(O, Arg, dVal))
return true;
@@ -1285,8 +1283,6 @@ bool parser<float>::parse(Option &O, Str
return false;
}
-
-
// generic_parser_base implementation
//
@@ -1303,18 +1299,17 @@ unsigned generic_parser_base::findOption
return e;
}
-
// Return the width of the option tag for printing...
size_t generic_parser_base::getOptionWidth(const Option &O) const {
if (O.hasArgStr()) {
- size_t Size = std::strlen(O.ArgStr)+6;
+ size_t Size = std::strlen(O.ArgStr) + 6;
for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
- Size = std::max(Size, std::strlen(getOption(i))+8);
+ Size = std::max(Size, std::strlen(getOption(i)) + 8);
return Size;
} else {
size_t BaseSize = 0;
for (unsigned i = 0, e = getNumOptions(); i != e; ++i)
- BaseSize = std::max(BaseSize, std::strlen(getOption(i))+8);
+ BaseSize = std::max(BaseSize, std::strlen(getOption(i)) + 8);
return BaseSize;
}
}
@@ -1329,7 +1324,7 @@ void generic_parser_base::printOptionInf
printHelpStr(O.HelpStr, GlobalWidth, std::strlen(O.ArgStr) + 6);
for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
- size_t NumSpaces = GlobalWidth-strlen(getOption(i))-8;
+ size_t NumSpaces = GlobalWidth - strlen(getOption(i)) - 8;
outs() << " =" << getOption(i);
outs().indent(NumSpaces) << " - " << getDescription(i) << '\n';
}
@@ -1349,12 +1344,11 @@ static const size_t MaxOptWidth = 8; //
// printGenericOptionDiff - Print the value of this option and it's default.
//
// "Generic" options have each value mapped to a name.
-void generic_parser_base::
-printGenericOptionDiff(const Option &O, const GenericOptionValue &Value,
- const GenericOptionValue &Default,
- size_t GlobalWidth) const {
+void generic_parser_base::printGenericOptionDiff(
+ const Option &O, const GenericOptionValue &Value,
+ const GenericOptionValue &Default, size_t GlobalWidth) const {
outs() << " -" << O.ArgStr;
- outs().indent(GlobalWidth-std::strlen(O.ArgStr));
+ outs().indent(GlobalWidth - std::strlen(O.ArgStr));
unsigned NumOpts = getNumOptions();
for (unsigned i = 0; i != NumOpts; ++i) {
@@ -1379,25 +1373,25 @@ printGenericOptionDiff(const Option &O,
// printOptionDiff - Specializations for printing basic value types.
//
-#define PRINT_OPT_DIFF(T) \
- void parser<T>:: \
- printOptionDiff(const Option &O, T V, OptionValue<T> D, \
- size_t GlobalWidth) const { \
- printOptionName(O, GlobalWidth); \
- std::string Str; \
- { \
- raw_string_ostream SS(Str); \
- SS << V; \
- } \
- outs() << "= " << Str; \
- size_t NumSpaces = MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0;\
- outs().indent(NumSpaces) << " (default: "; \
- if (D.hasValue()) \
- outs() << D.getValue(); \
- else \
- outs() << "*no default*"; \
- outs() << ")\n"; \
- } \
+#define PRINT_OPT_DIFF(T) \
+ void parser<T>::printOptionDiff(const Option &O, T V, OptionValue<T> D, \
+ size_t GlobalWidth) const { \
+ printOptionName(O, GlobalWidth); \
+ std::string Str; \
+ { \
+ raw_string_ostream SS(Str); \
+ SS << V; \
+ } \
+ outs() << "= " << Str; \
+ size_t NumSpaces = \
+ MaxOptWidth > Str.size() ? MaxOptWidth - Str.size() : 0; \
+ outs().indent(NumSpaces) << " (default: "; \
+ if (D.hasValue()) \
+ outs() << D.getValue(); \
+ else \
+ outs() << "*no default*"; \
+ outs() << ")\n"; \
+ }
PRINT_OPT_DIFF(bool)
PRINT_OPT_DIFF(boolOrDefault)
@@ -1408,9 +1402,9 @@ PRINT_OPT_DIFF(double)
PRINT_OPT_DIFF(float)
PRINT_OPT_DIFF(char)
-void parser<std::string>::
-printOptionDiff(const Option &O, StringRef V, OptionValue<std::string> D,
- size_t GlobalWidth) const {
+void parser<std::string>::printOptionDiff(const Option &O, StringRef V,
+ OptionValue<std::string> D,
+ size_t GlobalWidth) const {
printOptionName(O, GlobalWidth);
outs() << "= " << V;
size_t NumSpaces = MaxOptWidth > V.size() ? MaxOptWidth - V.size() : 0;
@@ -1423,8 +1417,8 @@ printOptionDiff(const Option &O, StringR
}
// Print a placeholder for options that don't yet support printOptionDiff().
-void basic_parser_impl::
-printOptionNoValue(const Option &O, size_t GlobalWidth) const {
+void basic_parser_impl::printOptionNoValue(const Option &O,
+ size_t GlobalWidth) const {
printOptionName(O, GlobalWidth);
outs() << "= *cannot print option value*\n";
}
@@ -1434,19 +1428,18 @@ printOptionNoValue(const Option &O, size
//
static int OptNameCompare(const void *LHS, const void *RHS) {
- typedef std::pair<const char *, Option*> pair_ty;
+ typedef std::pair<const char *, Option *> pair_ty;
- return strcmp(((const pair_ty*)LHS)->first, ((const pair_ty*)RHS)->first);
+ return strcmp(((const pair_ty *)LHS)->first, ((const pair_ty *)RHS)->first);
}
// Copy Options into a vector so we can sort them as we like.
-static void
-sortOpts(StringMap<Option*> &OptMap,
- SmallVectorImpl< std::pair<const char *, Option*> > &Opts,
- bool ShowHidden) {
- SmallPtrSet<Option*, 128> OptionSet; // Duplicate option detection.
+static void sortOpts(StringMap<Option *> &OptMap,
+ SmallVectorImpl<std::pair<const char *, Option *>> &Opts,
+ bool ShowHidden) {
+ SmallPtrSet<Option *, 128> OptionSet; // Duplicate option detection.
- for (StringMap<Option*>::iterator I = OptMap.begin(), E = OptMap.end();
+ for (StringMap<Option *>::iterator I = OptMap.begin(), E = OptMap.end();
I != E; ++I) {
// Ignore really-hidden options.
if (I->second->getOptionHiddenFlag() == ReallyHidden)
@@ -1460,8 +1453,8 @@ sortOpts(StringMap<Option*> &OptMap,
if (!OptionSet.insert(I->second).second)
continue;
- Opts.push_back(std::pair<const char *, Option*>(I->getKey().data(),
- I->second));
+ Opts.push_back(
+ std::pair<const char *, Option *>(I->getKey().data(), I->second));
}
// Sort the options list alphabetically.
@@ -1473,7 +1466,8 @@ namespace {
class HelpPrinter {
protected:
const bool ShowHidden;
- typedef SmallVector<std::pair<const char *, Option*>,128> StrOptionPairVector;
+ typedef SmallVector<std::pair<const char *, Option *>, 128>
+ StrOptionPairVector;
// Print the options. Opts is assumed to be alphabetically sorted.
virtual void printOptions(StrOptionPairVector &Opts, size_t MaxArgLen) {
for (size_t i = 0, e = Opts.size(); i != e; ++i)
@@ -1486,12 +1480,13 @@ public:
// Invoke the printer.
void operator=(bool Value) {
- if (Value == false) return;
+ if (Value == false)
+ return;
// Get all the options.
- SmallVector<Option*, 4> PositionalOpts;
- SmallVector<Option*, 4> SinkOpts;
- StringMap<Option*> OptMap;
+ SmallVector<Option *, 4> PositionalOpts;
+ SmallVector<Option *, 4> SinkOpts;
+ StringMap<Option *> OptMap;
GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
StrOptionPairVector Opts;
@@ -1503,7 +1498,7 @@ public:
outs() << "USAGE: " << ProgramName << " [options]";
// Print out the positional options.
- Option *CAOpt = nullptr; // The cl::ConsumeAfter option, if it exists...
+ Option *CAOpt = nullptr; // The cl::ConsumeAfter option, if it exists...
if (!PositionalOpts.empty() &&
PositionalOpts[0]->getNumOccurrencesFlag() == ConsumeAfter)
CAOpt = PositionalOpts[0];
@@ -1515,7 +1510,8 @@ public:
}
// Print the consume after option info if it exists...
- if (CAOpt) outs() << " " << CAOpt->HelpStr;
+ if (CAOpt)
+ outs() << " " << CAOpt->HelpStr;
outs() << "\n\n";
@@ -1551,12 +1547,12 @@ public:
}
// Make sure we inherit our base class's operator=()
- using HelpPrinter::operator= ;
+ using HelpPrinter::operator=;
protected:
void printOptions(StrOptionPairVector &Opts, size_t MaxArgLen) override {
std::vector<OptionCategory *> SortedCategories;
- std::map<OptionCategory *, std::vector<Option *> > CategorizedOptions;
+ std::map<OptionCategory *, std::vector<Option *>> CategorizedOptions;
// Collect registered option categories into vector in preparation for
// sorting.
@@ -1633,9 +1629,9 @@ private:
public:
explicit HelpPrinterWrapper(HelpPrinter &UncategorizedPrinter,
- CategorizedHelpPrinter &CategorizedPrinter) :
- UncategorizedPrinter(UncategorizedPrinter),
- CategorizedPrinter(CategorizedPrinter) { }
+ CategorizedHelpPrinter &CategorizedPrinter)
+ : UncategorizedPrinter(UncategorizedPrinter),
+ CategorizedPrinter(CategorizedPrinter) {}
// Invoke the printer.
void operator=(bool Value);
@@ -1650,7 +1646,6 @@ static HelpPrinter UncategorizedHiddenPr
static CategorizedHelpPrinter CategorizedNormalPrinter(false);
static CategorizedHelpPrinter CategorizedHiddenPrinter(true);
-
// Declare HelpPrinter wrappers that will decide whether or not to invoke
// a categorizing help printer
static HelpPrinterWrapper WrappedNormalPrinter(UncategorizedNormalPrinter,
@@ -1661,38 +1656,36 @@ static HelpPrinterWrapper WrappedHiddenP
// Define uncategorized help printers.
// -help-list is hidden by default because if Option categories are being used
// then -help behaves the same as -help-list.
-static cl::opt<HelpPrinter, true, parser<bool> >
-HLOp("help-list",
- cl::desc("Display list of available options (-help-list-hidden for more)"),
- cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed);
-
-static cl::opt<HelpPrinter, true, parser<bool> >
-HLHOp("help-list-hidden",
- cl::desc("Display list of all available options"),
- cl::location(UncategorizedHiddenPrinter), cl::Hidden, cl::ValueDisallowed);
+static cl::opt<HelpPrinter, true, parser<bool>> HLOp(
+ "help-list",
+ cl::desc("Display list of available options (-help-list-hidden for more)"),
+ cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed);
+
+static cl::opt<HelpPrinter, true, parser<bool>>
+ HLHOp("help-list-hidden", cl::desc("Display list of all available options"),
+ cl::location(UncategorizedHiddenPrinter), cl::Hidden,
+ cl::ValueDisallowed);
// Define uncategorized/categorized help printers. These printers change their
// behaviour at runtime depending on whether one or more Option categories have
// been declared.
-static cl::opt<HelpPrinterWrapper, true, parser<bool> >
-HOp("help", cl::desc("Display available options (-help-hidden for more)"),
- cl::location(WrappedNormalPrinter), cl::ValueDisallowed);
-
-static cl::opt<HelpPrinterWrapper, true, parser<bool> >
-HHOp("help-hidden", cl::desc("Display all available options"),
- cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed);
-
-
-
-static cl::opt<bool>
-PrintOptions("print-options",
- cl::desc("Print non-default options after command line parsing"),
- cl::Hidden, cl::init(false));
-
-static cl::opt<bool>
-PrintAllOptions("print-all-options",
- cl::desc("Print all option values after command line parsing"),
- cl::Hidden, cl::init(false));
+static cl::opt<HelpPrinterWrapper, true, parser<bool>>
+ HOp("help", cl::desc("Display available options (-help-hidden for more)"),
+ cl::location(WrappedNormalPrinter), cl::ValueDisallowed);
+
+static cl::opt<HelpPrinterWrapper, true, parser<bool>>
+ HHOp("help-hidden", cl::desc("Display all available options"),
+ cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed);
+
+static cl::opt<bool> PrintOptions(
+ "print-options",
+ cl::desc("Print non-default options after command line parsing"),
+ cl::Hidden, cl::init(false));
+
+static cl::opt<bool> PrintAllOptions(
+ "print-all-options",
+ cl::desc("Print all option values after command line parsing"), cl::Hidden,
+ cl::init(false));
void HelpPrinterWrapper::operator=(bool Value) {
if (Value == false)
@@ -1707,23 +1700,23 @@ void HelpPrinterWrapper::operator=(bool
HLOp.setHiddenFlag(NotHidden);
CategorizedPrinter = true; // Invoke categorized printer
- }
- else
+ } else
UncategorizedPrinter = true; // Invoke uncategorized printer
}
// Print the value of each option.
void cl::PrintOptionValues() {
- if (!PrintOptions && !PrintAllOptions) return;
+ if (!PrintOptions && !PrintAllOptions)
+ return;
// Get all the options.
- SmallVector<Option*, 4> PositionalOpts;
- SmallVector<Option*, 4> SinkOpts;
- StringMap<Option*> OptMap;
+ SmallVector<Option *, 4> PositionalOpts;
+ SmallVector<Option *, 4> SinkOpts;
+ StringMap<Option *> OptMap;
GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
- SmallVector<std::pair<const char *, Option*>, 128> Opts;
- sortOpts(OptMap, Opts, /*ShowHidden*/true);
+ SmallVector<std::pair<const char *, Option *>, 128> Opts;
+ sortOpts(OptMap, Opts, /*ShowHidden*/ true);
// Compute the maximum argument length...
size_t MaxArgLen = 0;
@@ -1736,7 +1729,7 @@ void cl::PrintOptionValues() {
static void (*OverrideVersionPrinter)() = nullptr;
-static std::vector<void (*)()>* ExtraVersionPrinters = nullptr;
+static std::vector<void (*)()> *ExtraVersionPrinters = nullptr;
namespace {
class VersionPrinter {
@@ -1758,7 +1751,8 @@ public:
OS << " with assertions";
#endif
std::string CPU = sys::getHostCPUName();
- if (CPU == "generic") CPU = "(unknown)";
+ if (CPU == "generic")
+ CPU = "(unknown)";
OS << ".\n"
#if (ENABLE_TIMESTAMPS == 1)
<< " Built " << __DATE__ << " (" << __TIME__ << ").\n"
@@ -1767,7 +1761,8 @@ public:
<< " Host CPU: " << CPU << '\n';
}
void operator=(bool OptionWasSpecified) {
- if (!OptionWasSpecified) return;
+ if (!OptionWasSpecified)
+ return;
if (OverrideVersionPrinter != nullptr) {
(*OverrideVersionPrinter)();
@@ -1790,13 +1785,12 @@ public:
};
} // End anonymous namespace
-
// Define the --version option that prints out the LLVM version for the tool
static VersionPrinter VersionPrinterInstance;
-static cl::opt<VersionPrinter, true, parser<bool> >
-VersOp("version", cl::desc("Display the version of this program"),
- cl::location(VersionPrinterInstance), cl::ValueDisallowed);
+static cl::opt<VersionPrinter, true, parser<bool>>
+ VersOp("version", cl::desc("Display the version of this program"),
+ cl::location(VersionPrinterInstance), cl::ValueDisallowed);
// Utility function for printing the help message.
void cl::PrintHelpMessage(bool Hidden, bool Categorized) {
@@ -1818,13 +1812,9 @@ void cl::PrintHelpMessage(bool Hidden, b
}
/// Utility function for printing version number.
-void cl::PrintVersionMessage() {
- VersionPrinterInstance.print();
-}
+void cl::PrintVersionMessage() { VersionPrinterInstance.print(); }
-void cl::SetVersionPrinter(void (*func)()) {
- OverrideVersionPrinter = func;
-}
+void cl::SetVersionPrinter(void (*func)()) { OverrideVersionPrinter = func; }
void cl::AddExtraVersionPrinter(void (*func)()) {
if (!ExtraVersionPrinters)
@@ -1833,11 +1823,10 @@ void cl::AddExtraVersionPrinter(void (*f
ExtraVersionPrinters->push_back(func);
}
-void cl::getRegisteredOptions(StringMap<Option*> &Map)
-{
+void cl::getRegisteredOptions(StringMap<Option *> &Map) {
// Get all the options.
- SmallVector<Option*, 4> PositionalOpts; //NOT USED
- SmallVector<Option*, 4> SinkOpts; //NOT USED
+ SmallVector<Option *, 4> PositionalOpts; // NOT USED
+ SmallVector<Option *, 4> SinkOpts; // NOT USED
assert(Map.size() == 0 && "StringMap must be empty");
GetOptionInfo(PositionalOpts, SinkOpts, Map);
return;
More information about the llvm-commits
mailing list