The word `separate' only has one `e'.
[oota-llvm.git] / include / Support / CommandLine.h
index ed2559bd2b9f1af962eddc1a4cf789896efc9585..b6c066006fee92f30de4b19bdf2178ecfe8c7dc5 100644 (file)
@@ -18,7 +18,6 @@
 #include <utility>
 #include <cstdarg>
 #include "boost/type_traits/object_traits.hpp"
-#include <assert.h>
 
 /// cl Namespace - This namespace contains all of the command line option
 /// processing machinery.  It is intentionally a short name to make qualified
@@ -35,11 +34,11 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
 // Flags permitted to be passed to command line arguments
 //
 
-enum NumOccurances {           // Flags for the number of occurances allowed...
-  Optional        = 0x01,      // Zero or One occurance
-  ZeroOrMore      = 0x02,      // Zero or more occurances allowed
-  Required        = 0x03,      // One occurance required
-  OneOrMore       = 0x04,      // One or more occurances required
+enum NumOccurrences {           // Flags for the number of occurrences allowed
+  Optional        = 0x01,      // Zero or One occurrence
+  ZeroOrMore      = 0x02,      // Zero or more occurrences allowed
+  Required        = 0x03,      // One occurrence required
+  OneOrMore       = 0x04,      // 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
@@ -50,7 +49,7 @@ enum NumOccurances {           // Flags for the number of occurances allowed...
   //
   ConsumeAfter    = 0x05,
 
-  OccurancesMask  = 0x07,
+  OccurrencesMask  = 0x07,
 };
 
 enum ValueExpected {           // Is a value required for the option?
@@ -105,13 +104,13 @@ class Option {
   friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
   friend class alias;
 
-  // handleOccurances - Overriden by subclasses to handle the value passed into
+  // handleOccurrences - Overriden by subclasses to handle the value passed into
   // an argument.  Should return true if there was an error processing the
   // argument and the program should exit.
   //
-  virtual bool handleOccurance(const char *ArgName, const std::string &Arg) = 0;
+  virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) = 0;
 
-  virtual enum NumOccurances getNumOccurancesFlagDefault() const { 
+  virtual enum NumOccurrences getNumOccurrencesFlagDefault() const { 
     return Optional;
   }
   virtual enum ValueExpected getValueExpectedFlagDefault() const {
@@ -124,16 +123,16 @@ class Option {
     return NormalFormatting;
   }
 
-  int NumOccurances;    // The number of times specified
+  int NumOccurrences;    // The number of times specified
   int Flags;            // Flags for the argument
 public:
   const char *ArgStr;   // The argument string itself (ex: "help", "o")
   const char *HelpStr;  // The descriptive text message for --help
   const char *ValueStr; // String describing what the value of this option is
 
-  inline enum NumOccurances getNumOccurancesFlag() const {
-    int NO = Flags & OccurancesMask;
-    return NO ? (enum NumOccurances)NO : getNumOccurancesFlagDefault();
+  inline enum NumOccurrences getNumOccurrencesFlag() const {
+    int NO = Flags & OccurrencesMask;
+    return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
   }
   inline enum ValueExpected getValueExpectedFlag() const {
     int VE = Flags & ValueMask;
@@ -170,20 +169,20 @@ public:
     Flags |= Flag;
   }
 
-  void setNumOccurancesFlag(enum NumOccurances Val) {
-    setFlag(Val, OccurancesMask);
+  void setNumOccurrencesFlag(enum NumOccurrences Val) {
+    setFlag(Val, OccurrencesMask);
   }
   void setValueExpectedFlag(enum ValueExpected Val) { setFlag(Val, ValueMask); }
   void setHiddenFlag(enum OptionHidden Val) { setFlag(Val, HiddenMask); }
   void setFormattingFlag(enum FormattingFlags V) { setFlag(V, FormattingMask); }
   void setMiscFlag(enum MiscFlags M) { setFlag(M, M); }
 protected:
-  Option() : NumOccurances(0), Flags(0),
+  Option() : NumOccurrences(0), Flags(0),
              ArgStr(""), HelpStr(""), ValueStr("") {}
 
 public:
   // addArgument - Tell the system that this Option subclass will handle all
-  // occurances of -ArgStr on the command line.
+  // occurrences of -ArgStr on the command line.
   //
   void addArgument(const char *ArgStr);
   void removeArgument(const char *ArgStr);
@@ -196,15 +195,15 @@ public:
   //
   virtual void printOptionInfo(unsigned GlobalWidth) const = 0;
 
-  // addOccurance - Wrapper around handleOccurance that enforces Flags
+  // addOccurrence - Wrapper around handleOccurrence that enforces Flags
   //
-  bool addOccurance(const char *ArgName, const std::string &Value);
+  bool addOccurrence(const char *ArgName, const std::string &Value);
 
   // Prints option name followed by message.  Always returns true.
   bool error(std::string Message, const char *ArgName = 0);
 
 public:
-  inline int getNumOccurances() const { return NumOccurances; }
+  inline int getNumOccurrences() const { return NumOccurrences; }
   virtual ~Option() {}
 };
 
@@ -375,7 +374,7 @@ struct generic_parser_base {
     // In which case, the value is required.  Otherwise if an arg str has not
     // been specified, we are of the form:
     //
-    //    -O2 or O2 or -la (where -l and -a are seperate options)
+    //    -O2 or O2 or -la (where -l and -a are separate options)
     //
     // If this is the case, we cannot allow a value.
     //
@@ -515,6 +514,21 @@ struct parser<int> : public basic_parser<int> {
 };
 
 
+//--------------------------------------------------
+// parser<unsigned>
+//
+template<>
+struct parser<unsigned> : public basic_parser<unsigned> {
+  
+  // parse - Return true on error.
+  bool parse(Option &O, const char *ArgName, const std::string &Arg,
+             unsigned &Val);
+
+  // getValueName - Overload in subclass to provide a better default value.
+  virtual const char *getValueName() const { return "uint"; }
+};
+
+
 //--------------------------------------------------
 // parser<double>
 //
@@ -584,8 +598,8 @@ template<> struct applicator<const char*> {
   static void opt(const char *Str, Opt &O) { O.setArgStr(Str); }
 };
 
-template<> struct applicator<NumOccurances> {
-  static void opt(NumOccurances NO, Option &O) { O.setNumOccurancesFlag(NO); }
+template<> struct applicator<NumOccurrences> {
+  static void opt(NumOccurrences NO, Option &O) { O.setNumOccurrencesFlag(NO); }
 };
 template<> struct applicator<ValueExpected> {
   static void opt(ValueExpected VE, Option &O) { O.setValueExpectedFlag(VE); }
@@ -686,7 +700,7 @@ class opt : public Option,
                                ::boost::is_class<DataType>::value> {
   ParserClass Parser;
 
-  virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
+  virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
     typename ParserClass::parser_data_type Val;
     if (Parser.parse(*this, ArgName, Arg, Val))
       return true;                            // Parse error!
@@ -832,14 +846,14 @@ template <class DataType, class Storage = bool,
 class list : public Option, public list_storage<DataType, Storage> {
   ParserClass Parser;
 
-  virtual enum NumOccurances getNumOccurancesFlagDefault() const { 
+  virtual enum NumOccurrences getNumOccurrencesFlagDefault() const { 
     return ZeroOrMore;
   }
   virtual enum ValueExpected getValueExpectedFlagDefault() const {
     return Parser.getValueExpectedFlagDefault();
   }
 
-  virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
+  virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
     typename ParserClass::parser_data_type Val;
     if (Parser.parse(*this, ArgName, Arg, Val))
       return true;  // Parse Error!
@@ -929,8 +943,8 @@ public:
 
 class alias : public Option {
   Option *AliasFor;
-  virtual bool handleOccurance(const char *ArgName, const std::string &Arg) {
-    return AliasFor->handleOccurance(AliasFor->ArgStr, Arg);
+  virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
+    return AliasFor->handleOccurrence(AliasFor->ArgStr, Arg);
   }
   // Aliases default to be hidden...
   virtual enum OptionHidden getOptionHiddenFlagDefault() const {return Hidden;}