clang 23.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 "Program.h"
11#include "clang/AST/ASTLambda.h"
12#include "clang/AST/Decl.h"
13#include "clang/AST/DeclCXX.h"
14
15using namespace clang;
16using namespace clang::interp;
17
18Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
20 bool HasThisPointer, bool HasRVO, bool IsLambdaStaticInvoker)
21 : P(P), Kind(FunctionKind::Normal), Source(Source), ArgSize(ArgSize),
22 ParamDescriptors(std::move(ParamDescriptors)), IsValid(false),
23 IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO),
24 HasBody(false), Defined(false) {
25 for (ParamDescriptor PD : this->ParamDescriptors) {
26 Params.insert({PD.Offset, PD});
27 }
28 assert(Params.size() == this->ParamDescriptors.size());
29
30 if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
31 Variadic = F->isVariadic();
32 Immediate = F->isImmediateFunction();
33 Constexpr = F->isConstexpr();
34 if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
35 Virtual = CD->isVirtual();
36 Kind = FunctionKind::Ctor;
37 } else if (const auto *CD = dyn_cast<CXXDestructorDecl>(F)) {
38 Virtual = CD->isVirtual();
39 Kind = FunctionKind::Dtor;
40 } else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
41 Virtual = MD->isVirtual();
42 if (IsLambdaStaticInvoker)
43 Kind = FunctionKind::LambdaStaticInvoker;
45 Kind = FunctionKind::LambdaCallOperator;
46 else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
47 Kind = FunctionKind::CopyOrMoveOperator;
48 } else {
49 Virtual = false;
50 }
51 } else {
52 Variadic = false;
53 Virtual = false;
54 Immediate = false;
55 Constexpr = false;
56 }
57}
58
60 auto It = Params.find(Offset);
61 assert(It != Params.end() && "Invalid parameter offset");
62 return It->second;
63}
64
66 assert(PC >= getCodeBegin() && "PC does not belong to this function");
67 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
68 assert(hasBody() && "Function has no body");
69 unsigned Offset = PC - getCodeBegin();
70 using Elem = std::pair<unsigned, SourceInfo>;
71 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
72 if (It == SrcMap.end())
73 return SrcMap.back().second;
74 return It->second;
75}
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Pointer into the code segment.
Definition Source.h:30
CodePtr getCodeBegin() const
Returns a pointer to the start of the code.
Definition Function.h:124
CodePtr getCodeEnd() const
Returns a pointer to the end of the code.
Definition Function.h:126
bool hasBody() const
Checks if the function already has a body attached.
Definition Function.h:216
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Definition Function.cpp:65
ParamDescriptor getParamDescriptor(unsigned Offset) const
Returns a parameter descriptor.
Definition Function.cpp:59
The program contains and links the bytecode for all functions.
Definition Program.h:36
Describes the statement/declaration an opcode was generated from.
Definition Source.h:74
llvm::PointerUnion< const FunctionDecl *, const BlockExpr * > FunctionDeclTy
Definition Function.h:66
The JSON file list parser is used to communicate input to InstallAPI.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition ASTLambda.h:28
#define false
Definition stdbool.h:26