class RewriteBuffer

Declaration

class RewriteBuffer { /* full declaration omitted */ };

Description

RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a new RewriteBuffer associated with them. The RewriteBuffer captures the modified text itself as well as information used to map between SourceLocation's in the original input and offsets in the RewriteBuffer. For example, if text is inserted into the buffer, any locations after the insertion point have to be mapped.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:25

Member Variables

private clang::DeltaTree Deltas
Deltas - Keep track of all the deltas in the source code due to insertions and deletions.
private clang::RewriteRope Buffer

Method Overview

  • private void AddInsertDelta(unsigned int OrigOffset, int Change)
  • private void AddReplaceDelta(unsigned int OrigOffset, int Change)
  • public void Initialize(const char * BufStart, const char * BufEnd)
  • public void Initialize(llvm::StringRef Input)
  • public void InsertText(unsigned int OrigOffset, llvm::StringRef Str, bool InsertAfter = true)
  • public void InsertTextAfter(unsigned int OrigOffset, llvm::StringRef Str)
  • public void InsertTextBefore(unsigned int OrigOffset, llvm::StringRef Str)
  • public void RemoveText(unsigned int OrigOffset, unsigned int Size, bool removeLineIfEmpty = false)
  • public void ReplaceText(unsigned int OrigOffset, unsigned int OrigLength, llvm::StringRef NewStr)
  • public clang::RewriteBuffer::iterator begin() const
  • public clang::RewriteBuffer::iterator end() const
  • private unsigned int getMappedOffset(unsigned int OrigOffset, bool AfterInserts = false) const
  • public unsigned int size() const
  • public llvm::raw_ostream & write(llvm::raw_ostream & Stream) const

Methods

void AddInsertDelta(unsigned int OrigOffset,
                    int Change)

Description

AddInsertDelta - When an insertion is made at a position, this method is used to record that information.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:104

Parameters

unsigned int OrigOffset
int Change

void AddReplaceDelta(unsigned int OrigOffset,
                     int Change)

Description

AddReplaceDelta - When a replacement/deletion is made at a position, this method is used to record that information.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:110

Parameters

unsigned int OrigOffset
int Change

void Initialize(const char* BufStart,
                const char* BufEnd)

Description

Initialize - Start this rewrite buffer out with a copy of the unmodified input buffer.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:43

Parameters

const char* BufStart
const char* BufEnd

void Initialize(llvm::StringRef Input)

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:46

Parameters

llvm::StringRef Input

void InsertText(unsigned int OrigOffset,
                llvm::StringRef Str,
                bool InsertAfter = true)

Description

InsertText - Insert some text at the specified point, where the offset in the buffer is specified relative to the original SourceBuffer. The text is inserted after the specified location.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:66

Parameters

unsigned int OrigOffset
llvm::StringRef Str
bool InsertAfter = true

void InsertTextAfter(unsigned int OrigOffset,
                     llvm::StringRef Str)

Description

InsertTextAfter - Insert some text at the specified point, where the offset in the buffer is specified relative to the original SourceBuffer. The text is inserted after the specified location.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:81

Parameters

unsigned int OrigOffset
llvm::StringRef Str

void InsertTextBefore(unsigned int OrigOffset,
                      llvm::StringRef Str)

Description

InsertTextBefore - Insert some text before the specified point, where the offset in the buffer is specified relative to the original SourceBuffer. The text is inserted before the specified location. This is method is the same as InsertText with "InsertAfter == false".

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:74

Parameters

unsigned int OrigOffset
llvm::StringRef Str

void RemoveText(unsigned int OrigOffset,
                unsigned int Size,
                bool removeLineIfEmpty = false)

Description

RemoveText - Remove the specified text.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:60

Parameters

unsigned int OrigOffset
unsigned int Size
bool removeLineIfEmpty = false

void ReplaceText(unsigned int OrigOffset,
                 unsigned int OrigLength,
                 llvm::StringRef NewStr)

Description

ReplaceText - This method replaces a range of characters in the input buffer with a new string. This is effectively a combined "remove/insert" operation.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:88

Parameters

unsigned int OrigOffset
unsigned int OrigLength
llvm::StringRef NewStr

clang::RewriteBuffer::iterator begin() const

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:37

clang::RewriteBuffer::iterator end() const

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:38

unsigned int getMappedOffset(
    unsigned int OrigOffset,
    bool AfterInserts = false) const

Description

getMappedOffset - Given an offset into the original SourceBuffer that this RewriteBuffer is based on, map it into the offset space of the RewriteBuffer. If AfterInserts is true and if the OrigOffset indicates a position where text is inserted, the location returned will be after any inserted text at the position.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:97

Parameters

unsigned int OrigOffset
bool AfterInserts = false

unsigned int size() const

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:39

llvm::raw_ostream& write(
    llvm::raw_ostream& Stream) const

Description

Write to \p Stream the result of applying all changes to the original buffer. Note that it isn't safe to use this function to overwrite memory mapped files in-place (PR17960). Consider using a higher-level utility such as Rewriter::overwriteChangedFiles() instead. The original buffer is not actually changed.

Declared at: clang/include/clang/Rewrite/Core/RewriteBuffer.h:57

Parameters

llvm::raw_ostream& Stream