From: James Dennett Date: Tue, 27 May 2014 19:13:04 +0000 (+0000) Subject: Add range accessors for captures of a LambdaExpr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc3f40cb78ab1c07450a1c3204c6a5d1a7b1a764;p=clang Add range accessors for captures of a LambdaExpr. Summary: This adds LambdaExpr::captures(), LambdaExpr::explicit_captures() and LambdaExpr::implicit_captures() as simple wrappers over the underlying *_begin()/*_end() functions. Reviewers: aaron.ballman Differential Revision: http://reviews.llvm.org/D3926 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209679 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index d641442f0a..4403b0858f 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1426,6 +1426,12 @@ public: /// both implicit and explicit. typedef const Capture *capture_iterator; + /// \brief An iterator over a range of lambda captures. + typedef llvm::iterator_range capture_range; + + /// \brief Retrieve this lambda's captures. + capture_range captures() const; + /// \brief Retrieve an iterator pointing to the first lambda capture. capture_iterator capture_begin() const; @@ -1435,6 +1441,9 @@ public: /// \brief Determine the number of captures in this lambda. unsigned capture_size() const { return NumCaptures; } + + /// \brief Retrieve this lambda's explicit captures. + capture_range explicit_captures() const; /// \brief Retrieve an iterator pointing to the first explicit /// lambda capture. @@ -1444,6 +1453,9 @@ public: /// explicit lambda captures. capture_iterator explicit_capture_end() const; + /// \brief Retrieve this lambda's implicit captures. + capture_range implicit_captures() const; + /// \brief Retrieve an iterator pointing to the first implicit /// lambda capture. capture_iterator implicit_capture_begin() const; diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index d6002a7824..1c906789ab 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -1030,6 +1030,10 @@ LambdaExpr::capture_iterator LambdaExpr::capture_end() const { return capture_begin() + NumCaptures; } +LambdaExpr::capture_range LambdaExpr::captures() const { + return capture_range(capture_begin(), capture_end()); +} + LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin() const { return capture_begin(); } @@ -1040,6 +1044,10 @@ LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end() const { return Data.Captures + Data.NumExplicitCaptures; } +LambdaExpr::capture_range LambdaExpr::explicit_captures() const { + return capture_range(explicit_capture_begin(), explicit_capture_end()); +} + LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin() const { return explicit_capture_end(); } @@ -1048,6 +1056,10 @@ LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end() const { return capture_end(); } +LambdaExpr::capture_range LambdaExpr::implicit_captures() const { + return capture_range(implicit_capture_begin(), implicit_capture_end()); +} + ArrayRef LambdaExpr::getCaptureInitIndexVars(capture_init_iterator Iter) const { assert(HasArrayIndexVars && "No array index-var data?");