r252134 - Make ArgumentAdjuster aware of the current file being processed.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 18:19:53 PST 2015


Author: alexfh
Date: Wed Nov  4 20:19:53 2015
New Revision: 252134

URL: http://llvm.org/viewvc/llvm-project?rev=252134&view=rev
Log:
Make ArgumentAdjuster aware of the current file being processed.

Summary:
This is needed to handle per-project configurations when adding extra
arguments in clang-tidy for example.

Reviewers: klimek, djasper

Subscribers: djasper, cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D14191

Modified:
    cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
    cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
    cfe/trunk/lib/Tooling/CommonOptionsParser.cpp
    cfe/trunk/lib/Tooling/Tooling.cpp
    cfe/trunk/unittests/Tooling/ToolingTest.cpp

Modified: cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h?rev=252134&r1=252133&r2=252134&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h (original)
+++ cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h Wed Nov  4 20:19:53 2015
@@ -17,6 +17,8 @@
 #ifndef LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
 #define LLVM_CLANG_TOOLING_ARGUMENTSADJUSTERS_H
 
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/StringRef.h"
 #include <functional>
 #include <string>
 #include <vector>
@@ -31,8 +33,8 @@ typedef std::vector<std::string> Command
 ///
 /// Command line argument adjuster is responsible for command line arguments
 /// modification before the arguments are used to run a frontend action.
-typedef std::function<CommandLineArguments(const CommandLineArguments &)>
-    ArgumentsAdjuster;
+typedef std::function<CommandLineArguments(
+    const CommandLineArguments &, StringRef Filename)> ArgumentsAdjuster;
 
 /// \brief Gets an argument adjuster that converts input command line arguments
 /// to the "syntax check only" variant.

Modified: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp?rev=252134&r1=252133&r2=252134&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp (original)
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp Wed Nov  4 20:19:53 2015
@@ -13,15 +13,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Tooling/ArgumentsAdjusters.h"
-#include "clang/Basic/LLVM.h"
-#include "llvm/ADT/StringRef.h"
 
 namespace clang {
 namespace tooling {
 
 /// Add -fsyntax-only option to the commnand line arguments.
 ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
-  return [](const CommandLineArguments &Args) {
+  return [](const CommandLineArguments &Args, StringRef /*unused*/) {
     CommandLineArguments AdjustedArgs;
     for (size_t i = 0, e = Args.size(); i != e; ++i) {
       StringRef Arg = Args[i];
@@ -36,7 +34,7 @@ ArgumentsAdjuster getClangSyntaxOnlyAdju
 }
 
 ArgumentsAdjuster getClangStripOutputAdjuster() {
-  return [](const CommandLineArguments &Args) {
+  return [](const CommandLineArguments &Args, StringRef /*unused*/) {
     CommandLineArguments AdjustedArgs;
     for (size_t i = 0, e = Args.size(); i < e; ++i) {
       StringRef Arg = Args[i];
@@ -55,7 +53,7 @@ ArgumentsAdjuster getClangStripOutputAdj
 
 ArgumentsAdjuster getInsertArgumentAdjuster(const CommandLineArguments &Extra,
                                             ArgumentInsertPosition Pos) {
-  return [Extra, Pos](const CommandLineArguments &Args) {
+  return [Extra, Pos](const CommandLineArguments &Args, StringRef /*unused*/) {
     CommandLineArguments Return(Args);
 
     CommandLineArguments::iterator I;
@@ -78,8 +76,8 @@ ArgumentsAdjuster getInsertArgumentAdjus
 
 ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First,
                                    ArgumentsAdjuster Second) {
-  return [First, Second](const CommandLineArguments &Args) {
-    return Second(First(Args));
+  return [First, Second](const CommandLineArguments &Args, StringRef File) {
+    return Second(First(Args, File), File);
   };
 }
 

Modified: cfe/trunk/lib/Tooling/CommonOptionsParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CommonOptionsParser.cpp?rev=252134&r1=252133&r2=252134&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/CommonOptionsParser.cpp (original)
+++ cfe/trunk/lib/Tooling/CommonOptionsParser.cpp Wed Nov  4 20:19:53 2015
@@ -86,7 +86,7 @@ private:
   adjustCommands(std::vector<CompileCommand> Commands) const {
     for (CompileCommand &Command : Commands)
       for (const auto &Adjuster : Adjusters)
-        Command.CommandLine = Adjuster(Command.CommandLine);
+        Command.CommandLine = Adjuster(Command.CommandLine, Command.Filename);
     return Commands;
   }
 };

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=252134&r1=252133&r2=252134&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Wed Nov  4 20:19:53 2015
@@ -409,7 +409,7 @@ int ClangTool::run(ToolAction *Action) {
 
       std::vector<std::string> CommandLine = CompileCommand.CommandLine;
       if (ArgsAdjuster)
-        CommandLine = ArgsAdjuster(CommandLine);
+        CommandLine = ArgsAdjuster(CommandLine, CompileCommand.Filename);
       assert(!CommandLine.empty());
       CommandLine[0] = MainExecutable;
       // FIXME: We need a callback mechanism for the tool writer to output a

Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=252134&r1=252133&r2=252134&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Wed Nov  4 20:19:53 2015
@@ -288,7 +288,7 @@ TEST(ClangToolTest, ArgumentAdjusters) {
   bool Found = false;
   bool Ran = false;
   ArgumentsAdjuster CheckSyntaxOnlyAdjuster =
-      [&Found, &Ran](const CommandLineArguments &Args) {
+      [&Found, &Ran](const CommandLineArguments &Args, StringRef /*unused*/) {
     Ran = true;
     if (std::find(Args.begin(), Args.end(), "-fsyntax-only") != Args.end())
       Found = true;




More information about the cfe-commits mailing list