clang
10.0.0git
|
A node in a syntax tree. More...
#include "clang/Tooling/Syntax/Tree.h"
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 |
A node in a syntax tree.
Each node is either a Leaf (representing tokens) or a Tree (representing language constructrs).
syntax::Node::Node | ( | NodeKind | Kind | ) |
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().
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().
|
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().
std::string syntax::Node::dump | ( | const Arena & | A | ) | const |
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().
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().
|
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.
|
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().
|
inline |
Definition at line 105 of file Tree.h.
Referenced by clang::syntax::Tree::classof(), and clang::syntax::MutationsImpl::replace().
|
inline |
|
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().
|
inline |
|
inline |
Definition at line 83 of file Tree.h.
Referenced by clang::syntax::Tree::classof(), and isDetached().
|
friend |
|
friend |