X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FCommandLine.h;h=3ae50136e4a9d38ae2d0b87c3a4351d98463ffde;hb=0eac0164c259fb4a9d824361029f175e3eeede5c;hp=2e1661286c75aa9fc958bbc059724ce116e39546;hpb=0008f654bf08dc631a1abaa175dd08f1fd1be75e;p=oota-llvm.git diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 2e1661286c7..3ae50136e4a 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -24,11 +24,12 @@ #include "llvm/Support/DataTypes.h" #include "llvm/Support/Compiler.h" #include "llvm/ADT/SmallVector.h" +#include +#include +#include #include -#include #include -#include -#include +#include namespace llvm { @@ -155,6 +156,7 @@ class Option { int NumOccurrences; // The number of times specified int Flags; // Flags for the argument 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") @@ -179,6 +181,7 @@ public: return Flags & MiscMask; } inline unsigned getPosition() const { return Position; } + inline unsigned getNumAdditionalVals() const { return AdditionalVals; } // hasArgStr - Return true if the argstr != "" bool hasArgStr() const { return ArgStr[0] != 0; } @@ -206,11 +209,14 @@ public: protected: explicit Option(unsigned DefaultFlags) : NumOccurrences(0), Flags(DefaultFlags | NormalFormatting), Position(0), - NextRegistered(0), ArgStr(""), HelpStr(""), ValueStr("") { + AdditionalVals(0), NextRegistered(0), + ArgStr(""), HelpStr(""), ValueStr("") { assert(getNumOccurrencesFlag() != 0 && getOptionHiddenFlag() != 0 && "Not all default flags specified!"); } + inline void setNumAdditionalVals(unsigned n) + { AdditionalVals = n; } public: // addArgument - Register this argument with the commandline system. // @@ -231,7 +237,7 @@ public: // addOccurrence - Wrapper around handleOccurrence that enforces Flags // bool addOccurrence(unsigned pos, const char *ArgName, - const std::string &Value); + const std::string &Value, bool MultiArg = false); // Prints option name followed by message. Always returns true. bool error(std::string Message, const char *ArgName = 0); @@ -531,10 +537,17 @@ struct basic_parser : public basic_parser_impl { // template<> class parser : public basic_parser { + const char *ArgStr; public: + // parse - Return true on error. bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val); + template + void initialize(Opt &O) { + ArgStr = O.ArgStr; + } + enum ValueExpected getValueExpectedFlagDefault() const { return ValueOptional; } @@ -666,6 +679,28 @@ public: EXTERN_TEMPLATE_INSTANTIATION(class basic_parser); +//-------------------------------------------------- +// parser +// +template<> +class parser : public basic_parser { +public: + // parse - Return true on error. + bool parse(Option &, const char *, const std::string &Arg, + char &Value) { + Value = Arg[0]; + return false; + } + + // getValueName - Overload in subclass to provide a better default value. + virtual const char *getValueName() const { return "char"; } + + // An out-of-line virtual method to provide a 'home' for this class. + virtual void anchor(); +}; + +EXTERN_TEMPLATE_INSTANTIATION(class basic_parser); + //===----------------------------------------------------------------------===// // applicator class - This class is used because we must use partial // specialization to handle literal string arguments specially (const char* does @@ -725,7 +760,7 @@ template class opt_storage { DataType *Location; // Where to store the object... - void check() { + void check() const { assert(Location != 0 && "cl::location(...) not specified for a command " "line option with external storage, " "or cl::init specified before cl::location()!!"); @@ -804,8 +839,8 @@ class opt : public Option, typename ParserClass::parser_data_type(); if (Parser.parse(*this, ArgName, Arg, Val)) return true; // Parse error! - setValue(Val); - setPosition(pos); + this->setValue(Val); + this->setPosition(pos); return false; } @@ -910,6 +945,7 @@ public: EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); +EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); //===----------------------------------------------------------------------===// @@ -1000,6 +1036,10 @@ public: return Positions[optnum]; } + void setNumAdditionalVals(unsigned n) { + Option::setNumAdditionalVals(n); + } + // One option... template explicit list(const M0t &M0) : Option(ZeroOrMore | NotHidden) { @@ -1065,6 +1105,16 @@ public: } }; +// multi_val - Modifier to set the number of additional values. +struct multi_val { + unsigned AdditionalVals; + explicit multi_val(unsigned N) : AdditionalVals(N) {} + + template + void apply(list &L) const { L.setNumAdditionalVals(AdditionalVals); } +}; + + //===----------------------------------------------------------------------===// // bits_storage class @@ -1079,7 +1129,7 @@ class bits_storage { template static unsigned Bit(const T &V) { unsigned BitPos = reinterpret_cast(V); - assert(BitPos < sizeof(unsigned) * 8 && + assert(BitPos < sizeof(unsigned) * CHAR_BIT && "enum exceeds width of bit vector!"); return 1 << BitPos; } @@ -1120,7 +1170,7 @@ class bits_storage { template static unsigned Bit(const T &V) { unsigned BitPos = reinterpret_cast(V); - assert(BitPos < sizeof(unsigned) * 8 && + assert(BitPos < sizeof(unsigned) * CHAR_BIT && "enum exceeds width of bit vector!"); return 1 << BitPos; }