Add ssize_t for VC++
[oota-llvm.git] / include / llvm / Support / CommandLine.h
index b53366399af4259878616e7d857be6d42bd139dd..0d1d14813cd4cc7eaa1d272addbf1f46b94ea19f 100644 (file)
@@ -1,4 +1,11 @@
-//===- Support/CommandLine.h - Flexible Command line parser ------*- C++ -*--=//
+//===- Support/CommandLine.h - Flexible Command line parser -----*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This class implements a command line argument processor that is useful when
 // creating a tool.  It provides a simple, minimalistic interface that is easily
 #ifndef SUPPORT_COMMANDLINE_H
 #define SUPPORT_COMMANDLINE_H
 
+#include "Support/type_traits.h"
 #include <string>
 #include <vector>
 #include <utility>
 #include <cstdarg>
-#include "boost/type_traits/object_traits.hpp"
+#include <cassert>
+
+namespace llvm {
 
 /// cl Namespace - This namespace contains all of the command line option
 /// processing machinery.  It is intentionally a short name to make qualified
@@ -27,8 +37,15 @@ namespace cl {
 //===----------------------------------------------------------------------===//
 // ParseCommandLineOptions - Command line option processing entry point.
 //
-void cl::ParseCommandLineOptions(int &argc, char **argv,
-                                const char *Overview = 0);
+void ParseCommandLineOptions(int &argc, char **argv,
+                             const char *Overview = 0);
+
+//===----------------------------------------------------------------------===//
+// ParseEnvironmentOptions - Environment variable option processing alternate
+//                           entry point.
+//
+void ParseEnvironmentOptions(const char *progName, const char *envvar,
+                             const char *Overview = 0);
 
 //===----------------------------------------------------------------------===//
 // Flags permitted to be passed to command line arguments
@@ -90,8 +107,9 @@ enum FormattingFlags {
 };
 
 enum MiscFlags {                // Miscellaneous flags to adjust argument
-  CommaSeparated   = 0x200,     // Should this cl::list split between commas?
-  MiscMask         = 0x200,
+  CommaSeparated     = 0x200,   // Should this cl::list split between commas?
+  PositionalEatsArgs = 0x400,   // Should this positional cl::list eat -args?
+  MiscMask           = 0x600,
 };
 
 
@@ -101,7 +119,7 @@ enum MiscFlags {                // Miscellaneous flags to adjust argument
 //
 class alias;
 class Option {
-  friend void cl::ParseCommandLineOptions(int &, char **, const char *, int);
+  friend void cl::ParseCommandLineOptions(int &, char **, const char *);
   friend class alias;
 
   // handleOccurrences - Overriden by subclasses to handle the value passed into
@@ -132,19 +150,23 @@ public:
 
   inline enum NumOccurrences getNumOccurrencesFlag() const {
     int NO = Flags & OccurrencesMask;
-    return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
+    return NO ? static_cast<enum NumOccurrences>(NO)
+              : getNumOccurrencesFlagDefault();
   }
   inline enum ValueExpected getValueExpectedFlag() const {
     int VE = Flags & ValueMask;
-    return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
+    return VE ? static_cast<enum ValueExpected>(VE)
+              : getValueExpectedFlagDefault();
   }
   inline enum OptionHidden getOptionHiddenFlag() const {
     int OH = Flags & HiddenMask;
-    return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
+    return OH ? static_cast<enum OptionHidden>(OH)
+              : getOptionHiddenFlagDefault();
   }
   inline enum FormattingFlags getFormattingFlag() const {
     int OH = Flags & FormattingMask;
-    return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
+    return OH ? static_cast<enum FormattingFlags>(OH)
+              : getFormattingFlagDefault();
   }
   inline unsigned getMiscFlags() const {
     return Flags & MiscMask;
@@ -291,7 +313,7 @@ public:
 
     // Process the varargs portion of the values...
     while (const char *EnumName = va_arg(ValueArgs, const char *)) {
-      DataType EnumVal = (DataType)va_arg(ValueArgs, int);
+      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
                                       std::make_pair(EnumVal, EnumDesc)));
@@ -374,7 +396,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.
     //
@@ -436,7 +458,8 @@ public:
   template <class DT>
   void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
     assert(findOption(Name) == Values.size() && "Option already exists!");
-    Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
+    Values.push_back(std::make_pair(Name,
+                             std::make_pair(static_cast<DataType>(V),HelpStr)));
   }
 
   // removeLiteralOption - Remove the specified option.
@@ -634,7 +657,8 @@ class opt_storage {
 
   void check() {
     assert(Location != 0 && "cl::location(...) not specified for a command "
-           "line option with external storage!");
+           "line option with external storage, "
+           "or cl::init specified before cl::location()!!");
   }
 public:
   opt_storage() : Location(0) {}
@@ -697,7 +721,7 @@ template <class DataType, bool ExternalStorage = false,
           class ParserClass = parser<DataType> >
 class opt : public Option, 
             public opt_storage<DataType, ExternalStorage,
-                               ::boost::is_class<DataType>::value> {
+                               is_class<DataType>::value> {
   ParserClass Parser;
 
   virtual bool handleOccurrence(const char *ArgName, const std::string &Arg) {
@@ -724,14 +748,17 @@ class opt : public Option,
   }
 public:
   // setInitialValue - Used by the cl::init modifier...
-  void setInitialValue(const DataType &V) { setValue(V); }
+  void setInitialValue(const DataType &V) { this->setValue(V); }
 
   ParserClass &getParser() { return Parser; }
 
-  operator DataType() const { return getValue(); }
+  operator DataType() const { return this->getValue(); }
 
   template<class T>
-  DataType &operator=(const T &Val) { setValue(Val); return getValue(); }
+  DataType &operator=(const T &Val) {
+    this->setValue(Val);
+    return this->getValue();
+  }
 
   // One option...
   template<class M0t>
@@ -1003,4 +1030,6 @@ struct aliasopt {
 
 } // End namespace cl
 
+} // End namespace llvm
+
 #endif