[cfe-commits] r128142 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp lib/Frontend/ASTUnit.cpp tools/driver/driver.cpp

Chris Lattner sabre at nondot.org
Tue Mar 22 21:04:01 PDT 2011


Author: lattner
Date: Tue Mar 22 23:04:01 2011
New Revision: 128142

URL: http://llvm.org/viewvc/llvm-project?rev=128142&view=rev
Log:
switch a few Driver APIs to use llvm::ArrayRef, cleaning up code.

Modified:
    cfe/trunk/include/clang/Driver/Driver.h
    cfe/trunk/lib/Driver/Driver.cpp
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/include/clang/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=128142&r1=128141&r2=128142&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Driver.h (original)
+++ cfe/trunk/include/clang/Driver/Driver.h Tue Mar 22 23:04:01 2011
@@ -25,6 +25,7 @@
 
 namespace llvm {
   class raw_ostream;
+  template<typename T> class ArrayRef;
 }
 namespace clang {
 namespace driver {
@@ -215,14 +216,14 @@
   /// argument vector. A null return value does not necessarily
   /// indicate an error condition, the diagnostics should be queried
   /// to determine if an error occurred.
-  Compilation *BuildCompilation(int argc, const char **argv);
+  Compilation *BuildCompilation(llvm::ArrayRef<const char *> Args);
 
   /// @name Driver Steps
   /// @{
 
   /// ParseArgStrings - Parse the given list of strings into an
   /// ArgList.
-  InputArgList *ParseArgStrings(const char **ArgBegin, const char **ArgEnd);
+  InputArgList *ParseArgStrings(llvm::ArrayRef<const char *> Args);
 
   /// BuildActions - Construct the list of actions to perform for the
   /// given arguments, which are only done for a single architecture.

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=128142&r1=128141&r2=128142&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Mar 22 23:04:01 2011
@@ -30,6 +30,7 @@
 #include "clang/Basic/Version.h"
 
 #include "llvm/Config/config.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Support/PrettyStackTrace.h"
@@ -100,11 +101,10 @@
   delete Host;
 }
 
-InputArgList *Driver::ParseArgStrings(const char **ArgBegin,
-                                      const char **ArgEnd) {
+InputArgList *Driver::ParseArgStrings(llvm::ArrayRef<const char *> ArgList) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
   unsigned MissingArgIndex, MissingArgCount;
-  InputArgList *Args = getOpts().ParseArgs(ArgBegin, ArgEnd,
+  InputArgList *Args = getOpts().ParseArgs(ArgList.begin(), ArgList.end(),
                                            MissingArgIndex, MissingArgCount);
 
   // Check for missing argument error.
@@ -206,7 +206,7 @@
   return DAL;
 }
 
-Compilation *Driver::BuildCompilation(int argc, const char **argv) {
+Compilation *Driver::BuildCompilation(llvm::ArrayRef<const char *> ArgList) {
   llvm::PrettyStackTraceString CrashInfo("Compilation construction");
 
   // FIXME: Handle environment options which effect driver behavior, somewhere
@@ -218,9 +218,7 @@
   // FIXME: This stuff needs to go into the Compilation, not the driver.
   bool CCCPrintOptions = false, CCCPrintActions = false;
 
-  const char **Start = argv + 1, **End = argv + argc;
-
-  InputArgList *Args = ParseArgStrings(Start, End);
+  InputArgList *Args = ParseArgStrings(ArgList.slice(1));
 
   // -no-canonical-prefixes is used very early in main.
   Args->ClaimAllArgs(options::OPT_no_canonical_prefixes);

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=128142&r1=128141&r2=128142&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Mar 22 23:04:01 2011
@@ -36,6 +36,7 @@
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Atomic.h"
@@ -1661,10 +1662,7 @@
     // Don't check that inputs exist, they have been remapped.
     TheDriver.setCheckInputsExist(false);
 
-    llvm::OwningPtr<driver::Compilation> C(
-      TheDriver.BuildCompilation(
-        Args->size(),
-        Args->size() ? &(*Args)[0] : 0 ));  // std::vector::data() not portable
+    llvm::OwningPtr<driver::Compilation> C(TheDriver.BuildCompilation(*Args));
 
     // Just print the cc1 options if -### was present.
     if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) {

Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=128142&r1=128141&r2=128142&view=diff
==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Tue Mar 22 23:04:01 2011
@@ -18,6 +18,7 @@
 #include "clang/Frontend/DiagnosticOptions.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/OwningPtr.h"
@@ -448,8 +449,7 @@
     argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end());
   }
 
-  llvm::OwningPtr<Compilation> C(TheDriver.BuildCompilation(argv.size(),
-                                                            &argv[0]));
+  llvm::OwningPtr<Compilation> C(TheDriver.BuildCompilation(argv));
   int Res = 0;
   if (C.get())
     Res = TheDriver.ExecuteCompilation(*C);





More information about the cfe-commits mailing list