slang::syntax::SyntaxNode class

Base class for all syntax nodes.

Derived classes

class SyntaxListBase
A base class for syntax nodes that represent a list of items.

Public static functions

static auto isKind(SyntaxKind) -> bool

Public functions

auto toString() const -> std::string
Print the node and all of its children to a string.
auto getFirstToken() const -> Token
Get the first leaf token in this subtree.
auto getLastToken() const -> Token
Get the last leaf token in this subtree.
auto sourceRange() const -> SourceRange
Get the source range of the node.
auto childNode(size_t index) const -> const SyntaxNode*
auto childNode(size_t index) -> SyntaxNode*
auto childToken(size_t index) const -> Token
auto getChildCount() const -> size_t
Gets the number of (direct) children underneath this node in the tree.
auto isEquivalentTo(const SyntaxNode& other) const -> bool
template<typename T>
auto as() -> T&
template<typename T>
auto as() const -> const T&
template<typename TVisitor, typename... Args>
auto visit(TVisitor& visitor, Args && ... args) -> decltype(auto)
template<typename TVisitor, typename... Args>
auto visit(TVisitor& visitor, Args && ... args) const -> decltype(auto)

Public variables

SyntaxNode* parent
SyntaxKind kind
The kind of syntax node.

Function documentation

static bool slang::syntax::SyntaxNode::isKind(SyntaxKind)

A base implemention of the method that checks correctness of dynamic casting. Derived nodes should reimplement this and return true if the provided syntax kind is compatible with the static type of the object.

const SyntaxNode* slang::syntax::SyntaxNode::childNode(size_t index) const

Gets the child syntax node at the specified index. If the child at the given index is not a node (probably a token) then this returns null.

SyntaxNode* slang::syntax::SyntaxNode::childNode(size_t index)

Gets the child syntax node at the specified index. If the child at the given index is not a node (probably a token) then this returns null.

Token slang::syntax::SyntaxNode::childToken(size_t index) const

Gets the child token at the specified index. If the child at the given index is not a token (probably a node) then this returns an empty Token.

bool slang::syntax::SyntaxNode::isEquivalentTo(const SyntaxNode& other) const

Returns true if this syntax node is "equivalent" to the other provided syntax node. Equivalence here is determined by the entire subtrees having the same kinds of syntax nodes in the same order and all leaf tokens having the same kinds and value text.

template<typename T>
T& slang::syntax::SyntaxNode::as()

Reinterprets this node as being of type T. In debug this will assert that the dynamic kind is appropriate for the specified static type.

template<typename T>
const T& slang::syntax::SyntaxNode::as() const

Reinterprets this node as being of type T. In debug this will assert that the dynamic kind is appropriate for the specified static type.

template<typename TVisitor, typename... Args>
decltype(auto) slang::syntax::SyntaxNode::visit(TVisitor& visitor, Args && ... args)

Applies a visitor object to this node by dispatching based on the dynamic kind. The given args are forwarded to the visitor.

template<typename TVisitor, typename... Args>
decltype(auto) slang::syntax::SyntaxNode::visit(TVisitor& visitor, Args && ... args) const

Applies a visitor object to this node by dispatching based on the dynamic kind. The given args are forwarded to the visitor.

Variable documentation

SyntaxNode* slang::syntax::SyntaxNode::parent

The parent node of this syntax node. The root of the syntax tree does not have a parent (will be nullptr).