clang 20.0.0git
FunctionPointer.cpp
Go to the documentation of this file.
1//===----------------------- FunctionPointer.cpp ----------------*- 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#include "FunctionPointer.h"
10
11namespace clang {
12namespace interp {
13
15 if (!Func)
16 return APValue(static_cast<Expr *>(nullptr), CharUnits::Zero(), {},
17 /*OnePastTheEnd=*/false, /*IsNull=*/true);
18
19 if (!Valid)
20 return APValue(static_cast<Expr *>(nullptr),
22 /*OnePastTheEnd=*/false, /*IsNull=*/false);
23
24 if (Func->getDecl())
25 return APValue(Func->getDecl(), CharUnits::fromQuantity(Offset), {},
26 /*OnePastTheEnd=*/false, /*IsNull=*/false);
27 return APValue(Func->getExpr(), CharUnits::fromQuantity(Offset), {},
28 /*OnePastTheEnd=*/false, /*IsNull=*/false);
29}
30
31void FunctionPointer::print(llvm::raw_ostream &OS) const {
32 OS << "FnPtr(";
33 if (Func && Valid)
34 OS << Func->getName();
35 else if (Func)
36 OS << reinterpret_cast<uintptr_t>(Func);
37 else
38 OS << "nullptr";
39 OS << ") + " << Offset;
40}
41
42} // namespace interp
43} // namespace clang
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
This represents one expression.
Definition: Expr.h:110
void print(llvm::raw_ostream &OS) const
APValue toAPValue(const ASTContext &) const
uint64_t getIntegerRepresentation() const
const std::string getName() const
Returns the name of the function decl this code was generated for.
Definition: Function.h:105
const BlockExpr * getExpr() const
Definition: Function.h:99
const FunctionDecl * getDecl() const
Returns the original FunctionDecl.
Definition: Function.h:96
The JSON file list parser is used to communicate input to InstallAPI.