From 5d51e8894624d5a12ed2c4fd80c31112d3d70f80 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Wed, 30 May 2012 16:04:29 +0000 Subject: [PATCH] Adds a toString method to Replacement, which helps debugging. Adds missing header guards to Refactoring.h. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157694 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Tooling/Refactoring.h | 9 +++++++++ lib/Tooling/Refactoring.cpp | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/include/clang/Tooling/Refactoring.h b/include/clang/Tooling/Refactoring.h index 56509a61d5..0e42a0ec64 100644 --- a/include/clang/Tooling/Refactoring.h +++ b/include/clang/Tooling/Refactoring.h @@ -16,6 +16,9 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_CLANG_TOOLING_REFACTORING_H +#define LLVM_CLANG_TOOLING_REFACTORING_H + #include "llvm/ADT/StringRef.h" #include "clang/Basic/SourceLocation.h" #include "clang/Tooling/Tooling.h" @@ -76,6 +79,9 @@ public: /// \brief Applies the replacement on the Rewriter. bool apply(Rewriter &Rewrite) const; + /// \brief Returns a human readable string representation. + std::string toString() const; + /// \brief Comparator to be able to use Replacement in std::set for uniquing. class Less { public: @@ -140,3 +146,6 @@ Replacement::Replacement(SourceManager &Sources, const Node &NodeToReplace, } // end namespace tooling } // end namespace clang + +#endif // end namespace LLVM_CLANG_TOOLING_REFACTORING_H + diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index 6e90ba010c..628435307c 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/lib/Tooling/Refactoring.cpp @@ -71,6 +71,14 @@ bool Replacement::apply(Rewriter &Rewrite) const { return RewriteSucceeded; } +std::string Replacement::toString() const { + std::string result; + llvm::raw_string_ostream stream(result); + stream << FilePath << ": " << Offset << ":+" << Length + << ":\"" << ReplacementText << "\""; + return result; +} + bool Replacement::Less::operator()(const Replacement &R1, const Replacement &R2) const { if (R1.FilePath != R2.FilePath) return R1.FilePath < R2.FilePath; -- 2.40.0