clang 22.0.0git
clang::syntax::Tree Class Reference

A node that has children and represents a syntactic language construct. More...

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

Inheritance diagram for clang::syntax::Tree:
[legend]

Classes

struct  ChildIterator
 child_iterator is not invalidated by mutations. More...
struct  ConstChildIterator

Public Member Functions

NodegetFirstChild ()
const NodegetFirstChild () const
NodegetLastChild ()
const NodegetLastChild () const
const LeaffindFirstLeaf () const
LeaffindFirstLeaf ()
const LeaffindLastLeaf () const
LeaffindLastLeaf ()
llvm::iterator_range< ChildIteratorgetChildren ()
llvm::iterator_range< ConstChildIteratorgetChildren () const
const NodefindChild (NodeRole R) const
 Find the first node with a corresponding role.
NodefindChild (NodeRole R)
Public Member Functions inherited from clang::syntax::Node
 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.

Static Public Member Functions

static bool classof (const Node *N)

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 (const Node &)=delete
 Nodes cannot simply be copied without violating tree invariants.
 Node (Node &&)=delete
 Idiomatically, nodes are allocated on an Arena and never moved.
Protected Member Functions inherited from clang::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.
 ~Node ()=default
 Nodes are allocated on Arenas; the destructor is never called.

Friends

class TreeBuilder
class FactoryImpl
class MutationsImpl

Detailed Description

A node that has children and represents a syntactic language construct.

Definition at line 144 of file Tree.h.

Member Function Documentation

◆ classof()

bool clang::syntax::Tree::classof ( const Node * N)
static

References Node().

◆ findChild() [1/2]

Node * clang::syntax::Tree::findChild ( NodeRole R)
inline

Definition at line 214 of file Tree.h.

References Node(), and clang::syntax::Node::Tree.

◆ findChild() [2/2]

const syntax::Node * syntax::Tree::findChild ( NodeRole R) const

Find the first node with a corresponding role.

Definition at line 302 of file Tree.cpp.

References clang::C, getChildren(), and Node().

Referenced by clang::syntax::TrailingReturnType::getArrowToken(), clang::syntax::CaseStatement::getBody(), clang::syntax::DefaultStatement::getBody(), clang::syntax::ForStatement::getBody(), clang::syntax::RangeBasedForStatement::getBody(), clang::syntax::SwitchStatement::getBody(), clang::syntax::WhileStatement::getBody(), clang::syntax::BreakStatement::getBreakKeyword(), clang::syntax::CaseStatement::getCaseKeyword(), clang::syntax::CaseStatement::getCaseValue(), clang::syntax::StaticAssertDeclaration::getCondition(), clang::syntax::ContinueStatement::getContinueKeyword(), clang::syntax::ExplicitTemplateInstantiation::getDeclaration(), clang::syntax::TemplateDeclaration::getDeclaration(), clang::syntax::TrailingReturnType::getDeclarator(), clang::syntax::DefaultStatement::getDefaultKeyword(), clang::syntax::IfStatement::getElseKeyword(), clang::syntax::IfStatement::getElseStatement(), clang::syntax::ExpressionStatement::getExpression(), clang::syntax::ExplicitTemplateInstantiation::getExternKeyword(), clang::syntax::ForStatement::getForKeyword(), clang::syntax::RangeBasedForStatement::getForKeyword(), clang::syntax::IfStatement::getIfKeyword(), clang::syntax::CompoundStatement::getLbrace(), clang::syntax::ArraySubscript::getLbracket(), clang::syntax::ParametersAndQualifiers::getLparen(), clang::syntax::ParenDeclarator::getLparen(), clang::syntax::StaticAssertDeclaration::getMessage(), clang::syntax::ParametersAndQualifiers::getParameters(), clang::syntax::CompoundStatement::getRbrace(), clang::syntax::ArraySubscript::getRbracket(), clang::syntax::ReturnStatement::getReturnKeyword(), clang::syntax::ReturnStatement::getReturnValue(), clang::syntax::ParametersAndQualifiers::getRparen(), clang::syntax::ParenDeclarator::getRparen(), clang::syntax::ArraySubscript::getSize(), clang::syntax::SwitchStatement::getSwitchKeyword(), clang::syntax::ExplicitTemplateInstantiation::getTemplateKeyword(), clang::syntax::TemplateDeclaration::getTemplateKeyword(), clang::syntax::IfStatement::getThenStatement(), clang::syntax::ParametersAndQualifiers::getTrailingReturn(), and clang::syntax::WhileStatement::getWhileKeyword().

◆ findFirstLeaf() [1/2]

Leaf * clang::syntax::Tree::findFirstLeaf ( )
inline

Definition at line 185 of file Tree.h.

References clang::syntax::Node::Tree.

◆ findFirstLeaf() [2/2]

const syntax::Leaf * syntax::Tree::findFirstLeaf ( ) const

Definition at line 282 of file Tree.cpp.

References clang::C, clang::cast(), findFirstLeaf(), getChildren(), and Node().

Referenced by findFirstLeaf().

◆ findLastLeaf() [1/2]

Leaf * clang::syntax::Tree::findLastLeaf ( )
inline

Definition at line 190 of file Tree.h.

References clang::syntax::Node::Tree.

◆ findLastLeaf() [2/2]

const syntax::Leaf * syntax::Tree::findLastLeaf ( ) const

Definition at line 292 of file Tree.cpp.

References clang::C, clang::cast(), findLastLeaf(), and getLastChild().

Referenced by findLastLeaf().

◆ getChildren() [1/2]

llvm::iterator_range< ChildIterator > clang::syntax::Tree::getChildren ( )
inline

◆ getChildren() [2/2]

llvm::iterator_range< ConstChildIterator > clang::syntax::Tree::getChildren ( ) const
inline

Definition at line 208 of file Tree.h.

References getFirstChild().

◆ getFirstChild() [1/2]

◆ getFirstChild() [2/2]

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

Definition at line 180 of file Tree.h.

References Node().

◆ getLastChild() [1/2]

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

Definition at line 181 of file Tree.h.

References Node().

Referenced by findLastLeaf().

◆ getLastChild() [2/2]

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

Definition at line 182 of file Tree.h.

References Node().

◆ Node() [1/3]

clang::syntax::Node::Node ( const Node & )
protecteddelete

Nodes cannot simply be copied without violating tree invariants.

◆ Node() [2/3]

clang::syntax::Node::Node ( Node && )
protecteddelete

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

◆ Node() [3/3]

◆ FactoryImpl

friend class FactoryImpl
friend

Definition at line 235 of file Tree.h.

References FactoryImpl, New, and Node().

Referenced by FactoryImpl.

◆ MutationsImpl

friend class MutationsImpl
friend

Definition at line 244 of file Tree.h.

References MutationsImpl, and Node().

Referenced by MutationsImpl.

◆ TreeBuilder

friend class TreeBuilder
friend

Definition at line 234 of file Tree.h.

References TreeBuilder.

Referenced by TreeBuilder.


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