template<typename TDerived>
slang::SyntaxRewriter class

A helper class that assists in rewriting syntax trees – useful for automated refactoring tools.

Base classes

template<typename TDerived>
class SyntaxVisitor

Public functions

auto transform(const std::shared_ptr<SyntaxTree>& tree) -> std::shared_ptr<SyntaxTree>

Protected functions

auto parse(string_view text) -> SyntaxNode&
A helper for derived classes that parses some text into syntax nodes.
void remove(const SyntaxNode& oldNode)
Register a removal for the given syntax node from the tree.
void replace(const SyntaxNode& oldNode, SyntaxNode& newNode)
Replace the given oldNode with newNode in the rewritten tree.
void insertBefore(const SyntaxNode& oldNode, SyntaxNode& newNode)
Insert newNode before oldNode in the rewritten tree.
void insertAfter(const SyntaxNode& oldNode, SyntaxNode& newNode)
Insert newNode after oldNode in the rewritten tree.

Function documentation

template<typename TDerived>
std::shared_ptr<SyntaxTree> slang::SyntaxRewriter<TDerived>::transform(const std::shared_ptr<SyntaxTree>& tree)

Returns if no changes are requested, returns the original syntax tree. Otherwise, the changes are applied and the newly rewritten syntax tree is returned.

Transforms the given syntax tree using the rewriter. The tree will be visited in order and each node will be given a chance to be rewritten (by providing visit() implementations in the derived class).