clang
20.0.0git
lib
AST
ByteCode
FunctionPointer.h
Go to the documentation of this file.
1
//===--- FunctionPointer.h - Types 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
#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H
10
#define LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H
11
12
#include "
Function.h
"
13
#include "
Primitives.h
"
14
#include "
clang/AST/APValue.h
"
15
16
namespace
clang
{
17
class
ASTContext;
18
namespace
interp {
19
20
class
FunctionPointer
final {
21
private
:
22
const
Function
*Func;
23
bool
Valid;
24
25
public
:
26
FunctionPointer
() =
default
;
27
FunctionPointer
(
const
Function
*Func) :
Func
(
Func
), Valid(
true
) {}
28
29
FunctionPointer
(
uintptr_t
IntVal,
const
Descriptor
*Desc =
nullptr
)
30
:
Func
(reinterpret_cast<const
Function
*>(IntVal)), Valid(
false
) {}
31
32
const
Function
*
getFunction
()
const
{
return
Func
; }
33
bool
isZero
()
const
{
return
!
Func
; }
34
bool
isValid
()
const
{
return
Valid; }
35
bool
isWeak
()
const
{
36
if
(!
Func
|| !Valid || !
Func
->getDecl())
37
return
false
;
38
39
return
Func
->getDecl()->isWeak();
40
}
41
42
APValue
toAPValue
(
const
ASTContext
&)
const
{
43
if
(!
Func
)
44
return
APValue
(
static_cast<
Expr
*
>
(
nullptr
),
CharUnits::Zero
(), {},
45
/*OnePastTheEnd=*/
false
,
/*IsNull=*/
true
);
46
47
if
(!Valid)
48
return
APValue
(
static_cast<
Expr
*
>
(
nullptr
),
49
CharUnits::fromQuantity
(
getIntegerRepresentation
()), {},
50
/*OnePastTheEnd=*/
false
,
/*IsNull=*/
false
);
51
52
if
(
Func
->getDecl())
53
return
APValue
(
Func
->getDecl(),
CharUnits::Zero
(), {},
54
/*OnePastTheEnd=*/
false
,
/*IsNull=*/
false
);
55
return
APValue
(
Func
->getExpr(),
CharUnits::Zero
(), {},
56
/*OnePastTheEnd=*/
false
,
/*IsNull=*/
false
);
57
}
58
59
void
print
(llvm::raw_ostream &OS)
const
{
60
OS <<
"FnPtr("
;
61
if
(
Func
&& Valid)
62
OS <<
Func
->getName();
63
else
if
(
Func
)
64
OS << reinterpret_cast<uintptr_t>(
Func
);
65
else
66
OS <<
"nullptr"
;
67
OS <<
")"
;
68
}
69
70
std::string
toDiagnosticString
(
const
ASTContext
&Ctx)
const
{
71
if
(!
Func
)
72
return
"nullptr"
;
73
74
return
toAPValue
(Ctx).
getAsString
(Ctx,
Func
->getDecl()->getType());
75
}
76
77
uint64_t
getIntegerRepresentation
()
const
{
78
return
static_cast<
uint64_t
>
(
reinterpret_cast<
uintptr_t
>
(
Func
));
79
}
80
81
ComparisonCategoryResult
compare
(
const
FunctionPointer
&RHS)
const
{
82
if
(
Func
== RHS.Func)
83
return
ComparisonCategoryResult::Equal
;
84
return
ComparisonCategoryResult::Unordered
;
85
}
86
};
87
88
inline
llvm::raw_ostream &
operator<<
(llvm::raw_ostream &OS,
89
FunctionPointer
FP) {
90
FP.
print
(OS);
91
return
OS;
92
}
93
94
}
// namespace interp
95
}
// namespace clang
96
97
#endif
APValue.h
Function.h
Primitives.h
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition:
APValue.h:122
clang::APValue::getAsString
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Definition:
APValue.cpp:946
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:187
clang::CharUnits::fromQuantity
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition:
CharUnits.h:63
clang::CharUnits::Zero
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition:
CharUnits.h:53
clang::Expr
This represents one expression.
Definition:
Expr.h:110
clang::interp::FunctionPointer
Definition:
FunctionPointer.h:20
clang::interp::FunctionPointer::isWeak
bool isWeak() const
Definition:
FunctionPointer.h:35
clang::interp::FunctionPointer::print
void print(llvm::raw_ostream &OS) const
Definition:
FunctionPointer.h:59
clang::interp::FunctionPointer::getFunction
const Function * getFunction() const
Definition:
FunctionPointer.h:32
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer(uintptr_t IntVal, const Descriptor *Desc=nullptr)
Definition:
FunctionPointer.h:29
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer()=default
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer(const Function *Func)
Definition:
FunctionPointer.h:27
clang::interp::FunctionPointer::compare
ComparisonCategoryResult compare(const FunctionPointer &RHS) const
Definition:
FunctionPointer.h:81
clang::interp::FunctionPointer::toAPValue
APValue toAPValue(const ASTContext &) const
Definition:
FunctionPointer.h:42
clang::interp::FunctionPointer::getIntegerRepresentation
uint64_t getIntegerRepresentation() const
Definition:
FunctionPointer.h:77
clang::interp::FunctionPointer::isValid
bool isValid() const
Definition:
FunctionPointer.h:34
clang::interp::FunctionPointer::toDiagnosticString
std::string toDiagnosticString(const ASTContext &Ctx) const
Definition:
FunctionPointer.h:70
clang::interp::FunctionPointer::isZero
bool isZero() const
Definition:
FunctionPointer.h:33
clang::interp::Function
Bytecode function.
Definition:
Function.h:81
clang::interp::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
Definition:
Boolean.h:151
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition:
CalledOnceCheck.h:17
clang::ComparisonCategoryResult
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
Definition:
ComparisonCategories.h:67
clang::ComparisonCategoryResult::Unordered
@ Unordered
clang::ComparisonCategoryResult::Equal
@ Equal
clang::PredefinedIdentKind::Func
@ Func
uintptr_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition:
opencl-c-base.h:164
true
#define true
Definition:
stdbool.h:25
false
#define false
Definition:
stdbool.h:26
clang::interp::Descriptor
Describes a memory block created by an allocation site.
Definition:
Descriptor.h:111
Generated on Fri Nov 22 2024 09:47:44 for clang by
1.9.6