[clang-tools-extra] r188404 - cpp11-migrate: Remove mention of 'headers' from serialization code
Edwin Vane
edwin.vane at intel.com
Wed Aug 14 12:02:28 PDT 2013
Author: revane
Date: Wed Aug 14 14:02:28 2013
New Revision: 188404
URL: http://llvm.org/viewvc/llvm-project?rev=188404&view=rev
Log:
cpp11-migrate: Remove mention of 'headers' from serialization code
* 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
Modified:
clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp
clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h
clang-tools-extra/trunk/cpp11-migrate/Core/IncludeExcludeInfo.cpp
clang-tools-extra/trunk/cpp11-migrate/Core/Reformatting.cpp
clang-tools-extra/trunk/cpp11-migrate/Core/ReplacementsYaml.h
clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp
clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp
clang-tools-extra/trunk/test/cpp11-migrate/HeaderReplacements/common.h.yaml
clang-tools-extra/trunk/unittests/cpp11-migrate/FileOverridesTest.cpp
clang-tools-extra/trunk/unittests/cpp11-migrate/ReformattingTest.cpp
clang-tools-extra/trunk/unittests/cpp11-migrate/ReplacementsYamlTest.cpp
Modified: clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.cpp Wed Aug 14 14:02:28 2013
@@ -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(
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(
E = HeadersReplaces.end();
I != E; ++I) {
HeaderOverride &HeaderOv = Headers[I->getKey()];
- HeaderOv.recordReplacements(TransformName, I->getValue());
+ HeaderOv.recordReplacements(I->getValue());
}
if (TrackChanges)
Modified: clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/FileOverrides.h Wed Aug 14 14:02:28 2013
@@ -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.
Modified: clang-tools-extra/trunk/cpp11-migrate/Core/IncludeExcludeInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/IncludeExcludeInfo.cpp?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/IncludeExcludeInfo.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/IncludeExcludeInfo.cpp Wed Aug 14 14:02:28 2013
@@ -151,6 +151,7 @@ bool IncludeExcludeInfo::isFileIncluded(
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)
Modified: clang-tools-extra/trunk/cpp11-migrate/Core/Reformatting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/Reformatting.cpp?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Reformatting.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Reformatting.cpp Wed Aug 14 14:02:28 2013
@@ -50,7 +50,7 @@ void Reformatter::reformatChanges(Source
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(
Modified: clang-tools-extra/trunk/cpp11-migrate/Core/ReplacementsYaml.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/cpp11-migrate/Core/ReplacementsYaml.h?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/ReplacementsYaml.h (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/ReplacementsYaml.h Wed Aug 14 14:02:28 2013
@@ -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.
///
//===----------------------------------------------------------------------===//
@@ -23,13 +25,15 @@
/// \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::Rep
}
};
-/// \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
Modified: 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=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/Core/Transform.cpp Wed Aug 14 14:02:28 2013
@@ -118,7 +118,7 @@ bool Transform::handleBeginSource(Compil
void Transform::handleEndSource() {
if (!getReplacements().empty()) {
SourceOverrides &SO = Overrides->getOrCreate(CurrentSource);
- SO.applyReplacements(getReplacements(), getName());
+ SO.applyReplacements(getReplacements());
}
if (Options().EnableTiming)
Modified: 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=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp (original)
+++ clang-tools-extra/trunk/cpp11-migrate/tool/Cpp11Migrate.cpp Wed Aug 14 14:02:28 2013
@@ -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
Modified: clang-tools-extra/trunk/test/cpp11-migrate/HeaderReplacements/common.h.yaml
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/cpp11-migrate/HeaderReplacements/common.h.yaml?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/cpp11-migrate/HeaderReplacements/common.h.yaml (original)
+++ clang-tools-extra/trunk/test/cpp11-migrate/HeaderReplacements/common.h.yaml Wed Aug 14 14:02:28 2013
@@ -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"
...
Modified: clang-tools-extra/trunk/unittests/cpp11-migrate/FileOverridesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/cpp11-migrate/FileOverridesTest.cpp?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/cpp11-migrate/FileOverridesTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/cpp11-migrate/FileOverridesTest.cpp Wed Aug 14 14:02:28 2013
@@ -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"
Modified: clang-tools-extra/trunk/unittests/cpp11-migrate/ReformattingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/cpp11-migrate/ReformattingTest.cpp?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/cpp11-migrate/ReformattingTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/cpp11-migrate/ReformattingTest.cpp Wed Aug 14 14:02:28 2013
@@ -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;
Modified: clang-tools-extra/trunk/unittests/cpp11-migrate/ReplacementsYamlTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/cpp11-migrate/ReplacementsYamlTest.cpp?rev=188404&r1=188403&r2=188404&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/cpp11-migrate/ReplacementsYamlTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/cpp11-migrate/ReplacementsYamlTest.cpp Wed Aug 14 14:02:28 2013
@@ -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());
}
}
More information about the cfe-commits
mailing list