[cfe-commits] r105762 - in /cfe/trunk: include/clang/Driver/Arg.h lib/Driver/Arg.cpp lib/Driver/ArgList.cpp lib/Driver/Driver.cpp lib/Driver/OptTable.cpp lib/Driver/Option.cpp

Daniel Dunbar daniel at zuster.org
Wed Jun 9 15:31:08 PDT 2010


Author: ddunbar
Date: Wed Jun  9 17:31:08 2010
New Revision: 105762

URL: http://llvm.org/viewvc/llvm-project?rev=105762&view=rev
Log:
Driver: Eliminate Arg subclasses, which are now unnecessary.

Modified:
    cfe/trunk/include/clang/Driver/Arg.h
    cfe/trunk/lib/Driver/Arg.cpp
    cfe/trunk/lib/Driver/ArgList.cpp
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Driver/OptTable.cpp
    cfe/trunk/lib/Driver/Option.cpp

Modified: cfe/trunk/include/clang/Driver/Arg.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Arg.h?rev=105762&r1=105761&r2=105762&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Arg.h (original)
+++ cfe/trunk/include/clang/Driver/Arg.h Wed Jun  9 17:31:08 2010
@@ -10,13 +10,6 @@
 #ifndef CLANG_DRIVER_ARG_H_
 #define CLANG_DRIVER_ARG_H_
 
-#include "llvm/Support/Casting.h"
-using llvm::isa;
-using llvm::cast;
-using llvm::cast_or_null;
-using llvm::dyn_cast;
-using llvm::dyn_cast_or_null;
-
 #include "Util.h"
 #include "llvm/ADT/SmallVector.h"
 #include <vector>
@@ -35,19 +28,10 @@
   /// ArgList to provide efficient iteration over all instances of a
   /// particular option.
   class Arg {
-  public:
-    enum ArgClass {
-      FlagClass = 0,
-      PositionalClass,
-      JoinedClass,
-      SeparateClass,
-      CommaJoinedClass,
-      JoinedAndSeparateClass
-    };
+    Arg(const Arg &); // DO NOT IMPLEMENT
+    void operator=(const Arg &); // DO NOT IMPLEMENT
 
   private:
-    ArgClass Kind;
-
     /// The option this argument is an instance of.
     const Option *Opt;
 
@@ -69,15 +53,14 @@
     /// The argument values, as C strings.
     llvm::SmallVector<const char *, 2> Values;
 
-  protected:
-    Arg(ArgClass Kind, const Option *Opt, unsigned Index,
-        const Arg *BaseArg = 0);
-
   public:
-    Arg(const Arg &);
-    virtual ~Arg();
+    Arg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
+    Arg(const Option *Opt, unsigned Index,
+        const char *Value0, const Arg *BaseArg = 0);
+    Arg(const Option *Opt, unsigned Index,
+        const char *Value0, const char *Value1, const Arg *BaseArg = 0);
+    ~Arg();
 
-    ArgClass getKind() const { return Kind; }
     const Option &getOption() const { return *Opt; }
     unsigned getIndex() const { return Index; }
 
@@ -126,85 +109,6 @@
     std::string getAsString(const ArgList &Args) const;
   };
 
-  /// FlagArg - An argument with no value.
-  class FlagArg : public Arg {
-  public:
-    FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg = 0);
-
-    static bool classof(const Arg *A) {
-      return A->getKind() == Arg::FlagClass;
-    }
-    static bool classof(const FlagArg *) { return true; }
-  };
-
-  /// PositionalArg - A simple positional argument.
-  class PositionalArg : public Arg {
-  public:
-    PositionalArg(const Option *Opt, unsigned Index, const char *Value,
-                  const Arg *BaseArg = 0);
-
-    static bool classof(const Arg *A) {
-      return A->getKind() == Arg::PositionalClass;
-    }
-    static bool classof(const PositionalArg *) { return true; }
-  };
-
-  /// JoinedArg - A single value argument where the value is joined
-  /// (suffixed) to the option.
-  class JoinedArg : public Arg {
-  public:
-    JoinedArg(const Option *Opt, unsigned Index, const char *Value,
-              const Arg *BaseArg = 0);
-
-    static bool classof(const Arg *A) {
-      return A->getKind() == Arg::JoinedClass;
-    }
-    static bool classof(const JoinedArg *) { return true; }
-  };
-
-  /// SeparateArg - An argument where one or more values follow the
-  /// option specifier immediately in the argument vector.
-  class SeparateArg : public Arg {
-  public:
-    SeparateArg(const Option *Opt, unsigned Index, const char *Value,
-                const Arg *BaseArg = 0);
-
-    static bool classof(const Arg *A) {
-      return A->getKind() == Arg::SeparateClass;
-    }
-    static bool classof(const SeparateArg *) { return true; }
-  };
-
-  /// CommaJoinedArg - An argument with multiple values joined by
-  /// commas and joined (suffixed) to the option specifier.
-  ///
-  /// The key point of this arg is that it renders its values into
-  /// separate arguments, which allows it to be used as a generic
-  /// mechanism for passing arguments through to tools.
-  class CommaJoinedArg : public Arg {
-  public:
-    CommaJoinedArg(const Option *Opt, unsigned Index, const char *Str,
-                   const Arg *BaseArg = 0);
-
-    static bool classof(const Arg *A) {
-      return A->getKind() == Arg::CommaJoinedClass;
-    }
-    static bool classof(const CommaJoinedArg *) { return true; }
-  };
-
-  /// JoinedAndSeparateArg - An argument with both joined and separate
-  /// values.
-  class JoinedAndSeparateArg : public Arg {
-  public:
-    JoinedAndSeparateArg(const Option *Opt, unsigned Index,
-                         const char *Value0, const char *Value1, 
-                         const Arg *BaseArg = 0);
-
-    static bool classof(const Arg *A) {
-      return A->getKind() == Arg::JoinedAndSeparateClass;
-    }
-    static bool classof(const JoinedAndSeparateArg *) { return true; }
-  };
 } // end namespace driver
 } // end namespace clang
 

