Debian Codegraph @

llvm-project/clang/lib/AST/Interp/ByteCodeStmtGen.h

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