Go to the documentation of this file.
21 #ifndef LLVM_CLANG_TOOLING_SYNTAX_TREE_H
22 #define LLVM_CLANG_TOOLING_SYNTAX_TREE_H
29 #include "llvm/ADT/ArrayRef.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/ADT/iterator.h"
32 #include "llvm/Support/Allocator.h"
56 std::pair<FileID, ArrayRef<Token>>
57 lexBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer);
65 llvm::DenseMap<FileID, std::vector<Token>> ExtraTokens;
67 llvm::BumpPtrAllocator Allocator;
91 Node &operator=(
const Node &) =
delete;
100 bool isDetached()
const;
131 void assertInvariants()
const;
133 void assertInvariantsRecursive()
const;
149 Node *PreviousSibling;
152 unsigned Original : 1;
153 unsigned CanModify : 1;
172 template <
typename DerivedT,
typename NodeT>
173 class ChildIteratorBase
174 :
public llvm::iterator_facade_base<DerivedT, std::forward_iterator_tag,
178 using Base = ChildIteratorBase;
181 ChildIteratorBase() =
default;
182 explicit ChildIteratorBase(NodeT *N) : N(N) {}
184 friend bool operator==(
const DerivedT &LHS,
const DerivedT &RHS) {
185 return LHS.N == RHS.N;
189 DerivedT &operator++() {
190 N = N->getNextSibling();
191 return *
static_cast<DerivedT *
>(
this);
196 explicit operator bool()
const {
return N !=
nullptr; }
198 NodeT *asPointer()
const {
return N; }
221 using Base::ChildIteratorBase;
224 : ChildIteratorBase<ConstChildIterator, const Node> {
225 using Base::ChildIteratorBase;
257 void appendChildLowLevel(
Node *Child);
258 void prependChildLowLevel(
Node *Child);
271 Node *FirstChild =
nullptr;
272 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 LangOptions & getLangOptions() const
const Leaf * findFirstLeaf() const
This class handles loading and caching of source files into memory.
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...
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.
A list of tokens obtained by preprocessing a text buffer and operations to map between the expanded a...
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)
const TokenBuffer & getTokenBuffer() const
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 inside the expanded token stream.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
NodeRole
A relation between a parent and child node, e.g.
A token coming directly from a file or from a macro invocation.
Node * findChild(NodeRole R)
NodeKind
A kind of a syntax node, used for implementing casts.
const Leaf * findLastLeaf() const
llvm::iterator_range< ChildIterator > getChildren()
Arena(SourceManager &SourceMgr, const LangOptions &LangOpts, const TokenBuffer &Tokens)
bool isOriginal() const
Whether the node was created from the AST backed by the source code rather than added later through m...
const Node * getNextSibling() const
const Node * getFirstChild() const
const SourceManager & getSourceManager() const
const Node * getLastChild() const
const Token * getToken() const
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)