Modified: cfe/trunk/lib/Driver/Arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Arg.cpp?rev=105762&r1=105761&r2=105762&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Arg.cpp (original)
+++ cfe/trunk/lib/Driver/Arg.cpp Wed Jun  9 17:31:08 2010
@@ -16,12 +16,26 @@
 
 using namespace clang::driver;
 
-Arg::Arg(ArgClass _Kind, const Option *_Opt, unsigned _Index,
-         const Arg *_BaseArg)
-  : Kind(_Kind), Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
+Arg::Arg(const Option *_Opt, unsigned _Index, const Arg *_BaseArg)
+  : Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
     Claimed(false), OwnsValues(false) {
 }
 
+Arg::Arg(const Option *_Opt, unsigned _Index, 
+         const char *Value0, const Arg *_BaseArg)
+  : Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
+    Claimed(false), OwnsValues(false) {
+  Values.push_back(Value0);
+}
+
+Arg::Arg(const Option *_Opt, unsigned _Index, 
+         const char *Value0, const char *Value1, const Arg *_BaseArg)
+  : Opt(_Opt), BaseArg(_BaseArg), Index(_Index),
+    Claimed(false), OwnsValues(false) {
+  Values.push_back(Value0);
+  Values.push_back(Value1);
+}
+
 Arg::~Arg() {
   if (OwnsValues) {
     for (unsigned i = 0, e = Values.size(); i != e; ++i)
@@ -31,28 +45,19 @@
 
 void Arg::dump() const {
   llvm::errs() << "<";
-  switch (Kind) {
-  default:
-    assert(0 && "Invalid kind");
-#define P(N) case N: llvm::errs() << #N; break
-    P(FlagClass);
-    P(PositionalClass);
-    P(JoinedClass);
-    P(SeparateClass);
-    P(CommaJoinedClass);
-    P(JoinedAndSeparateClass);
-#undef P
-  }
 
   llvm::errs() << " Opt:";
   Opt->dump();
 
   llvm::errs() << " Index:" << Index;
 
-  if (isa<CommaJoinedArg>(this) || isa<SeparateArg>(this))
-    llvm::errs() << " NumValues:" << getNumValues();
+  llvm::errs() << " Values: [";
+  for (unsigned i = 0, e = Values.size(); i != e; ++i) {
+    if (i) llvm::errs() << ", ";
+    llvm::errs() << "'" << Values[i] << "'";
+  }
 
-  llvm::errs() << ">\n";
+  llvm::errs() << "]>\n";
 }
 
 std::string Arg::getAsString(const ArgList &Args) const {
@@ -114,59 +119,3 @@
     break;
   }
 }
-
-FlagArg::FlagArg(const Option *Opt, unsigned Index, const Arg *BaseArg)
-  : Arg(FlagClass, Opt, Index, BaseArg) {
-}
-
-PositionalArg::PositionalArg(const Option *Opt, unsigned Index,
-                             const char *Value0, const Arg *BaseArg)
-  : Arg(PositionalClass, Opt, Index, BaseArg) {
-  getValues().push_back(Value0);
-}
-
-JoinedArg::JoinedArg(const Option *Opt, unsigned Index, const char *Value0,
-                     const Arg *BaseArg)
-  : Arg(JoinedClass, Opt, Index, BaseArg) {
-  getValues().push_back(Value0);
-}
-
-CommaJoinedArg::CommaJoinedArg(const Option *Opt, unsigned Index,
-                               const char *Str, const Arg *BaseArg)
-  : Arg(CommaJoinedClass, Opt, Index, BaseArg) {
-  const char *Prev = Str;
-  for (;; ++Str) {
-    char c = *Str;
-
-    if (!c || c == ',') {
-      if (Prev != Str) {
-        char *Value = new char[Str - Prev + 1];
-        memcpy(Value, Prev, Str - Prev);
-        Value[Str - Prev] = '\0';
-        getValues().push_back(Value);
-      }
-
-      if (!c)
-        break;
-
-      Prev = Str + 1;
-    }
-  }
-
-  setOwnsValues(true);
-}
-
-SeparateArg::SeparateArg(const Option *Opt, unsigned Index, const char *Value0,
-                         const Arg *BaseArg)
-  : Arg(SeparateClass, Opt, Index, BaseArg) {
-  getValues().push_back(Value0);
-}
-
-JoinedAndSeparateArg::JoinedAndSeparateArg(const Option *Opt, unsigned Index,
-                                           const char *Value0,
-                                           const char *Value1,
-                                           const Arg *BaseArg)
-  : Arg(JoinedAndSeparateClass, Opt, Index, BaseArg) {
-  getValues().push_back(Value0);
-  getValues().push_back(Value1);
-}

Modified: cfe/trunk/lib/Driver/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ArgList.cpp?rev=105762&r1=105761&r2=105762&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Wed Jun  9 17:31:08 2010
@@ -257,7 +257,7 @@
 }
 
 Arg *DerivedArgList::MakeFlagArg(const Arg *BaseArg, const Option *Opt) const {
-  Arg *A = new FlagArg(Opt, BaseArgs.MakeIndex(Opt->getName()), BaseArg);
+  Arg *A = new Arg(Opt, BaseArgs.MakeIndex(Opt->getName()), BaseArg);
   SynthesizedArgs.push_back(A);
   return A;
 }
