clang
24.0.0git
lib
AST
ByteCode
EvaluationResult.h
Go to the documentation of this file.
1
//===------ EvaluationResult.h - Result class for the 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
#ifndef LLVM_CLANG_AST_INTERP_EVALUATION_RESULT_H
10
#define LLVM_CLANG_AST_INTERP_EVALUATION_RESULT_H
11
12
#include "
DeclOrExpr.h
"
13
#include "
clang/AST/APValue.h
"
14
#include "
clang/AST/Decl.h
"
15
#include "
clang/AST/Expr.h
"
16
17
namespace
clang
{
18
namespace
interp
{
19
class
EvalEmitter
;
20
class
Context
;
21
class
Pointer
;
22
class
SourceInfo
;
23
class
InterpState
;
24
25
/// Defines the result of an evaluation.
26
///
27
/// The Kind defined if the evaluation was invalid, valid (but empty, e.g. for
28
/// void expressions) or if we have a valid evaluation result.
29
///
30
/// We use this class to inspect and diagnose the result, as well as
31
/// convert it to the requested form.
32
class
EvaluationResult
final {
33
public
:
34
enum
ResultKind
{
35
Empty
,
// Initial state.
36
Invalid
,
// Result is invalid.
37
Valid
,
// Result is valid and empty.
38
};
39
40
private
:
41
#ifndef NDEBUG
42
const
Context
*Ctx =
nullptr
;
43
#endif
44
APValue
Value
;
45
ResultKind Kind =
Empty
;
46
DeclOrExpr
Source =
nullptr
;
47
48
void
setSource(
DeclOrExpr
D) { Source = D; }
49
50
void
takeValue(
APValue
&&
V
) {
51
assert(
empty
());
52
Value
= std::move(
V
);
53
Kind =
Valid
;
54
assert(!
empty
());
55
}
56
void
setInvalid() {
57
// We are NOT asserting empty() here, since setting it to invalid
58
// is allowed even if there is already a result.
59
Kind = Invalid;
60
}
61
void
setValid() {
62
assert(
empty
());
63
Kind =
Valid
;
64
}
65
66
public
:
67
#ifndef NDEBUG
68
EvaluationResult
(
const
Context
*Ctx) : Ctx(Ctx) {}
69
#else
70
EvaluationResult
(
const
Context
*Ctx) {}
71
#endif
72
73
bool
empty
()
const
{
return
Kind ==
Empty
; }
74
bool
isInvalid
()
const
{
return
Kind ==
Invalid
; }
75
76
/// Moves the APValue containing the evaluation result to the caller.
77
APValue
stealAPValue
() {
return
std::move(Value); }
78
79
/// Check that all subobjects of the given pointer have been initialized.
80
bool
checkFullyInitialized
(
InterpState
&S,
const
Pointer
&Ptr)
const
;
81
/// Check that none of the blocks the given pointer (transitively) points
82
/// to are dynamically allocated.
83
bool
checkDynamicAllocations
(
InterpState
&S,
const
Pointer
&Ptr,
84
SourceInfo
Info);
85
86
QualType
getSourceType
()
const
{
87
if
(
const
auto
*D = Source.asValueDecl())
88
return
D->getType();
89
if
(
const
auto
*E = Source.asExpr())
90
return
E->getType();
91
return
QualType
();
92
}
93
94
/// Dump to stderr.
95
void
dump
()
const
;
96
97
friend
class
EvalEmitter
;
98
friend
class
InterpState
;
99
};
100
101
}
// namespace interp
102
}
// namespace clang
103
104
#endif
APValue.h
V
#define V(N, I)
Definition
ASTContext.h:3796
DeclOrExpr.h
Decl.h
Expr.h
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition
APValue.h:122
clang::QualType
A (possibly-)qualified type.
Definition
TypeBase.h:938
clang::Value
Definition
Value.h:95
clang::interp::Context
Holds all information required to evaluate constexpr code in a module.
Definition
Context.h:47
clang::interp::EvalEmitter
An emitter which evaluates opcodes as they are emitted.
Definition
EvalEmitter.h:31
clang::interp::EvaluationResult::checkDynamicAllocations
bool checkDynamicAllocations(InterpState &S, const Pointer &Ptr, SourceInfo Info)
Check that none of the blocks the given pointer (transitively) points to are dynamically allocated.
Definition
EvaluationResult.cpp:247
clang::interp::EvaluationResult::EvalEmitter
friend class EvalEmitter
Definition
EvaluationResult.h:97
clang::interp::EvaluationResult::getSourceType
QualType getSourceType() const
Definition
EvaluationResult.h:86
clang::interp::EvaluationResult::stealAPValue
APValue stealAPValue()
Moves the APValue containing the evaluation result to the caller.
Definition
EvaluationResult.h:77
clang::interp::EvaluationResult::InterpState
friend class InterpState
Definition
EvaluationResult.h:98
clang::interp::EvaluationResult::isInvalid
bool isInvalid() const
Definition
EvaluationResult.h:74
clang::interp::EvaluationResult::checkFullyInitialized
bool checkFullyInitialized(InterpState &S, const Pointer &Ptr) const
Check that all subobjects of the given pointer have been initialized.
Definition
EvaluationResult.cpp:135
clang::interp::EvaluationResult::EvaluationResult
EvaluationResult(const Context *Ctx)
Definition
EvaluationResult.h:68
clang::interp::EvaluationResult::dump
void dump() const
Dump to stderr.
Definition
Disasm.cpp:647
clang::interp::EvaluationResult::ResultKind
ResultKind
Definition
EvaluationResult.h:34
clang::interp::EvaluationResult::Empty
@ Empty
Definition
EvaluationResult.h:35
clang::interp::EvaluationResult::Valid
@ Valid
Definition
EvaluationResult.h:37
clang::interp::EvaluationResult::Invalid
@ Invalid
Definition
EvaluationResult.h:36
clang::interp::EvaluationResult::empty
bool empty() const
Definition
EvaluationResult.h:73
clang::interp::InterpState
Interpreter context.
Definition
InterpState.h:43
clang::interp::Pointer
A pointer to a memory block, live or dead.
Definition
Pointer.h:414
clang::interp::SourceInfo
Describes the statement/declaration an opcode was generated from.
Definition
Source.h:77
clang::interp
Definition
ASTContext.h:164
clang
Top level wrappers for InstallAPI frontend operations.
Definition
CalledOnceCheck.h:17
clang::EmbedResult::Empty
@ Empty
Definition
Preprocessor.h:132
clang::VarArgKind::Valid
@ Valid
Definition
Sema.h:671
clang::interp::DeclOrExpr
Definition
DeclOrExpr.h:20
Generated on
for clang by
1.14.0