clang  14.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. More...
 
Nodeoperator= (const Node &)=delete
 
 Node (Node &&)=delete
 Idiomatically, nodes are allocated on an Arena and never moved. More...
 
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. More...
 
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. More...
 
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. More...
 
const TreegetParent () const
 
TreegetParent ()
 
const NodegetNextSibling () const
 
NodegetNextSibling ()
 
const NodegetPreviousSibling () const
 
NodegetPreviousSibling ()
 
std::string dump (const SourceManager &SM) const
 Dumps the structure of a subtree. For debugging and testing purposes. More...
 
std::string dumpTokens (const SourceManager &SM) const
 Dumps the tokens forming this subtree. More...
 
void assertInvariants () const
 Asserts invariants on this node of the tree and its immediate children. More...
 
void assertInvariantsRecursive () const
 Runs checkInvariants on all nodes in the subtree. No-op if NDEBUG is set. More...
 

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. More...
 
 ~Node ()=default
 Nodes are allocated on Arenas; the destructor is never called. More...
 

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 80 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 55 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 269 of file Tree.cpp.

Referenced by assertInvariantsRecursive(), 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 306 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 114 of file Tree.h.

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

◆ dump()

std::string syntax::Node::dump ( const SourceManager SM) const

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

Definition at line 250 of file Tree.cpp.

References SM, and string().

◆ dumpTokens()

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

Dumps the tokens forming this subtree.

Definition at line 257 of file Tree.cpp.

References SM, string(), and clang::ast_matchers::traverse().

◆ getKind()

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

Definition at line 96 of file Tree.h.

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

◆ getNextSibling() [1/2]

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

Definition at line 120 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 117 of file Tree.h.

References Parent.

◆ getParent() [2/2]

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

◆ getPreviousSibling() [1/2]

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

Definition at line 122 of file Tree.h.

◆ getPreviousSibling() [2/2]

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

Definition at line 121 of file Tree.h.

◆ getRole()

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

Definition at line 97 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 62 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 107 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 143 of file Tree.h.

◆ MutationsImpl

friend class MutationsImpl
friend

Definition at line 141 of file Tree.h.

◆ Tree

friend class Tree
friend

Definition at line 137 of file Tree.h.

◆ TreeBuilder

friend class TreeBuilder
friend

Definition at line 139 of file Tree.h.


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