[clang-tools-extra] r223249 - Make ArgumentsAdjuster an std::function (clang-tools-extra part of D6505).

Alexander Kornienko alexfh at google.com
Wed Dec 3 09:53:03 PST 2014


Author: alexfh
Date: Wed Dec  3 11:53:03 2014
New Revision: 223249

URL: http://llvm.org/viewvc/llvm-project?rev=223249&view=rev
Log:
Make ArgumentsAdjuster an std::function (clang-tools-extra part of D6505).

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

Modified:
    clang-tools-extra/trunk/modularize/Modularize.cpp

Modified: clang-tools-extra/trunk/modularize/Modularize.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=223249&r1=223248&r2=223249&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/Modularize.cpp (original)
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Wed Dec  3 11:53:03 2014
@@ -304,32 +304,24 @@ std::string findInputFile(const CommandL
   return Inputs.back();
 }
 
-// We provide this derivation to add in "-include (file)" arguments for header
+// This arguments adjuster inserts "-include (file)" arguments for header
 // dependencies.
-class AddDependenciesAdjuster : public ArgumentsAdjuster {
-public:
-  AddDependenciesAdjuster(DependencyMap &Dependencies)
-      : Dependencies(Dependencies) {}
-
-private:
-  // Callback for adjusting commandline arguments.
-  CommandLineArguments Adjust(const CommandLineArguments &Args) {
+ArgumentsAdjuster getAddDependenciesAdjuster(DependencyMap &Dependencies) {
+  return [&Dependencies](const CommandLineArguments &Args) {
     std::string InputFile = findInputFile(Args);
     DependentsVector &FileDependents = Dependencies[InputFile];
-    int Count = FileDependents.size();
-    if (Count == 0)
-      return Args;
     CommandLineArguments NewArgs(Args);
-    for (int Index = 0; Index < Count; ++Index) {
-      NewArgs.push_back("-include");
-      std::string File(std::string("\"") + FileDependents[Index] +
-                       std::string("\""));
-      NewArgs.push_back(FileDependents[Index]);
+    if (int Count = FileDependents.size()) {
+      for (int Index = 0; Index < Count; ++Index) {
+        NewArgs.push_back("-include");
+        std::string File(std::string("\"") + FileDependents[Index] +
+                         std::string("\""));
+        NewArgs.push_back(FileDependents[Index]);
+      }
     }
     return NewArgs;
-  }
-  DependencyMap &Dependencies;
-};
+  };
+}
 
 // FIXME: The Location class seems to be something that we might
 // want to design to be applicable to a wider range of tools, and stick it
@@ -734,7 +726,7 @@ int main(int Argc, const char **Argv) {
   // Parse all of the headers, detecting duplicates.
   EntityMap Entities;
   ClangTool Tool(*Compilations, Headers);
-  Tool.appendArgumentsAdjuster(new AddDependenciesAdjuster(Dependencies));
+  Tool.appendArgumentsAdjuster(getAddDependenciesAdjuster(Dependencies));
   int HadErrors = 0;
   ModularizeFrontendActionFactory Factory(Entities, *PPTracker, HadErrors);
   HadErrors |= Tool.run(&Factory);





More information about the cfe-commits mailing list