]> granicus.if.org Git - clang/commitdiff
Driver: Add Arg::getAsString and use when dumping arguments to
authorDaniel Dunbar <daniel@zuster.org>
Fri, 20 Mar 2009 06:14:23 +0000 (06:14 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 20 Mar 2009 06:14:23 +0000 (06:14 +0000)
diagnostics.
 - This ensures that the whole argument and values are printed,
   instead of just the option name.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67366 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Arg.h
lib/Driver/Arg.cpp
lib/Driver/Driver.cpp

index 30bb56ad778c9b28c11eb82e273c1409f1d18171..a9e34d20c87b4c264b9931647b430daee39ef95e 100644 (file)
@@ -95,6 +95,10 @@ namespace driver {
     static bool classof(const Arg *) { return true; }    
 
     void dump() const;
+
+    /// getAsString - Return a formatted version of the argument and
+    /// its values, for debugging and diagnostics.
+    std::string getAsString(const ArgList &Args) const;
   };
 
   /// FlagArg - An argument with no value.
index eba39dd4f48ee9a0bef0f7f86cd4c865b43c7fc6..c43c9fbe4b1abf2f7582170ee5d85d218a369276 100644 (file)
@@ -50,6 +50,22 @@ void Arg::dump() const {
   llvm::errs() << ">\n";
 }
 
+std::string Arg::getAsString(const ArgList &Args) const {
+  std::string Res;
+  llvm::raw_string_ostream OS(Res);
+
+  ArgStringList ASL;
+  render(Args, ASL);
+  for (ArgStringList::iterator 
+         it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
+    if (it != ASL.begin())
+      OS << ' ';
+    OS << *it;
+  }
+
+  return OS.str();
+}
+
 void Arg::renderAsInput(const ArgList &Args, ArgStringList &Output) const {
   if (!getOption().hasNoOptAsInput()) {
     render(Args, Output);
index 2ae88267b0ec8e8519bda8862d8b266972e40950..2c324010dac294f89a94816b839c82531975e51c 100644 (file)
@@ -75,7 +75,7 @@ ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
     Arg *A = getOpts().ParseOneArg(*Args, Index, End);
     if (A) {
       if (A->getOption().isUnsupported()) {
-        Diag(clang::diag::err_drv_unsupported_opt) << A->getOption().getName();
+        Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args);
         continue;
       }
 
@@ -368,10 +368,10 @@ void Driver::BuildUniversalActions(const ArgList &Args,
     // overwriting the same files.
     if (const Arg *A = Args.getLastArg(options::OPT_M_Group))
       Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
-        << A->getOption().getName();
+        << A->getAsString(Args);
     if (const Arg *A = Args.getLastArg(options::OPT_save_temps))
       Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) 
-        << A->getOption().getName();
+        << A->getAsString(Args);
   }
 
   ActionList SingleActions;
@@ -534,7 +534,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
   // Reject -Z* at the top level, these options should never have been
   // exposed by gcc.
   if (Arg *A = Args.getLastArg(options::OPT_Z))
-    Diag(clang::diag::err_drv_use_of_Z_option) << A->getValue(Args);
+    Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args);
 
   // Construct the actions to perform.
   ActionList LinkerInputs;
@@ -552,7 +552,7 @@ void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const {
       // Claim here to avoid the more general unused warning.
       InputArg->claim();
       Diag(clang::diag::warn_drv_input_file_unused) 
-        << InputArg->getValue(Args)
+        << InputArg->getAsString(Args)
         << getPhaseName(InitialPhase)
         << FinalPhaseArg->getOption().getName();
       continue;
@@ -699,7 +699,7 @@ void Driver::BuildJobs(Compilation &C) const {
     // printed.
     if (!A->isClaimed())
       Diag(clang::diag::warn_drv_unused_argument) 
-        << A->getOption().getName();
+        << A->getAsString(C.getArgs());
   }
 }