clang 20.0.0git
|
Maintains a set of replacements that are conflict-free. More...
#include "clang/Tooling/Core/Replacement.h"
Public Types | |
using | const_iterator = ReplacementsImpl::const_iterator |
using | const_reverse_iterator = ReplacementsImpl::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. | |
Replacements | merge (const Replacements &Replaces) const |
Merges Replaces into the current replacements. | |
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 212 of file Replacement.h.
using clang::tooling::Replacements::const_iterator = ReplacementsImpl::const_iterator |
Definition at line 217 of file Replacement.h.
using clang::tooling::Replacements::const_reverse_iterator = ReplacementsImpl::const_reverse_iterator |
Definition at line 218 of file Replacement.h.
|
default |
Referenced by merge().
|
inlineexplicit |
Definition at line 222 of file Replacement.h.
llvm::Error 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 246 of file Replacement.cpp.
References clang::tooling::Replacement::getFilePath(), clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), clang::tooling::Replacement::getReplacementText(), clang::tooling::insert_conflict, clang::tooling::Range::overlapsWith(), and clang::tooling::wrong_file_path.
Referenced by clang::format::WhitespaceManager::addReplacement(), clang::tooling::applyAtomicChanges(), clang::tooling::calculateRangesAfterReplacements(), clang::syntax::computeReplacements(), clang::format::internal::reformat(), clang::format::replaceToken(), clang::tooling::ReplaceStmtWithText::run(), clang::tooling::ReplaceNodeWithTemplate::run(), clang::tooling::ReplaceStmtWithStmt::run(), clang::tooling::ReplaceIfStmtWithItsBody::run(), clang::format::sortCppIncludes(), and clang::format::sortJavaImports().
|
inline |
Definition at line 281 of file Replacement.h.
Referenced by clang::tooling::calculateRangesAfterReplacements(), and clang::format::processReplacements().
|
inline |
Definition at line 277 of file Replacement.h.
|
inline |
Definition at line 279 of file Replacement.h.
Referenced by clang::tooling::applyAllReplacements(), clang::tooling::calculateRangesAfterReplacements(), merge(), and clang::format::processReplacements().
|
inline |
Definition at line 283 of file Replacement.h.
std::vector< Range > Replacements::getAffectedRanges | ( | ) | const |
Definition at line 535 of file Replacement.cpp.
References combineAndSortRanges(), clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), and clang::tooling::Replacement::getReplacementText().
Referenced by clang::tooling::applyAtomicChanges(), clang::tooling::calculateRangesAfterReplacements(), and clang::format::processReplacements().
Definition at line 547 of file Replacement.cpp.
References clang::tooling::Replacement::getLength(), clang::tooling::Replacement::getOffset(), and clang::tooling::Replacement::getReplacementText().
Replacements Replacements::merge | ( | const Replacements & | Replaces | ) | const |
Merges Replaces
into the current replacements.
Replaces
refers to code after applying the current replacements.
Definition at line 444 of file Replacement.cpp.
References empty(), clang::First, Replacements(), and clang::Result.
Referenced by clang::tooling::applyAtomicChanges(), clang::tooling::calculateRangesAfterReplacements(), clang::format::processReplacements(), and clang::format::internal::reformat().
|
inline |
Definition at line 289 of file Replacement.h.
|
inline |
Definition at line 285 of file Replacement.h.
Referenced by clang::tooling::applyAllReplacements().
|
inline |
Definition at line 287 of file Replacement.h.
Referenced by clang::tooling::applyAllReplacements().
|
inline |
Definition at line 275 of file Replacement.h.