From: Daniel Dunbar Date: Fri, 20 Mar 2009 06:14:23 +0000 (+0000) Subject: Driver: Add Arg::getAsString and use when dumping arguments to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38dd3d54186cf44ea9d37f463c3f2800ab526b82;p=clang Driver: Add Arg::getAsString and use when dumping arguments to 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 --- diff --git a/include/clang/Driver/Arg.h b/include/clang/Driver/Arg.h index 30bb56ad77..a9e34d20c8 100644 --- a/include/clang/Driver/Arg.h +++ b/include/clang/Driver/Arg.h @@ -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. diff --git a/lib/Driver/Arg.cpp b/lib/Driver/Arg.cpp index eba39dd4f4..c43c9fbe4b 100644 --- a/lib/Driver/Arg.cpp +++ b/lib/Driver/Arg.cpp @@ -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); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 2ae88267b0..2c324010da 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -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()); } }