/src/llvm-project/clang/lib/AST/Interp/InterpState.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- InterpState.h - Interpreter state for the constexpr VM -*- 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 | | // Definition of the interpreter state and entry point. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_AST_INTERP_INTERPSTATE_H |
14 | | #define LLVM_CLANG_AST_INTERP_INTERPSTATE_H |
15 | | |
16 | | #include "Context.h" |
17 | | #include "Function.h" |
18 | | #include "InterpFrame.h" |
19 | | #include "InterpStack.h" |
20 | | #include "State.h" |
21 | | #include "clang/AST/APValue.h" |
22 | | #include "clang/AST/ASTDiagnostic.h" |
23 | | #include "clang/AST/Expr.h" |
24 | | #include "clang/AST/OptionalDiagnostic.h" |
25 | | |
26 | | namespace clang { |
27 | | namespace interp { |
28 | | class Context; |
29 | | class Function; |
30 | | class InterpStack; |
31 | | class InterpFrame; |
32 | | class SourceMapper; |
33 | | |
34 | | /// Interpreter context. |
35 | | class InterpState final : public State, public SourceMapper { |
36 | | public: |
37 | | InterpState(State &Parent, Program &P, InterpStack &Stk, Context &Ctx, |
38 | | SourceMapper *M = nullptr); |
39 | | |
40 | | ~InterpState(); |
41 | | |
42 | | InterpState(const InterpState &) = delete; |
43 | | InterpState &operator=(const InterpState &) = delete; |
44 | | |
45 | | // Stack frame accessors. |
46 | 0 | Frame *getSplitFrame() { return Parent.getCurrentFrame(); } |
47 | | Frame *getCurrentFrame() override; |
48 | 0 | unsigned getCallStackDepth() override { |
49 | 0 | return Current ? (Current->getDepth() + 1) : 1; |
50 | 0 | } |
51 | 0 | const Frame *getBottomFrame() const override { |
52 | 0 | return Parent.getBottomFrame(); |
53 | 0 | } |
54 | | |
55 | | // Access objects from the walker context. |
56 | 0 | Expr::EvalStatus &getEvalStatus() const override { |
57 | 0 | return Parent.getEvalStatus(); |
58 | 0 | } |
59 | 0 | ASTContext &getCtx() const override { return Parent.getCtx(); } |
60 | | |
61 | | // Forward status checks and updates to the walker. |
62 | 0 | bool checkingForUndefinedBehavior() const override { |
63 | 0 | return Parent.checkingForUndefinedBehavior(); |
64 | 0 | } |
65 | 0 | bool keepEvaluatingAfterFailure() const override { |
66 | 0 | return Parent.keepEvaluatingAfterFailure(); |
67 | 0 | } |
68 | 0 | bool checkingPotentialConstantExpression() const override { |
69 | 0 | return Parent.checkingPotentialConstantExpression(); |
70 | 0 | } |
71 | 0 | bool noteUndefinedBehavior() override { |
72 | 0 | return Parent.noteUndefinedBehavior(); |
73 | 0 | } |
74 | 0 | bool inConstantContext() const { return Parent.InConstantContext; } |
75 | 0 | bool hasActiveDiagnostic() override { return Parent.hasActiveDiagnostic(); } |
76 | 0 | void setActiveDiagnostic(bool Flag) override { |
77 | 0 | Parent.setActiveDiagnostic(Flag); |
78 | 0 | } |
79 | 0 | void setFoldFailureDiagnostic(bool Flag) override { |
80 | 0 | Parent.setFoldFailureDiagnostic(Flag); |
81 | 0 | } |
82 | 0 | bool hasPriorDiagnostic() override { return Parent.hasPriorDiagnostic(); } |
83 | | |
84 | | /// Reports overflow and return true if evaluation should continue. |
85 | | bool reportOverflow(const Expr *E, const llvm::APSInt &Value); |
86 | | |
87 | | /// Deallocates a pointer. |
88 | | void deallocate(Block *B); |
89 | | |
90 | | /// Delegates source mapping to the mapper. |
91 | 0 | SourceInfo getSource(const Function *F, CodePtr PC) const override { |
92 | 0 | return M ? M->getSource(F, PC) : F->getSource(PC); |
93 | 0 | } |
94 | | |
95 | 0 | Context &getContext() const { return Ctx; } |
96 | | |
97 | | private: |
98 | | /// AST Walker state. |
99 | | State &Parent; |
100 | | /// Dead block chain. |
101 | | DeadBlock *DeadBlocks = nullptr; |
102 | | /// Reference to the offset-source mapping. |
103 | | SourceMapper *M; |
104 | | |
105 | | public: |
106 | | /// Reference to the module containing all bytecode. |
107 | | Program &P; |
108 | | /// Temporary stack. |
109 | | InterpStack &Stk; |
110 | | /// Interpreter Context. |
111 | | Context &Ctx; |
112 | | /// The current frame. |
113 | | InterpFrame *Current = nullptr; |
114 | | }; |
115 | | |
116 | | } // namespace interp |
117 | | } // namespace clang |
118 | | |
119 | | #endif |