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
26 if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
27 Variadic = F->isVariadic();
28 Immediate = F->isImmediateFunction();
29 Constexpr = F->isConstexpr();
30 if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
31 Virtual = CD->isVirtual();
32 Kind = FunctionKind::Ctor;
33 } else if (const auto *CD = dyn_cast<CXXDestructorDecl>(F)) {
34 Virtual = CD->isVirtual();
35 Kind = FunctionKind::Dtor;
36 } else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
37 Virtual = MD->isVirtual();
38 if (IsLambdaStaticInvoker)
39 Kind = FunctionKind::LambdaStaticInvoker;
41 Kind = FunctionKind::LambdaCallOperator;
42 else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
43 Kind = FunctionKind::CopyOrMoveOperator;
44 } else {
45 Virtual = false;
46 }
47 } else {
48 Variadic = false;
49 Virtual = false;
50 Immediate = false;
51 Constexpr = false;
52 }
53}
54
56 assert(PC >= getCodeBegin() && "PC does not belong to this function");
57 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
58 assert(hasBody() && "Function has no body");
59 unsigned Offset = PC - getCodeBegin();
60 using Elem = std::pair<unsigned, SourceInfo>;
61 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
62 if (It == SrcMap.end())
63 return SrcMap.back().second;
64 return It->second;
65}
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:128
CodePtr getCodeEnd() const
Returns a pointer to the end of the code.
Definition Function.h:130
bool hasBody() const
Checks if the function already has a body attached.
Definition Function.h:222
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Definition Function.cpp:55
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