Index: include/clang/Tooling/ArgumentsAdjusters.h =================================================================== --- include/clang/Tooling/ArgumentsAdjusters.h (revision 188102) +++ include/clang/Tooling/ArgumentsAdjusters.h (working copy) @@ -16,6 +16,7 @@ #ifndef LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H #define LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H +#include "llvm/ADT/StringRef.h" #include #include @@ -36,10 +37,12 @@ public: /// \brief Returns adjusted command line arguments. /// + /// \param InputFile Input file. /// \param Args Input sequence of command line arguments. /// /// \returns Modified sequence of command line arguments. - virtual CommandLineArguments Adjust(const CommandLineArguments &Args) = 0; + virtual CommandLineArguments Adjust(llvm::StringRef InputFile, + const CommandLineArguments &Args) = 0; virtual ~ArgumentsAdjuster() { } }; @@ -49,13 +52,15 @@ /// This class implements ArgumentsAdjuster interface and converts input /// command line arguments to the "syntax check only" variant. class ClangSyntaxOnlyAdjuster : public ArgumentsAdjuster { - virtual CommandLineArguments Adjust(const CommandLineArguments &Args); + virtual CommandLineArguments Adjust(llvm::StringRef InputFile, + const CommandLineArguments &Args); }; /// \brief An argument adjuster which removes output-related command line /// arguments. class ClangStripOutputAdjuster : public ArgumentsAdjuster { - virtual CommandLineArguments Adjust(const CommandLineArguments &Args); + virtual CommandLineArguments Adjust(llvm::StringRef InputFile, + const CommandLineArguments &Args); }; } // end namespace tooling Index: tools/clang-check/ClangCheck.cpp =================================================================== --- tools/clang-check/ClangCheck.cpp (revision 188102) +++ tools/clang-check/ClangCheck.cpp (working copy) @@ -146,7 +146,8 @@ } virtual CommandLineArguments - Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE { + Adjust(llvm::StringRef InputFile, + const CommandLineArguments &Args) LLVM_OVERRIDE { CommandLineArguments Return(Args); CommandLineArguments::iterator I; Index: unittests/Tooling/ToolingTest.cpp =================================================================== --- unittests/Tooling/ToolingTest.cpp (revision 188102) +++ unittests/Tooling/ToolingTest.cpp (working copy) @@ -196,11 +196,14 @@ struct CheckSyntaxOnlyAdjuster: public ArgumentsAdjuster { bool &Found; bool &Ran; + std::string &File; - CheckSyntaxOnlyAdjuster(bool &Found, bool &Ran) : Found(Found), Ran(Ran) { } + CheckSyntaxOnlyAdjuster(bool &Found, bool &Ran, std::string &File) + : Found(Found), Ran(Ran), File(File) { } virtual CommandLineArguments - Adjust(const CommandLineArguments &Args) LLVM_OVERRIDE { + Adjust(llvm::StringRef InputFile, + const CommandLineArguments &Args) LLVM_OVERRIDE { Ran = true; for (unsigned I = 0, E = Args.size(); I != E; ++I) { if (Args[I] == "-fsyntax-only") { @@ -208,6 +211,7 @@ break; } } + File = InputFile; return Args; } }; @@ -220,18 +224,22 @@ bool Found = false; bool Ran = false; - Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran)); + std::string File; + Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran, File)); Tool.run(newFrontendActionFactory()); EXPECT_TRUE(Ran); EXPECT_TRUE(Found); + EXPECT_TRUE(File.compare(File.length() - 4, 4, "a.cc") == 0); Ran = Found = false; + File.clear(); Tool.clearArgumentsAdjusters(); - Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran)); + Tool.appendArgumentsAdjuster(new CheckSyntaxOnlyAdjuster(Found, Ran, File)); Tool.appendArgumentsAdjuster(new ClangSyntaxOnlyAdjuster()); Tool.run(newFrontendActionFactory()); EXPECT_TRUE(Ran); EXPECT_FALSE(Found); + EXPECT_TRUE(File.compare(File.length() - 4, 4, "a.cc") == 0); } } // end namespace tooling Index: lib/Tooling/ArgumentsAdjusters.cpp =================================================================== --- lib/Tooling/ArgumentsAdjusters.cpp (revision 188102) +++ lib/Tooling/ArgumentsAdjusters.cpp (working copy) @@ -24,7 +24,8 @@ /// Add -fsyntax-only option to the commnand line arguments. CommandLineArguments -ClangSyntaxOnlyAdjuster::Adjust(const CommandLineArguments &Args) { +ClangSyntaxOnlyAdjuster::Adjust(StringRef InputFile, + const CommandLineArguments &Args) { CommandLineArguments AdjustedArgs; for (size_t i = 0, e = Args.size(); i != e; ++i) { StringRef Arg = Args[i]; @@ -38,7 +39,8 @@ } CommandLineArguments -ClangStripOutputAdjuster::Adjust(const CommandLineArguments &Args) { +ClangStripOutputAdjuster::Adjust(llvm::StringRef InputFile, + const CommandLineArguments &Args) { CommandLineArguments AdjustedArgs; for (size_t i = 0, e = Args.size(); i < e; ++i) { StringRef Arg = Args[i]; Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp (revision 188102) +++ lib/Tooling/Tooling.cpp (working copy) @@ -308,7 +308,7 @@ CompileCommands[I].second.Directory + "\n!"); std::vector CommandLine = CompileCommands[I].second.CommandLine; for (unsigned I = 0, E = ArgsAdjusters.size(); I != E; ++I) - CommandLine = ArgsAdjusters[I]->Adjust(CommandLine); + CommandLine = ArgsAdjusters[I]->Adjust(File, CommandLine); assert(!CommandLine.empty()); CommandLine[0] = MainExecutable; // FIXME: We need a callback mechanism for the tool writer to output a