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 "PrimType.h"
20#include "clang/AST/StmtVisitor.h"
21
22namespace clang {
23namespace interp {
24
25template <class Emitter> class LoopScope;
26template <class Emitter> class SwitchScope;
27template <class Emitter> class LabelScope;
28
29/// Compilation context for statements.
30template <class Emitter>
31class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
32 using LabelTy = typename Emitter::LabelTy;
33 using AddrTy = typename Emitter::AddrTy;
34 using OptLabelTy = std::optional<LabelTy>;
35 using CaseMap = llvm::DenseMap<const SwitchCase *, LabelTy>;
36
37public:
38 template<typename... Tys>
39 ByteCodeStmtGen(Tys&&... Args)
40 : ByteCodeExprGen<Emitter>(std::forward<Tys>(Args)...) {}
41
42protected:
43 bool visitFunc(const FunctionDecl *F) override;
44
45private:
46 friend class LabelScope<Emitter>;
47 friend class LoopScope<Emitter>;
48 friend class SwitchScope<Emitter>;
49
50 // Statement visitors.
51 bool visitStmt(const Stmt *S);
52 bool visitCompoundStmt(const CompoundStmt *S);
53 bool visitLoopBody(const Stmt *S);
54 bool visitDeclStmt(const DeclStmt *DS);
55 bool visitReturnStmt(const ReturnStmt *RS);
56 bool visitIfStmt(const IfStmt *IS);
57 bool visitWhileStmt(const WhileStmt *S);
58 bool visitDoStmt(const DoStmt *S);
59 bool visitForStmt(const ForStmt *S);
60 bool visitCXXForRangeStmt(const CXXForRangeStmt *S);
61 bool visitBreakStmt(const BreakStmt *S);
62 bool visitContinueStmt(const ContinueStmt *S);
63 bool visitSwitchStmt(const SwitchStmt *S);
64 bool visitCaseStmt(const CaseStmt *S);
65 bool visitDefaultStmt(const DefaultStmt *S);
66 bool visitAttributedStmt(const AttributedStmt *S);
67 bool visitCXXTryStmt(const CXXTryStmt *S);
68
69 bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
70
71 /// Type of the expression returned by the function.
72 std::optional<PrimType> ReturnType;
73
74 /// Switch case mapping.
75 CaseMap CaseLabels;
76
77 /// Point to break to.
78 OptLabelTy BreakLabel;
79 /// Point to continue to.
80 OptLabelTy ContinueLabel;
81 /// Default case label.
82 OptLabelTy DefaultLabel;
83};
84
85extern template class ByteCodeStmtGen<ByteCodeEmitter>;
86extern template class ByteCodeExprGen<EvalEmitter>;
87
88} // namespace interp
89} // namespace clang
90
91#endif
92

source code of clang/lib/AST/Interp/ByteCodeStmtGen.h