cpp11-migrate: Remove mention of 'headers' from serialization code
authorEdwin Vane <edwin.vane@intel.com>
Wed, 14 Aug 2013 19:02:28 +0000 (19:02 +0000)
committerEdwin Vane <edwin.vane@intel.com>
Wed, 14 Aug 2013 19:02:28 +0000 (19:02 +0000)
* HeaderChangeDocument -> MigratorDocument
* HeaderFileName -> TargetFile
* SourceFileName -> MainSourceFile
* Removed TransformID
* Comments updated, at least with respect to serialization
* Unit tests updated.

Differential Revision: http://llvm-reviews.chandlerc.com/D1403

llvm-svn: 188404

clang-tools-extra/cpp11-migrate/Core/FileOverrides.cpp
clang-tools-extra/cpp11-migrate/Core/FileOverrides.h
clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp
clang-tools-extra/cpp11-migrate/Core/Reformatting.cpp
clang-tools-extra/cpp11-migrate/Core/ReplacementsYaml.h
clang-tools-extra/cpp11-migrate/Core/Transform.cpp
clang-tools-extra/cpp11-migrate/tool/Cpp11Migrate.cpp
clang-tools-extra/test/cpp11-migrate/HeaderReplacements/common.h.yaml
clang-tools-extra/unittests/cpp11-migrate/FileOverridesTest.cpp
clang-tools-extra/unittests/cpp11-migrate/ReformattingTest.cpp
clang-tools-extra/unittests/cpp11-migrate/ReplacementsYamlTest.cpp

index 377438fc5cc93844cb624696c61db8378dbea183..1772a4f553b8d718adea6924735ae4930c710a20 100644 (file)
@@ -29,19 +29,18 @@ using namespace clang;
 using namespace clang::tooling;
 
 void HeaderOverride::recordReplacements(
-    llvm::StringRef TransformID, const clang::tooling::Replacements &Replaces) {
-  HeaderChangeDoc.TransformID = TransformID;
-  HeaderChangeDoc.Replacements.resize(Replaces.size());
+    const clang::tooling::Replacements &Replaces) {
+  MigratorDoc.Replacements.resize(Replaces.size());
   std::copy(Replaces.begin(), Replaces.end(),
-            HeaderChangeDoc.Replacements.begin());
+            MigratorDoc.Replacements.begin());
 }
 
 SourceOverrides::SourceOverrides(llvm::StringRef MainFileName,
                                  bool TrackChanges)
     : MainFileName(MainFileName), TrackChanges(TrackChanges) {}
 
