xref: /freebsd/contrib/llvm-project/clang/lib/AST/ByteCode/FunctionPointer.cpp (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===----------------------- FunctionPointer.cpp ----------------*- C++ -*-===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric 
9*700637cbSDimitry Andric #include "FunctionPointer.h"
10*700637cbSDimitry Andric 
11*700637cbSDimitry Andric namespace clang {
12*700637cbSDimitry Andric namespace interp {
13*700637cbSDimitry Andric 
toAPValue(const ASTContext &) const14*700637cbSDimitry Andric APValue FunctionPointer::toAPValue(const ASTContext &) const {
15*700637cbSDimitry Andric   if (!Func)
16*700637cbSDimitry Andric     return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {},
17*700637cbSDimitry Andric                    /*OnePastTheEnd=*/false, /*IsNull=*/true);
18*700637cbSDimitry Andric 
19*700637cbSDimitry Andric   if (Func->getDecl())
20*700637cbSDimitry Andric     return APValue(Func->getDecl(), CharUnits::fromQuantity(0), {},
21*700637cbSDimitry Andric                    /*OnePastTheEnd=*/false, /*IsNull=*/false);
22*700637cbSDimitry Andric   return APValue(Func->getExpr(), CharUnits::fromQuantity(0), {},
23*700637cbSDimitry Andric                  /*OnePastTheEnd=*/false, /*IsNull=*/false);
24*700637cbSDimitry Andric }
25*700637cbSDimitry Andric 
print(llvm::raw_ostream & OS) const26*700637cbSDimitry Andric void FunctionPointer::print(llvm::raw_ostream &OS) const {
27*700637cbSDimitry Andric   OS << "FnPtr(";
28*700637cbSDimitry Andric   if (Func)
29*700637cbSDimitry Andric     OS << Func->getName();
30*700637cbSDimitry Andric   else
31*700637cbSDimitry Andric     OS << "nullptr";
32*700637cbSDimitry Andric   OS << ")";
33*700637cbSDimitry Andric }
34*700637cbSDimitry Andric 
35*700637cbSDimitry Andric } // namespace interp
36*700637cbSDimitry Andric } // namespace clang
37