]> granicus.if.org Git - clang/commitdiff
Make ArgumentAdjuster aware of the current file being processed.
authorAlexander Kornienko <alexfh@google.com>
Thu, 5 Nov 2015 02:19:53 +0000 (02:19 +0000)
committerAlexander Kornienko <alexfh@google.com>
Thu, 5 Nov 2015 02:19:53 +0000 (02:19 +0000)
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

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

include/clang/Tooling/ArgumentsAdjusters.h
lib/Tooling/ArgumentsAdjusters.cpp
lib/Tooling/CommonOptionsParser.cpp
lib/Tooling/Tooling.cpp
unittests/Tooling/ToolingTest.cpp

index a92e0214200593643fd8c5dd8468460bea3ef518..1fd7be688761aac900a8289db7da79e51423b1fb 100644 (file)
@@ -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> CommandLineArguments;
 ///
 /// 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.
index 1722ede08a8625517685f5b73c3631ba391811f2..2f3d829d7d197b8d41f9563d14c0150a76cc1e4c 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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 getClangSyntaxOnlyAdjuster() {
 }
 
 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 getClangStripOutputAdjuster() {
 
 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 getInsertArgumentAdjuster(const char *Extra,
 
 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);
   };
 }
 
index 289874bfd8a345d831664ef7ce2ee579f1a05efc..e6b986709a6e380e27b96f1ba877f0a4e1f6eeec 100644 (file)
@@ -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;
   }
 };
index 220b62558bfbcbc9036e5adb01f745a4d95ecc72..fd5596ec2ded10ee8bb3e172d1f43efd9103275c 100644 (file)
@@ -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
index b9f6df487f6ed7eaa0a4b5f00932f8891e4355e1..c4b174f183da8d8f272f8faf3a0a7288631f39bd 100644 (file)
@@ -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;