clang  10.0.0svn
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;
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
Represents a function declaration or definition.
Definition: Decl.h:1784
Sets the context for break/continue statements.
Stmt - This represents one statement.
Definition: Stmt.h:66
IfStmt - This represents an if/then/else.
Definition: Stmt.h:1822
Scope managing label targets.
constexpr XRayInstrMask Function
Definition: XRayInstr.h:38
Represents a variable declaration or definition.
Definition: Decl.h:827
LineState State
Compilation context for statements.
Definition: Format.h:2392
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1320
typename Emitter::AddrTy AddrTy
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:2620
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
Definition: Stmt.h:1213
bool visitFunc(const FunctionDecl *F) override
Dataflow Directional Tag Classes.
Compilation context for expressions.
typename Emitter::LabelTy LabelTy