class Replacements
Declaration
class Replacements { /* full declaration omitted */ };
Description
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).
Declared at: clang/include/clang/Tooling/Core/Replacement.h:209
Member Variables
- private clang::tooling::Replacements::ReplacementsImpl Replaces
Method Overview
- public Replacements(const clang::tooling::Replacement & R)
- private Replacements(clang::tooling::Replacements::const_iterator Begin, clang::tooling::Replacements::const_iterator End)
- public Replacements()
- public llvm::Error add(const clang::tooling::Replacement & R)
- public clang::tooling::Replacements::const_iterator begin() const
- public void clear()
- public bool empty() const
- public clang::tooling::Replacements::const_iterator end() const
- public std::vector<Range> getAffectedRanges() const
- private clang::tooling::Replacements getCanonicalReplacements() const
- private clang::tooling::Replacement getReplacementInChangedCode(const clang::tooling::Replacement & R) const
- public unsigned int getShiftedCodePosition(unsigned int Position) const
- public clang::tooling::Replacements merge(const clang::tooling::Replacements & Replaces) const
- private llvm::Expected<Replacements> mergeIfOrderIndependent(const clang::tooling::Replacement & R) const
- public clang::tooling::Replacements::const_reverse_iterator rbegin() const
- public clang::tooling::Replacements::const_reverse_iterator rend() const
- public unsigned int size() const
Methods
¶Replacements(const clang::tooling::Replacement& R)
Replacements(const clang::tooling::Replacement& R)
Declared at: clang/include/clang/Tooling/Core/Replacement.h:219
Parameters
- const clang::tooling::Replacement& R
¶Replacements(
clang::tooling::Replacements::const_iterator
Begin,
clang::tooling::Replacements::const_iterator
End)
Replacements(
clang::tooling::Replacements::const_iterator
Begin,
clang::tooling::Replacements::const_iterator
End)
Declared at: clang/include/clang/Tooling/Core/Replacement.h:291
Parameters
- clang::tooling::Replacements::const_iterator Begin
- clang::tooling::Replacements::const_iterator End
¶Replacements()
Replacements()
Declared at: clang/include/clang/Tooling/Core/Replacement.h:217
¶llvm::Error add(
const clang::tooling::Replacement& R)
llvm::Error add(
const clang::tooling::Replacement& R)
Description
Adds a new replacement \p R to the current set of replacements.\p 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: - don't overlap (being directly adjacent is fine) and - are overlapping deletions. - are insertions at the same offset and applying them in either order has the same effect, i.e. X + Y = Y + X when inserting X and Y respectively. - are identical replacements, i.e. applying the same replacement twice is equivalent to applying it once. Examples: 1. 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"). 2. Replacement A(0, 2, "123") and B(0, 2, "123") are order-independent since applying them in either order gives (0, 2, "123"). 3. Replacement A(0, 3, "123") and B(2, 3, "321") are order-independent since either order gives (0, 5, "12321"). 4. Replacement A(0, 3, "ab") and B(0, 3, "ab") are order-independent since applying the same replacement twice is equivalent to applying it once. Replacements with offset UINT_MAX are special - we do not detect conflicts for such replacements since users may add them intentionally as a special category of replacements.
Declared at: clang/include/clang/Tooling/Core/Replacement.h:258
Parameters
- const clang::tooling::Replacement& R
¶clang::tooling::Replacements::const_iterator
begin() const
clang::tooling::Replacements::const_iterator
begin() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:278
¶void clear()
void clear()
Declared at: clang/include/clang/Tooling/Core/Replacement.h:274
¶bool empty() const
bool empty() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:276
¶clang::tooling::Replacements::const_iterator end()
const
clang::tooling::Replacements::const_iterator end()
const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:280
¶std::vector<Range> getAffectedRanges() const
std::vector<Range> getAffectedRanges() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:265
¶clang::tooling::Replacements
getCanonicalReplacements() const
clang::tooling::Replacements
getCanonicalReplacements() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:302
¶clang::tooling::Replacement
getReplacementInChangedCode(
const clang::tooling::Replacement& R) const
clang::tooling::Replacement
getReplacementInChangedCode(
const clang::tooling::Replacement& R) const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:296
Parameters
- const clang::tooling::Replacement& R
¶unsigned int getShiftedCodePosition(
unsigned int Position) const
unsigned int getShiftedCodePosition(
unsigned int Position) const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:270
Parameters
- unsigned int Position
¶clang::tooling::Replacements merge(
const clang::tooling::Replacements& Replaces)
const
clang::tooling::Replacements merge(
const clang::tooling::Replacements& Replaces)
const
Description
Merges \p Replaces into the current replacements. \p Replaces refers to code after applying the current replacements.
Declared at: clang/include/clang/Tooling/Core/Replacement.h:262
Parameters
- const clang::tooling::Replacements& Replaces
¶llvm::Expected<Replacements>
mergeIfOrderIndependent(
const clang::tooling::Replacement& R) const
llvm::Expected<Replacements>
mergeIfOrderIndependent(
const clang::tooling::Replacement& R) const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:308
Parameters
- const clang::tooling::Replacement& R
¶clang::tooling::Replacements::
const_reverse_iterator
rbegin() const
clang::tooling::Replacements::
const_reverse_iterator
rbegin() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:282
¶clang::tooling::Replacements::
const_reverse_iterator
rend() const
clang::tooling::Replacements::
const_reverse_iterator
rend() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:284
¶unsigned int size() const
unsigned int size() const
Declared at: clang/include/clang/Tooling/Core/Replacement.h:272