clang  6.0.0svn
Public Types | Public Member Functions | Friends | List of all members
clang::RewriteBuffer Class Reference

RewriteBuffer - As code is rewritten, SourceBuffer's from the original input with modifications get a new RewriteBuffer associated with them. More...

#include "clang/Rewrite/Core/RewriteBuffer.h"

Public Types

typedef RewriteRope::const_iterator iterator
 

Public Member Functions

iterator begin () const
 
iterator end () const
 
unsigned size () const
 
void Initialize (const char *BufStart, const char *BufEnd)
 Initialize - Start this rewrite buffer out with a copy of the unmodified input buffer. More...
 
void Initialize (StringRef Input)
 
raw_ostream & write (raw_ostream &Stream) const
 Write to Stream the result of applying all changes to the original buffer. More...
 
void RemoveText (unsigned OrigOffset, unsigned Size, bool removeLineIfEmpty=false)
 RemoveText - Remove the specified text. More...
 
void InsertText (unsigned OrigOffset, StringRef Str, bool InsertAfter=true)
 InsertText - Insert some text at the specified point, where the offset in the buffer is specified relative to the original SourceBuffer. More...
 
void InsertTextBefore (unsigned OrigOffset, StringRef Str)
 InsertTextBefore - Insert some text before the specified point, where the offset in the buffer is specified relative to the original SourceBuffer. More...
 
void InsertTextAfter (unsigned OrigOffset, StringRef Str)
 InsertTextAfter - Insert some text at the specified point, where the offset in the buffer is specified relative to the original SourceBuffer. More...
 
void ReplaceText (unsigned OrigOffset, unsigned OrigLength, StringRef NewStr)
 ReplaceText - This method replaces a range of characters in the input buffer with a new string. More...
 

Friends

class Rewriter
 

Detailed 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.

Definition at line 27 of file RewriteBuffer.h.

Member Typedef Documentation

◆ iterator

Definition at line 34 of file RewriteBuffer.h.

Member Function Documentation

◆ begin()

iterator clang::RewriteBuffer::begin ( ) const
inline

Definition at line 35 of file RewriteBuffer.h.

References clang::RewriteRope::begin().

◆ end()

iterator clang::RewriteBuffer::end ( ) const
inline

Definition at line 36 of file RewriteBuffer.h.

References clang::RewriteRope::end().

◆ Initialize() [1/2]

void clang::RewriteBuffer::Initialize ( const char *  BufStart,
const char *  BufEnd 
)
inline

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

Definition at line 41 of file RewriteBuffer.h.

References clang::RewriteRope::assign().

◆ Initialize() [2/2]

void clang::RewriteBuffer::Initialize ( StringRef  Input)
inline

Definition at line 44 of file RewriteBuffer.h.

◆ InsertText()

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

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.

Definition at line 92 of file Rewriter.cpp.

Referenced by clang::Rewriter::IncreaseIndentation(), InsertTextAfter(), and InsertTextBefore().

◆ InsertTextAfter()

void clang::RewriteBuffer::InsertTextAfter ( unsigned  OrigOffset,
StringRef  Str 
)
inline

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.

Definition at line 80 of file RewriteBuffer.h.

References clang::DeltaTree::AddDelta(), clang::DeltaTree::getDeltaAt(), InsertText(), and ReplaceText().

Referenced by clang::html::AddLineNumbers(), and clang::RewriteMacrosInInput().

◆ InsertTextBefore()

void clang::RewriteBuffer::InsertTextBefore ( unsigned  OrigOffset,
StringRef  Str 
)
inline

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".

Definition at line 73 of file RewriteBuffer.h.

References InsertText().

Referenced by clang::html::AddLineNumbers(), and clang::RewriteMacrosInInput().

◆ RemoveText()

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

RemoveText - Remove the specified text.

Definition at line 49 of file Rewriter.cpp.

◆ ReplaceText()

void RewriteBuffer::ReplaceText ( unsigned  OrigOffset,
unsigned  OrigLength,
StringRef  NewStr 
)

ReplaceText - This method replaces a range of characters in the input buffer with a new string.

This is effectively a combined "remove/insert" operation.

This is effectively a combined "remove+insert" operation.

Definition at line 108 of file Rewriter.cpp.

Referenced by clang::html::EscapeText(), InsertTextAfter(), and clang::Rewriter::ReplaceText().

◆ size()

unsigned clang::RewriteBuffer::size ( ) const
inline

Definition at line 37 of file RewriteBuffer.h.

References clang::RewriteRope::size().

◆ write()

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

Write to 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.

Definition at line 25 of file Rewriter.cpp.

Referenced by clang::index::SimpleFormatContext::getRewrittenText(), and clang::FixItRewriter::WriteFixedFile().

Friends And Related Function Documentation

◆ Rewriter

friend class Rewriter
friend

Definition at line 28 of file RewriteBuffer.h.


The documentation for this class was generated from the following files: