class Rewriter

Declaration

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

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:32

Member Variables

private clang::SourceManager* SourceMgr = nullptr
private const clang::LangOptions* LangOpts = nullptr
private std::map<FileID, RewriteBuffer> RewriteBuffers

Method Overview

  • public bool IncreaseIndentation(clang::SourceRange range, clang::SourceLocation parentIndent)
  • public bool IncreaseIndentation(clang::CharSourceRange range, clang::SourceLocation parentIndent)
  • public bool InsertText(clang::SourceLocation Loc, llvm::StringRef Str, bool InsertAfter = true, bool indentNewLines = false)
  • public bool InsertTextAfter(clang::SourceLocation Loc, llvm::StringRef Str)
  • public bool InsertTextAfterToken(clang::SourceLocation Loc, llvm::StringRef Str)
  • public bool InsertTextBefore(clang::SourceLocation Loc, llvm::StringRef Str)
  • public bool RemoveText(clang::SourceRange range, clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions())
  • public bool RemoveText(clang::CharSourceRange range, clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions())
  • public bool RemoveText(clang::SourceLocation Start, unsigned int Length, clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions())
  • public bool ReplaceText(clang::SourceRange range, clang::SourceRange replacementRange)
  • public bool ReplaceText(clang::SourceRange range, llvm::StringRef NewStr)
  • public bool ReplaceText(clang::CharSourceRange range, llvm::StringRef NewStr)
  • public bool ReplaceText(clang::SourceLocation Start, unsigned int OrigLength, llvm::StringRef NewStr)
  • public Rewriter(clang::SourceManager & SM, const clang::LangOptions & LO)
  • public Rewriter()
  • public clang::Rewriter::const_buffer_iterator buffer_begin() const
  • public clang::Rewriter::buffer_iterator buffer_begin()
  • public clang::Rewriter::const_buffer_iterator buffer_end() const
  • public clang::Rewriter::buffer_iterator buffer_end()
  • public clang::RewriteBuffer & getEditBuffer(clang::FileID FID)
  • public const clang::LangOptions & getLangOpts() const
  • private unsigned int getLocationOffsetAndFileID(clang::SourceLocation Loc, clang::FileID & FID) const
  • public int getRangeSize(clang::SourceRange Range, clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()) const
  • public int getRangeSize(const clang::CharSourceRange & Range, clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()) const
  • public const clang::RewriteBuffer * getRewriteBufferFor(clang::FileID FID) const
  • public std::string getRewrittenText(clang::CharSourceRange Range) const
  • public std::string getRewrittenText(clang::SourceRange Range) const
  • public clang::SourceManager & getSourceMgr() const
  • public static bool isRewritable(clang::SourceLocation Loc)
  • public bool overwriteChangedFiles()
  • public void setSourceMgr(clang::SourceManager & SM, const clang::LangOptions & LO)

Methods

bool IncreaseIndentation(
    clang::SourceRange range,
    clang::SourceLocation parentIndent)

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:185

Parameters

clang::SourceRange range
clang::SourceLocation parentIndent

bool IncreaseIndentation(
    clang::CharSourceRange range,
    clang::SourceLocation parentIndent)

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:184

Parameters

clang::CharSourceRange range
clang::SourceLocation parentIndent

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

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:115

Parameters

clang::SourceLocation Loc
llvm::StringRef Str
bool InsertAfter = true
bool indentNewLines = false
if true new lines in the string are indented using the indentation of the source line in position \p Loc.

bool InsertTextAfter(clang::SourceLocation Loc,
                     llvm::StringRef Str)

Description

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

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:123

Parameters

clang::SourceLocation Loc
llvm::StringRef Str

bool InsertTextAfterToken(
    clang::SourceLocation Loc,
    llvm::StringRef Str)

Description

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

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:129

Parameters

clang::SourceLocation Loc
llvm::StringRef Str

bool InsertTextBefore(clang::SourceLocation Loc,
                      llvm::StringRef Str)

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:136

Parameters

clang::SourceLocation Loc
llvm::StringRef Str

bool RemoveText(
    clang::SourceRange range,
    clang::Rewriter::RewriteOptions opts =
        clang::Rewriter::RewriteOptions())

Description

Remove the specified text region.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:151

Parameters

clang::SourceRange range
clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()

bool RemoveText(
    clang::CharSourceRange range,
    clang::Rewriter::RewriteOptions opts =
        clang::Rewriter::RewriteOptions())

Description

Remove the specified text region.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:145

Parameters

clang::CharSourceRange range
clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()

bool RemoveText(
    clang::SourceLocation Start,
    unsigned int Length,
    clang::Rewriter::RewriteOptions opts =
        clang::Rewriter::RewriteOptions())

Description

RemoveText - Remove the specified text region.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:141

Parameters

clang::SourceLocation Start
unsigned int Length
clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()

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

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/Rewriter.h:178

Parameters

clang::SourceRange range
clang::SourceRange replacementRange

bool ReplaceText(clang::SourceRange range,
                 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/Rewriter.h:171

Parameters

clang::SourceRange range
llvm::StringRef NewStr

bool ReplaceText(clang::CharSourceRange range,
                 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/Rewriter.h:164

Parameters

clang::CharSourceRange range
llvm::StringRef NewStr

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

Parameters

clang::SourceLocation Start
unsigned int OrigLength
llvm::StringRef NewStr

Rewriter(clang::SourceManager& SM,
         const clang::LangOptions& LO)

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:69

Parameters

clang::SourceManager& SM
const clang::LangOptions& LO

Rewriter()

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:68

clang::Rewriter::const_buffer_iterator
buffer_begin() const

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:207

clang::Rewriter::buffer_iterator buffer_begin()

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:205

clang::Rewriter::const_buffer_iterator
buffer_end() const

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:208

clang::Rewriter::buffer_iterator buffer_end()

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:206

clang::RewriteBuffer& getEditBuffer(
    clang::FileID FID)

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:194

Parameters

clang::FileID FID

const clang::LangOptions& getLangOpts() const

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:78

unsigned int getLocationOffsetAndFileID(
    clang::SourceLocation Loc,
    clang::FileID& FID) const

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:218

Parameters

clang::SourceLocation Loc
clang::FileID& FID

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

Description

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

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

Parameters

clang::SourceRange Range
clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()

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

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:90

Parameters

const clang::CharSourceRange& Range
clang::Rewriter::RewriteOptions opts = clang::Rewriter::RewriteOptions()

const clang::RewriteBuffer* getRewriteBufferFor(
    clang::FileID FID) const

Description

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

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:198

Parameters

clang::FileID FID

std::string getRewrittenText(
    clang::CharSourceRange Range) const

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:98

Parameters

clang::CharSourceRange Range

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

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:105

Parameters

clang::SourceRange Range

clang::SourceManager& getSourceMgr() const

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:77

static bool isRewritable(
    clang::SourceLocation Loc)

Description

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

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:82

Parameters

clang::SourceLocation Loc

bool overwriteChangedFiles()

Description

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.

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:215

void setSourceMgr(clang::SourceManager& SM,
                  const clang::LangOptions& LO)

Declared at: clang/include/clang/Rewrite/Core/Rewriter.h:72

Parameters

clang::SourceManager& SM
const clang::LangOptions& LO