[clang-tools-extra] r178785 - lib-ified core cpp11-migrate functionality to support unit tests

Edwin Vane edwin.vane at intel.com
Thu Apr 4 13:19:59 PDT 2013


Author: revane
Date: Thu Apr  4 15:19:58 2013
New Revision: 178785

URL: http://llvm.org/viewvc/llvm-project?rev=178785&view=rev
Log:
lib-ified core cpp11-migrate functionality to support unit tests

Summary:
Transform.* and Transforms.* moved to form a new library: libmigrateCore.
#includes updated to point to new header locations.

To support autoconf build, Cpp11Migrate.cpp moved to new subdirectory 'tool'
which also contains build files for creating final binary.

CMake and autoconf updated to build the new library and link it with
cpp11-migrate and with cpp11-migrate unit tests.

Dummy unit tests replaced with simple, but real, tests for Transform's public
interface.

TODO: Lib-ifying the transforms to further simplify build of cpp11-migrate.


Added:
    clang-tools-extra/trunk/cpp11-migrate/Core/
    clang-tools-extra/trunk/cpp11-migrate/Core/CMakeLists.txt
    clang-tools-extra/trunk/cpp11-migrate/Core/Makefile
    clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp
    clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h
    clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp
    clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.h
    clang-tools-extra/trunk/cpp11-migrate/tool/
    clang-tools-extra/trunk/cpp11-migrate/tool/CMakeLists.txt
    clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
    clang-tools-extra/trunk/cpp11-migrate/tool/Makefile
Removed:
    clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp
    clang-tools-extra/trunk/cpp11-migrate/Transform.cpp
    clang-tools-extra/trunk/cpp11-migrate/Transform.h
    clang-tools-extra/trunk/cpp11-migrate/Transforms.cpp
    clang-tools-extra/trunk/cpp11-migrate/Transforms.h
Modified:
    clang-tools-extra/trunk/cpp11-migrate/CMakeLists.txt
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.h
    clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h
    clang-tools-extra/trunk/cpp11-migrate/Makefile
    clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h
    clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.h
    clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.h
    clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h

Modified: clang-tools-extra/trunk/cpp11-migrate/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/CMakeLists.txt?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/cpp11-migrate/CMakeLists.txt Thu Apr  4 15:19:58 2013
@@ -2,32 +2,5 @@ set(LLVM_LINK_COMPONENTS support)
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
-set (Cpp11MigrateSources
-  Cpp11Migrate.cpp
-  Transforms.cpp
-  Transform.cpp
-  )
-
-# For each transform subdirectory.
-file(GLOB_RECURSE LoopConvertSources "LoopConvert/*.cpp")
-list(APPEND Cpp11MigrateSources ${LoopConvertSources})
-
-file(GLOB_RECURSE UseNullptrSources "UseNullptr/*.cpp")
-list(APPEND Cpp11MigrateSources ${UseNullptrSources})
-
-file(GLOB_RECURSE UseAutoSources "UseAuto/*.cpp")
-list(APPEND Cpp11MigrateSources ${UseAutoSources})
-
-add_clang_executable(cpp11-migrate
-  ${Cpp11MigrateSources}
-  )
-
-add_dependencies(cpp11-migrate
-  clang-headers
-  )
-
-target_link_libraries(cpp11-migrate
-  clangTooling
-  clangBasic
-  clangASTMatchers
-  )
+add_subdirectory(tool)
+add_subdirectory(Core)

Added: clang-tools-extra/trunk/cpp11-migrate/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/CMakeLists.txt?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/CMakeLists.txt Thu Apr  4 15:19:58 2013
@@ -0,0 +1,11 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(migrateCore
+  Transforms.cpp
+  Transform.cpp
+  )
+target_link_libraries(migrateCore
+  clangTooling
+  clangBasic
+  clangASTMatchers
+  )

Added: clang-tools-extra/trunk/cpp11-migrate/Core/Makefile
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Makefile?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Makefile (added)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Makefile Thu Apr  4 15:19:58 2013
@@ -0,0 +1,14 @@
+##===- cpp11-migrate/Core/Makefile -------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+CLANG_LEVEL := ../../../..
+LIBRARYNAME := migrateCore
+
+include $(CLANG_LEVEL)/Makefile
+
+CPP.Flags += -I$(PROJ_SRC_DIR)/..

Added: clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp (added)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp Thu Apr  4 15:19:58 2013
@@ -0,0 +1,37 @@
+#include "Core/Transform.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void collectResults(clang::Rewriter &Rewrite,
+                    const FileContentsByPath &InputStates,
+                    FileContentsByPath &Results) {
+  // Copy the contents of InputStates to be modified.
+  Results = InputStates;
+
+  for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(),
+                                 E = Rewrite.buffer_end();
+       I != E; ++I) {
+    const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
+    assert(Entry != 0 && "Expected a FileEntry");
+    assert(Entry->getName() != 0 &&
+           "Unexpected NULL return from FileEntry::getName()");
+
+    std::string ResultBuf;
+
+    // Get a copy of the rewritten buffer from the Rewriter.
+    llvm::raw_string_ostream StringStream(ResultBuf);
+    I->second.write(StringStream);
+
+    // Cause results to be written to ResultBuf.
+    StringStream.str();
+
+    // FIXME: Use move semantics to avoid copies of the buffer contents if
+    // benchmarking shows the copies are expensive, especially for large source
+    // files.
+    Results[Entry->getName()] = ResultBuf;
+  }
+}

