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 *FD = PB->getFieldDecl())
25 OS << "$this." << FD->getNameAsString();
26 } else if (const auto *E = getAsNewAllocation())
27 OS << "NewAllocation at " << E;
28 else
29 llvm_unreachable("access path base invalid");
30 for (const auto &E : Elements)
31 E.dump(OS);
32}
33
34void Loan::dump(llvm::raw_ostream &OS) const {
35 OS << getID() << " (Path: ";
36 Path.dump(OS);
37 OS << ")";
38}
39
40const PlaceholderBase *
41LoanManager::getOrCreatePlaceholderBase(const ParmVarDecl *PVD) {
42 llvm::FoldingSetNodeID ID;
44 llvm::FoldingSetInsertToken InsertToken;
45 if (PlaceholderBase *Existing = PlaceholderBases.lookup(ID, InsertToken))
46 return Existing;
47
48 void *Mem = LoanAllocator.Allocate<PlaceholderBase>();
49 PlaceholderBase *NewPB = new (Mem) PlaceholderBase(PVD);
50 PlaceholderBases.insert(NewPB, InsertToken);
51 return NewPB;
52}
53
54const PlaceholderBase *
55LoanManager::getOrCreatePlaceholderBase(const CXXMethodDecl *MD) {
56 llvm::FoldingSetNodeID ID;
58 llvm::FoldingSetInsertToken InsertToken;
59 if (PlaceholderBase *Existing = PlaceholderBases.lookup(ID, InsertToken))
60 return Existing;
61
62 void *Mem = LoanAllocator.Allocate<PlaceholderBase>();
63 PlaceholderBase *NewPB = new (Mem) PlaceholderBase(MD);
64 PlaceholderBases.insert(NewPB, InsertToken);
65 return NewPB;
66}
67
68const PlaceholderBase *
69LoanManager::getOrCreatePlaceholderBase(const FieldDecl *FD) {
70 llvm::FoldingSetNodeID ID;
72 llvm::FoldingSetInsertToken InsertToken;
73 if (PlaceholderBase *Existing = PlaceholderBases.lookup(ID, InsertToken))
74 return Existing;
75
76 void *Mem = LoanAllocator.Allocate<PlaceholderBase>();
77 PlaceholderBase *NewPB = new (Mem) PlaceholderBase(FD);
78 PlaceholderBases.insert(NewPB, InsertToken);
79 return NewPB;
80}
81} // namespace clang::lifetimes::internal
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2150
Represents a member of a struct/union/class.
Definition Decl.h:3299
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4974
Represents a parameter to a function.
Definition Decl.h:1820
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:713
const clang::CXXNewExpr * getAsNewAllocation() const
Definition Loans.h:162
const clang::ValueDecl * getAsValueDecl() const
Definition Loans.h:150
const clang::MaterializeTemporaryExpr * getAsMaterializeTemporaryExpr() const
Definition Loans.h:154
const PlaceholderBase * getAsPlaceholderBase() const
Definition Loans.h:158
void dump(llvm::raw_ostream &OS) const
Definition Loans.cpp:13
void dump(llvm::raw_ostream &OS) const
Definition Loans.cpp:34
Represents the base of a placeholder access path, which is a function parameter, the implicit 'this' ...
Definition Loans.h:77
static void Profile(llvm::FoldingSetNodeID &ID, KeyTy ParamMethodOrField)
Definition Loans.h:102