clang 24.0.0git
Loans.cpp
Go to the documentation of this file.
1//===- Loans.cpp - Loan Implementation --------------------------*- 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
10
12
13void AccessPath::dump(llvm::raw_ostream &OS) const {
14 if (const clang::ValueDecl *VD = getAsValueDecl())
15 OS << VD->getNameAsString();
16 else if (const clang::MaterializeTemporaryExpr *MTE =
18 OS << "MaterializeTemporaryExpr at " << MTE;
19 else if (const PlaceholderBase *PB = getAsPlaceholderBase()) {
20 if (const auto *PVD = PB->getParmVarDecl())
21 OS << "$" << PVD->getNameAsString();
22 else if (PB->getImplicitThisParent())
23 OS << "$this";
24 } else if (const auto *E = getAsNewAllocation())
25 OS << "NewAllocation at " << E;
26 else
27 llvm_unreachable("access path base invalid");
28 for (const auto &E : Elements)
29 E.dump(OS);
30}
31
32void Loan::dump(llvm::raw_ostream &OS) const {
33 OS << getID() << " (Path: ";
34 Path.dump(OS);
35 OS << ")";
36}
37
38const PlaceholderBase *
39LoanManager::getOrCreatePlaceholderBase(const ParmVarDecl *PVD) {
40 llvm::FoldingSetNodeID ID;
41 ID.AddPointer(PVD);
42 void *InsertPos = nullptr;
43 if (PlaceholderBase *Existing =
44 PlaceholderBases.FindNodeOrInsertPos(ID, InsertPos))
45 return Existing;
46
47 void *Mem = LoanAllocator.Allocate<PlaceholderBase>();
48 PlaceholderBase *NewPB = new (Mem) PlaceholderBase(PVD);
49 PlaceholderBases.InsertNode(NewPB, InsertPos);
50 return NewPB;
51}
52
53const PlaceholderBase *
54LoanManager::getOrCreatePlaceholderBase(const CXXMethodDecl *MD) {
55 llvm::FoldingSetNodeID ID;
56 ID.AddPointer(MD);
57 void *InsertPos = nullptr;
58 if (PlaceholderBase *Existing =
59 PlaceholderBases.FindNodeOrInsertPos(ID, InsertPos))
60 return Existing;
61
62 void *Mem = LoanAllocator.Allocate<PlaceholderBase>();
63 PlaceholderBase *NewPB = new (Mem) PlaceholderBase(MD);
64 PlaceholderBases.InsertNode(NewPB, InsertPos);
65 return NewPB;
66}
67} // namespace clang::lifetimes::internal
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4919
Represents a parameter to a function.
Definition Decl.h:1819
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
const clang::CXXNewExpr * getAsNewAllocation() const
Definition Loans.h:148
const clang::ValueDecl * getAsValueDecl() const
Definition Loans.h:136
const clang::MaterializeTemporaryExpr * getAsMaterializeTemporaryExpr() const
Definition Loans.h:140
const PlaceholderBase * getAsPlaceholderBase() const
Definition Loans.h:144
void dump(llvm::raw_ostream &OS) const
Definition Loans.cpp:13
void dump(llvm::raw_ostream &OS) const
Definition Loans.cpp:32
Represents the base of a placeholder access path, which is either a function parameter or the implici...
Definition Loans.h:77