clang 20.0.0git
Function.cpp
Go to the documentation of this file.
1//===--- Function.h - Bytecode function for the 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#include "Function.h"
10#include "Opcode.h"
11#include "Program.h"
12#include "clang/AST/Decl.h"
13#include "clang/AST/DeclCXX.h"
15
16using namespace clang;
17using namespace clang::interp;
18
19Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
21 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
23 bool HasThisPointer, bool HasRVO, bool UnevaluatedBuiltin)
24 : P(P), Source(Source), ArgSize(ArgSize), ParamTypes(std::move(ParamTypes)),
25 Params(std::move(Params)), ParamOffsets(std::move(ParamOffsets)),
26 HasThisPointer(HasThisPointer), HasRVO(HasRVO),
27 IsUnevaluatedBuiltin(UnevaluatedBuiltin) {
28 if (const auto *F = Source.dyn_cast<const FunctionDecl *>())
29 Variadic = F->isVariadic();
30}
31
32Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
33 auto It = Params.find(Offset);
34 assert(It != Params.end() && "Invalid parameter offset");
35 return It->second;
36}
37
38SourceInfo Function::getSource(CodePtr PC) const {
39 assert(PC >= getCodeBegin() && "PC does not belong to this function");
40 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
41 assert(hasBody() && "Function has no body");
42 unsigned Offset = PC - getCodeBegin();
43 using Elem = std::pair<unsigned, SourceInfo>;
44 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
45 if (It == SrcMap.end())
46 return SrcMap.back().second;
47 return It->second;
48}
49
50bool Function::isVirtual() const {
51 if (const auto *M = dyn_cast_if_present<CXXMethodDecl>(
52 Source.dyn_cast<const FunctionDecl *>()))
53 return M->isVirtual();
54 return false;
55}
StringRef P
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Represents a function declaration or definition.
Definition: Decl.h:1932
Pointer into the code segment.
Definition: Source.h:30
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:83
The program contains and links the bytecode for all functions.
Definition: Program.h:39
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:77
llvm::PointerUnion< const FunctionDecl *, const BlockExpr * > FunctionDeclTy
Definition: Function.h:60
The JSON file list parser is used to communicate input to InstallAPI.