clang 19.0.0git
Public Member Functions | Protected Member Functions | Friends | List of all members
clang::syntax::Node Class Reference

A node in a syntax tree. More...

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

Inheritance diagram for clang::syntax::Node:
Inheritance graph
[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 37 of file Tree.cpp.

References clang::syntax::Detached.

◆ ~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.

◆ Node() [3/3]

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

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

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 239 of file Tree.cpp.

References clang::C, clang::syntax::ListDelimiter, and clang::syntax::ListElement.

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 277 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(), 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 220 of file Tree.cpp.

◆ dumpTokens()

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

Dumps the tokens forming this subtree.

Definition at line 227 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.

◆ getNextSibling() [2/2]

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

◆ getParent() [1/2]

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

Definition at line 91 of file Tree.h.

◆ 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.

◆ getPreviousSibling() [2/2]

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

Definition at line 95 of file Tree.h.

◆ getRole()

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

Definition at line 71 of file Tree.h.

◆ isDetached()

bool syntax::Node::isDetached ( ) const

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

Definition at line 44 of file Tree.cpp.

References clang::syntax::Detached.

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

◆ 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

◆ operator=() [2/2]

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

Friends And Related Function Documentation

◆ FactoryImpl

friend class FactoryImpl
friend

Definition at line 117 of file Tree.h.

◆ MutationsImpl

friend class MutationsImpl
friend

Definition at line 115 of file Tree.h.

◆ Tree

friend class Tree
friend

Definition at line 111 of file Tree.h.

◆ TreeBuilder

friend class TreeBuilder
friend

Definition at line 113 of file Tree.h.


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