clang
19.0.0git
lib
AST
Interp
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 "
FunctionPointer.h
"
13
#include "
Pointer.h
"
14
#include "
clang/AST/APValue.h
"
15
#include "
clang/AST/Decl.h
"
16
#include "
clang/AST/Expr.h
"
17
#include <optional>
18
#include <variant>
19
20
namespace
clang
{
21
namespace
interp {
22
class
EvalEmitter;
23
class
Context;
24
25
/// Defines the result of an evaluation.
26
///
27
/// The result might be in different forms--one of the pointer types,
28
/// an APValue, or nothing.
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
LValue
,
// Result is an lvalue/pointer.
37
RValue
,
// Result is an rvalue.
38
Invalid
,
// Result is invalid.
39
Valid
,
// Result is valid and empty.
40
};
41
42
using
DeclTy
= llvm::PointerUnion<const Decl *, const Expr *>;
43
44
private
:
45
const
Context
*Ctx =
nullptr
;
46
std::variant<std::monostate, Pointer, FunctionPointer, APValue>
Value
;
47
ResultKind
Kind =
Empty
;
48
DeclTy
Source =
nullptr
;
// Currently only needed for dump().
49
50
EvaluationResult
(
ResultKind
Kind) : Kind(Kind) {
51
// Leave everything empty. Can be used as an
52
// error marker or for void return values.
53
assert(Kind ==
Valid
|| Kind ==
Invalid
);
54
}
55
56
void
setSource(
DeclTy
D) { Source = D; }
57
58
void
setValue(
const
APValue
&
V
) {
59
// V could still be an LValue.
60
assert(
empty
());
61
Value
= std::move(
V
);
62
Kind =
RValue
;
63
}
64
void
setPointer(
const
Pointer
P
) {
65
assert(
empty
());
66
Value
=
P
;
67
Kind =
LValue
;
68
}
69
void
setFunctionPointer(
const
FunctionPointer &
P
) {
70
assert(
empty
());
71
Value
=
P
;
72
Kind
=
LValue
;
73
}
74
void
setInvalid() {
75
// We are NOT asserting empty() here, since setting it to invalid
76
// is allowed even if there is already a result.
77
Kind
=
Invalid
;
78
}
79
void
setValid() {
80
assert(
empty
());
81
Kind
=
Valid
;
82
}
83
84
public
:
85
EvaluationResult
(
const
Context
*Ctx) : Ctx(Ctx) {}
86
87
bool
empty
()
const
{
return
Kind ==
Empty
; }
88
bool
isInvalid
()
const
{
return
Kind ==
Invalid
; }
89
bool
isLValue
()
const
{
return
Kind ==
LValue
; }
90
bool
isRValue
()
const
{
return
Kind ==
RValue
; }
91
92
/// Returns an APValue for the evaluation result. The returned
93
/// APValue might be an LValue or RValue.
94
APValue
toAPValue
()
const
;
95
96
/// If the result is an LValue, convert that to an RValue
97
/// and return it. This may fail, e.g. if the result is an
98
/// LValue and we can't read from it.
99
std::optional<APValue>
toRValue
()
const
;
100
101
bool
checkFullyInitialized
(
InterpState
&S,
const
Pointer
&Ptr)
const
;
102
103
/// Dump to stderr.
104
void
dump
()
const
;
105
106
friend
class
EvalEmitter
;
107
};
108
109
}
// namespace interp
110
}
// namespace clang
111
112
#endif
APValue.h
V
#define V(N, I)
Definition:
ASTContext.h:3284
P
StringRef P
Definition:
ASTMatchersInternal.cpp:564
Decl.h
Expr.h
FunctionPointer.h
Pointer.h
Value
Value
Definition:
UninitializedValues.cpp:120
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition:
APValue.h:122
clang::Value
Definition:
Value.h:93
clang::interp::Context
Holds all information required to evaluate constexpr code in a module.
Definition:
Context.h:40
clang::interp::EvalEmitter
An emitter which evaluates opcodes as they are emitted.
Definition:
EvalEmitter.h:31
clang::interp::EvaluationResult
Defines the result of an evaluation.
Definition:
EvaluationResult.h:32
clang::interp::EvaluationResult::dump
void dump() const
Dump to stderr.
Definition:
EvaluationResult.cpp:158
clang::interp::EvaluationResult::toRValue
std::optional< APValue > toRValue() const
If the result is an LValue, convert that to an RValue and return it.
Definition:
EvaluationResult.cpp:39
clang::interp::EvaluationResult::isLValue
bool isLValue() const
Definition:
EvaluationResult.h:89
clang::interp::EvaluationResult::toAPValue
APValue toAPValue() const
Returns an APValue for the evaluation result.
Definition:
EvaluationResult.cpp:18
clang::interp::EvaluationResult::isRValue
bool isRValue() const
Definition:
EvaluationResult.h:90
clang::interp::EvaluationResult::DeclTy
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition:
EvaluationResult.h:42
clang::interp::EvaluationResult::isInvalid
bool isInvalid() const
Definition:
EvaluationResult.h:88
clang::interp::EvaluationResult::checkFullyInitialized
bool checkFullyInitialized(InterpState &S, const Pointer &Ptr) const
Definition:
EvaluationResult.cpp:137
clang::interp::EvaluationResult::EvaluationResult
EvaluationResult(const Context *Ctx)
Definition:
EvaluationResult.h:85
clang::interp::EvaluationResult::ResultKind
ResultKind
Definition:
EvaluationResult.h:34
clang::interp::EvaluationResult::Empty
@ Empty
Definition:
EvaluationResult.h:35
clang::interp::EvaluationResult::RValue
@ RValue
Definition:
EvaluationResult.h:37
clang::interp::EvaluationResult::LValue
@ LValue
Definition:
EvaluationResult.h:36
clang::interp::EvaluationResult::Valid
@ Valid
Definition:
EvaluationResult.h:39
clang::interp::EvaluationResult::Invalid
@ Invalid
Definition:
EvaluationResult.h:38
clang::interp::EvaluationResult::empty
bool empty() const
Definition:
EvaluationResult.h:87
clang::interp::InterpState
Interpreter context.
Definition:
InterpState.h:35
clang::interp::Pointer
A pointer to a memory block, live or dead.
Definition:
Pointer.h:80
clang::ObjCPropertyAttribute::Kind
Kind
Definition:
DeclObjCCommon.h:22
clang::interp::DeclTy
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition:
Descriptor.h:27
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition:
CalledOnceCheck.h:17
Generated on Fri Apr 26 2024 19:32:11 for clang by
1.9.6