================
@@ -34,46 +34,116 @@ struct AccessPath {
   AccessPath(const clang::ValueDecl *D) : D(D) {}
 };
 
-/// Information about a single borrow, or "Loan". A loan is created when a
-/// reference or pointer is created.
-struct Loan {
+/// An abstract base class for a single "Loan" which represents a lifetime
+/// dependency.
+class Loan {
   /// TODO: Represent opaque loans.
   /// TODO: Represent nullptr: loans to no path. Accessing it UB! Currently it
   /// is represented as empty LoanSet
-  LoanID ID;
+public:
+  enum class Kind : uint8_t {
+    /// A regular borrow of a variable within the function that has a path and
+    /// can expire.
+    Borrow,
+    /// A non-expiring placeholder loan for a parameter, representing a borrow
+    /// from the function's caller.
+    Placeholder
+  };
+
+  Loan(Kind K, LoanID ID) : K(K), ID(ID) {}
+  virtual ~Loan() = default;
+
+  Kind getKind() const { return K; }
+  LoanID getID() const { return ID; }
+
+  virtual void dump(llvm::raw_ostream &OS) const = 0;
+
+private:
+  const Kind K;
+  const LoanID ID;
+};
+
+/// Information about a single borrow loan. A borrow loan is created when a
+/// reference or pointer is created.
+class BorrowLoan : public Loan {
   AccessPath Path;
   /// The expression that creates the loan, e.g., &x.
   const Expr *IssueExpr;
 
-  Loan(LoanID id, AccessPath path, const Expr *IssueExpr)
-      : ID(id), Path(path), IssueExpr(IssueExpr) {}
+public:
+  BorrowLoan(LoanID ID, AccessPath Path, const Expr *IssueExpr)
----------------
usx95 wrote:

Let's avoid using the verb borrow and instead use "lend" (suitable in context 
of loans)
```cpp
/// PathLoan represents lending a storage location that is visible within the
/// function's scope (e.g., a local variable on stack).
```

https://github.com/llvm/llvm-project/pull/169767
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to