brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 9e8ea2f Raw
56 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H10#define LLVM_CLANG_AST_INTERP_FUNCTION_POINTER_H11 12#include "Function.h"13#include "Primitives.h"14 15namespace clang {16class ASTContext;17class APValue;18namespace interp {19 20class FunctionPointer final {21private:22  const Function *Func;23 24public: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 interp53} // namespace clang54 55#endif56