clang 20.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"
18
19namespace clang {
20namespace 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.
25syntax::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
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
Defines the clang::TokenKind enum and support functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
A memory arena for syntax trees.
Definition: Tree.h:36
The no-op statement, i.e. ';'.
Definition: Nodes.h:231
A leaf node points to a single token.
Definition: Tree.h:132
A node in a syntax tree.
Definition: Tree.h:54
A TokenBuffer-powered token manager.
A node that has children and represents a syntactic language construct.
Definition: Tree.h:144
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
syntax::TranslationUnit * buildSyntaxTree(Arena &A, TokenBufferTokenManager &TBTM, ASTContext &Context)
Build a syntax tree for the main file.
Definition: BuildTree.cpp:1754
syntax::EmptyStatement * createEmptyStatement(syntax::Arena &A, TokenBufferTokenManager &TBTM)
Definition: Synthesis.cpp:235
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
NodeKind
A kind of a syntax node, used for implementing casts.
Definition: Nodes.h:32
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
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
The JSON file list parser is used to communicate input to InstallAPI.