Path: blob/main/contrib/llvm-project/clang/lib/AST/Interp/Function.cpp
35291 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 "Opcode.h"10#include "Program.h"11#include "clang/AST/Decl.h"12#include "clang/AST/DeclCXX.h"13#include "clang/Basic/Builtins.h"1415using namespace clang;16using namespace clang::interp;1718Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize,19llvm::SmallVectorImpl<PrimType> &&ParamTypes,20llvm::DenseMap<unsigned, ParamDescriptor> &&Params,21llvm::SmallVectorImpl<unsigned> &&ParamOffsets,22bool HasThisPointer, bool HasRVO, bool UnevaluatedBuiltin)23: P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),24ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),25ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),26HasRVO(HasRVO), Variadic(F->isVariadic()),27IsUnevaluatedBuiltin(UnevaluatedBuiltin) {}2829Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {30auto It = Params.find(Offset);31assert(It != Params.end() && "Invalid parameter offset");32return It->second;33}3435SourceInfo Function::getSource(CodePtr PC) const {36assert(PC >= getCodeBegin() && "PC does not belong to this function");37assert(PC <= getCodeEnd() && "PC Does not belong to this function");38assert(hasBody() && "Function has no body");39unsigned Offset = PC - getCodeBegin();40using Elem = std::pair<unsigned, SourceInfo>;41auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());42if (It == SrcMap.end())43return SrcMap.back().second;44return It->second;45}4647bool Function::isVirtual() const {48if (const auto *M = dyn_cast<CXXMethodDecl>(F))49return M->isVirtual();50return false;51}525354