Go to the documentation of this file.
21 #ifndef LLVM_CLANG_TOOLING_SYNTAX_TREE_H
22 #define LLVM_CLANG_TOOLING_SYNTAX_TREE_H
26 #include "llvm/ADT/iterator.h"
27 #include "llvm/Support/Allocator.h"
41 llvm::BumpPtrAllocator Allocator;
65 Node &operator=(
const Node &) =
delete;
74 bool isDetached()
const;
105 void assertInvariants()
const;
107 void assertInvariantsRecursive()
const;
123 Node *PreviousSibling;
126 unsigned Original : 1;
127 unsigned CanModify : 1;
147 template <
typename DerivedT,
typename NodeT>
148 class ChildIteratorBase
149 :
public llvm::iterator_facade_base<DerivedT, std::forward_iterator_tag,
153 using Base = ChildIteratorBase;
156 ChildIteratorBase() =
default;
157 explicit ChildIteratorBase(NodeT *N) : N(N) {}
159 friend bool operator==(
const DerivedT &LHS,
const DerivedT &RHS) {
160 return LHS.N == RHS.N;
164 DerivedT &operator++() {
165 N = N->getNextSibling();
166 return *
static_cast<DerivedT *
>(
this);
171 explicit operator bool()
const {
return N !=
nullptr; }
173 NodeT *asPointer()
const {
return N; }
196 using Base::ChildIteratorBase;
199 : ChildIteratorBase<ConstChildIterator, const Node> {
200 using Base::ChildIteratorBase;
232 void appendChildLowLevel(
Node *Child);
233 void prependChildLowLevel(
Node *Child);
246 Node *FirstChild =
nullptr;
247 Node *LastChild =
nullptr;
bool canBeEmpty() const
Whether this list can be empty in syntactically and semantically correct code.
ConstChildIterator()=default
const Node * getPreviousSibling() const
clang::tok::TokenKind getDelimiterTokenKind() const
Returns the appropriate delimiter for this list.
const Tree * getParent() const
TerminationKind getTerminationKind() const
const Leaf * findFirstLeaf() const
bool canModify() const
If this function return false, the tree cannot be modified because there is no reasonable way to prod...
A list of Elements separated or terminated by a fixed token.
static bool classof(const Node *N)
A node that has children and represents a syntactic language construct.
Node(NodeKind Kind)
Newly created nodes are detached from a tree, parent and sibling links are set when the node is added...
TokenManager::Key getTokenKey() const
A helper class for constructing the syntax tree while traversing a clang AST.
std::vector< Node * > getElementsAsNodes()
Returns the elements of the list.
std::vector< ElementAndDelimiter< Node > > getElementsAsNodesAndDelimiters()
Returns the elements and corresponding delimiters.
Defines interfaces for operating "Token" in the clang syntax-tree.
child_iterator is not invalidated by mutations.
static bool classof(const Node *N)
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
llvm::iterator_range< ConstChildIterator > getChildren() const
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
ConstChildIterator(const ChildIterator &I)
uintptr_t Key
A key to identify a specific token.
A memory arena for syntax trees.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
const Node * findChild(NodeRole R) const
Find the first node with a corresponding role.
static bool classof(const Node *N)
llvm::BumpPtrAllocator & getAllocator()
Node * getPreviousSibling()
Exposes private syntax tree APIs required to implement node synthesis.
A leaf node points to a single token.
NodeRole
A relation between a parent and child node, e.g.
Node * findChild(NodeRole R)
NodeKind
A kind of a syntax node, used for implementing casts.
const Leaf * findLastLeaf() const
llvm::iterator_range< ChildIterator > getChildren()
bool isOriginal() const
Whether the node was created from the AST backed by the source code rather than added later through m...
Leaf(TokenManager::Key K)
const Node * getNextSibling() const
const Node * getFirstChild() const
const Node * getLastChild() const
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)