[C+11] Add 'override' keyword to methods in the support library.
[oota-llvm.git] / include / llvm / Support / CommandLine.h
index 8fb4630667af2b3613962403d889a3f62619aa26..b7d1592f137992a2d5ef923ef700d11e8ad9d1bf 100644 (file)
@@ -21,8 +21,8 @@
 #define LLVM_SUPPORT_COMMANDLINE_H
 
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/Twine.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include <cassert>
@@ -149,8 +149,8 @@ private:
 public:
   OptionCategory(const char *const Name, const char *const Description = 0)
       : Name(Name), Description(Description) { registerCategory(); }
-  const char *getName() { return Name; }
-  const char *getDescription() { return Description; }
+  const char *getName() const { return Name; }
+  const char *getDescription() const { return Description; }
 };
 
 // The general Option Category (used as default category).
@@ -249,6 +249,12 @@ public:
   //
   void addArgument();
 
+  /// Unregisters this option from the CommandLine system.
+  ///
+  /// This option must have been the last option registered.
+  /// For testing purposes only.
+  void removeArgument();
+
   Option *getNextRegisteredOption() const { return NextRegistered; }
 
   // Return the width of the option tag for printing...
@@ -350,6 +356,9 @@ struct cat {
 struct GenericOptionValue {
   virtual ~GenericOptionValue() {}
   virtual bool compare(const GenericOptionValue &V) const = 0;
+
+private:
+  virtual void anchor();
 };
 
 template<class DataType> struct OptionValue;
@@ -371,7 +380,9 @@ struct OptionValueBase : public GenericOptionValue {
 
   bool compare(const DataType &/*V*/) const { return false; }
 
-  virtual bool compare(const GenericOptionValue& /*V*/) const { return false; }
+  bool compare(const GenericOptionValue& /*V*/) const override {
+    return false;
+  }
 };
 
 // Simple copy of the option value.
@@ -395,7 +406,7 @@ public:
     return Valid && (Value != V);
   }
 
-  virtual bool compare(const GenericOptionValue &V) const {
+  bool compare(const GenericOptionValue &V) const override {
     const OptionValueCopy<DataType> &VC =
       static_cast< const OptionValueCopy<DataType>& >(V);
     if (!VC.hasValue()) return false;
@@ -441,7 +452,7 @@ struct OptionValue<cl::boolOrDefault> : OptionValueCopy<cl::boolOrDefault> {
     return *this;
   }
 private:
-  virtual void anchor();
+  void anchor() override;
 };
 
 template<>
@@ -458,7 +469,7 @@ struct OptionValue<std::string> : OptionValueCopy<std::string> {
     return *this;
   }
 private:
-  virtual void anchor();
+  void anchor() override;
 };
 
 //===----------------------------------------------------------------------===//
@@ -637,14 +648,14 @@ public:
   typedef DataType parser_data_type;
 
   // Implement virtual functions needed by generic_parser_base
-  unsigned getNumOptions() const { return unsigned(Values.size()); }
-  const char *getOption(unsigned N) const { return Values[N].Name; }
-  const char *getDescription(unsigned N) const {
+  unsigned getNumOptions() const override { return unsigned(Values.size()); }
+  const char *getOption(unsigned N) const override { return Values[N].Name; }
+  const char *getDescription(unsigned N) const override {
     return Values[N].HelpStr;
   }
 
   // getOptionValue - Return the value of option name N.
-  virtual const GenericOptionValue &getOptionValue(unsigned N) const {
+  const GenericOptionValue &getOptionValue(unsigned N) const override {
     return Values[N].V;
   }
 
@@ -753,13 +764,13 @@ public:
   }
 
   // getValueName - Do not print =<value> at all.
-  virtual const char *getValueName() const { return 0; }
+  const char *getValueName() const override { return 0; }
 
   void printOptionDiff(const Option &O, bool V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<bool>);
@@ -777,13 +788,13 @@ public:
   }
 
   // getValueName - Do not print =<value> at all.
-  virtual const char *getValueName() const { return 0; }
+  const char *getValueName() const override { return 0; }
 
   void printOptionDiff(const Option &O, boolOrDefault V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
@@ -798,13 +809,13 @@ public:
   bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val);
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "int"; }
+  const char *getValueName() const override { return "int"; }
 
   void printOptionDiff(const Option &O, int V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<int>);
