clang API Documentation

Classes | Public Types | Public Member Functions | Static Public Member Functions
clang::Rewriter Class Reference

#include <Rewriter.h>

List of all members.

Classes

struct  RewriteOptions

Public Types

typedef std::map< FileID,
RewriteBuffer >::iterator 
buffer_iterator
typedef std::map< FileID,
RewriteBuffer >
::const_iterator 
const_buffer_iterator

Public Member Functions

 Rewriter (SourceManager &SM, const LangOptions &LO)
 Rewriter ()
void setSourceMgr (SourceManager &SM, const LangOptions &LO)
SourceManagergetSourceMgr () const
const LangOptionsgetLangOpts () const
int getRangeSize (SourceRange Range, RewriteOptions opts=RewriteOptions()) const
int getRangeSize (const CharSourceRange &Range, RewriteOptions opts=RewriteOptions()) const
std::string getRewrittenText (SourceRange Range) const
bool InsertText (SourceLocation Loc, StringRef Str, bool InsertAfter=true, bool indentNewLines=false)
bool InsertTextAfter (SourceLocation Loc, StringRef Str)
bool InsertTextAfterToken (SourceLocation Loc, StringRef Str)
 Insert the specified string after the token in the specified location.
bool InsertTextBefore (SourceLocation Loc, StringRef Str)
bool RemoveText (SourceLocation Start, unsigned Length, RewriteOptions opts=RewriteOptions())
 RemoveText - Remove the specified text region.
bool RemoveText (CharSourceRange range, RewriteOptions opts=RewriteOptions())
 Remove the specified text region.
bool RemoveText (SourceRange range, RewriteOptions opts=RewriteOptions())
 Remove the specified text region.
bool ReplaceText (SourceLocation Start, unsigned OrigLength, StringRef NewStr)
bool ReplaceText (SourceRange range, StringRef NewStr)
bool ReplaceText (SourceRange range, SourceRange replacementRange)
bool IncreaseIndentation (CharSourceRange range, SourceLocation parentIndent)
 Increase indentation for the lines between the given source range. To determine what the indentation should be, 'parentIndent' is used that should be at a source location with an indentation one degree lower than the given range.
bool IncreaseIndentation (SourceRange range, SourceLocation parentIndent)
RewriteBuffergetEditBuffer (FileID FID)
const RewriteBuffergetRewriteBufferFor (FileID FID) const
buffer_iterator buffer_begin ()
buffer_iterator buffer_end ()
const_buffer_iterator buffer_begin () const
const_buffer_iterator buffer_end () const
bool overwriteChangedFiles ()

Static Public Member Functions

static bool isRewritable (SourceLocation Loc)

Detailed Description

Rewriter - This is the main interface to the rewrite buffers. Its primary job is to dispatch high-level requests to the low-level RewriteBuffers that are involved.

Definition at line 126 of file Rewriter.h.


Member Typedef Documentation

Definition at line 148 of file Rewriter.h.

typedef std::map<FileID, RewriteBuffer>::const_iterator clang::Rewriter::const_buffer_iterator

Definition at line 149 of file Rewriter.h.


Constructor & Destructor Documentation

clang::Rewriter::Rewriter ( SourceManager SM,
const LangOptions LO 
) [inline, explicit]

Definition at line 151 of file Rewriter.h.

clang::Rewriter::Rewriter ( ) [inline, explicit]

Definition at line 153 of file Rewriter.h.


Member Function Documentation

Definition at line 274 of file Rewriter.h.

Definition at line 275 of file Rewriter.h.

getEditBuffer - This is like getRewriteBufferFor, but always returns a buffer, and allows you to write on it directly. This is useful if you want efficient low-level access to apis for scribbling on one specific FileID's buffer.

getEditBuffer - Get or create a RewriteBuffer for the specified FileID.

Definition at line 225 of file Rewriter.cpp.

References clang::SourceManager::getBufferData().