-void SourceOverrides::applyReplacements(clang::tooling::Replacements &Replaces,
-                                        llvm::StringRef TransformName) {
+void
+SourceOverrides::applyReplacements(clang::tooling::Replacements &Replaces) {
   llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts(
       new DiagnosticOptions());
   DiagnosticsEngine Diagnostics(
@@ -49,12 +48,11 @@ void SourceOverrides::applyReplacements(clang::tooling::Replacements &Replaces,
       DiagOpts.getPtr());
   FileManager Files((FileSystemOptions()));
   SourceManager SM(Diagnostics, Files);
-  applyReplacements(Replaces, SM, TransformName);
+  applyReplacements(Replaces, SM);
 }
 
 void SourceOverrides::applyReplacements(clang::tooling::Replacements &Replaces,
-                                        clang::SourceManager &SM,
-                                        llvm::StringRef TransformName) {
+                                        clang::SourceManager &SM) {
   applyOverrides(SM);
 
   Rewriter Rewrites(SM, LangOptions());
@@ -121,7 +119,7 @@ void SourceOverrides::applyReplacements(clang::tooling::Replacements &Replaces,
                                        E = HeadersReplaces.end();
        I != E; ++I) {
     HeaderOverride &HeaderOv = Headers[I->getKey()];
-    HeaderOv.recordReplacements(TransformName, I->getValue());
+    HeaderOv.recordReplacements(I->getValue());
   }
 
   if (TrackChanges)
index 594d3c88a2d0a9b03091dbab5c54bde719bc244b..08c120f24979f7d330bff38dcb6bc426bfad350d 100644 (file)
@@ -64,16 +64,16 @@ public:
   /// \brief Constructors.
   /// @{
   HeaderOverride() {}
-  HeaderOverride(llvm::StringRef HeaderFileName,
-                 llvm::StringRef SourceFileName) {
-    HeaderChangeDoc.HeaderFileName = HeaderFileName;
-    HeaderChangeDoc.SourceFileName = SourceFileName;
+  HeaderOverride(llvm::StringRef TargetFile,
+                 llvm::StringRef MainSourceFile) {
+    MigratorDoc.TargetFile = TargetFile;
+    MigratorDoc.MainSourceFile= MainSourceFile;
   }
   /// @}
 
   /// \brief Getter for FileName.
   llvm::StringRef getFileName() const {
-    return HeaderChangeDoc.HeaderFileName;
+    return MigratorDoc.TargetFile;
   }
 
   /// \brief Accessor for ContentOverride.
@@ -88,15 +88,14 @@ public:
   /// \brief Swaps the content of ContentOverride with \p S.
   void swapContentOverride(std::string &S) { ContentOverride.swap(S); }
 
-  /// \brief Getter for HeaderChangeDoc.
-  const HeaderChangeDocument &getHeaderChangeDoc() const {
-    return HeaderChangeDoc;
+  /// \brief Getter for MigratorDoc.
+  const MigratorDocument &getMigratorDoc() const {
+    return MigratorDoc;
   }
 
   /// \brief Stores the replacements made by a transform to the header this
   /// object represents.
-  void recordReplacements(llvm::StringRef TransformID,
-                          const clang::tooling::Replacements &Replaces);
+  void recordReplacements(const clang::tooling::Replacements &Replaces);
 
   /// \brief Helper function to adjust the changed ranges.
   void adjustChangedRanges(const clang::tooling::Replacements &Replaces) {
@@ -106,7 +105,7 @@ public:
 private:
   std::string ContentOverride;
   ChangedRanges Changes;
-  HeaderChangeDocument HeaderChangeDoc;
+  MigratorDocument MigratorDoc;
 };
 
 /// \brief Container mapping header file names to override information.
@@ -141,12 +140,9 @@ public:
   ///
   /// \param Replaces The replacements to apply.
   /// \param SM A user provided SourceManager to be used when applying rewrites.
-  /// \param TransformName The name of the transform the replacements come from.
   void applyReplacements(clang::tooling::Replacements &Replaces,
-                         clang::SourceManager &SM,
-                         llvm::StringRef TransformName);
-  void applyReplacements(clang::tooling::Replacements &Replaces,
-                         llvm::StringRef TransformName);
+                         clang::SourceManager &SM);
+  void applyReplacements(clang::tooling::Replacements &Replaces);
 
   /// \brief Convenience function for applying this source's overrides to
   /// the given SourceManager.
index d6bc333ca209396ca0cfb5e92cd754bb95d1e680..e3f07c5f0d3e9b0ef98b8c7c0f1fd8dde7428b9f 100644 (file)
@@ -151,6 +151,7 @@ bool IncludeExcludeInfo::isFileIncluded(StringRef FilePath) const {
        I != E; ++I)
     if ((InIncludeList = fileHasPathPrefix(FilePath, *I)))
       break;
+
   // If file is not in the list of included paths then it is not necessary
   // to check the excluded path list.
   if (!InIncludeList)
index e50206fc0f7495a5dbb3fdcd0bf789c2462cd4b2..9bcce2abdc12284a921fff6f45a6e35fbcde6849 100644 (file)
@@ -50,7 +50,7 @@ void Reformatter::reformatChanges(SourceOverrides &Overrides,
         reformatSingleFile(Header.getFileName(), Header.getChanges(), SM);
     Replaces.insert(HeaderReplaces.begin(), HeaderReplaces.end());
   }
-  Overrides.applyReplacements(Replaces, SM, "reformatter");
+  Overrides.applyReplacements(Replaces, SM);
 }
 
 tooling::Replacements Reformatter::reformatSingleFile(
index e19f4b4388861504e5f7d25e4e7b6360afa62fbd..8fe20bbf04d9ccc8f0e975b4d1a01fcc9accedff 100644 (file)
@@ -8,8 +8,10 @@
 //===----------------------------------------------------------------------===//
 ///
 /// \file
-/// \brief This file provides structs to store the migrator specific header
-/// replacements and the YAML traits for Replacements.
+/// \brief This file provides functionality to serialize replacements for a
+/// single file. It is used by the C++11 Migrator to store all the changes made
+/// by a single transform to a particular file resulting from migrating a
+/// translation unit of a particular main source file.
 ///
 //===----------------------------------------------------------------------===//
 
 
 /// \brief The top-level YAML document that contains the details for the
 /// replacement.
-struct HeaderChangeDocument {
-  std::string TransformID;
+struct MigratorDocument {
   std::vector<clang::tooling::Replacement> Replacements;
-  std::string HeaderFileName;
-  std::string SourceFileName;
+  std::string TargetFile;
+  std::string MainSourceFile;
 };
 
+// FIXME: Put the YAML support for Replacement into clang::tooling. NOTE: The
+// implementation below doesn't serialize the filename for Replacements.
+
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Replacement)
 
 namespace llvm {
@@ -85,15 +89,14 @@ struct MappingTraits<clang::tooling::Replacement> {
   }
 };
 
-/// \brief Specialized MappingTraits for HeaderChangeDocument to be converted
+/// \brief Specialized MappingTraits for MigratorDocument to be converted
 /// to/from a YAML File.
 template <>
-struct MappingTraits<HeaderChangeDocument> {
-  static void mapping(IO &Io, HeaderChangeDocument &TD) {
-    Io.mapRequired("TransformID", TD.TransformID);
+struct MappingTraits<MigratorDocument> {
+  static void mapping(IO &Io, MigratorDocument &TD) {
     Io.mapRequired("Replacements", TD.Replacements);
-    Io.mapRequired("HeaderFileName", TD.HeaderFileName);
-    Io.mapRequired("SourceFileName", TD.SourceFileName);
+    Io.mapRequired("TargetFile", TD.TargetFile);
+    Io.mapRequired("MainSourceFile", TD.MainSourceFile);
   }
 };
 } // end namespace yaml
index bd08716d97410d509a593fd77b1275b6a4dab49b..925206385024ae6309216d427c4cbe4298f71203 100644 (file)
@@ -118,7 +118,7 @@ bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) {
 void Transform::handleEndSource() {
   if (!getReplacements().empty()) {
     SourceOverrides &SO = Overrides->getOrCreate(CurrentSource);
-    SO.applyReplacements(getReplacements(), getName());
+    SO.applyReplacements(getReplacements());
   }
 
   if (Options().EnableTiming)
index 4db2d1e915a03eb25b4e067c2943e0a16ef70949..9f295417d3674543962efa8e62da9d639bdc445f 100644 (file)
@@ -357,8 +357,8 @@ int main(int argc, const char **argv) {
           continue;
         }
         llvm::yaml::Output YAML(ReplacementsFile);
-        YAML << const_cast<HeaderChangeDocument &>(
-                    HeaderI->getValue().getHeaderChangeDoc());
+        YAML << const_cast<MigratorDocument &>(
+                    HeaderI->getValue().getMigratorDoc());
       } else {
         // If -yaml-only was not specified, then change headers on disk.
         // FIXME: This is transitional behaviour. Remove this functionality
index 7bd17f045aec9ad8ba63706e78c27e6483ccf32d..c69e138173e1e6d87c95b4ce6fb0ec3ba046fb8a 100644 (file)
@@ -1,5 +1,4 @@
 ---
-TransformID:     "LoopConvert"
 Replacements:
   - Offset:          432
     Length:          61
@@ -7,6 +6,6 @@ Replacements:
   - Offset:          506
     Length:          2
     ReplacementText: "elem"
-HeaderFileName: "$(path)/common.h"
-SourceFileName: "$(path)/main.cpp"
+TargetFile:      "$(path)/common.h"
+MainSourceFile:  "$(path)/main.cpp"
 ...
index 382c5a8c737e411473eb1077c8ed42a2c186302d..fc54474af8401ec3822f870e93080377d9bb793d 100644 (file)
@@ -32,8 +32,7 @@ TEST(SourceOverridesTest, Interface) {
       strlen("std::vector<such_a_long_name_for_a_type>::const_iterator");
   Replaces.insert(
       Replacement(FileName, 0, ReplacementLength, "auto"));
-  Overrides.applyReplacements(Replaces, VFHelper.getNewSourceManager(),
-                              "use-auto");
+  Overrides.applyReplacements(Replaces, VFHelper.getNewSourceManager());
   EXPECT_TRUE(Overrides.isSourceOverriden());
 
   std::string ExpectedContent = "auto long_type =\n"
index a5caa0a3d77243eb507a187ab3a27461af9295ef..fcde6b81db41ff952fd9e420d6cc8fe99725f399 100644 (file)
@@ -39,8 +39,7 @@ TEST(Reformatter, SingleReformat) {
       FileName, Changes, VFHelper.getNewSourceManager());
 
   SourceOverrides Overrides(FileName, /*TrackChanges=*/false);
-  Overrides.applyReplacements(Replaces, VFHelper.getNewSourceManager(),
-                              "reformatter");
+  Overrides.applyReplacements(Replaces, VFHelper.getNewSourceManager());
 
   std::string Expected, Result;
 
index 7b95e4dcadd3e4b4908e6556505fc657749019e7..ce548764f72441802e9571e30424e9dc4ecc64af 100644 (file)
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// Test for the Yaml files generated by transforms on header files.
+// Tests that change description files can be written and read.
 //
 //===----------------------------------------------------------------------===//
 
@@ -20,9 +20,8 @@ using namespace llvm;
 TEST(ReplacementsYamlTest, writeReadTest) {
   using clang::tooling::Replacement;
 
-  const std::string HeaderFileName = "/path/to/common.h";
-  const std::string SourceFileName = "/path/to/source.cpp";
-  const std::string TransformID = "loop-convert";
+  const std::string TargetFile = "/path/to/common.h";
+  const std::string MainSourceFile = "/path/to/source.cpp";
   const unsigned int ReplacementOffset1 = 232;
   const unsigned int ReplacementLength1 = 56;
   const std::string ReplacementText1 = "(auto & elem : V)";
@@ -30,15 +29,14 @@ TEST(ReplacementsYamlTest, writeReadTest) {
   const unsigned int ReplacementLength2 = 2;
   const std::string ReplacementText2 = "elem";
 
-  HeaderChangeDocument HCD;
-  HCD.TransformID = TransformID;
-  HCD.Replacements.push_back(Replacement(HeaderFileName, ReplacementOffset1,
+  MigratorDocument Doc;
+  Doc.Replacements.push_back(Replacement(TargetFile, ReplacementOffset1,
                                         ReplacementLength1, ReplacementText1));
-  HCD.Replacements.push_back(Replacement(HeaderFileName, ReplacementOffset2,
+  Doc.Replacements.push_back(Replacement(TargetFile, ReplacementOffset2,
                                         ReplacementLength2, ReplacementText2));
 
-  HCD.HeaderFileName = HeaderFileName.c_str();
-  HCD.SourceFileName = SourceFileName.c_str();
+  Doc.TargetFile = TargetFile.c_str();
+  Doc.MainSourceFile= MainSourceFile.c_str();
 
   std::string YamlContent;
   llvm::raw_string_ostream YamlContentStream(YamlContent);
@@ -46,7 +44,7 @@ TEST(ReplacementsYamlTest, writeReadTest) {
   // Write to the YAML file.
   {
     yaml::Output YAML(YamlContentStream);
-    YAML << HCD;
+    YAML << Doc;
     YamlContentStream.str();
     ASSERT_NE(YamlContent.length(), 0u);
   }
@@ -54,23 +52,22 @@ TEST(ReplacementsYamlTest, writeReadTest) {
   // Read from the YAML file and verify that what was written is exactly what
   // we read back.
   {
-    HeaderChangeDocument HCDActual;
+    MigratorDocument DocActual;
     yaml::Input YAML(YamlContent);
-    YAML >> HCDActual;
+    YAML >> DocActual;
     ASSERT_NO_ERROR(YAML.error());
-    EXPECT_EQ(HeaderFileName, HCDActual.HeaderFileName);
-    EXPECT_EQ(SourceFileName, HCDActual.SourceFileName);
-    EXPECT_EQ(TransformID, HCDActual.TransformID);
-    ASSERT_EQ(2u, HCDActual.Replacements.size());
+    EXPECT_EQ(TargetFile, DocActual.TargetFile);
+    EXPECT_EQ(MainSourceFile, DocActual.MainSourceFile);
+    ASSERT_EQ(2u, DocActual.Replacements.size());
 
-    EXPECT_EQ(ReplacementOffset1, HCDActual.Replacements[0].getOffset());
-    EXPECT_EQ(ReplacementLength1, HCDActual.Replacements[0].getLength());
+    EXPECT_EQ(ReplacementOffset1, DocActual.Replacements[0].getOffset());
+    EXPECT_EQ(ReplacementLength1, DocActual.Replacements[0].getLength());
     EXPECT_EQ(ReplacementText1,
-              HCDActual.Replacements[0].getReplacementText().str());
+              DocActual.Replacements[0].getReplacementText().str());
 
-    EXPECT_EQ(ReplacementOffset2, HCDActual.Replacements[1].getOffset());
-    EXPECT_EQ(ReplacementLength2, HCDActual.Replacements[1].getLength());
+    EXPECT_EQ(ReplacementOffset2, DocActual.Replacements[1].getOffset());
+    EXPECT_EQ(ReplacementLength2, DocActual.Replacements[1].getLength());
     EXPECT_EQ(ReplacementText2,
-              HCDActual.Replacements[1].getReplacementText().str());
+              DocActual.Replacements[1].getReplacementText().str());
   }
 }