clang  14.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_TREE_H
11 #define LLVM_CLANG_TOOLING_SYNTAX_TREE_H
12 
13 #include "clang/AST/Decl.h"
14 #include "clang/Basic/TokenKinds.h"
17 
18 namespace clang {
19 namespace syntax {
20 
21 /// Build a syntax tree for the main file.
22 /// This usually covers the whole TranslationUnitDecl, but can be restricted by
23 /// the ASTContext's traversal scope.
24 syntax::TranslationUnit *buildSyntaxTree(Arena &A, ASTContext &Context);
25 
26 // Create syntax trees from subtrees not backed by the source code.
27 
28 // Synthesis of Leafs
29 /// Create `Leaf` from token with `Spelling` and assert it has the desired
30 /// `TokenKind`.
32  StringRef Spelling);
33 
34 /// Infer the token spelling from its `TokenKind`, then create `Leaf` from
35 /// this token
37 
38 // Synthesis of Trees
39 /// Creates the concrete syntax node according to the specified `NodeKind` `K`.
40 /// Returns it as a pointer to the base class `Tree`.
43  ArrayRef<std::pair<syntax::Node *, syntax::NodeRole>> Children,
45 
46 // Synthesis of Syntax Nodes
48 
49 /// Creates a completely independent copy of `N` with its macros expanded.
50 ///
51 /// The copy is:
52 /// * Detached, i.e. `Parent == NextSibling == nullptr` and
53 /// `Role == Detached`.
54 /// * Synthesized, i.e. `Original == false`.
56 } // namespace syntax
57 } // namespace clang
58 #endif
clang::syntax::Node
A node in a syntax tree.
Definition: Tree.h:80
clang::syntax::createLeaf
syntax::Leaf * createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef Spelling)
Create Leaf from token with Spelling and assert it has the desired TokenKind.
Definition: Synthesis.cpp:37
Decl.h
TokenKinds.h
clang::syntax::Tree
A node that has children and represents a syntactic language construct.
Definition: Tree.h:169
clang::syntax::buildSyntaxTree
syntax::TranslationUnit * buildSyntaxTree(Arena &A, ASTContext &Context)
Build a syntax tree for the main file.
Definition: BuildTree.cpp:1747
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
clang::syntax::EmptyStatement
The no-op statement, i.e. ';'.
Definition: Nodes.h:236
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:41
llvm::ArrayRef
Definition: LLVM.h:34
clang::syntax::createEmptyStatement
syntax::EmptyStatement * createEmptyStatement(syntax::Arena &A)
Definition: Synthesis.cpp:227
Tree.h
Nodes.h
clang::syntax::Leaf
A leaf node points to a single token inside the expanded token stream.
Definition: Tree.h:157
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:197
clang
Definition: CalledOnceCheck.h:17
clang::syntax::NodeKind
NodeKind
A kind of a syntax node, used for implementing casts.
Definition: Nodes.h:37
clang::syntax::deepCopyExpandingMacros
syntax::Node * deepCopyExpandingMacros(syntax::Arena &A, const syntax::Node *N)
Creates a completely independent copy of N with its macros expanded.
Definition: Synthesis.cpp:210