@@ -820,13 +831,13 @@ public:
   bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val);
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "uint"; }
+  const char *getValueName() const override { return "uint"; }
 
   void printOptionDiff(const Option &O, unsigned V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
@@ -842,13 +853,13 @@ public:
              unsigned long long &Val);
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "uint"; }
+  const char *getValueName() const override { return "uint"; }
 
   void printOptionDiff(const Option &O, unsigned long long V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<unsigned long long>);
@@ -863,13 +874,13 @@ public:
   bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val);
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "number"; }
+  const char *getValueName() const override { return "number"; }
 
   void printOptionDiff(const Option &O, double V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<double>);
@@ -884,13 +895,13 @@ public:
   bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val);
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "number"; }
+  const char *getValueName() const override { return "number"; }
 
   void printOptionDiff(const Option &O, float V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<float>);
@@ -908,13 +919,13 @@ public:
   }
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "string"; }
+  const char *getValueName() const override { return "string"; }
 
   void printOptionDiff(const Option &O, StringRef V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
@@ -932,13 +943,13 @@ public:
   }
 
   // getValueName - Overload in subclass to provide a better default value.
-  virtual const char *getValueName() const { return "char"; }
+  const char *getValueName() const override { return "char"; }
 
   void printOptionDiff(const Option &O, char V, OptVal Default,
                        size_t GlobalWidth) const;
 
   // An out-of-line virtual method to provide a 'home' for this class.
-  virtual void anchor();
+  void anchor() override;
 };
 
 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<char>);
