| 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 |
|
| 24 |
public: |
| 25 |
FunctionPointer() = default; |
| 26 |
FunctionPointer(const Function *Func) : Func(Func) {} |
| 27 |
|
| 28 |
const Function *getFunction() const { return Func; } |
| 29 |
bool isZero() const { return !Func; } |
| 30 |
bool isWeak() const { |
| 31 |
if (!Func || !Func->getDecl()) |
| 32 |
return false; |
| 33 |
|
| 34 |
return Func->getDecl()->isWeak(); |
| 35 |
} |
| 36 |
|
| 37 |
APValue toAPValue(const ASTContext &) const; |
| 38 |
void print(llvm::raw_ostream &OS) const; |
| 39 |
|
| 40 |
std::string toDiagnosticString(const ASTContext &Ctx) const { |
| 41 |
if (!Func) |
| 42 |
return "nullptr"; |
| 43 |
|
| 44 |
return toAPValue(Ctx).getAsString(Ctx, Func->getDecl()->getType()); |
| 45 |
} |
| 46 |
|
| 47 |
uint64_t getIntegerRepresentation() const { |
| 48 |
return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(Func)); |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
} // namespace interp |
| 53 |
} // namespace clang |
| 54 |
|
| 55 |
#endif |