clang 10.0.0git

ByteCodeStmtGen.h
Go to the documentation of this file.
1 //===--- ByteCodeStmtGen.h - Code generator for expressions -----*- 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 //
9 // Defines the constexpr bytecode compiler.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_AST_INTERP_BYTECODESTMTGEN_H
14 #define LLVM_CLANG_AST_INTERP_BYTECODESTMTGEN_H
15
16 #include "ByteCodeEmitter.h"
17 #include "ByteCodeExprGen.h"
18 #include "EvalEmitter.h"
19 #include "Pointer.h"
20 #include "PrimType.h"
21 #include "Record.h"
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/Expr.h"
24 #include "clang/AST/StmtVisitor.h"
25 #include "llvm/ADT/Optional.h"
26
27 namespace clang {
28 class QualType;
29
30 namespace interp {
31 class Function;
32 class State;
33
34 template <class Emitter> class LoopScope;
35 template <class Emitter> class SwitchScope;
36 template <class Emitter> class LabelScope;
37
38 /// Compilation context for statements.
39 template <class Emitter>
40 class ByteCodeStmtGen : public ByteCodeExprGen<Emitter> {
41 using LabelTy = typename Emitter::LabelTy;
42 using AddrTy = typename Emitter::AddrTy;
43 using OptLabelTy = llvm::Optional<LabelTy>;
44 using CaseMap = llvm::DenseMap<const SwitchCase *, LabelTy>;
45
46 public:
47 template<typename... Tys>
48 ByteCodeStmtGen(Tys&&... Args)
49 : ByteCodeExprGen<Emitter>(std::forward<Tys>(Args)...) {}
50
51 protected:
52 bool visitFunc(const FunctionDecl *F) override;
53
54 private:
55 friend class LabelScope<Emitter>;
56 friend class LoopScope<Emitter>;
57 friend class SwitchScope<Emitter>;
58
59 // Statement visitors.
60 bool visitStmt(const Stmt *S);
61 bool visitCompoundStmt(const CompoundStmt *S);
62 bool visitDeclStmt(const DeclStmt *DS);
63 bool visitReturnStmt(const ReturnStmt *RS);
64 bool visitIfStmt(const IfStmt *IS);
65
66 /// Compiles a variable declaration.
67 bool visitVarDecl(const VarDecl *VD);
68
69 private:
70 /// Type of the expression returned by the function.
71 llvm::Optional<PrimType> ReturnType;
72
73 /// Switch case mapping.
74 CaseMap CaseLabels;
75
76 /// Point to break to.
77 OptLabelTy BreakLabel;
78 /// Point to continue to.
79 OptLabelTy ContinueLabel;
80 /// Default case label.
81 OptLabelTy DefaultLabel;
82 };
83
84 extern template class ByteCodeExprGen<EvalEmitter>;
85
86 } // namespace interp
87 } // namespace clang
88
89 #endif
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1783
clang::interp::LoopScope
Sets the context for break/continue statements.
Definition: ByteCodeStmtGen.cpp:37
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::IfStmt
IfStmt - This represents an if/then/else.
Definition: Stmt.h:1834
clang::interp::LabelScope
Scope managing label targets.
Definition: ByteCodeStmtGen.cpp:26
clang::XRayInstrKind::Function
constexpr XRayInstrMask Function
Definition: XRayInstr.h:38
clang::interp::ByteCodeStmtGen::ByteCodeStmtGen
ByteCodeStmtGen(Tys &&... Args)
Definition: ByteCodeStmtGen.h:48
ByteCodeEmitter.h
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:820
llvm::Optional< LabelTy >
State
LineState State
Definition: UnwrappedLineFormatter.cpp:932
clang::interp::ByteCodeStmtGen
Compilation context for statements.
Definition: ByteCodeStmtGen.h:40
std
Definition: Format.h:2445
PrimType.h
clang::interp::SwitchScope
Definition: ByteCodeStmtGen.cpp:61
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1332
clang::interp::ByteCodeExprGen::AddrTy
typename Emitter::AddrTy AddrTy
Definition: ByteCodeExprGen.h:52
StmtVisitor.h
clang::ReturnStmt
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:2636
clang::DeclStmt
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:1225
clang::interp::ByteCodeStmtGen::visitFunc
bool visitFunc(const FunctionDecl *F) override
Definition: ByteCodeStmtGen.cpp:93
Emitter
Decl.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
Pointer.h
Record.h
clang::interp::ByteCodeExprGen
Compilation context for expressions.
Definition: ByteCodeExprGen.h:41
Expr.h
clang::interp::ByteCodeExprGen::LabelTy
typename Emitter::LabelTy LabelTy
Definition: ByteCodeExprGen.h:51
ByteCodeExprGen.h
EvalEmitter.h