clang
6.0.0
|
Maintains a set of replacements that are conflict-free. More...
#include "clang/Tooling/Core/Replacement.h"
Public Types | |
typedef ReplacementsImpl::const_iterator | const_iterator |
typedef ReplacementsImpl::const_reverse_iterator | const_reverse_iterator |
Public Member Functions | |
Replacements ()=default | |
Replacements (const Replacement &R) | |
llvm::Error | add (const Replacement &R) |
Adds a new replacement R to the current set of replacements. More... | |
LLVM_NODISCARD Replacements | merge (const Replacements &Replaces) const |
Merges Replaces into the current replacements. More... | |
std::vector< Range > | getAffectedRanges () const |
unsigned | getShiftedCodePosition (unsigned Position) const |
unsigned | size () const |
void | clear () |
bool | empty () const |
const_iterator | begin () const |
const_iterator | end () const |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | rend () const |
bool | operator== (const Replacements &RHS) const |
Maintains a set of replacements that are conflict-free.
Two replacements are considered conflicts if they overlap or have the same offset (i.e. order-dependent).
Definition at line 205 of file Replacement.h.
typedef ReplacementsImpl::const_iterator clang::tooling::Replacements::const_iterator |
Definition at line 210 of file Replacement.h.
typedef ReplacementsImpl::const_reverse_iterator clang::tooling::Replacements::const_reverse_iterator |
Definition at line 211 of file Replacement.h.
|
default |
|
inlineexplicit |
Definition at line 215 of file Replacement.h.
References clang::Error.
llvm::Error clang::tooling::Replacements::add | ( | const Replacement & | R | ) |
Adds a new replacement R
to the current set of replacements.
R
must have the same file path as all existing replacements. Returns success
if the replacement is successfully inserted; otherwise, it returns an llvm::Error, i.e. there is a conflict between R and the existing replacements (i.e. they are order-dependent) or R's file path is different from the filepath of existing replacements. Callers must explicitly check the Error returned, and the returned error can be converted to a string message with llvm::toString()
. This prevents users from adding order-dependent replacements. To control the order in which order-dependent replacements are applied, use merge({R}) with R referring to the changed code after applying all existing replacements. Two replacements A and B are considered order-independent if applying them in either order produces the same result. Note that the range of the replacement that is applied later still refers to the original code. These include (but not restricted to) replacements that:
Replacement A(0, 0, "a") and B(0, 0, "aa") are order-independent since applying them in either order gives replacement (0, 0, "aaa"). However, A(0, 0, "a") and B(0, 0, "b") are order-dependent since applying A first gives (0, 0, "ab") while applying B first gives (B, A, "ba").
Definition at line 227 of file Replacement.cpp.
References clang::tooling::Replacement::getFilePath(), clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), UINT_MAX, and clang::tooling::wrong_file_path.
Referenced by clang::tooling::applyAtomicChanges(), clang::tooling::calculateRangesAfterReplacements(), clang::tooling::AtomicChange::insert(), clang::tooling::AtomicChange::replace(), clang::tooling::ReplaceStmtWithText::run(), clang::tooling::ReplaceNodeWithTemplate::run(), clang::tooling::ReplaceStmtWithStmt::run(), and clang::tooling::ReplaceIfStmtWithItsBody::run().
|
inline |
Definition at line 274 of file Replacement.h.
References begin().
Referenced by begin(), and clang::tooling::calculateRangesAfterReplacements().
|
inline |
|
inline |
Definition at line 272 of file Replacement.h.
References empty().
Referenced by clang::tooling::applyAllReplacements(), clang::tooling::calculateRangesAfterReplacements(), empty(), and merge().
|
inline |
std::vector< Range > clang::tooling::Replacements::getAffectedRanges | ( | ) | const |
Definition at line 511 of file Replacement.cpp.
References clang::tooling::combineAndSortRanges(), clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), clang::tooling::Replacement::getReplacementText(), and clang::prec::Shift.
Referenced by clang::tooling::applyAtomicChanges(), and clang::tooling::calculateRangesAfterReplacements().
unsigned clang::tooling::Replacements::getShiftedCodePosition | ( | unsigned | Position | ) | const |
Definition at line 523 of file Replacement.cpp.
Referenced by clang::tooling::AtomicChange::insert().
Replacements clang::tooling::Replacements::merge | ( | const Replacements & | Replaces | ) | const |
Merges Replaces
into the current replacements.
Replaces
refers to code after applying the current replacements.
Definition at line 424 of file Replacement.cpp.
References empty().
Referenced by clang::tooling::calculateRangesAfterReplacements(), clang::tooling::AtomicChange::insert(), and clang::tooling::ReplacementError::message().
|
inline |
Definition at line 282 of file Replacement.h.
References clang::tooling::applyAllReplacements(), Begin, and End.
|
inline |
|
inline |
|
inline |