1212#include " clang/AST/APValue.h"
1313#include " clang/AST/Decl.h"
1414#include " clang/AST/Expr.h"
15- #include < optional>
16- #include < variant>
1715
1816namespace clang {
1917namespace interp {
@@ -25,8 +23,8 @@ class InterpState;
2523
2624// / Defines the result of an evaluation.
2725// /
28- // / The result might be in different forms--one of the pointer types,
29- // / an APValue, or nothing .
26+ // / The Kind defined if the evaluation was invalid, valid (but empty, e.g. for
27+ // / void expressions) or if we have a valid evaluation result .
3028// /
3129// / We use this class to inspect and diagnose the result, as well as
3230// / convert it to the requested form.
@@ -41,16 +39,12 @@ class EvaluationResult final {
4139 using DeclTy = llvm::PointerUnion<const Decl *, const Expr *>;
4240
4341private:
42+ #ifndef NDEBUG
4443 const Context *Ctx = nullptr ;
44+ #endif
4545 APValue Value;
4646 ResultKind Kind = Empty;
47- DeclTy Source = nullptr ; // Currently only needed for dump().
48-
49- EvaluationResult (ResultKind Kind) : Kind(Kind) {
50- // Leave everything empty. Can be used as an
51- // error marker or for void return values.
52- assert (Kind == Valid || Kind == Invalid);
53- }
47+ DeclTy Source = nullptr ;
5448
5549 void setSource (DeclTy D) { Source = D; }
5650
@@ -69,7 +63,11 @@ class EvaluationResult final {
6963 }
7064
7165public:
66+ #ifndef NDEBUG
7267 EvaluationResult (const Context *Ctx) : Ctx(Ctx) {}
68+ #else
69+ EvaluationResult (const Context *Ctx) {}
70+ #endif
7371
7472 bool empty () const { return Kind == Empty; }
7573 bool isInvalid () const { return Kind == Invalid; }
@@ -94,7 +92,7 @@ class EvaluationResult final {
9492 if (const auto *D =
9593 dyn_cast_if_present<ValueDecl>(Source.dyn_cast <const Decl *>()))
9694 return D->getType ();
97- else if (const auto *E = Source.dyn_cast <const Expr *>())
95+ if (const auto *E = Source.dyn_cast <const Expr *>())
9896 return E->getType ();
9997 return QualType ();
10098 }
0 commit comments