clang  19.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 "PrimType.h"
20 #include "clang/AST/StmtVisitor.h"
21 
22 namespace clang {
23 namespace interp {
24 
25 template <class Emitter> class LoopScope;
26 template <class Emitter> class SwitchScope;
27 template <class Emitter> class LabelScope;
28 
29 /// Compilation context for statements.
30 template <class Emitter>
31 class 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 
37 public:
38  template<typename... Tys>
39  ByteCodeStmtGen(Tys&&... Args)
40  : ByteCodeExprGen<Emitter>(std::forward<Tys>(Args)...) {}
41 
42 protected:
43  bool visitFunc(const FunctionDecl *F) override;
44 
45 private:
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 
85 extern template class ByteCodeStmtGen<ByteCodeEmitter>;
86 extern template class ByteCodeExprGen<EvalEmitter>;
87 
88 } // namespace interp
89 } // namespace clang
90 
91 #endif
Represents an attribute applied to a statement.
Definition: Stmt.h:2080
BreakStmt - This represents a break.
Definition: Stmt.h:2980
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:135
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
CaseStmt - Represent a case statement.
Definition: Stmt.h:1801
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
ContinueStmt - This represents a continue.
Definition: Stmt.h:2950
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1497
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2725
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2781
Represents a function declaration or definition.
Definition: Decl.h:1972
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2138
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3019
Stmt - This represents one statement.
Definition: Stmt.h:84
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2388
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2584
Compilation context for expressions.
typename Emitter::LabelTy LabelTy
typename Emitter::AddrTy AddrTy
Compilation context for statements.
bool visitFunc(const FunctionDecl *F) override
Scope managing label targets.
Sets the context for break/continue statements.
Code completion in a.
The JSON file list parser is used to communicate input to InstallAPI.
Definition: Format.h:5433