@@ -1017,8 +1028,8 @@ template<> struct applicator<const char*> {
 };
 
 template<> struct applicator<NumOccurrencesFlag> {
-  static void opt(NumOccurrencesFlag NO, Option &O) {
-    O.setNumOccurrencesFlag(NO);
+  static void opt(NumOccurrencesFlag N, Option &O) {
+    O.setNumOccurrencesFlag(N);
   }
 };
 template<> struct applicator<ValueExpected> {
@@ -1052,7 +1063,7 @@ class opt_storage {
   DataType *Location;   // Where to store the object...
   OptionValue<DataType> Default;
 
-  void check() const {
+  void check_location() const {
     assert(Location != 0 && "cl::location(...) not specified for a command "
            "line option with external storage, "
            "or cl::init specified before cl::location()!!");
@@ -1070,14 +1081,14 @@ public:
 
   template<class T>
   void setValue(const T &V, bool initial = false) {
-    check();
+    check_location();
     *Location = V;
     if (initial)
       Default = V;
   }
 
-  DataType &getValue() { check(); return *Location; }
-  const DataType &getValue() const { check(); return *Location; }
+  DataType &getValue() { check_location(); return *Location; }
+  const DataType &getValue() const { check_location(); return *Location; }
 
   operator DataType() const { return this->getValue(); }
 
@@ -1148,8 +1159,8 @@ class opt : public Option,
                                is_class<DataType>::value> {
   ParserClass Parser;
 
-  virtual bool handleOccurrence(unsigned pos, StringRef ArgName,
-                                StringRef Arg) {
+  bool handleOccurrence(unsigned pos, StringRef ArgName,
+                        StringRef Arg) override {
     typename ParserClass::parser_data_type Val =
        typename ParserClass::parser_data_type();
     if (Parser.parse(*this, ArgName, Arg, Val))
@@ -1159,20 +1170,20 @@ class opt : public Option,
     return false;
   }
 
-  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+  enum ValueExpected getValueExpectedFlagDefault() const override {
     return Parser.getValueExpectedFlagDefault();
   }
-  virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
+  void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) override {
     return Parser.getExtraOptionNames(OptionNames);
   }
 
   // Forward printing stuff to the parser...
-  virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
-  virtual void printOptionInfo(size_t GlobalWidth) const {
+  size_t getOptionWidth() const override {return Parser.getOptionWidth(*this);}
+  void printOptionInfo(size_t GlobalWidth) const override {
     Parser.printOptionInfo(*this, GlobalWidth);
   }
 
-  virtual void printOptionValue(size_t GlobalWidth, bool Force) const {
+  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);
@@ -1319,14 +1330,15 @@ class list : public Option, public list_storage<DataType, Storage> {
   std::vector<unsigned> Positions;
   ParserClass Parser;
 
-  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+  enum ValueExpected getValueExpectedFlagDefault() const override {
     return Parser.getValueExpectedFlagDefault();
   }
-  virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
+  void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) override {
     return Parser.getExtraOptionNames(OptionNames);
   }
 
-  virtual bool handleOccurrence(unsigned pos, StringRef ArgName, StringRef Arg){
+  bool handleOccurrence(unsigned pos, StringRef ArgName,
+                        StringRef Arg) override {
     typename ParserClass::parser_data_type Val =
       typename ParserClass::parser_data_type();
     if (Parser.parse(*this, ArgName, Arg, Val))
@@ -1338,13 +1350,14 @@ class list : public Option, public list_storage<DataType, Storage> {
   }
 
   // Forward printing stuff to the parser...
-  virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
-  virtual void printOptionInfo(size_t GlobalWidth) const {
+  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.
-  virtual void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const {}
+  void printOptionValue(size_t /*GlobalWidth*/,
+                        bool /*Force*/) const override {}
 
   void done() {
     addArgument();
@@ -1521,14 +1534,15 @@ class bits : public Option, public bits_storage<DataType, Storage> {
   std::vector<unsigned> Positions;
   ParserClass Parser;
 
-  virtual enum ValueExpected getValueExpectedFlagDefault() const {
+  enum ValueExpected getValueExpectedFlagDefault() const override {
     return Parser.getValueExpectedFlagDefault();
   }
-  virtual void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) {
+  void getExtraOptionNames(SmallVectorImpl<const char*> &OptionNames) override {
     return Parser.getExtraOptionNames(OptionNames);
   }
 
-  virtual bool handleOccurrence(unsigned pos, StringRef ArgName, StringRef Arg){
+  bool handleOccurrence(unsigned pos, StringRef ArgName,
+                        StringRef Arg) override {
     typename ParserClass::parser_data_type Val =
       typename ParserClass::parser_data_type();
     if (Parser.parse(*this, ArgName, Arg, Val))
@@ -1540,13 +1554,14 @@ class bits : public Option, public bits_storage<DataType, Storage> {
   }
 
   // Forward printing stuff to the parser...
-  virtual size_t getOptionWidth() const {return Parser.getOptionWidth(*this);}
-  virtual void printOptionInfo(size_t GlobalWidth) const {
+  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.
-  virtual void printOptionValue(size_t /*GlobalWidth*/, bool /*Force*/) const {}
+  void printOptionValue(size_t /*GlobalWidth*/,
+                        bool /*Force*/) const override {}
 
   void done() {
     addArgument();
@@ -1631,17 +1646,21 @@ public:
 
 class alias : public Option {
   Option *AliasFor;
-  virtual bool handleOccurrence(unsigned pos, StringRef /*ArgName*/,
-                                StringRef Arg) LLVM_OVERRIDE {
+  bool handleOccurrence(unsigned pos, StringRef /*ArgName*/,
+                                StringRef Arg) override {
     return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
   }
   // Handle printing stuff...
-  virtual size_t getOptionWidth() const LLVM_OVERRIDE;
-  virtual void printOptionInfo(size_t GlobalWidth) const LLVM_OVERRIDE;
+  size_t getOptionWidth() const override;
+  void printOptionInfo(size_t GlobalWidth) const override;
 
   // Aliases do not need to print their values.
-  virtual void printOptionValue(size_t /*GlobalWidth*/,
-                                bool /*Force*/) const LLVM_OVERRIDE {}
+  void printOptionValue(size_t /*GlobalWidth*/,
+                        bool /*Force*/) const override {}
+
+  ValueExpected getValueExpectedFlagDefault() const override {
+    return AliasFor->getValueExpectedFlag();
+  }
 
   void done() {
     if (!hasArgStr())
@@ -1752,6 +1771,7 @@ void getRegisteredOptions(StringMap<Option*> &Map);
 /// \brief Saves strings in the inheritor's stable storage and returns a stable
 /// raw character pointer.
 class StringSaver {
+  virtual void anchor();
 public:
   virtual const char *SaveString(const char *Str) = 0;
   virtual ~StringSaver() {};  // Pacify -Wnon-virtual-dtor.
@@ -1792,7 +1812,7 @@ typedef void (*TokenizerCallback)(StringRef Source, StringSaver &Saver,
 /// before expansion and will be modified in place.
 ///
 /// \param [in] Saver Delegates back to the caller for saving parsed strings.
-/// \param [in] Tokenize Tokenization strategy. Typically Unix or Windows.
+/// \param [in] Tokenizer Tokenization strategy. Typically Unix or Windows.
 /// \param [in,out] Argv Command line into which to expand response files.
 /// \return true if all @files were expanded successfully or there were none.
 bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,