#include <slang/syntax/SyntaxVisitor.h>
template<typename TDerived>
SyntaxRewriter class
A helper class that assists in rewriting syntax trees – useful for automated refactoring tools.
Base classes
-
template<typename TDerived>class SyntaxVisitor<TDerived>
- Use this type as a base class for syntax tree visitors.
Public functions
-
auto transform(const std::
shared_ptr<SyntaxTree>& tree, const SourceLibrary* library = nullptr) -> std:: shared_ptr<SyntaxTree> - Transforms the given syntax tree using the rewriter.
Protected functions
-
auto parse(std::
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.
- void insertAtFront(const SyntaxListBase& list, SyntaxNode& newNode, Token separator = {})
- Insert newNode at the front of list in the rewritten tree.
- void insertAtBack(const SyntaxListBase& list, SyntaxNode& newNode, Token separator = {})
- Insert newNode at the back of list in the rewritten tree.
Function documentation
template<typename TDerived>
std:: shared_ptr<SyntaxTree> slang:: syntax:: SyntaxRewriter<TDerived>:: transform(const std:: shared_ptr<SyntaxTree>& tree,
const SourceLibrary* library = nullptr)
Transforms the given syntax tree using the rewriter.
Returns | if no changes are requested, returns the original syntax tree. Otherwise, the changes are applied and the newly rewritten syntax tree is returned. |
---|
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).