Referenced by clang::html::AddLineNumbers(), clang::tooling::applyAllReplacements(), clang::html::EscapeText(), clang::index::SimpleFormatContext::getRewrittenText(), clang::html::HighlightRange(), IncreaseIndentation(), InsertText(), InsertTextAfterToken(), RemoveText(), ReplaceText(), clang::RewriteMacrosInInput(), and clang::html::SyntaxHighlight().

const LangOptions& clang::Rewriter::getLangOpts ( ) const [inline]

Definition at line 160 of file Rewriter.h.

Referenced by clang::html::HighlightRange().

int Rewriter::getRangeSize ( SourceRange  Range,
RewriteOptions  opts = RewriteOptions() 
) const

getRangeSize - Return the size in bytes of the specified range if they are in the same file. If not, this returns -1.

Definition at line 159 of file Rewriter.cpp.

References clang::CharSourceRange::getTokenRange().

Referenced by InsertTextAfterToken(), RemoveText(), and ReplaceText().

int Rewriter::getRangeSize ( const CharSourceRange Range,
RewriteOptions  opts = RewriteOptions() 
) const

getRewriteBufferFor - Return the rewrite buffer for the specified FileID. If no modification has been made to it, return null.

Definition at line 265 of file Rewriter.h.

Referenced by applyEditsToTemp(), clang::FixItRewriter::IsModified(), clang::RewriteMacrosInInput(), and clang::FixItRewriter::WriteFixedFile().

std::string Rewriter::getRewrittenText ( SourceRange  Range) const

getRewrittenText - Return the rewritten form of the text in the specified range. If the start or end of the range was unrewritable or if they are in different buffers, this returns an empty string.

Note that this method is not particularly efficient.

Definition at line 170 of file Rewriter.cpp.

References clang::RewriteBuffer::begin(), clang::SourceRange::getBegin(), clang::SourceManager::getCharacterData(), clang::SourceRange::getEnd(), isRewritable(), and clang::Lexer::MeasureTokenLength().

Increase indentation for the lines between the given source range. To determine what the indentation should be, 'parentIndent' is used that should be at a source location with an indentation one degree lower than the given range.

Definition at line 329 of file Rewriter.cpp.

References clang::CharSourceRange::getBegin(), clang::SourceManager::getBufferData(), clang::SrcMgr::FileInfo::getContentCache(), getEditBuffer(), clang::CharSourceRange::getEnd(), clang::SrcMgr::SLocEntry::getFile(), clang::SourceManager::getLineNumber(), clang::SourceManager::getSLocEntry(), clang::RewriteBuffer::InsertText(), clang::CharSourceRange::isInvalid(), isRewritable(), clang::isWhitespace(), and clang::SrcMgr::ContentCache::SourceLineCache.

Referenced by IncreaseIndentation().

bool clang::Rewriter::IncreaseIndentation ( SourceRange  range,
SourceLocation  parentIndent 
) [inline]

Definition at line 252 of file Rewriter.h.

References clang::CharSourceRange::getTokenRange(), and IncreaseIndentation().

bool Rewriter::InsertText ( SourceLocation  Loc,
StringRef  Str,
bool  InsertAfter = true,
bool  indentNewLines = false 
)

InsertText - Insert the specified string at the specified location in the original buffer. This method returns true (and does nothing) if the input location was not rewritable, false otherwise.

Parameters:
indentNewLinesif true new lines in the string are indented using the indentation of the source line in position Loc.

InsertText - Insert the specified string at the specified location in the original buffer.

Definition at line 240 of file Rewriter.cpp.

References clang::SourceManager::getBufferData(), clang::SrcMgr::FileInfo::getContentCache(), getEditBuffer(), clang::SrcMgr::SLocEntry::getFile(), clang::SourceManager::getLineNumber(), clang::SourceManager::getSLocEntry(), clang::RewriteBuffer::InsertText(), isRewritable(), clang::isWhitespace(), and clang::SrcMgr::ContentCache::SourceLineCache.

Referenced by InsertTextAfter(), and InsertTextBefore().

