forked from OSchip/llvm-project
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. llvm-svn: 101521
This commit is contained in:
parent
076a3278a1
commit
40884c0520
|
@ -16,13 +16,15 @@
|
|||
#define LLVM_CLANG_REWRITER_H
|
||||
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "clang/Rewrite/RewriteRope.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include "clang/Rewrite/DeltaTree.h"
|
||||
#include "clang/Rewrite/RewriteRope.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm { class raw_ostream; }
|
||||
|
||||
namespace clang {
|
||||
class LangOptions;
|
||||
|
@ -53,6 +55,8 @@ public:
|
|||
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);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ FixItRewriter::~FixItRewriter() {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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 @@ bool Rewriter::ReplaceStmt(Stmt *From, Stmt *To) {
|
|||
ReplaceText(From->getLocStart(), Size, Str);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue