clang 22.0.0git
clang::syntax::Node Class Reference

A node in a syntax tree. More...

#include "clang/Tooling/Syntax/Tree.h"

Inheritance diagram for clang::syntax::Node:
[legend]

Public Member Functions

 Node (const Node &)=delete
 Nodes cannot simply be copied without violating tree invariants.
Nodeoperator= (const Node &)=delete
 Node (Node &&)=delete
 Idiomatically, nodes are allocated on an Arena and never moved.
Nodeoperator= (Node &&)=delete
NodeKind getKind () const
NodeRole getRole () const
bool isDetached () const
 Whether the node is detached from a tree, i.e. does not have a parent.
bool isOriginal () const
 Whether the node was created from the AST backed by the source code rather than added later through mutation APIs or created with factory functions.
bool canModify () const
 If this function return false, the tree cannot be modified because there is no reasonable way to produce the corresponding textual replacements.
const TreegetParent () const
TreegetParent ()
const NodegetNextSibling () const
NodegetNextSibling ()
const NodegetPreviousSibling () const
NodegetPreviousSibling ()
std::string dump (const TokenManager &SM) const
 Dumps the structure of a subtree. For debugging and testing purposes.
std::string dumpTokens (const TokenManager &SM) const
 Dumps the tokens forming this subtree.
void assertInvariants () const
 Asserts invariants on this node of the tree and its immediate children.
void assertInvariantsRecursive () const
 Runs checkInvariants on all nodes in the subtree. No-op if NDEBUG is set.

Protected Member Functions

 Node (NodeKind Kind)
 Newly created nodes are detached from a tree, parent and sibling links are set when the node is added as a child to another one.
 ~Node ()=default
 Nodes are allocated on Arenas; the destructor is never called.

Friends

class Tree
class TreeBuilder
class MutationsImpl
class FactoryImpl

Detailed Description

A node in a syntax tree.

Each node is either a Leaf (representing tokens) or a Tree (representing language constructrs).

Definition at line 54 of file Tree.h.

Constructor & Destructor Documentation

◆ Node() [1/3]

syntax::Node::Node ( NodeKind Kind)
protected

Newly created nodes are detached from a tree, parent and sibling links are set when the node is added as a child to another one.

Definition at line 36 of file Tree.cpp.

References clang::syntax::Detached, false, and clang::nullptr.

Referenced by assertInvariants(), clang::syntax::Leaf::classof(), FactoryImpl, getNextSibling(), getNextSibling(), getPreviousSibling(), getPreviousSibling(), clang::syntax::Leaf::Leaf(), Node(), Node(), operator=(), and operator=().

◆ ~Node()

clang::syntax::Node::~Node ( )
protecteddefault

Nodes are allocated on Arenas; the destructor is never called.

◆ Node() [2/3]

clang::syntax::Node::Node ( const Node & )
delete

Nodes cannot simply be copied without violating tree invariants.

References Node().

◆ Node() [3/3]

clang::syntax::Node::Node ( Node && )
delete

Idiomatically, nodes are allocated on an Arena and never moved.

References Node().

Member Function Documentation

◆ assertInvariants()

void syntax::Node::assertInvariants ( ) const

Asserts invariants on this node of the tree and its immediate children.

Will not recurse into the subtree. No-op if NDEBUG is set.

Definition at line 238 of file Tree.cpp.

References clang::C, getParent(), clang::isa(), isDetached(), clang::syntax::ListDelimiter, clang::syntax::ListElement, Next, Node(), and clang::T.

Referenced by assertInvariantsRecursive(), clang::syntax::createLeaf(), and clang::syntax::MutationsImpl::remove().

◆ assertInvariantsRecursive()

void syntax::Node::assertInvariantsRecursive ( ) const

Runs checkInvariants on all nodes in the subtree. No-op if NDEBUG is set.

Definition at line 276 of file Tree.cpp.

References assertInvariants(), and clang::ast_matchers::traverse().

◆ canModify()

bool clang::syntax::Node::canModify ( ) const
inline

If this function return false, the tree cannot be modified because there is no reasonable way to produce the corresponding textual replacements.

This can happen when the node crosses macro expansion boundaries.

Note that even if the node is not modifiable, its child nodes can be modifiable.

Definition at line 88 of file Tree.h.

Referenced by clang::syntax::MutationsImpl::remove(), clang::syntax::removeStatement(), and clang::syntax::MutationsImpl::replace().

◆ dump()

std::string syntax::Node::dump ( const TokenManager & SM) const

Dumps the structure of a subtree. For debugging and testing purposes.

Definition at line 219 of file Tree.cpp.

◆ dumpTokens()

std::string syntax::Node::dumpTokens ( const TokenManager & SM) const

Dumps the tokens forming this subtree.

Definition at line 226 of file Tree.cpp.

References clang::syntax::TokenManager::getText(), and clang::ast_matchers::traverse().

◆ getKind()

NodeKind clang::syntax::Node::getKind ( ) const
inline

Definition at line 70 of file Tree.h.

Referenced by clang::syntax::deepCopyExpandingMacros().

◆ getNextSibling() [1/2]

Node * clang::syntax::Node::getNextSibling ( )
inline

Definition at line 94 of file Tree.h.

References Node().

◆ getNextSibling() [2/2]

const Node * clang::syntax::Node::getNextSibling ( ) const
inline

Definition at line 93 of file Tree.h.

References Node().

Referenced by clang::syntax::MutationsImpl::remove(), and clang::syntax::MutationsImpl::replace().

◆ getParent() [1/2]

Tree * clang::syntax::Node::getParent ( )
inline

Definition at line 91 of file Tree.h.

References Tree.

◆ getParent() [2/2]

const Tree * clang::syntax::Node::getParent ( ) const
inline

◆ getPreviousSibling() [1/2]

Node * clang::syntax::Node::getPreviousSibling ( )
inline

Definition at line 96 of file Tree.h.

References Node().

◆ getPreviousSibling() [2/2]

const Node * clang::syntax::Node::getPreviousSibling ( ) const
inline

Definition at line 95 of file Tree.h.

References Node().

◆ getRole()

NodeRole clang::syntax::Node::getRole ( ) const
inline

Definition at line 71 of file Tree.h.

Referenced by isDetached().

◆ isDetached()

bool syntax::Node::isDetached ( ) const

Whether the node is detached from a tree, i.e. does not have a parent.

Definition at line 43 of file Tree.cpp.

References clang::syntax::Detached, and getRole().

Referenced by assertInvariants().

◆ isOriginal()

bool clang::syntax::Node::isOriginal ( ) const
inline

Whether the node was created from the AST backed by the source code rather than added later through mutation APIs or created with factory functions.

When this flag is true, all subtrees are also original. This flag is set to false on any modifications to the node or any of its subtrees, even if this simply involves swapping existing subtrees.

Definition at line 81 of file Tree.h.

◆ operator=() [1/2]

Node & clang::syntax::Node::operator= ( const Node & )
delete

References Node().

◆ operator=() [2/2]

Node & clang::syntax::Node::operator= ( Node && )
delete

References Node().

◆ FactoryImpl

friend class FactoryImpl
friend

Definition at line 117 of file Tree.h.

References FactoryImpl, Node(), and Tree.

Referenced by FactoryImpl.

◆ MutationsImpl

friend class MutationsImpl
friend

Definition at line 115 of file Tree.h.

References MutationsImpl.

Referenced by MutationsImpl.

◆ Tree

◆ TreeBuilder

friend class TreeBuilder
friend

Definition at line 113 of file Tree.h.

References TreeBuilder.

Referenced by TreeBuilder.


The documentation for this class was generated from the following files: