clang  6.0.0svn
Public Types | Public Member Functions | List of all members
clang::tooling::Replacements Class Reference

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< RangegetAffectedRanges () 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

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

Definition at line 205 of file Replacement.h.

Member Typedef Documentation

◆ const_iterator

typedef ReplacementsImpl::const_iterator clang::tooling::Replacements::const_iterator

Definition at line 210 of file Replacement.h.

◆ const_reverse_iterator

typedef ReplacementsImpl::const_reverse_iterator clang::tooling::Replacements::const_reverse_iterator

Definition at line 211 of file Replacement.h.

Constructor & Destructor Documentation

◆ Replacements() [1/2]

clang::tooling::Replacements::Replacements ( )

◆ Replacements() [2/2]

clang::tooling::Replacements::Replacements ( const Replacement R)

Definition at line 215 of file Replacement.h.

References clang::Error.

Member Function Documentation

◆ add()

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:

  • 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:

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

  1. Replacement A(0, 2, "123") and B(0, 2, "123") are order-independent since applying them in either order gives (0, 2, "123").
  2. Replacement A(0, 3, "123") and B(2, 3, "321") are order-independent since either order gives (0, 5, "12321").
  3. 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.

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

◆ begin()

const_iterator clang::tooling::Replacements::begin ( ) const

Definition at line 274 of file Replacement.h.

References begin().

Referenced by begin(), and clang::tooling::calculateRangesAfterReplacements().

◆ clear()

void clang::tooling::Replacements::clear ( )

Definition at line 270 of file Replacement.h.

References clear().

Referenced by clear().

◆ empty()

bool clang::tooling::Replacements::empty ( ) const

◆ end()

const_iterator clang::tooling::Replacements::end ( ) const

Definition at line 276 of file Replacement.h.

References end().

Referenced by end().

◆ getAffectedRanges()

std::vector< Range > clang::tooling::Replacements::getAffectedRanges ( ) const

◆ getShiftedCodePosition()

unsigned clang::tooling::Replacements::getShiftedCodePosition ( unsigned  Position) const

Definition at line 523 of file Replacement.cpp.

Referenced by clang::tooling::AtomicChange::insert().

◆ merge()

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

◆ operator==()

bool clang::tooling::Replacements::operator== ( const Replacements RHS) const

Definition at line 282 of file Replacement.h.

References clang::tooling::applyAllReplacements(), Begin, and End.

◆ rbegin()

const_reverse_iterator clang::tooling::Replacements::rbegin ( ) const

Definition at line 278 of file Replacement.h.

References rbegin().

Referenced by rbegin().

◆ rend()

const_reverse_iterator clang::tooling::Replacements::rend ( ) const

Definition at line 280 of file Replacement.h.

References rend().

Referenced by rend().

◆ size()

unsigned clang::tooling::Replacements::size ( ) const

Definition at line 268 of file Replacement.h.

References size().

Referenced by size().

The documentation for this class was generated from the following files: