slang::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 childToken(size_t index) const -> Token
auto getChildCount() const -> size_t
Gets the number of (direct) children underneath this node in the tree.
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::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::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.

Token slang::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.

template<typename T>
T& slang::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::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::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::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::SyntaxNode::parent

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