Added: clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h (added)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transform.h Thu Apr  4 15:19:58 2013
@@ -0,0 +1,177 @@
+//===-- cpp11-migrate/Transform.h - Transform Base Class Def'n --*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file provides the definition for the base Transform class from
+/// which all transforms must subclass.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
+#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
+
+#include <string>
+#include <vector>
+
+// For RewriterContainer
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/Support/raw_ostream.h"
+////
+
+
+/// \brief Description of the riskiness of actions that can be taken by
+/// transforms.
+enum RiskLevel {
+  /// Transformations that will not change semantics.
+  RL_Safe,
+
+  /// Transformations that might change semantics.
+  RL_Reasonable,
+
+  /// Transformations that are likely to change semantics.
+  RL_Risky
+};
+
+// Forward declarations
+namespace clang {
+namespace tooling {
+class CompilationDatabase;
+} // namespace tooling
+} // namespace clang
+
+/// \brief The key is the path of a file, which is mapped to a
+/// buffer with the possibly modified contents of that file.
+typedef std::map<std::string, std::string> FileContentsByPath;
+
+/// \brief In \p Results place copies of the buffers resulting from applying
+/// all rewrites represented by \p Rewrite.
+///
+/// \p Results is made up of pairs {filename, buffer contents}. Pairs are
+/// simply appended to \p Results.
+void collectResults(clang::Rewriter &Rewrite,
+                    const FileContentsByPath &InputStates,
+                    FileContentsByPath &Results);
+
+/// \brief Class for containing a Rewriter instance and all of
+/// its lifetime dependencies.
+///
+/// Subclasses of Transform using RefactoringTools will need to create
+/// Rewriters in order to apply Replacements and get the resulting buffer.
+/// Rewriter requires some objects to exist at least as long as it does so this
+/// class contains instances of those objects.
+///
+/// FIXME: These objects should really come from somewhere more global instead
+/// of being recreated for every Transform subclass, especially diagnostics.
+class RewriterContainer {
+public:
+  RewriterContainer(clang::FileManager &Files,
+                    const FileContentsByPath &InputStates)
+    : DiagOpts(new clang::DiagnosticOptions()),
+      DiagnosticPrinter(llvm::errs(), DiagOpts.getPtr()),
+      Diagnostics(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>(
+                    new clang::DiagnosticIDs()),
+                  DiagOpts.getPtr(), &DiagnosticPrinter, false),
+      Sources(Diagnostics, Files),
+      Rewrite(Sources, DefaultLangOptions) {
+
+    // Overwrite source manager's file contents with data from InputStates
+    for (FileContentsByPath::const_iterator I = InputStates.begin(),
+                                            E = InputStates.end();
+         I != E; ++I) {
+      Sources.overrideFileContents(Files.getFile(I->first),
+                                   llvm::MemoryBuffer::getMemBuffer(I->second));
+    }
+  }
+
+  clang::Rewriter &getRewriter() { return Rewrite; }
+
+private:
+  clang::LangOptions DefaultLangOptions;
+  llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts;
+  clang::TextDiagnosticPrinter DiagnosticPrinter;
+  clang::DiagnosticsEngine Diagnostics;
+  clang::SourceManager Sources;
+  clang::Rewriter Rewrite;
+};
+
+/// \brief Abstract base class for all C++11 migration transforms.
+class Transform {
+public:
+  Transform(llvm::StringRef Name) : Name(Name) {
+    Reset();
+  }
+
+  virtual ~Transform() {}
+
+  /// \brief Apply a transform to all files listed in \p SourcePaths.
+  ///
+  /// \p Database must contain information for how to compile all files in \p
+  /// SourcePaths. \p InputStates contains the file contents of files in \p
+  /// SourcePaths and should take precedence over content of files on disk.
+  /// Upon return, \p ResultStates shall contain the result of performing this
+  /// transform on the files listed in \p SourcePaths.
+  virtual int apply(const FileContentsByPath &InputStates,
+                    RiskLevel MaxRiskLevel,
+                    const clang::tooling::CompilationDatabase &Database,
+                    const std::vector<std::string> &SourcePaths,
+                    FileContentsByPath &ResultStates) = 0;
+
+  /// \brief Query if changes were made during the last call to apply().
+  bool getChangesMade() const { return AcceptedChanges > 0; }
+
+  /// \brief Query if changes were not made due to conflicts with other changes
+  /// made during the last call to apply() or if changes were too risky for the
+  /// requested risk level.
+  bool getChangesNotMade() const {
+    return RejectedChanges > 0 || DeferredChanges > 0;
+  }
+
+  /// \brief Query the number of accepted changes.
+  unsigned getAcceptedChanges() const { return AcceptedChanges; }
+  /// \brief Query the number of changes considered too risky.
+  unsigned getRejectedChanges() const { return RejectedChanges; }
+  /// \brief Query the number of changes not made because they conflicted with
+  /// early changes.
+  unsigned getDeferredChanges() const { return DeferredChanges; }
+
+  /// \brief Query transform name.
+  llvm::StringRef getName() const { return Name; }
+
+  /// \brief Reset internal state of the transform.
+  ///
+  /// Useful if calling apply() several times with one instantiation of a
+  /// transform.
+  void Reset() {
+    AcceptedChanges = 0;
+    RejectedChanges = 0;
+    DeferredChanges = 0;
+  }
+
+protected:
+  void setAcceptedChanges(unsigned Changes) {
+    AcceptedChanges = Changes;
+  }
+  void setRejectedChanges(unsigned Changes) {
+    RejectedChanges = Changes;
+  }
+  void setDeferredChanges(unsigned Changes) {
+    DeferredChanges = Changes;
+  }
+
+private:
+  const std::string Name;
+  unsigned AcceptedChanges;
+  unsigned RejectedChanges;
+  unsigned DeferredChanges;
+};
+
+#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H