bool clang::Rewriter::InsertTextAfter ( SourceLocation  Loc,
StringRef  Str 
) [inline]

InsertTextAfter - Insert the specified string at the specified location in the original buffer. This method returns true (and does nothing) if the input location was not rewritable, false otherwise. Text is inserted after any other text that has been previously inserted at the some point (the default behavior for InsertText).

Definition at line 197 of file Rewriter.h.

References InsertText().

Referenced by clang::html::AddHeaderFooterInternalBuiltinCSS().

bool Rewriter::InsertTextAfterToken ( SourceLocation  Loc,
StringRef  Str 
)

Insert the specified string after the token in the specified location.

Definition at line 281 of file Rewriter.cpp.

References getEditBuffer(), getRangeSize(), clang::Rewriter::RewriteOptions::IncludeInsertsAtBeginOfRange, clang::RewriteBuffer::InsertText(), and isRewritable().

bool clang::Rewriter::InsertTextBefore ( SourceLocation  Loc,
StringRef  Str 
) [inline]

InsertText - Insert the specified string at the specified location in the original buffer. This method returns true (and does nothing) if the input location was not rewritable, false otherwise. Text is inserted before any other text that has been previously inserted at the some point.

Definition at line 210 of file Rewriter.h.

References InsertText().

Referenced by clang::html::AddHeaderFooterInternalBuiltinCSS().

static bool clang::Rewriter::isRewritable ( SourceLocation  Loc) [inline, static]

isRewritable - Return true if this location is a raw file location, which is rewritable. Locations from macros, etc are not rewritable.

Definition at line 164 of file Rewriter.h.

References clang::SourceLocation::isFileID().

Referenced by getRangeSize(), getRewrittenText(), IncreaseIndentation(), InsertText(), InsertTextAfterToken(), RemoveText(), and ReplaceText().

overwriteChangedFiles - Save all changed files to disk.

Returns true if any files were not saved successfully. Outputs diagnostics via the source manager's diagnostic engine in case of an error.

Definition at line 452 of file Rewriter.cpp.

References buffer_begin(), buffer_end(), clang::SourceManager::getFileEntryForID(), clang::FileEntry::getName(), and getSourceMgr().

RemoveText - Remove the specified text region.

Definition at line 293 of file Rewriter.cpp.

References getEditBuffer(), isRewritable(), clang::Rewriter::RewriteOptions::RemoveLineIfEmpty, and clang::RewriteBuffer::RemoveText().

Referenced by RemoveText().

Remove the specified text region.

Definition at line 219 of file Rewriter.h.

References clang::CharSourceRange::getBegin(), getRangeSize(), and RemoveText().

Remove the specified text region.

Definition at line 225 of file Rewriter.h.

References clang::SourceRange::getBegin(), getRangeSize(), and RemoveText().

bool Rewriter::ReplaceText ( SourceLocation  Start,
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.

Definition at line 305 of file Rewriter.cpp.

References getEditBuffer(), isRewritable(), and clang::RewriteBuffer::ReplaceText().

Referenced by clang::tooling::Replacement::apply(), and ReplaceText().

bool clang::Rewriter::ReplaceText ( SourceRange  range,
StringRef  NewStr 
) [inline]

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

Definition at line 238 of file Rewriter.h.

References clang::SourceRange::getBegin(), getRangeSize(), and ReplaceText().

bool Rewriter::ReplaceText ( SourceRange  range,
SourceRange  replacementRange 
)

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

Definition at line 315 of file Rewriter.cpp.

References clang::SourceRange::getBegin(), clang::SourceManager::getBufferData(), clang::SourceRange::getEnd(), getRangeSize(), clang::SourceRange::isInvalid(), isRewritable(), and ReplaceText().

void clang::Rewriter::setSourceMgr ( SourceManager SM,
const LangOptions LO 
) [inline]

Definition at line 155 of file Rewriter.h.

References SM.

Referenced by clang::RewriteMacrosInInput().


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