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;
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;
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::TokenKind enum and support functions.
A memory arena for syntax trees.
llvm::BumpPtrAllocator & getAllocator()
Exposes private syntax tree APIs required to implement node synthesis.
A leaf node points to a single token.
TokenManager::Key getTokenKey() const
static bool classof(const Node *N)
A list of Elements separated or terminated by a fixed token.
bool canBeEmpty() const
Whether this list can be empty in syntactically and semantically correct code.
static bool classof(const Node *N)
std::vector< Node * > getElementsAsNodes()
Returns the elements of the list.
std::vector< ElementAndDelimiter< Node > > getElementsAsNodesAndDelimiters()
Returns the elements and corresponding delimiters.
TerminationKind getTerminationKind() const
clang::tok::TokenKind getDelimiterTokenKind() const
Returns the appropriate delimiter for this list.
void assertInvariants() const
Asserts invariants on this node of the tree and its immediate children.
Node * getPreviousSibling()
bool canModify() const
If this function return false, the tree cannot be modified because there is no reasonable way to prod...
void assertInvariantsRecursive() const
Runs checkInvariants on all nodes in the subtree. No-op if NDEBUG is set.
const Node * getPreviousSibling() const
Node(NodeKind Kind)
Newly created nodes are detached from a tree, parent and sibling links are set when the node is added...
std::string dump(const TokenManager &SM) const
Dumps the structure of a subtree. For debugging and testing purposes.
Node(const Node &)=delete
Nodes cannot simply be copied without violating tree invariants.
Node & operator=(Node &&)=delete
const Node * getNextSibling() const
~Node()=default
Nodes are allocated on Arenas; the destructor is never called.
std::string dumpTokens(const TokenManager &SM) const
Dumps the tokens forming this subtree.
Node(Node &&)=delete
Idiomatically, nodes are allocated on an Arena and never moved.
Node & operator=(const Node &)=delete
bool isOriginal() const
Whether the node was created from the AST backed by the source code rather than added later through m...
const Tree * getParent() const
bool isDetached() const
Whether the node is detached from a tree, i.e. does not have a parent.
Defines interfaces for operating "Token" in the clang syntax-tree.
uintptr_t Key
A key to identify a specific token.
A node that has children and represents a syntactic language construct.
const Node * getLastChild() const
static bool classof(const Node *N)
const Leaf * findLastLeaf() const
const Leaf * findFirstLeaf() const
Node * findChild(NodeRole R)
const Node * findChild(NodeRole R) const
Find the first node with a corresponding role.
llvm::iterator_range< ChildIterator > getChildren()
const Node * getFirstChild() const
llvm::iterator_range< ConstChildIterator > getChildren() const
A helper class for constructing the syntax tree while traversing a clang AST.
NodeRole
A relation between a parent and child node, e.g.
NodeKind
A kind of a syntax node, used for implementing casts.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
child_iterator is not invalidated by mutations.
ConstChildIterator()=default
ConstChildIterator(const ChildIterator &I)