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
15
namespace
clang
{
16
class
ASTContext;
17
class
APValue
;
18
namespace
interp {
19
20
class
FunctionPointer
final {
21
private
:
22
const
Function
*Func;
23
uint64_t Offset;
24
bool
Valid;
25
26
public
:
27
FunctionPointer
() =
default
;
28
FunctionPointer
(
const
Function
*Func, uint64_t Offset = 0)
29
:
Func
(
Func
), Offset(Offset), Valid(
true
) {}
30
31
FunctionPointer
(
uintptr_t
IntVal,
const
Descriptor
*Desc =
nullptr
)
32
:
Func
(reinterpret_cast<const
Function
*>(IntVal)), Offset(0),
33
Valid(
false
) {}
34
35
const
Function
*
getFunction
()
const
{
return
Func
; }
36
uint64_t
getOffset
()
const
{
return
Offset; }
37
bool
isZero
()
const
{
return
!
Func
; }
38
bool
isValid
()
const
{
return
Valid; }
39
bool
isWeak
()
const
{
40
if
(!
Func
|| !Valid || !
Func
->getDecl())
41
return
false
;
42
43
return
Func
->getDecl()->isWeak();
44
}
45
46
APValue
toAPValue
(
const
ASTContext
&)
const
;
47
void
print
(llvm::raw_ostream &OS)
const
;
48
49
std::string
toDiagnosticString
(
const
ASTContext
&Ctx)
const
{
50
if
(!
Func
)
51
return
"nullptr"
;
52
53
return
toAPValue
(Ctx).
getAsString
(Ctx,
Func
->getDecl()->getType());
54
}
55
56
uint64_t
getIntegerRepresentation
()
const
{
57
return
static_cast<
uint64_t
>
(
reinterpret_cast<
uintptr_t
>
(
Func
));
58
}
59
60
ComparisonCategoryResult
compare
(
const
FunctionPointer
&RHS)
const
{
61
if
(
Func
== RHS.Func && Offset == RHS.Offset)
62
return
ComparisonCategoryResult::Equal
;
63
return
ComparisonCategoryResult::Unordered
;
64
}
65
};
66
67
inline
llvm::raw_ostream &
operator<<
(llvm::raw_ostream &OS,
68
FunctionPointer
FP) {
69
FP.
print
(OS);
70
return
OS;
71
}
72
73
}
// namespace interp
74
}
// namespace clang
75
76
#endif
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::interp::FunctionPointer
Definition:
FunctionPointer.h:20
clang::interp::FunctionPointer::isWeak
bool isWeak() const
Definition:
FunctionPointer.h:39
clang::interp::FunctionPointer::print
void print(llvm::raw_ostream &OS) const
Definition:
FunctionPointer.cpp:31
clang::interp::FunctionPointer::getFunction
const Function * getFunction() const
Definition:
FunctionPointer.h:35
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer(uintptr_t IntVal, const Descriptor *Desc=nullptr)
Definition:
FunctionPointer.h:31
clang::interp::FunctionPointer::getOffset
uint64_t getOffset() const
Definition:
FunctionPointer.h:36
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer()=default
clang::interp::FunctionPointer::compare
ComparisonCategoryResult compare(const FunctionPointer &RHS) const
Definition:
FunctionPointer.h:60
clang::interp::FunctionPointer::toAPValue
APValue toAPValue(const ASTContext &) const
Definition:
FunctionPointer.cpp:14
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer(const Function *Func, uint64_t Offset=0)
Definition:
FunctionPointer.h:28
clang::interp::FunctionPointer::getIntegerRepresentation
uint64_t getIntegerRepresentation() const
Definition:
FunctionPointer.h:56
clang::interp::FunctionPointer::isValid
bool isValid() const
Definition:
FunctionPointer.h:38
clang::interp::FunctionPointer::toDiagnosticString
std::string toDiagnosticString(const ASTContext &Ctx) const
Definition:
FunctionPointer.h:49
clang::interp::FunctionPointer::isZero
bool isZero() const
Definition:
FunctionPointer.h:37
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::ConstantResultStorageKind::APValue
@ APValue
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 Mon Dec 16 2024 17:53:42 for clang by
1.9.6