clang  16.0.0git
BuildTree.h
Go to the documentation of this file.
1 //===- BuildTree.h - build syntax trees -----------------------*- C++ -*-=====//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // Functions to construct a syntax tree from an AST.
9 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_TOOLING_SYNTAX_BUILDTREE_H
11 #define LLVM_CLANG_TOOLING_SYNTAX_BUILDTREE_H
12 
13 #include "clang/AST/Decl.h"
14 #include "clang/Basic/TokenKinds.h"
18 
19 namespace clang {
20 namespace syntax {
21 
22 /// Build a syntax tree for the main file.
23 /// This usually covers the whole TranslationUnitDecl, but can be restricted by
24 /// the ASTContext's traversal scope.
25 syntax::TranslationUnit *
27 
28 // Create syntax trees from subtrees not backed by the source code.
29 
30 // Synthesis of Leafs
31 /// Create `Leaf` from token with `Spelling` and assert it has the desired
32 /// `TokenKind`.
34  tok::TokenKind K, StringRef Spelling);
35 
36 /// Infer the token spelling from its `TokenKind`, then create `Leaf` from
37 /// this token
39  tok::TokenKind K);
40 
41 // Synthesis of Trees
42 /// Creates the concrete syntax node according to the specified `NodeKind` `K`.
43 /// Returns it as a pointer to the base class `Tree`.
46  ArrayRef<std::pair<syntax::Node *, syntax::NodeRole>> Children,
48 
49 // Synthesis of Syntax Nodes
52 
53 /// Creates a completely independent copy of `N` with its macros expanded.
54 ///
55 /// The copy is:
56 /// * Detached, i.e. `Parent == NextSibling == nullptr` and
57 /// `Role == Detached`.
58 /// * Synthesized, i.e. `Original == false`.
61  const syntax::Node *N);
62 } // namespace syntax
63 } // namespace clang
64 #endif
clang::syntax::Node
A node in a syntax tree.
Definition: Tree.h:54
clang::syntax::deepCopyExpandingMacros
syntax::Node * deepCopyExpandingMacros(syntax::Arena &A, TokenBufferTokenManager &TBTM, const syntax::Node *N)
Creates a completely independent copy of N with its macros expanded.
Definition: Synthesis.cpp:217
Decl.h
TokenKinds.h
clang::syntax::Tree
A node that has children and represents a syntactic language construct.
Definition: Tree.h:144
clang::syntax::createLeaf
syntax::Leaf * createLeaf(syntax::Arena &A, TokenBufferTokenManager &TBTM, tok::TokenKind K, StringRef Spelling)
Create Leaf from token with Spelling and assert it has the desired TokenKind.
Definition: Synthesis.cpp:40
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::syntax::createEmptyStatement
syntax::EmptyStatement * createEmptyStatement(syntax::Arena &A, TokenBufferTokenManager &TBTM)
Definition: Synthesis.cpp:235
TokenBufferTokenManager.h
clang::syntax::EmptyStatement
The no-op statement, i.e. ';'.
Definition: Nodes.h:231
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::syntax::Arena
A memory arena for syntax trees.
Definition: Tree.h:36
llvm::ArrayRef
Definition: LLVM.h:34
Tree.h
Nodes.h
clang::syntax::Leaf
A leaf node points to a single token.
Definition: Tree.h:132
clang::syntax::createTree
syntax::Tree * createTree(syntax::Arena &A, ArrayRef< std::pair< syntax::Node *, syntax::NodeRole >> Children, syntax::NodeKind K)
Creates the concrete syntax node according to the specified NodeKind K.
Definition: Synthesis.cpp:204
clang
Definition: CalledOnceCheck.h:17
clang::syntax::NodeKind
NodeKind
A kind of a syntax node, used for implementing casts.
Definition: Nodes.h:32
clang::syntax::TokenBufferTokenManager
A TokenBuffer-powered token manager.
Definition: TokenBufferTokenManager.h:20
clang::syntax::buildSyntaxTree
syntax::TranslationUnit * buildSyntaxTree(Arena &A, TokenBufferTokenManager &TBTM, ASTContext &Context)
Build a syntax tree for the main file.
Definition: BuildTree.cpp:1753