clang
18.0.0git
lib
AST
Interp
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
24
public
:
25
FunctionPointer
() :
Func
(nullptr) {}
26
FunctionPointer
(
const
Function
*Func) :
Func
(
Func
) { assert(
Func
); }
27
28
const
Function
*
getFunction
()
const
{
return
Func
; }
29
30
APValue
toAPValue
()
const
{
31
if
(!
Func
)
32
return
APValue
(
static_cast<
Expr
*
>
(
nullptr
),
CharUnits::Zero
(), {},
33
/*OnePastTheEnd=*/
false
,
/*IsNull=*/
true
);
34
35
return
APValue
(
Func
->getDecl(),
CharUnits::Zero
(), {},
36
/*OnePastTheEnd=*/
false
,
/*IsNull=*/
false
);
37
}
38
39
void
print
(llvm::raw_ostream &OS)
const
{
40
OS <<
"FnPtr("
;
41
if
(
Func
)
42
OS <<
Func
->getName();
43
else
44
OS <<
"nullptr"
;
45
OS <<
")"
;
46
}
47
48
std::string
toDiagnosticString
(
const
ASTContext
&Ctx)
const
{
49
if
(!
Func
)
50
return
"nullptr"
;
51
52
return
toAPValue
().
getAsString
(Ctx,
Func
->getDecl()->getType());
53
}
54
55
ComparisonCategoryResult
compare
(
const
FunctionPointer
&RHS)
const
{
56
if
(
Func
== RHS.Func)
57
return
ComparisonCategoryResult::Equal
;
58
return
ComparisonCategoryResult::Unordered
;
59
}
60
};
61
62
inline
llvm::raw_ostream &
operator<<
(llvm::raw_ostream &OS,
63
FunctionPointer
FP) {
64
FP.
print
(OS);
65
return
OS;
66
}
67
68
}
// namespace interp
69
}
// namespace clang
70
71
#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:942
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:182
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::print
void print(llvm::raw_ostream &OS) const
Definition:
FunctionPointer.h:39
clang::interp::FunctionPointer::getFunction
const Function * getFunction() const
Definition:
FunctionPointer.h:28
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer()
Definition:
FunctionPointer.h:25
clang::interp::FunctionPointer::FunctionPointer
FunctionPointer(const Function *Func)
Definition:
FunctionPointer.h:26
clang::interp::FunctionPointer::compare
ComparisonCategoryResult compare(const FunctionPointer &RHS) const
Definition:
FunctionPointer.h:55
clang::interp::FunctionPointer::toAPValue
APValue toAPValue() const
Definition:
FunctionPointer.h:30
clang::interp::FunctionPointer::toDiagnosticString
std::string toDiagnosticString(const ASTContext &Ctx) const
Definition:
FunctionPointer.h:48
clang::interp::Function
Bytecode function.
Definition:
Function.h:76
clang::interp::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
Definition:
Boolean.h:156
clang
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
Generated on Thu Dec 7 2023 15:45:37 for clang by
1.9.6