|
|
|||
File indexing completed on 2026-05-10 08:36:38
0001 //===--- LambdaCapture.h - Types for C++ Lambda Captures --------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// 0009 /// \file 0010 /// Defines the LambdaCapture class. 0011 /// 0012 //===----------------------------------------------------------------------===// 0013 0014 #ifndef LLVM_CLANG_AST_LAMBDACAPTURE_H 0015 #define LLVM_CLANG_AST_LAMBDACAPTURE_H 0016 0017 #include "clang/AST/Decl.h" 0018 #include "clang/Basic/Lambda.h" 0019 #include "llvm/ADT/PointerIntPair.h" 0020 0021 namespace clang { 0022 0023 /// Describes the capture of a variable or of \c this, or of a 0024 /// C++1y init-capture. 0025 class LambdaCapture { 0026 enum { 0027 /// Flag used by the Capture class to indicate that the given 0028 /// capture was implicit. 0029 Capture_Implicit = 0x01, 0030 0031 /// Flag used by the Capture class to indicate that the 0032 /// given capture was by-copy. 0033 /// 0034 /// This includes the case of a non-reference init-capture. 0035 Capture_ByCopy = 0x02, 0036 0037 /// Flag used by the Capture class to distinguish between a capture 0038 /// of '*this' and a capture of a VLA type. 0039 Capture_This = 0x04 0040 }; 0041 0042 // Decl could represent: 0043 // - a VarDecl* that represents the variable that was captured or the 0044 // init-capture. 0045 // - or, is a nullptr and Capture_This is set in Bits if this represents a 0046 // capture of '*this' by value or reference. 0047 // - or, is a nullptr and Capture_This is not set in Bits if this represents 0048 // a capture of a VLA type. 0049 llvm::PointerIntPair<Decl*, 3> DeclAndBits; 0050 0051 SourceLocation Loc; 0052 SourceLocation EllipsisLoc; 0053 0054 friend class ASTStmtReader; 0055 friend class ASTStmtWriter; 0056 0057 public: 0058 /// Create a new capture of a variable or of \c this. 0059 /// 0060 /// \param Loc The source location associated with this capture. 0061 /// 0062 /// \param Kind The kind of capture (this, byref, bycopy), which must 0063 /// not be init-capture. 0064 /// 0065 /// \param Implicit Whether the capture was implicit or explicit. 0066 /// 0067 /// \param Var The local variable being captured, or null if capturing 0068 /// \c this. 0069 /// 0070 /// \param EllipsisLoc The location of the ellipsis (...) for a 0071 /// capture that is a pack expansion, or an invalid source 0072 /// location to indicate that this is not a pack expansion. 0073 LambdaCapture(SourceLocation Loc, bool Implicit, LambdaCaptureKind Kind, 0074 ValueDecl *Var = nullptr, 0075 SourceLocation EllipsisLoc = SourceLocation()); 0076 0077 /// Determine the kind of capture. 0078 LambdaCaptureKind getCaptureKind() const; 0079 0080 /// Determine whether this capture handles the C++ \c this 0081 /// pointer. 0082 bool capturesThis() const { 0083 return DeclAndBits.getPointer() == nullptr && 0084 (DeclAndBits.getInt() & Capture_This); 0085 } 0086 0087 /// Determine whether this capture handles a variable. 0088 bool capturesVariable() const { 0089 return isa_and_nonnull<ValueDecl>(DeclAndBits.getPointer()); 0090 } 0091 0092 /// Determine whether this captures a variable length array bound 0093 /// expression. 0094 bool capturesVLAType() const { 0095 return DeclAndBits.getPointer() == nullptr && 0096 !(DeclAndBits.getInt() & Capture_This); 0097 } 0098 0099 /// Retrieve the declaration of the local variable being 0100 /// captured. 0101 /// 0102 /// This operation is only valid if this capture is a variable capture 0103 /// (other than a capture of \c this). 0104 ValueDecl *getCapturedVar() const { 0105 assert(capturesVariable() && "No variable available for capture"); 0106 return static_cast<ValueDecl *>(DeclAndBits.getPointer()); 0107 } 0108 0109 /// Determine whether this was an implicit capture (not 0110 /// written between the square brackets introducing the lambda). 0111 bool isImplicit() const { 0112 return DeclAndBits.getInt() & Capture_Implicit; 0113 } 0114 0115 /// Determine whether this was an explicit capture (written 0116 /// between the square brackets introducing the lambda). 0117 bool isExplicit() const { return !isImplicit(); } 0118 0119 /// Retrieve the source location of the capture. 0120 /// 0121 /// For an explicit capture, this returns the location of the 0122 /// explicit capture in the source. For an implicit capture, this 0123 /// returns the location at which the variable or \c this was first 0124 /// used. 0125 SourceLocation getLocation() const { return Loc; } 0126 0127 /// Determine whether this capture is a pack expansion, 0128 /// which captures a function parameter pack. 0129 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 0130 0131 /// Retrieve the location of the ellipsis for a capture 0132 /// that is a pack expansion. 0133 SourceLocation getEllipsisLoc() const { 0134 assert(isPackExpansion() && "No ellipsis location for a non-expansion"); 0135 return EllipsisLoc; 0136 } 0137 }; 0138 0139 } // end namespace clang 0140 0141 #endif // LLVM_CLANG_AST_LAMBDACAPTURE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|