Path: blob/main/contrib/llvm-project/clang/lib/AST/ByteCode/Function.cpp
213799 views
//===--- Function.h - Bytecode function for the VM --------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "Function.h"9#include "Program.h"10#include "clang/AST/Decl.h"11#include "clang/AST/DeclCXX.h"1213using namespace clang;14using namespace clang::interp;1516Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,17llvm::SmallVectorImpl<PrimType> &&ParamTypes,18llvm::DenseMap<unsigned, ParamDescriptor> &&Params,19llvm::SmallVectorImpl<unsigned> &&ParamOffsets,20bool HasThisPointer, bool HasRVO, bool IsLambdaStaticInvoker)21: P(P), Kind(FunctionKind::Normal), Source(Source), ArgSize(ArgSize),22ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),23ParamOffsets(std::move(ParamOffsets)), IsValid(false),24IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO),25HasBody(false), Defined(false) {26if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {27Variadic = F->isVariadic();28Immediate = F->isImmediateFunction();29Constexpr = F->isConstexpr() || F->hasAttr<MSConstexprAttr>();30if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {31Virtual = CD->isVirtual();32Kind = FunctionKind::Ctor;33} else if (const auto *CD = dyn_cast<CXXDestructorDecl>(F)) {34Virtual = CD->isVirtual();35Kind = FunctionKind::Dtor;36} else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {37Virtual = MD->isVirtual();38if (IsLambdaStaticInvoker)39Kind = FunctionKind::LambdaStaticInvoker;40else if (clang::isLambdaCallOperator(F))41Kind = FunctionKind::LambdaCallOperator;42else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())43Kind = FunctionKind::CopyOrMoveOperator;44} else {45Virtual = false;46}47} else {48Variadic = false;49Virtual = false;50Immediate = false;51Constexpr = false;52}53}5455Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {56auto It = Params.find(Offset);57assert(It != Params.end() && "Invalid parameter offset");58return It->second;59}6061SourceInfo Function::getSource(CodePtr PC) const {62assert(PC >= getCodeBegin() && "PC does not belong to this function");63assert(PC <= getCodeEnd() && "PC Does not belong to this function");64assert(hasBody() && "Function has no body");65unsigned Offset = PC - getCodeBegin();66using Elem = std::pair<unsigned, SourceInfo>;67auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());68if (It == SrcMap.end())69return SrcMap.back().second;70return It->second;71}727374