Added: clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp (added)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.cpp Thu Apr  4 15:19:58 2013
@@ -0,0 +1,67 @@
+//===-- cpp11-migrate/Transforms.cpp - class Transforms Impl ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file provides the implementation for class Transforms.
+///
+//===----------------------------------------------------------------------===//
+
+#include "Core/Transforms.h"
+#include "LoopConvert/LoopConvert.h"
+#include "UseNullptr/UseNullptr.h"
+#include "UseAuto/UseAuto.h"
+
+namespace cl = llvm::cl;
+
+template <typename T>
+Transform *ConstructTransform() {
+  return new T();
+}
+
+Transforms::~Transforms() {
+  for (std::vector<Transform*>::iterator I = ChosenTransforms.begin(),
+       E = ChosenTransforms.end(); I != E; ++I) {
+    delete *I;
+  }
+  for (OptionVec::iterator I = Options.begin(),
+       E = Options.end(); I != E; ++I) {
+    delete I->first;
+  }
+}
+
+void Transforms::createTransformOpts() {
+  Options.push_back(
+    OptionVec::value_type(
+      new cl::opt<bool>("loop-convert",
+        cl::desc("Make use of range-based for loops where possible")),
+      &ConstructTransform<LoopConvertTransform>));
+
+  Options.push_back(
+    OptionVec::value_type(
+      new cl::opt<bool>("use-nullptr",
+        cl::desc("Make use of nullptr keyword where possible")),
+      &ConstructTransform<UseNullptrTransform>));
+
+  Options.push_back(
+    OptionVec::value_type(
+      new cl::opt<bool>("use-auto",
+        cl::desc("Use of 'auto' type specifier")),
+      &ConstructTransform<UseAutoTransform>));
+
+  // Add more transform options here.
+}
+
+void Transforms::createSelectedTransforms() {
+  for (OptionVec::iterator I = Options.begin(),
+       E = Options.end(); I != E; ++I) {
+    if (*I->first) {
+      ChosenTransforms.push_back(I->second());
+    }
+  }
+}

Added: clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.h?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.h (added)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transforms.h Thu Apr  4 15:19:58 2013
@@ -0,0 +1,70 @@
+//===-- cpp11-migrate/Transforms.h - class Transforms Def'n -----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file provides the definition for class Transforms which is
+/// responsible for defining the command-line arguments exposing
+/// transformations to the user and applying requested transforms.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
+#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
+
+#include "llvm/Support/CommandLine.h"
+#include <vector>
+
+// Forward declarations
+namespace llvm {
+namespace cl {
+class Option;
+} // namespace cl
+} // namespace llvm
+class Transform;
+
+typedef Transform *(*TransformCreator)();
+
+/// \brief Class encapsulating the creation of command line bool options
+/// for each transform and instantiating transforms chosen by the user.
+class Transforms {
+public:
+  typedef std::vector<Transform*> TransformVec;
+  typedef TransformVec::const_iterator const_iterator;
+
+public:
+
+  ~Transforms();
+
+  /// \brief Create command line options using LLVM's command line library.
+  ///
+  /// Be sure to call *before* parsing options.
+  void createTransformOpts();
+
+  /// \brief Instantiate all transforms that were selected on the command line.
+  ///
+  /// Call *after* parsing options.
+  void createSelectedTransforms();
+
+  /// \brief Return an iterator to the start of a container of instantiated
+  /// transforms.
+  const_iterator begin() const { return ChosenTransforms.begin(); }
+
+  /// \brief Return an iterator to the end of a container of instantiated
+  /// transforms.
+  const_iterator end() const { return ChosenTransforms.end(); }
+
+private:
+  typedef std::vector<std::pair<llvm::cl::opt<bool>*, TransformCreator> >
+    OptionVec;
+
+private:
+  TransformVec ChosenTransforms;
+  OptionVec Options;
+};
+
+#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H

