[cfe-commits] r157694 - in /cfe/trunk: include/clang/Tooling/Refactoring.h lib/Tooling/Refactoring.cpp

Manuel Klimek klimek at google.com
Wed May 30 09:04:30 PDT 2012


Author: klimek
Date: Wed May 30 11:04:29 2012
New Revision: 157694

URL: http://llvm.org/viewvc/llvm-project?rev=157694&view=rev
Log:
Adds a toString method to Replacement, which helps debugging.
Adds missing header guards to Refactoring.h.


Modified:
    cfe/trunk/include/clang/Tooling/Refactoring.h
    cfe/trunk/lib/Tooling/Refactoring.cpp

Modified: cfe/trunk/include/clang/Tooling/Refactoring.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring.h?rev=157694&r1=157693&r2=157694&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Refactoring.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring.h Wed May 30 11:04:29 2012
@@ -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 @@
   /// \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 @@
 
 } // end namespace tooling
 } // end namespace clang
+
+#endif // end namespace LLVM_CLANG_TOOLING_REFACTORING_H
+

Modified: cfe/trunk/lib/Tooling/Refactoring.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring.cpp?rev=157694&r1=157693&r2=157694&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Refactoring.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring.cpp Wed May 30 11:04:29 2012
@@ -71,6 +71,14 @@
   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;





More information about the cfe-commits mailing list