clang 20.0.0git
|
Rewriter - This is the main interface to the rewrite buffers. More...
#include "clang/Rewrite/Core/Rewriter.h"
Classes | |
struct | RewriteOptions |
Public Types | |
using | buffer_iterator = std::map< FileID, llvm::RewriteBuffer >::iterator |
using | const_buffer_iterator = std::map< FileID, llvm::RewriteBuffer >::const_iterator |
Public Member Functions | |
Rewriter ()=default | |
Rewriter (SourceManager &SM, const LangOptions &LO) | |
void | setSourceMgr (SourceManager &SM, const LangOptions &LO) |
SourceManager & | getSourceMgr () const |
const LangOptions & | getLangOpts () const |
int | getRangeSize (SourceRange Range, RewriteOptions opts=RewriteOptions()) const |
getRangeSize - Return the size in bytes of the specified range if they are in the same file. | |
int | getRangeSize (const CharSourceRange &Range, RewriteOptions opts=RewriteOptions()) const |
getRangeSize - Return the size in bytes of the specified range if they are in the same file. | |
std::string | getRewrittenText (CharSourceRange Range) const |
getRewrittenText - Return the rewritten form of the text in the specified range. | |
std::string | getRewrittenText (SourceRange Range) const |
getRewrittenText - Return the rewritten form of the text in the specified range. | |
bool | InsertText (SourceLocation Loc, StringRef Str, bool InsertAfter=true, bool indentNewLines=false) |
InsertText - Insert the specified string at the specified location in the original buffer. | |
bool | InsertTextAfter (SourceLocation Loc, StringRef Str) |
InsertTextAfter - Insert the specified string at the specified location in the original buffer. | |
bool | InsertTextAfterToken (SourceLocation Loc, StringRef Str) |
Insert the specified string after the token in the specified location. | |
bool | InsertTextBefore (SourceLocation Loc, StringRef Str) |
InsertText - Insert the specified string at the specified location in the original buffer. | |
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) |
ReplaceText - This method replaces a range of characters in the input buffer with a new string. | |
bool | ReplaceText (CharSourceRange range, StringRef NewStr) |
ReplaceText - This method replaces a range of characters in the input buffer with a new string. | |
bool | ReplaceText (SourceRange range, StringRef NewStr) |
ReplaceText - This method replaces a range of characters in the input buffer with a new string. | |
bool | ReplaceText (SourceRange range, SourceRange replacementRange) |
ReplaceText - This method replaces a range of characters in the input buffer with a new string. | |
bool | IncreaseIndentation (CharSourceRange range, SourceLocation parentIndent) |
Increase indentation for the lines between the given source range. | |
bool | IncreaseIndentation (SourceRange range, SourceLocation parentIndent) |
llvm::RewriteBuffer & | getEditBuffer (FileID FID) |
getEditBuffer - This is like getRewriteBufferFor, but always returns a buffer, and allows you to write on it directly. | |
const llvm::RewriteBuffer * | getRewriteBufferFor (FileID FID) const |
getRewriteBufferFor - Return the rewrite buffer for the specified FileID. | |
buffer_iterator | buffer_begin () |
buffer_iterator | buffer_end () |
const_buffer_iterator | buffer_begin () const |
const_buffer_iterator | buffer_end () const |
bool | overwriteChangedFiles () |
overwriteChangedFiles - Save all changed files to disk. | |
Static Public Member Functions | |
static bool | isRewritable (SourceLocation Loc) |
isRewritable - Return true if this location is a raw file location, which is rewritable. | |
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 32 of file Rewriter.h.
using clang::Rewriter::buffer_iterator = std::map<FileID, llvm::RewriteBuffer>::iterator |
Definition at line 65 of file Rewriter.h.
using clang::Rewriter::const_buffer_iterator = std::map<FileID, llvm::RewriteBuffer>::const_iterator |
Definition at line 66 of file Rewriter.h.
|
explicitdefault |
|
inlineexplicit |
Definition at line 70 of file Rewriter.h.
|
inline |
Definition at line 206 of file Rewriter.h.
Referenced by clang::arcmt::MigrationProcess::applyTransform(), and overwriteChangedFiles().
|
inline |
Definition at line 208 of file Rewriter.h.
|
inline |
Definition at line 207 of file Rewriter.h.
Referenced by clang::arcmt::MigrationProcess::applyTransform(), and overwriteChangedFiles().
|
inline |
Definition at line 209 of file Rewriter.h.
RewriteBuffer & Rewriter::getEditBuffer | ( | FileID | FID | ) |
getEditBuffer - This is like getRewriteBufferFor, but always returns a buffer, and allows you to write on it directly.
getEditBuffer - Get or create a RewriteBuffer for the specified FileID.
This is useful if you want efficient low-level access to apis for scribbling on one specific FileID's buffer.
Definition at line 142 of file Rewriter.cpp.
References clang::SourceManager::getBufferData().
Referenced by clang::html::AddLineNumbers(), clang::html::EscapeText(), clang::html::HighlightRange(), IncreaseIndentation(), InsertText(), InsertTextAfterToken(), RemoveText(), and ReplaceText().
|
inline |
Definition at line 79 of file Rewriter.h.
Referenced by clang::html::HighlightRange().
int Rewriter::getRangeSize | ( | const CharSourceRange & | 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 46 of file Rewriter.cpp.
References clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), clang::Rewriter::RewriteOptions::IncludeInsertsAtBeginOfRange, clang::Rewriter::RewriteOptions::IncludeInsertsAtEndOfRange, isRewritable(), clang::Lexer::MeasureTokenLength(), and Range.
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 76 of file Rewriter.cpp.
References getRangeSize(), clang::CharSourceRange::getTokenRange(), and Range.
Referenced by getRangeSize(), InsertTextAfterToken(), RemoveText(), and ReplaceText().
|
inline |
getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
If no modification has been made to it, return null.
Definition at line 199 of file Rewriter.h.
Referenced by applyEditsToTemp(), and clang::FixItRewriter::WriteFixedFile().
std::string Rewriter::getRewrittenText | ( | CharSourceRange | 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 85 of file Rewriter.cpp.
References clang::SourceRange::getBegin(), clang::SourceManager::getCharacterData(), clang::SourceRange::getEnd(), isRewritable(), clang::Lexer::MeasureTokenLength(), and Range.
Referenced by getRewrittenText().
|
inline |
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 106 of file Rewriter.h.
References getRewrittenText(), clang::CharSourceRange::getTokenRange(), and Range.
|
inline |
Definition at line 78 of file Rewriter.h.
Referenced by clang::html::AddHeaderFooterInternalBuiltinCSS(), clang::html::AddLineNumbers(), clang::html::EscapeText(), clang::html::HighlightRange(), and overwriteChangedFiles().
bool Rewriter::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.
Definition at line 246 of file Rewriter.cpp.
References clang::SourceManager::getBufferData(), clang::SrcMgr::FileInfo::getContentCache(), getEditBuffer(), clang::SrcMgr::SLocEntry::getFile(), clang::SourceManager::getLineNumber(), clang::SourceManager::getSLocEntry(), isRewritable(), isWhitespaceExceptNL(), and clang::SrcMgr::ContentCache::SourceLineCache.
Referenced by IncreaseIndentation().
|
inline |
Definition at line 186 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.
indentNewLines | if true new lines in the string are indented using the indentation of the source line in position Loc . |
Definition at line 157 of file Rewriter.cpp.
References clang::SourceManager::getBufferData(), clang::SrcMgr::FileInfo::getContentCache(), getEditBuffer(), clang::SrcMgr::SLocEntry::getFile(), clang::SourceManager::getLineNumber(), clang::SourceManager::getSLocEntry(), isRewritable(), isWhitespaceExceptNL(), Loc, and clang::SrcMgr::ContentCache::SourceLineCache.
Referenced by InsertTextAfter(), and InsertTextBefore().
|
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 124 of file Rewriter.h.
References InsertText(), and Loc.
bool Rewriter::InsertTextAfterToken | ( | SourceLocation | Loc, |
StringRef | Str | ||
) |
Insert the specified string after the token in the specified location.
Definition at line 198 of file Rewriter.cpp.
References getEditBuffer(), getRangeSize(), clang::Rewriter::RewriteOptions::IncludeInsertsAtBeginOfRange, isRewritable(), and Loc.
|
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 137 of file Rewriter.h.
References InsertText(), and Loc.
|
inlinestatic |
isRewritable - Return true if this location is a raw file location, which is rewritable.
Locations from macros, etc are not rewritable.
Definition at line 83 of file Rewriter.h.
References Loc.
Referenced by getRangeSize(), getRewrittenText(), IncreaseIndentation(), InsertText(), InsertTextAfterToken(), RemoveText(), and ReplaceText().
bool Rewriter::overwriteChangedFiles | ( | ) |
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 314 of file Rewriter.cpp.
References buffer_begin(), buffer_end(), Diag(), E, clang::DiagnosticsEngine::Error, clang::SourceManager::getDiagnostics(), clang::SourceManager::getFileEntryRefForID(), clang::SourceManager::getFileManager(), clang::FileEntryRef::getName(), getSourceMgr(), clang::FileManager::makeAbsolutePath(), and Path.
|
inline |
Remove the specified text region.
Definition at line 146 of file Rewriter.h.
References getRangeSize(), and RemoveText().
bool Rewriter::RemoveText | ( | SourceLocation | Start, |
unsigned | Length, | ||
RewriteOptions | opts = RewriteOptions() |
||
) |
RemoveText - Remove the specified text region.
Definition at line 210 of file Rewriter.cpp.
References getEditBuffer(), isRewritable(), and clang::Rewriter::RewriteOptions::RemoveLineIfEmpty.
Referenced by RemoveText().
|
inline |
Remove the specified text region.
Definition at line 152 of file Rewriter.h.
References getRangeSize(), and RemoveText().
|
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 165 of file Rewriter.h.
References getRangeSize(), and ReplaceText().
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 222 of file Rewriter.cpp.
References getEditBuffer(), and isRewritable().
Referenced by 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 232 of file Rewriter.cpp.
References clang::SourceRange::getBegin(), clang::SourceManager::getBufferData(), getRangeSize(), clang::SourceRange::isInvalid(), isRewritable(), and ReplaceText().
|
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 172 of file Rewriter.h.
References getRangeSize(), and ReplaceText().
|
inline |
Definition at line 73 of file Rewriter.h.
References SM.