clang 20.0.0git
|
A node in a syntax tree. More...
#include "clang/Tooling/Syntax/Tree.h"
Public Member Functions | |
Node (const Node &)=delete | |
Nodes cannot simply be copied without violating tree invariants. | |
Node & | operator= (const Node &)=delete |
Node (Node &&)=delete | |
Idiomatically, nodes are allocated on an Arena and never moved. | |
Node & | operator= (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 Tree * | getParent () const |
Tree * | getParent () |
const Node * | getNextSibling () const |
Node * | getNextSibling () |
const Node * | getPreviousSibling () const |
Node * | getPreviousSibling () |
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 |
A node in a syntax tree.
Each node is either a Leaf (representing tokens) or a Tree (representing language constructrs).
|
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.
|
protecteddefault |
Nodes are allocated on Arenas; the destructor is never called.
|
delete |
Nodes cannot simply be copied without violating tree invariants.
|
delete |
Idiomatically, nodes are allocated on an Arena and never moved.
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, clang::syntax::ListElement, and clang::T.
Referenced by assertInvariantsRecursive(), clang::syntax::createLeaf(), and clang::syntax::MutationsImpl::remove().
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().
|
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().
std::string syntax::Node::dump | ( | const TokenManager & | SM | ) | const |
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().
|
inline |
Definition at line 70 of file Tree.h.
Referenced by clang::syntax::deepCopyExpandingMacros().
|
inline |
Definition at line 93 of file Tree.h.
Referenced by clang::syntax::MutationsImpl::remove(), and clang::syntax::MutationsImpl::replace().
|
inline |
Definition at line 90 of file Tree.h.
Referenced by clang::syntax::MutationsImpl::remove(), and clang::syntax::MutationsImpl::replace().
|
inline |
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().
|
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.
|
friend |
|
friend |
|
friend |