//===- Tree.h - structure of the syntax tree ------------------*- C++ -*-=====// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Defines the basic structure of the syntax tree. There are two kinds of nodes: // - leaf nodes correspond to tokens, // - tree nodes correspond to language grammar constructs. // // The tree is initially built from an AST. Each node of a newly built tree // covers a continuous subrange of expanded tokens (i.e. tokens after // preprocessing), the specific tokens coverered are stored in the leaf nodes of // a tree. A post-order traversal of a tree will visit leaf nodes in an order // corresponding the original order of expanded tokens. // // This is still work in progress and highly experimental, we leave room for // ourselves to completely change the design and/or implementation. //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLING_SYNTAX_TREE_H #define LLVM_CLANG_TOOLING_SYNTAX_TREE_H #include "clang/Basic/TokenKinds.h" #include "clang/Tooling/Syntax/TokenManager.h" #include "llvm/ADT/iterator.h" #include "llvm/Support/Allocator.h" #include <cstdint> #include <vector> namespace clang { namespace syntax { /// A memory arena for syntax trees. // FIXME: use BumpPtrAllocator directly. class Arena { … }; class Tree; class TreeBuilder; class FactoryImpl; class MutationsImpl; enum class NodeKind : uint16_t; enum class NodeRole : uint8_t; /// A node in a syntax tree. Each node is either a Leaf (representing tokens) or /// a Tree (representing language constructrs). class Node { … }; /// A leaf node points to a single token. // FIXME: add TokenKind field (borrow some bits from the Node::kind). class Leaf final : public Node { … }; /// A node that has children and represents a syntactic language construct. class Tree : public Node { … }; /// A list of Elements separated or terminated by a fixed token. /// /// This type models the following grammar construct: /// delimited-list(element, delimiter, termination, canBeEmpty) class List : public Tree { … }; } // namespace syntax } // namespace clang #endif