@@ -265,7 +265,7 @@
 Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option *Opt,
                                        llvm::StringRef Value) const {
   unsigned Index = BaseArgs.MakeIndex(Value);
-  Arg *A = new PositionalArg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
+  Arg *A = new Arg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
   SynthesizedArgs.push_back(A);
   return A;
 }
@@ -273,7 +273,7 @@
 Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option *Opt,
                                      llvm::StringRef Value) const {
   unsigned Index = BaseArgs.MakeIndex(Opt->getName(), Value);
-  Arg *A = new SeparateArg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
+  Arg *A = new Arg(Opt, Index, BaseArgs.getArgString(Index), BaseArg);
   SynthesizedArgs.push_back(A);
   return A;
 }
@@ -281,9 +281,9 @@
 Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option *Opt,
                                    llvm::StringRef Value) const {
   unsigned Index = BaseArgs.MakeIndex(Opt->getName() + Value.str());
-  Arg *A = new JoinedArg(Opt, Index,
-                         BaseArgs.getArgString(Index) + strlen(Opt->getName()),
-                         BaseArg);
+  Arg *A = new Arg(Opt, Index,
+                   BaseArgs.getArgString(Index) + strlen(Opt->getName()),
+                   BaseArg);
   SynthesizedArgs.push_back(A);
   return A;
 }

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=105762&r1=105761&r2=105762&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Jun  9 17:31:08 2010
@@ -976,7 +976,7 @@
     // just using Args was better?
     const Arg &Input = IA->getInputArg();
     Input.claim();
-    if (isa<PositionalArg>(Input)) {
+    if (Input.getOption().matches(options::OPT_INPUT)) {
       const char *Name = Input.getValue(C.getArgs());
       Result = InputInfo(Name, A->getType(), Name);
     } else

Modified: cfe/trunk/lib/Driver/OptTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/OptTable.cpp?rev=105762&r1=105761&r2=105762&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/OptTable.cpp (original)
+++ cfe/trunk/lib/Driver/OptTable.cpp Wed Jun  9 17:31:08 2010
@@ -188,7 +188,7 @@
 
   // Anything that doesn't start with '-' is an input, as is '-' itself.
   if (Str[0] != '-' || Str[1] == '\0')
-    return new PositionalArg(TheInputOption, Index++, Str);
+    return new Arg(TheInputOption, Index++, Str);
 
   const Info *Start = OptionInfos + FirstSearchableIndex;
   const Info *End = OptionInfos + getNumOptions();
@@ -221,7 +221,7 @@
       return 0;
   }
 
