Skip to content

Commit

Permalink
Adds function to get any token pointer.
Browse files Browse the repository at this point in the history
Adds the getTokenPtr function.
  • Loading branch information
suzizecat committed Mar 1, 2024
1 parent 25f8d08 commit ff6bafc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/slang/syntax/SyntaxNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class SLANG_EXPORT SyntaxNode {
/// an empty Token.
Token childToken(size_t index) const;

/// Gets a pointer to the child token at the specified index. If the
/// child at the given index is not a token (probably a node) then
/// this returns null.
Token* childTokenPtr(size_t index);

/// Gets the number of (direct) children underneath this node in the tree.
size_t getChildCount() const; // Note: implemented in AllSyntax.cpp

Expand Down
7 changes: 7 additions & 0 deletions source/syntax/SyntaxNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ parsing::Token SyntaxNode::childToken(size_t index) const {
return child.token();
}

parsing::Token* SyntaxNode::childTokenPtr(size_t index) {
auto child = getChildPtr(index);
if (!child.isToken())
return nullptr;
return child.token();
}

bool SyntaxNode::isEquivalentTo(const SyntaxNode& other) const {
size_t childCount = getChildCount();
if (kind != other.kind || childCount != other.getChildCount())
Expand Down

0 comments on commit ff6bafc

Please sign in to comment.