[cfe-commits] r81385 - in /cfe/trunk: include/clang/Driver/ArgList.h lib/Driver/ArgList.cpp

Daniel Dunbar daniel at zuster.org
Wed Sep 9 15:32:27 PDT 2009


Author: ddunbar
Date: Wed Sep  9 17:32:26 2009
New Revision: 81385

URL: http://llvm.org/viewvc/llvm-project?rev=81385&view=rev
Log:
StringRefize ArgList construction of ArgStrings.

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

Modified: cfe/trunk/include/clang/Driver/ArgList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ArgList.h?rev=81385&r1=81384&r2=81385&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ArgList.h (original)
+++ cfe/trunk/include/clang/Driver/ArgList.h Wed Sep  9 17:32:26 2009
@@ -14,10 +14,15 @@
 
 #include "clang/Driver/Util.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
 
 #include <list>
 #include <string>
 
+namespace llvm {
+  class Twine;
+}
+
 namespace clang {
 namespace driver {
   class Arg;
@@ -136,7 +141,14 @@
 
     /// MakeArgString - Construct a constant string pointer whose
     /// lifetime will match that of the ArgList.
-    virtual const char *MakeArgString(const char *Str) const = 0;
+    virtual const char *MakeArgString(llvm::StringRef Str) const = 0;
+    const char *MakeArgString(const char *Str) const {
+      return MakeArgString(llvm::StringRef(Str));
+    }
+    const char *MakeArgString(std::string Str) const {
+      return MakeArgString(llvm::StringRef(Str));
+    }
+    const char *MakeArgString(const llvm::Twine &Str) const;
 
     /// @}
   };
@@ -181,10 +193,10 @@
 
   public:
     /// MakeIndex - Get an index for the given string(s).
-    unsigned MakeIndex(const char *String0) const;
-    unsigned MakeIndex(const char *String0, const char *String1) const;
+    unsigned MakeIndex(llvm::StringRef String0) const;
+    unsigned MakeIndex(llvm::StringRef String0, llvm::StringRef String1) const;
 
-    virtual const char *MakeArgString(const char *Str) const;
+    virtual const char *MakeArgString(llvm::StringRef Str) const;
 
     /// @}
   };
@@ -218,7 +230,7 @@
     /// @name Arg Synthesis
     /// @{
 
-    virtual const char *MakeArgString(const char *Str) const;
+    virtual const char *MakeArgString(llvm::StringRef Str) const;
 
     /// MakeFlagArg - Construct a new FlagArg for the given option
     /// \arg Id.
@@ -227,17 +239,17 @@
     /// MakePositionalArg - Construct a new Positional arg for the
     /// given option \arg Id, with the provided \arg Value.
     Arg *MakePositionalArg(const Arg *BaseArg, const Option *Opt,
-                           const char *Value) const;
+                           llvm::StringRef Value) const;
 
     /// MakeSeparateArg - Construct a new Positional arg for the
     /// given option \arg Id, with the provided \arg Value.
     Arg *MakeSeparateArg(const Arg *BaseArg, const Option *Opt,
-                         const char *Value) const;
+                         llvm::StringRef Value) const;
 
     /// MakeJoinedArg - Construct a new Positional arg for the
     /// given option \arg Id, with the provided \arg Value.
     Arg *MakeJoinedArg(const Arg *BaseArg, const Option *Opt,
-                       const char *Value) const;
+                       llvm::StringRef Value) const;
 
     /// @}
   };

Modified: cfe/trunk/lib/Driver/ArgList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ArgList.cpp?rev=81385&r1=81384&r2=81385&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ArgList.cpp (original)
+++ cfe/trunk/lib/Driver/ArgList.cpp Wed Sep  9 17:32:26 2009
@@ -11,6 +11,10 @@
 #include "clang/Driver/Arg.h"
 #include "clang/Driver/Option.h"
 
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/raw_ostream.h"
+
 using namespace clang::driver;
 
 ArgList::ArgList(arglist_type &_Args) : Args(_Args) {
@@ -182,6 +186,12 @@
   }
 }
 
+const char *ArgList::MakeArgString(const llvm::Twine &T) const {
+  llvm::SmallString<256> Str;
+  T.toVector(Str);
+  return MakeArgString(Str.str());
+}
+
 //
 
 InputArgList::InputArgList(const char **ArgBegin, const char **ArgEnd)
@@ -195,7 +205,7 @@
     delete *it;
 }
 
-unsigned InputArgList::MakeIndex(const char *String0) const {
+unsigned InputArgList::MakeIndex(llvm::StringRef String0) const {
   unsigned Index = ArgStrings.size();
 
   // Tuck away so we have a reliable const char *.
@@ -205,8 +215,8 @@
   return Index;
 }
 
-unsigned InputArgList::MakeIndex(const char *String0,
-                                 const char *String1) const {
+unsigned InputArgList::MakeIndex(llvm::StringRef String0,
+                                 llvm::StringRef String1) const {
   unsigned Index0 = MakeIndex(String0);
   unsigned Index1 = MakeIndex(String1);
   assert(Index0 + 1 == Index1 && "Unexpected non-consecutive indices!");
@@ -214,7 +224,7 @@
   return Index0;
 }
 
-const char *InputArgList::MakeArgString(const char *Str) const {
+const char *InputArgList::MakeArgString(llvm::StringRef Str) const {
   return getArgString(MakeIndex(Str));
 }
 
@@ -232,7 +242,7 @@
     delete *it;
 }
 
-const char *DerivedArgList::MakeArgString(const char *Str) const {
+const char *DerivedArgList::MakeArgString(llvm::StringRef Str) const {
   return BaseArgs.MakeArgString(Str);
 }
 
@@ -241,18 +251,18 @@
 }
 
 Arg *DerivedArgList::MakePositionalArg(const Arg *BaseArg, const Option *Opt,
-                                       const char *Value) const {
+                                       llvm::StringRef Value) const {
   return new PositionalArg(Opt, BaseArgs.MakeIndex(Value), BaseArg);
 }
 
 Arg *DerivedArgList::MakeSeparateArg(const Arg *BaseArg, const Option *Opt,
-                                     const char *Value) const {
+                                     llvm::StringRef Value) const {
   return new SeparateArg(Opt, BaseArgs.MakeIndex(Opt->getName(), Value), 1,
                          BaseArg);
 }
 
 Arg *DerivedArgList::MakeJoinedArg(const Arg *BaseArg, const Option *Opt,
-                                   const char *Value) const {
+                                   llvm::StringRef Value) const {
   std::string Joined(Opt->getName());
   Joined += Value;
   return new JoinedArg(Opt, BaseArgs.MakeIndex(Joined.c_str()), BaseArg);





More information about the cfe-commits mailing list