-  return new PositionalArg(TheUnknownOption, Index++, Str);
+  return new Arg(TheUnknownOption, Index++, Str);
 }
 
 InputArgList *OptTable::ParseArgs(const char **ArgBegin, const char **ArgEnd,

Modified: cfe/trunk/lib/Driver/Option.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Option.cpp?rev=105762&r1=105761&r2=105762&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Option.cpp (original)
+++ cfe/trunk/lib/Driver/Option.cpp Wed Jun  9 17:31:08 2010
@@ -147,7 +147,7 @@
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
     return 0;
 
-  return new FlagArg(this, Index++);
+  return new Arg(this, Index++);
 }
 
 JoinedOption::JoinedOption(OptSpecifier ID, const char *Name,
@@ -158,7 +158,7 @@
 Arg *JoinedOption::accept(const InputArgList &Args, unsigned &Index) const {
   // Always matches.
   const char *Value = Args.getArgString(Index) + strlen(getName());
-  return new JoinedArg(this, Index++, Value);
+  return new Arg(this, Index++, Value);
 }
 
 CommaJoinedOption::CommaJoinedOption(OptSpecifier ID, const char *Name,
@@ -169,13 +169,32 @@
 
 Arg *CommaJoinedOption::accept(const InputArgList &Args,
                                unsigned &Index) const {
-  // Always matches. We count the commas now so we can answer
-  // getNumValues easily.
+  // Always matches.
+  const char *Str = Args.getArgString(Index) + strlen(getName());
+  Arg *A = new Arg(this, Index++);
+
+  // Parse out the comma separated values.
+  const char *Prev = Str;
+  for (;; ++Str) {
+    char c = *Str;
+
+    if (!c || c == ',') {
+      if (Prev != Str) {
+        char *Value = new char[Str - Prev + 1];
+        memcpy(Value, Prev, Str - Prev);
+        Value[Str - Prev] = '\0';
+        A->getValues().push_back(Value);
+      }
+
+      if (!c)
+        break;
 
-  // Get the suffix string.
-  // FIXME: Avoid strlen, and move to helper method?
-  const char *Suffix = Args.getArgString(Index) + strlen(getName());
-  return new CommaJoinedArg(this, Index++, Suffix);
+      Prev = Str + 1;
+    }
+  }
+  A->setOwnsValues(true);
+
+  return A;
 }
 
 SeparateOption::SeparateOption(OptSpecifier ID, const char *Name,
@@ -193,7 +212,7 @@
   if (Index > Args.getNumInputArgStrings())
     return 0;
 
-  return new SeparateArg(this, Index - 2, Args.getArgString(Index - 1));
+  return new Arg(this, Index - 2, Args.getArgString(Index - 1));
 }
 
 MultiArgOption::MultiArgOption(OptSpecifier ID, const char *Name,
@@ -213,8 +232,8 @@
   if (Index > Args.getNumInputArgStrings())
     return 0;
 
-  Arg *A = new SeparateArg(this, Index - 1 - NumArgs,
-                           Args.getArgString(Index - NumArgs));
+  Arg *A = new Arg(this, Index - 1 - NumArgs,
+                    Args.getArgString(Index - NumArgs));
   for (unsigned i = 1; i != NumArgs; ++i)
     A->getValues().push_back(Args.getArgString(Index - NumArgs + i));
   return A;
@@ -233,7 +252,7 @@
   // FIXME: Avoid strlen.
   if (strlen(getName()) != strlen(Args.getArgString(Index))) {
     const char *Value = Args.getArgString(Index) + strlen(getName());
-    return new JoinedArg(this, Index++, Value);
+    return new Arg(this, Index++, Value);
   }
 
   // Otherwise it must be separate.
@@ -241,8 +260,7 @@
   if (Index > Args.getNumInputArgStrings())
     return 0;
 
-  return new SeparateArg(this, Index - 2,
-                         Args.getArgString(Index - 1));
+  return new Arg(this, Index - 2, Args.getArgString(Index - 1));
 }
 
 JoinedAndSeparateOption::JoinedAndSeparateOption(OptSpecifier ID,
@@ -260,7 +278,6 @@
   if (Index > Args.getNumInputArgStrings())
     return 0;
 
-  return new JoinedAndSeparateArg(this, Index - 2,
-                                  Args.getArgString(Index-2)+strlen(getName()),
-                                  Args.getArgString(Index-1));
+  return new Arg(this, Index - 2, Args.getArgString(Index-2)+strlen(getName())
+                 , Args.getArgString(Index-1));
 }





More information about the cfe-commits mailing list