[cfe-commits] r101521 - in /cfe/trunk: include/clang/Rewrite/Rewriter.h lib/Frontend/FixItRewriter.cpp lib/Rewrite/Rewriter.cpp

Nick Lewycky nicholas at mxc.ca
Fri Apr 16 11:49:45 PDT 2010


Author: nicholas
Date: Fri Apr 16 13:49:45 2010
New Revision: 101521

URL: http://llvm.org/viewvc/llvm-project?rev=101521&view=rev
Log:
Add a write(raw_ostream&) method to RewriteBuffer. This uses an inefficient
implementation today but is the right place if we want to make it faster some
day.

Modified:
    cfe/trunk/include/clang/Rewrite/Rewriter.h
    cfe/trunk/lib/Frontend/FixItRewriter.cpp
    cfe/trunk/lib/Rewrite/Rewriter.cpp

Modified: cfe/trunk/include/clang/Rewrite/Rewriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Rewrite/Rewriter.h?rev=101521&r1=101520&r2=101521&view=diff
==============================================================================
--- cfe/trunk/include/clang/Rewrite/Rewriter.h (original)
+++ cfe/trunk/include/clang/Rewrite/Rewriter.h Fri Apr 16 13:49:45 2010
@@ -16,13 +16,15 @@
 #define LLVM_CLANG_REWRITER_H
 
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Rewrite/DeltaTree.h"
 #include "clang/Rewrite/RewriteRope.h"
-#include <map>
-#include <vector>
+#include "llvm/ADT/StringRef.h"
 #include <cstring>
+#include <map>
 #include <string>
-#include "clang/Rewrite/DeltaTree.h"
-#include "llvm/ADT/StringRef.h"
+#include <vector>
+
+namespace llvm { class raw_ostream; }
 
 namespace clang {
   class LangOptions;
@@ -53,6 +55,8 @@
   iterator end() const { return Buffer.end(); }
   unsigned size() const { return Buffer.size(); }
 
+  llvm::raw_ostream &write(llvm::raw_ostream &) const;
+
   /// RemoveText - Remove the specified text.
   void RemoveText(unsigned OrigOffset, unsigned Size);
 

Modified: cfe/trunk/lib/Frontend/FixItRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FixItRewriter.cpp?rev=101521&r1=101520&r2=101521&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FixItRewriter.cpp (original)
+++ cfe/trunk/lib/Frontend/FixItRewriter.cpp Fri Apr 16 13:49:45 2010
@@ -39,7 +39,7 @@
 bool FixItRewriter::WriteFixedFile(FileID ID, llvm::raw_ostream &OS) {
   const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(ID);
   if (!RewriteBuf) return true;
-  OS << std::string(RewriteBuf->begin(), RewriteBuf->end());
+  RewriteBuf->write(OS);
   OS.flush();
   return false;
 }

Modified: cfe/trunk/lib/Rewrite/Rewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Rewriter.cpp?rev=101521&r1=101520&r2=101521&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Rewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Rewriter.cpp Fri Apr 16 13:49:45 2010
@@ -20,6 +20,12 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace clang;
 
+llvm::raw_ostream &RewriteBuffer::write(llvm::raw_ostream &os) const {
+  // FIXME: eliminate the copy by writing out each chunk at a time
+  os << std::string(begin(), end());
+  return os;
+}
+
 void RewriteBuffer::RemoveText(unsigned OrigOffset, unsigned Size) {
   // Nothing to remove, exit early.
   if (Size == 0) return;
@@ -222,5 +228,3 @@
   ReplaceText(From->getLocStart(), Size, Str);
   return false;
 }
-
-





More information about the cfe-commits mailing list