clang 10.0.0git

Public 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:
[legend]

## Public 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...
NodeKind | kind () const
NodeRole | role () 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 Tree * | parent () const
Tree * | parent ()
const Node * | nextSibling () const
Node * | nextSibling ()
std::string | dump (const Arena &A) const
| Dumps the structure of a subtree. For debugging and testing purposes. More...
std::string | dumpTokens (const Arena &A) 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...

## 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 76 of file Tree.h.

## Constructor & Destructor Documentation

## ◆ Node()

syntax::Node::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.

Definition at line 59 of file Tree.cpp.

References Parent.

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

References isDetached(), and parent().

Referenced by assertInvariantsRecursive().

## ◆ assertInvariantsRecursive()

void syntax::Node::assertInvariantsRecursive | ( |  | ) | const

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

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

Referenced by clang::syntax::MutationsImpl::replace().

## ◆ dump()

std::string syntax::Node::dump | ( | const Arena & | A | ) | const

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

Definition at line 186 of file Tree.cpp.

## ◆ dumpTokens()

std::string syntax::Node::dumpTokens | ( | const Arena & | A | ) | const

Dumps the tokens forming this subtree.

Definition at line 193 of file Tree.cpp.

References clang::syntax::Arena::sourceManager(), and clang::ast_matchers::traverse().

## ◆ isDetached()

bool syntax::Node::isDetached | ( |  | ) | const

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

Definition at line 64 of file Tree.cpp.

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

Referenced by clang::syntax::MutationsImpl::addAfter(), assertInvariants(), 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 93 of file Tree.h.

## ◆ kind()

NodeKind clang::syntax::Node::kind | ( |  | ) | const
| inline

Definition at line 82 of file Tree.h.

Referenced by clang::syntax::TranslationUnit::classof(), clang::syntax::Expression::classof(), clang::syntax::UnknownExpression::classof(), clang::syntax::Leaf::classof(), clang::syntax::Statement::classof(), clang::syntax::Tree::classof(), clang::syntax::UnknownStatement::classof(), clang::syntax::DeclarationStatement::classof(), clang::syntax::EmptyStatement::classof(), clang::syntax::SwitchStatement::classof(), clang::syntax::CaseStatement::classof(), clang::syntax::DefaultStatement::classof(), clang::syntax::IfStatement::classof(), clang::syntax::ForStatement::classof(), clang::syntax::WhileStatement::classof(), clang::syntax::ContinueStatement::classof(), clang::syntax::BreakStatement::classof(), clang::syntax::ReturnStatement::classof(), clang::syntax::RangeBasedForStatement::classof(), clang::syntax::ExpressionStatement::classof(), clang::syntax::CompoundStatement::classof(), clang::syntax::Declaration::classof(), clang::syntax::UnknownDeclaration::classof(), clang::syntax::EmptyDeclaration::classof(), clang::syntax::StaticAssertDeclaration::classof(), clang::syntax::LinkageSpecificationDeclaration::classof(), clang::syntax::SimpleDeclaration::classof(), clang::syntax::NamespaceDefinition::classof(), clang::syntax::NamespaceAliasDefinition::classof(), clang::syntax::UsingNamespaceDirective::classof(), clang::syntax::UsingDeclaration::classof(), and clang::syntax::TypeAliasDeclaration::classof().

## ◆ nextSibling() [1/2]

const Node* clang::syntax::Node::nextSibling | ( |  | ) | const
| inline

Definition at line 105 of file Tree.h.

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

## ◆ nextSibling() [2/2]

Node* clang::syntax::Node::nextSibling | ( |  | ) |
| inline

Definition at line 106 of file Tree.h.

References dump().

## ◆ parent() [1/2]

const Tree* clang::syntax::Node::parent | ( |  | ) | const
| inline

Definition at line 102 of file Tree.h.

References Parent.

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

## ◆ parent() [2/2]

Tree* clang::syntax::Node::parent | ( |  | ) |
| inline

Definition at line 103 of file Tree.h.

References Parent.

## ◆ role()

NodeRole clang::syntax::Node::role | ( |  | ) | const
| inline

Definition at line 83 of file Tree.h.

Referenced by clang::syntax::Tree::classof(), and isDetached().

## Friends And Related Function Documentation

## ◆ FactoryImpl

friend class FactoryImpl
| friend

Definition at line 127 of file Tree.h.

## ◆ MutationsImpl

friend class MutationsImpl
| friend

Definition at line 125 of file Tree.h.

## ◆ Tree

friend class Tree
| friend

Definition at line 121 of file Tree.h.

## ◆ TreeBuilder

friend class TreeBuilder
| friend

Definition at line 123 of file Tree.h.

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

- include/clang/Tooling/Syntax/Tree.h
- lib/Tooling/Syntax/Tree.cpp