clang 22.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 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
22 bool HasThisPointer, bool HasRVO, bool IsLambdaStaticInvoker)
23 : P(P), Kind(FunctionKind::Normal), Source(Source), ArgSize(ArgSize),
24 ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
25 ParamOffsets(std::move(ParamOffsets)), IsValid(false),
26 IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO),
27 HasBody(false), Defined(false) {
28 if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
29 Variadic = F->isVariadic();
30 Immediate = F->isImmediateFunction();
31 Constexpr = F->isConstexpr() || F->hasAttr<MSConstexprAttr>();
32 if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
33 Virtual = CD->isVirtual();
34 Kind = FunctionKind::Ctor;
35 } else if (const auto *CD = dyn_cast<CXXDestructorDecl>(F)) {
36 Virtual = CD->isVirtual();
37 Kind = FunctionKind::Dtor;
38 } else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
39 Virtual = MD->isVirtual();
40 if (IsLambdaStaticInvoker)
41 Kind = FunctionKind::LambdaStaticInvoker;
43 Kind = FunctionKind::LambdaCallOperator;
44 else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
45 Kind = FunctionKind::CopyOrMoveOperator;
46 } else {
47 Virtual = false;
48 }
49 } else {
50 Variadic = false;
51 Virtual = false;
52 Immediate = false;
53 Constexpr = false;
54 }
55}
56
57Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
58 auto It = Params.find(Offset);
59 assert(It != Params.end() && "Invalid parameter offset");
60 return It->second;
61}
62
63SourceInfo Function::getSource(CodePtr PC) const {
64 assert(PC >= getCodeBegin() && "PC does not belong to this function");
65 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
66 assert(hasBody() && "Function has no body");
67 unsigned Offset = PC - getCodeBegin();
68 using Elem = std::pair<unsigned, SourceInfo>;
69 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
70 if (It == SrcMap.end())
71 return SrcMap.back().second;
72 return It->second;
73}
This file provides some common utility functions for processing Lambda related AST Constructs.
StringRef P
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Pointer into the code segment.
Definition: Source.h:30
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:96
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:73
llvm::PointerUnion< const FunctionDecl *, const BlockExpr * > FunctionDeclTy
Definition: Function.h:65
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