Removed: clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp?rev=178784&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Cpp11Migrate.cpp (removed)
@@ -1,136 +0,0 @@
-//===-- cpp11-migrate/Cpp11Migrate.cpp - Main file C++11 migration tool ---===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file implements the C++11 feature migration tool main function
-/// and transformation framework.
-///
-/// See user documentation for usage instructions.
-///
-//===----------------------------------------------------------------------===//
-
-#include "Transforms.h"
-#include "Transform.h"
-#include "clang/Frontend/FrontendActions.h"
-#include "clang/Tooling/CommonOptionsParser.h"
-#include "clang/Tooling/Tooling.h"
-#include "llvm/Support/Signals.h"
-
-namespace cl = llvm::cl;
-using namespace clang::tooling;
-
-static cl::opt<RiskLevel> MaxRiskLevel(
-    "risk", cl::desc("Select a maximum risk level:"),
-    cl::values(clEnumValN(RL_Safe, "safe", "Only safe transformations"),
-               clEnumValN(RL_Reasonable, "reasonable",
-                          "Enable transformations that might change "
-                          "semantics (default)"),
-               clEnumValN(RL_Risky, "risky",
-                          "Enable transformations that are likely to "
-                          "change semantics"),
-               clEnumValEnd),
-    cl::init(RL_Reasonable));
-
-static cl::opt<bool> FinalSyntaxCheck(
-    "final-syntax-check",
-    cl::desc("Check for correct syntax after applying transformations"),
-    cl::init(false));
-
-static cl::opt<bool>
-SummaryMode("summary", cl::desc("Print transform summary"),
-            cl::init(false));
-
-class EndSyntaxArgumentsAdjuster : public ArgumentsAdjuster {
-  CommandLineArguments Adjust(const CommandLineArguments &Args) {
-    CommandLineArguments AdjustedArgs = Args;
-    AdjustedArgs.push_back("-fsyntax-only");
-    AdjustedArgs.push_back("-std=c++11");
-    return AdjustedArgs;
-  }
-};
-
-int main(int argc, const char **argv) {
-  llvm::sys::PrintStackTraceOnErrorSignal();
-  Transforms TransformManager;
-
-  TransformManager.createTransformOpts();
-
-  // This causes options to be parsed.
-  CommonOptionsParser OptionsParser(argc, argv);
-
-  TransformManager.createSelectedTransforms();
-
-  if (TransformManager.begin() == TransformManager.end()) {
-    llvm::errs() << "No selected transforms\n";
-    return 1;
-  }
-
-  FileContentsByPath FileStates1, FileStates2,
-      *InputFileStates = &FileStates1, *OutputFileStates = &FileStates2;
-
-  // Apply transforms.
-  for (Transforms::const_iterator I = TransformManager.begin(),
-                                  E = TransformManager.end();
-       I != E; ++I) {
-    if ((*I)->apply(*InputFileStates, MaxRiskLevel,
-                    OptionsParser.getCompilations(),
-                    OptionsParser.getSourcePathList(), *OutputFileStates) !=
-        0) {
-      // FIXME: Improve ClangTool to not abort if just one file fails.
-      return 1;
-    }
-    if (SummaryMode) {
-      llvm::outs() << "Transform: " << (*I)->getName()
-                   << " - Accepted: "
-                   << (*I)->getAcceptedChanges();
-      if ((*I)->getChangesNotMade()) {
-         llvm::outs() << " - Rejected: "
-                      << (*I)->getRejectedChanges()
-                      << " - Deferred: "
-                      << (*I)->getDeferredChanges();
-      }
-      llvm::outs() << "\n";
-    }
-    std::swap(InputFileStates, OutputFileStates);
-    OutputFileStates->clear();
-  }
-
-  // Final state of files is pointed at by InputFileStates.
-
-  if (FinalSyntaxCheck) {
-    ClangTool EndSyntaxTool(OptionsParser.getCompilations(),
-                            OptionsParser.getSourcePathList());
-
-    // Add c++11 support to clang.
-    EndSyntaxTool.setArgumentsAdjuster(new EndSyntaxArgumentsAdjuster);
-
-    for (FileContentsByPath::const_iterator I = InputFileStates->begin(),
-                                            E = InputFileStates->end();
-         I != E; ++I) {
-      EndSyntaxTool.mapVirtualFile(I->first, I->second);
-    }
-
-    if (EndSyntaxTool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>())
-        != 0) {
-      return 1;
-    }
-  }
-
-  // Write results to file.
-  for (FileContentsByPath::const_iterator I = InputFileStates->begin(),
-                                          E = InputFileStates->end();
-       I != E; ++I) {
-    std::string ErrorInfo;
-    llvm::raw_fd_ostream FileStream(I->first.c_str(), ErrorInfo,
-                                    llvm::raw_fd_ostream::F_Binary);
-    FileStream << I->second;
-  }
-
-  return 0;
-}

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.h?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopActions.h Thu Apr  4 15:19:58 2013
@@ -16,7 +16,7 @@
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_LOOP_ACTIONS_H
 
 #include "StmtAncestor.h"
-#include "Transform.h"
+#include "Core/Transform.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"

Modified: clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/LoopConvert/LoopConvert.h Thu Apr  4 15:19:58 2013
@@ -16,7 +16,7 @@
 #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_LOOP_CONVERT_H
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_LOOP_CONVERT_H
 
-#include "Transform.h"
+#include "Core/Transform.h"
 #include "llvm/Support/Compiler.h" // For LLVM_OVERRIDE
 
 /// \brief Subclass of Transform that transforms for-loops into range-based

