clang  11.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:
Inheritance graph
[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 Treeparent () const
 
Treeparent ()
 
const NodenextSibling () const
 
NodenextSibling ()
 
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 clang::syntax::Detached, and 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 217 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 236 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 197 of file Tree.cpp.

◆ dumpTokens()

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

Dumps the tokens forming this subtree.

Definition at line 204 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 65 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::Leaf::classof(), clang::syntax::Tree::classof(), clang::syntax::TranslationUnit::classof(), clang::syntax::Expression::classof(), clang::syntax::NameSpecifier::classof(), clang::syntax::NestedNameSpecifier::classof(), clang::syntax::UnqualifiedId::classof(), clang::syntax::IdExpression::classof(), clang::syntax::UnknownExpression::classof(), clang::syntax::ParenExpression::classof(), clang::syntax::IntegerLiteralExpression::classof(), clang::syntax::CharacterLiteralExpression::classof(), clang::syntax::FloatingLiteralExpression::classof(), clang::syntax::StringLiteralExpression::classof(), clang::syntax::BoolLiteralExpression::classof(), clang::syntax::CxxNullPtrExpression::classof(), clang::syntax::UserDefinedLiteralExpression::classof(), clang::syntax::IntegerUserDefinedLiteralExpression::classof(), clang::syntax::FloatUserDefinedLiteralExpression::classof(), clang::syntax::CharUserDefinedLiteralExpression::classof(), clang::syntax::StringUserDefinedLiteralExpression::classof(), clang::syntax::UnaryOperatorExpression::classof(), clang::syntax::PrefixUnaryOperatorExpression::classof(), clang::syntax::PostfixUnaryOperatorExpression::classof(), clang::syntax::BinaryOperatorExpression::classof(), clang::syntax::Statement::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::TemplateDeclaration::classof(), clang::syntax::ExplicitTemplateInstantiation::classof(), clang::syntax::NamespaceDefinition::classof(), clang::syntax::NamespaceAliasDefinition::classof(), clang::syntax::UsingNamespaceDirective::classof(), clang::syntax::UsingDeclaration::classof(), clang::syntax::TypeAliasDeclaration::classof(), clang::syntax::Declarator::classof(), clang::syntax::SimpleDeclarator::classof(), clang::syntax::ParenDeclarator::classof(), clang::syntax::ArraySubscript::classof(), clang::syntax::TrailingReturnType::classof(), clang::syntax::ParametersAndQualifiers::classof(), and clang::syntax::MemberPointer::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

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