Modified: clang-tools-extra/trunk/cpp11-migrate/Makefile
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Makefile?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Makefile (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Makefile Thu Apr  4 15:19:58 2013
@@ -8,42 +8,8 @@
 ##===----------------------------------------------------------------------===##
 
 CLANG_LEVEL := ../../..
-
-TOOLNAME = cpp11-migrate
-NO_INSTALL = 1
-
-# No plugins, optimize startup time.
-TOOL_NO_EXPORTS = 1
-
 include $(CLANG_LEVEL)/../../Makefile.config
 
-SOURCES = Cpp11Migrate.cpp Transforms.cpp Transform.cpp
-
-# For each Transform subdirectory add to SOURCES and BUILT_SOURCES.
-# BUILT_SOURCES ensures a subdirectory is created to house object files from
-# transform subdirectories. See below for more on .objdir.
-SOURCES += $(addprefix LoopConvert/,$(notdir $(wildcard $(PROJ_SRC_DIR)/LoopConvert/*.cpp)))
-BUILT_SOURCES = $(ObjDir)/LoopConvert/.objdir
-SOURCES += $(addprefix UseNullptr/,$(notdir $(wildcard $(PROJ_SRC_DIR)/UseNullptr/*.cpp)))
-BUILT_SOURCES += $(ObjDir)/UseNullptr/.objdir
-SOURCES += $(addprefix UseAuto/,$(notdir $(wildcard $(PROJ_SRC_DIR)/UseAuto/*.cpp)))
-BUILT_SOURCES += $(ObjDir)/UseAuto/.objdir
-
-LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc
-USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
-		   clangRewriteFrontend.a clangRewriteCore.a clangParse.a \
-		   clangSema.a clangAnalysis.a \
-		   clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a
+DIRS = Core tool
 
 include $(CLANG_LEVEL)/Makefile
-
-# BUILT_SOURCES gets used as a prereq for many top-level targets. However, at
-# the point those targets are defined, $(ObjDir) hasn't been defined and so the
-# directory to create becomes /<name>/ which is not what we want. So instead,
-# this .objdir recipe is defined at at point where $(ObjDir) is defined and
-# it's specialized to $(ObjDir) to ensure it only works on targets we want it
-# to.
-$(ObjDir)/%.objdir:
-	$(Verb) $(MKDIR) $(ObjDir)/$* > /dev/null
-	$(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
-

Removed: clang-tools-extra/trunk/cpp11-migrate/Transform.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Transform.cpp?rev=178784&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Transform.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Transform.cpp (removed)
@@ -1,37 +0,0 @@
-#include "Transform.h"
-#include "clang/Basic/FileManager.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Rewrite/Core/Rewriter.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace clang;
-
-void collectResults(clang::Rewriter &Rewrite,
-                    const FileContentsByPath &InputStates,
-                    FileContentsByPath &Results) {
-  // Copy the contents of InputStates to be modified.
-  Results = InputStates;
-
-  for (Rewriter::buffer_iterator I = Rewrite.buffer_begin(),
-                                 E = Rewrite.buffer_end();
-       I != E; ++I) {
-    const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
-    assert(Entry != 0 && "Expected a FileEntry");
-    assert(Entry->getName() != 0 &&
-           "Unexpected NULL return from FileEntry::getName()");
-
-    std::string ResultBuf;
-
-    // Get a copy of the rewritten buffer from the Rewriter.
-    llvm::raw_string_ostream StringStream(ResultBuf);
-    I->second.write(StringStream);
-
-    // Cause results to be written to ResultBuf.
-    StringStream.str();
-
-    // FIXME: Use move semantics to avoid copies of the buffer contents if
-    // benchmarking shows the copies are expensive, especially for large source
-    // files.
-    Results[Entry->getName()] = ResultBuf;
-  }
-}

Removed: clang-tools-extra/trunk/cpp11-migrate/Transform.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Transform.h?rev=178784&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Transform.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Transform.h (removed)
@@ -1,177 +0,0 @@
-//===-- cpp11-migrate/Transform.h - Transform Base Class Def'n --*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file provides the definition for the base Transform class from
-/// which all transforms must subclass.
-///
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
-#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H
-
-#include <string>
-#include <vector>
-
-// For RewriterContainer
-#include "clang/Rewrite/Core/Rewriter.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/DiagnosticOptions.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
-#include "clang/Basic/SourceManager.h"
-#include "llvm/Support/raw_ostream.h"
-////
-
-
-/// \brief Description of the riskiness of actions that can be taken by
-/// transforms.
-enum RiskLevel {
-  /// Transformations that will not change semantics.
-  RL_Safe,
-
-  /// Transformations that might change semantics.
-  RL_Reasonable,
-
-  /// Transformations that are likely to change semantics.
-  RL_Risky
-};
-
-// Forward declarations
-namespace clang {
-namespace tooling {
-class CompilationDatabase;
-} // namespace tooling
-} // namespace clang
-
-/// \brief The key is the path of a file, which is mapped to a
-/// buffer with the possibly modified contents of that file.
-typedef std::map<std::string, std::string> FileContentsByPath;
-
-/// \brief In \p Results place copies of the buffers resulting from applying
-/// all rewrites represented by \p Rewrite.
-///
-/// \p Results is made up of pairs {filename, buffer contents}. Pairs are
-/// simply appended to \p Results.
-void collectResults(clang::Rewriter &Rewrite,
-                    const FileContentsByPath &InputStates,
-                    FileContentsByPath &Results);
-
-/// \brief Class for containing a Rewriter instance and all of
-/// its lifetime dependencies.
-///
-/// Subclasses of Transform using RefactoringTools will need to create
-/// Rewriters in order to apply Replacements and get the resulting buffer.
-/// Rewriter requires some objects to exist at least as long as it does so this
-/// class contains instances of those objects.
-///
-/// FIXME: These objects should really come from somewhere more global instead
-/// of being recreated for every Transform subclass, especially diagnostics.
-class RewriterContainer {
-public:
-  RewriterContainer(clang::FileManager &Files,
-                    const FileContentsByPath &InputStates)
-    : DiagOpts(new clang::DiagnosticOptions()),
-      DiagnosticPrinter(llvm::errs(), DiagOpts.getPtr()),
-      Diagnostics(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>(
-                    new clang::DiagnosticIDs()),
-                  DiagOpts.getPtr(), &DiagnosticPrinter, false),
-      Sources(Diagnostics, Files),
-      Rewrite(Sources, DefaultLangOptions) {
-
-    // Overwrite source manager's file contents with data from InputStates
-    for (FileContentsByPath::const_iterator I = InputStates.begin(),
-                                            E = InputStates.end();
-         I != E; ++I) {
-      Sources.overrideFileContents(Files.getFile(I->first),
-                                   llvm::MemoryBuffer::getMemBuffer(I->second));
-    }
-  }
-
-  clang::Rewriter &getRewriter() { return Rewrite; }
-
-private:
-  clang::LangOptions DefaultLangOptions;
-  llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts;
-  clang::TextDiagnosticPrinter DiagnosticPrinter;
-  clang::DiagnosticsEngine Diagnostics;
-  clang::SourceManager Sources;
-  clang::Rewriter Rewrite;
-};
-
-/// \brief Abstract base class for all C++11 migration transforms.
-class Transform {
-public:
-  Transform(llvm::StringRef Name) : Name(Name) {
-    Reset();
-  }
-
-  virtual ~Transform() {}
-
-  /// \brief Apply a transform to all files listed in \p SourcePaths.
-  ///
-  /// \p Database must contain information for how to compile all files in \p
-  /// SourcePaths. \p InputStates contains the file contents of files in \p
-  /// SourcePaths and should take precedence over content of files on disk.
-  /// Upon return, \p ResultStates shall contain the result of performing this
-  /// transform on the files listed in \p SourcePaths.
-  virtual int apply(const FileContentsByPath &InputStates,
-                    RiskLevel MaxRiskLevel,
-                    const clang::tooling::CompilationDatabase &Database,
-                    const std::vector<std::string> &SourcePaths,
-                    FileContentsByPath &ResultStates) = 0;
-
-  /// \brief Query if changes were made during the last call to apply().
-  bool getChangesMade() const { return AcceptedChanges > 0; }
-
-  /// \brief Query if changes were not made due to conflicts with other changes
-  /// made during the last call to apply() or if changes were too risky for the
-  /// requested risk level.
-  bool getChangesNotMade() const {
-    return RejectedChanges > 0 || DeferredChanges > 0;
-  }
-
-  /// \brief Query the number of accepted changes.
-  unsigned getAcceptedChanges() const { return AcceptedChanges; }
-  /// \brief Query the number of changes considered too risky.
-  unsigned getRejectedChanges() const { return RejectedChanges; }
-  /// \brief Query the number of changes not made because they conflicted with
-  /// early changes.
-  unsigned getDeferredChanges() const { return DeferredChanges; }
-
-  /// \brief Query transform name.
-  llvm::StringRef getName() const { return Name; }
-
-  /// \brief Reset internal state of the transform.
-  ///
-  /// Useful if calling apply() several times with one instantiation of a
-  /// transform.
-  void Reset() {
-    AcceptedChanges = 0;
-    RejectedChanges = 0;
-    DeferredChanges = 0;
-  }
-
-protected:
-  void setAcceptedChanges(unsigned Changes) {
-    AcceptedChanges = Changes;
-  }
-  void setRejectedChanges(unsigned Changes) {
-    RejectedChanges = Changes;
-  }
-  void setDeferredChanges(unsigned Changes) {
-    DeferredChanges = Changes;
-  }
-
-private:
-  const std::string Name;
-  unsigned AcceptedChanges;
-  unsigned RejectedChanges;
-  unsigned DeferredChanges;
-};
-
-#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORM_H

Removed: clang-tools-extra/trunk/cpp11-migrate/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Transforms.cpp?rev=178784&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Transforms.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Transforms.cpp (removed)
@@ -1,67 +0,0 @@
-//===-- cpp11-migrate/Transforms.cpp - class Transforms Impl ----*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file provides the implementation for class Transforms.
-///
-//===----------------------------------------------------------------------===//
-
-#include "Transforms.h"
-#include "LoopConvert/LoopConvert.h"
-#include "UseNullptr/UseNullptr.h"
-#include "UseAuto/UseAuto.h"
-
-namespace cl = llvm::cl;
-
-template <typename T>
-Transform *ConstructTransform() {
-  return new T();
-}
-
-Transforms::~Transforms() {
-  for (std::vector<Transform*>::iterator I = ChosenTransforms.begin(),
-       E = ChosenTransforms.end(); I != E; ++I) {
-    delete *I;
-  }
-  for (OptionVec::iterator I = Options.begin(),
-       E = Options.end(); I != E; ++I) {
-    delete I->first;
-  }
-}
-
-void Transforms::createTransformOpts() {
-  Options.push_back(
-    OptionVec::value_type(
-      new cl::opt<bool>("loop-convert",
-        cl::desc("Make use of range-based for loops where possible")),
-      &ConstructTransform<LoopConvertTransform>));
-
-  Options.push_back(
-    OptionVec::value_type(
-      new cl::opt<bool>("use-nullptr",
-        cl::desc("Make use of nullptr keyword where possible")),
-      &ConstructTransform<UseNullptrTransform>));
-
-  Options.push_back(
-    OptionVec::value_type(
-      new cl::opt<bool>("use-auto",
-        cl::desc("Use of 'auto' type specifier")),
-      &ConstructTransform<UseAutoTransform>));
-
-  // Add more transform options here.
-}
-
-void Transforms::createSelectedTransforms() {
-  for (OptionVec::iterator I = Options.begin(),
-       E = Options.end(); I != E; ++I) {
-    if (*I->first) {
-      ChosenTransforms.push_back(I->second());
-    }
-  }
-}

Removed: clang-tools-extra/trunk/cpp11-migrate/Transforms.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Transforms.h?rev=178784&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Transforms.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Transforms.h (removed)
@@ -1,70 +0,0 @@
-//===-- cpp11-migrate/Transforms.h - class Transforms Def'n -----*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file provides the definition for class Transforms which is
-/// responsible for defining the command-line arguments exposing
-/// transformations to the user and applying requested transforms.
-///
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
-#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H
-
-#include "llvm/Support/CommandLine.h"
-#include <vector>
-
-// Forward declarations
-namespace llvm {
-namespace cl {
-class Option;
-} // namespace cl
-} // namespace llvm
-class Transform;
-
-typedef Transform *(*TransformCreator)();
-
-/// \brief Class encapsulating the creation of command line bool options
-/// for each transform and instantiating transforms chosen by the user.
-class Transforms {
-public:
-  typedef std::vector<Transform*> TransformVec;
-  typedef TransformVec::const_iterator const_iterator;
-
-public:
-
-  ~Transforms();
-
-  /// \brief Create command line options using LLVM's command line library.
-  ///
-  /// Be sure to call *before* parsing options.
-  void createTransformOpts();
-
-  /// \brief Instantiate all transforms that were selected on the command line.
-  ///
-  /// Call *after* parsing options.
-  void createSelectedTransforms();
-
-  /// \brief Return an iterator to the start of a container of instantiated
-  /// transforms.
-  const_iterator begin() const { return ChosenTransforms.begin(); }
-
-  /// \brief Return an iterator to the end of a container of instantiated
-  /// transforms.
-  const_iterator end() const { return ChosenTransforms.end(); }
-
-private:
-  typedef std::vector<std::pair<llvm::cl::opt<bool>*, TransformCreator> >
-    OptionVec;
-
-private:
-  TransformVec ChosenTransforms;
-  OptionVec Options;
-};
-
-#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_TRANSFORMS_H

Modified: clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAuto.h Thu Apr  4 15:19:58 2013
@@ -17,7 +17,7 @@
 #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_AUTO_H
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_AUTO_H
 
-#include "Transform.h"
+#include "Core/Transform.h"
 #include "llvm/Support/Compiler.h"
 
 /// \brief Subclass of Transform that transforms type specifiers for variable

Modified: clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.h?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseAuto/UseAutoActions.h Thu Apr  4 15:19:58 2013
@@ -15,7 +15,7 @@
 #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_AUTO_ACTIONS_H
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_AUTO_ACTIONS_H
 
-#include "Transform.h"
+#include "Core/Transform.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Tooling/Refactoring.h"
 

Modified: clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.h?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/NullptrActions.h Thu Apr  4 15:19:58 2013
@@ -15,7 +15,7 @@
 #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_NULLPTR_ACTIONS_H
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_NULLPTR_ACTIONS_H
 
-#include "Transform.h"
+#include "Core/Transform.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Tooling/Refactoring.h"
 

Modified: clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h?rev=178785&r1=178784&r2=178785&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/UseNullptr/UseNullptr.h Thu Apr  4 15:19:58 2013
@@ -16,7 +16,7 @@
 #ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_NULLPTR_H
 #define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_USE_NULLPTR_H
 
-#include "Transform.h"
+#include "Core/Transform.h"
 #include "llvm/Support/Compiler.h" // For LLVM_OVERRIDE
 
 /// \brief Subclass of Transform that transforms null pointer constants into

Added: clang-tools-extra/trunk/cpp11-migrate/tool/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/tool/CMakeLists.txt?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/CMakeLists.txt Thu Apr  4 15:19:58 2013
@@ -0,0 +1,29 @@
+set(LLVM_LINK_COMPONENTS support)
+
+set (Cpp11MigrateSources
+  Cpp11Migrate.cpp
+  )
+
+# FIXME: Lib-ify the transforms to simplify the build rules.
+
+# For each transform subdirectory.
+file(GLOB_RECURSE LoopConvertSources "../LoopConvert/*.cpp")
+list(APPEND Cpp11MigrateSources ${LoopConvertSources})
+
+file(GLOB_RECURSE UseNullptrSources "../UseNullptr/*.cpp")
+list(APPEND Cpp11MigrateSources ${UseNullptrSources})
+
+file(GLOB_RECURSE UseAutoSources "../UseAuto/*.cpp")
+list(APPEND Cpp11MigrateSources ${UseAutoSources})
+
+add_clang_executable(cpp11-migrate
+  ${Cpp11MigrateSources}
+  )
+
+add_dependencies(cpp11-migrate
+  clang-headers
+  )
+
+target_link_libraries(cpp11-migrate
+  migrateCore
+  )

Added: clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp (added)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp Thu Apr  4 15:19:58 2013
@@ -0,0 +1,136 @@
+//===-- cpp11-migrate/Cpp11Migrate.cpp - Main file C++11 migration tool ---===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file implements the C++11 feature migration tool main function
+/// and transformation framework.
+///
+/// See user documentation for usage instructions.
+///
+//===----------------------------------------------------------------------===//
+
+#include "Core/Transforms.h"
+#include "Core/Transform.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Signals.h"
+
+namespace cl = llvm::cl;
+using namespace clang::tooling;
+
+static cl::opt<RiskLevel> MaxRiskLevel(
+    "risk", cl::desc("Select a maximum risk level:"),
+    cl::values(clEnumValN(RL_Safe, "safe", "Only safe transformations"),
+               clEnumValN(RL_Reasonable, "reasonable",
+                          "Enable transformations that might change "
+                          "semantics (default)"),
+               clEnumValN(RL_Risky, "risky",
+                          "Enable transformations that are likely to "
+                          "change semantics"),
+               clEnumValEnd),
+    cl::init(RL_Reasonable));
+
+static cl::opt<bool> FinalSyntaxCheck(
+    "final-syntax-check",
+    cl::desc("Check for correct syntax after applying transformations"),
+    cl::init(false));
+
+static cl::opt<bool>
+SummaryMode("summary", cl::desc("Print transform summary"),
+            cl::init(false));
+
+class EndSyntaxArgumentsAdjuster : public ArgumentsAdjuster {
+  CommandLineArguments Adjust(const CommandLineArguments &Args) {
+    CommandLineArguments AdjustedArgs = Args;
+    AdjustedArgs.push_back("-fsyntax-only");
+    AdjustedArgs.push_back("-std=c++11");
+    return AdjustedArgs;
+  }
+};
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal();
+  Transforms TransformManager;
+
+  TransformManager.createTransformOpts();
+
+  // This causes options to be parsed.
+  CommonOptionsParser OptionsParser(argc, argv);
+
+  TransformManager.createSelectedTransforms();
+
+  if (TransformManager.begin() == TransformManager.end()) {
+    llvm::errs() << "No selected transforms\n";
+    return 1;
+  }
+
+  FileContentsByPath FileStates1, FileStates2,
+      *InputFileStates = &FileStates1, *OutputFileStates = &FileStates2;
+
+  // Apply transforms.
+  for (Transforms::const_iterator I = TransformManager.begin(),
+                                  E = TransformManager.end();
+       I != E; ++I) {
+    if ((*I)->apply(*InputFileStates, MaxRiskLevel,
+                    OptionsParser.getCompilations(),
+                    OptionsParser.getSourcePathList(), *OutputFileStates) !=
+        0) {
+      // FIXME: Improve ClangTool to not abort if just one file fails.
+      return 1;
+    }
+    if (SummaryMode) {
+      llvm::outs() << "Transform: " << (*I)->getName()
+                   << " - Accepted: "
+                   << (*I)->getAcceptedChanges();
+      if ((*I)->getChangesNotMade()) {
+         llvm::outs() << " - Rejected: "
+                      << (*I)->getRejectedChanges()
+                      << " - Deferred: "
+                      << (*I)->getDeferredChanges();
+      }
+      llvm::outs() << "\n";
+    }
+    std::swap(InputFileStates, OutputFileStates);
+    OutputFileStates->clear();
+  }
+
+  // Final state of files is pointed at by InputFileStates.
+
+  if (FinalSyntaxCheck) {
+    ClangTool EndSyntaxTool(OptionsParser.getCompilations(),
+                            OptionsParser.getSourcePathList());
+
+    // Add c++11 support to clang.
+    EndSyntaxTool.setArgumentsAdjuster(new EndSyntaxArgumentsAdjuster);
+
+    for (FileContentsByPath::const_iterator I = InputFileStates->begin(),
+                                            E = InputFileStates->end();
+         I != E; ++I) {
+      EndSyntaxTool.mapVirtualFile(I->first, I->second);
+    }
+
+    if (EndSyntaxTool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>())
+        != 0) {
+      return 1;
+    }
+  }
+
+  // Write results to file.
+  for (FileContentsByPath::const_iterator I = InputFileStates->begin(),
+                                          E = InputFileStates->end();
+       I != E; ++I) {
+    std::string ErrorInfo;
+    llvm::raw_fd_ostream FileStream(I->first.c_str(), ErrorInfo,
+                                    llvm::raw_fd_ostream::F_Binary);
+    FileStream << I->second;
+  }
+
+  return 0;
+}

Added: clang-tools-extra/trunk/cpp11-migrate/tool/Makefile
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/tool/Makefile?rev=178785&view=auto
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/Makefile (added)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/Makefile Thu Apr  4 15:19:58 2013
@@ -0,0 +1,53 @@
+##===- tools/extra/loop-convert/Makefile ----sssss----------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+CLANG_LEVEL := ../../../..
+include $(CLANG_LEVEL)/../../Makefile.config
+
+TOOLNAME = cpp11-migrate
+NO_INSTALL = 1
+
+# No plugins, optimize startup time.
+TOOL_NO_EXPORTS = 1
+
+SOURCES = Cpp11Migrate.cpp
+
+# FIXME: All these gross relative paths will go away once transforms are lib-ified.
+
+# For each Transform subdirectory add to SOURCES and BUILT_SOURCES.
+# BUILT_SOURCES ensures a subdirectory is created to house object files from
+# transform subdirectories. See below for more on .objdir.
+SOURCES += $(addprefix ../LoopConvert/,$(notdir $(wildcard $(PROJ_SRC_DIR)/../LoopConvert/*.cpp)))
+BUILT_SOURCES = $(ObjDir)/../LoopConvert/.objdir
+SOURCES += $(addprefix ../UseNullptr/,$(notdir $(wildcard $(PROJ_SRC_DIR)/../UseNullptr/*.cpp)))
+BUILT_SOURCES += $(ObjDir)/../UseNullptr/.objdir
+SOURCES += $(addprefix ../UseAuto/,$(notdir $(wildcard $(PROJ_SRC_DIR)/../UseAuto/*.cpp)))
+BUILT_SOURCES += $(ObjDir)/../UseAuto/.objdir
+
+LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc
+USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
+		   clangRewriteFrontend.a clangRewriteCore.a clangParse.a \
+		   clangSema.a clangAnalysis.a \
+		   clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a \
+			 migrateCore.a
+
+include $(CLANG_LEVEL)/Makefile
+
+CPP.Flags += -I$(PROJ_SRC_DIR)/..
+
+# BUILT_SOURCES gets used as a prereq for many top-level targets. However, at
+# the point those targets are defined, $(ObjDir) hasn't been defined and so the
+# directory to create becomes /<name>/ which is not what we want. So instead,
+# this .objdir recipe is defined at at point where $(ObjDir) is defined and
+# it's specialized to $(ObjDir) to ensure it only works on targets we want it
+# to.
+$(ObjDir)/%.objdir:
+	$(Verb) $(MKDIR) $(ObjDir)/$* > /dev/null
+	$(Verb) $(DOTDIR_TIMESTAMP_COMMAND) > $@
+





More information about the cfe-commits mailing list