clang API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Friends
clang::LambdaExpr Class Reference

A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked later. More...

#include <ExprCXX.h>

Inheritance diagram for clang::LambdaExpr:
Inheritance graph
[legend]
Collaboration diagram for clang::LambdaExpr:
Collaboration graph
[legend]

List of all members.

Public Types

typedef const Capturecapture_iterator
 An iterator that walks over the captures of the lambda, both implicit and explicit.
typedef llvm::iterator_range
< capture_iterator
capture_range
 An iterator over a range of lambda captures.
typedef Expr ** capture_init_iterator
 Iterator that walks over the capture initialization arguments.

Public Member Functions

LambdaCaptureDefault getCaptureDefault () const
 Determine the default capture kind for this lambda.
SourceLocation getCaptureDefaultLoc () const
 Retrieve the location of this lambda's capture-default, if any.
capture_range captures () const
 Retrieve this lambda's captures.
capture_iterator capture_begin () const
 Retrieve an iterator pointing to the first lambda capture.
capture_iterator capture_end () const
 Retrieve an iterator pointing past the end of the sequence of lambda captures.
unsigned capture_size () const
 Determine the number of captures in this lambda.
capture_range explicit_captures () const
 Retrieve this lambda's explicit captures.
capture_iterator explicit_capture_begin () const
 Retrieve an iterator pointing to the first explicit lambda capture.
capture_iterator explicit_capture_end () const
 Retrieve an iterator pointing past the end of the sequence of explicit lambda captures.
capture_range implicit_captures () const
 Retrieve this lambda's implicit captures.
capture_iterator implicit_capture_begin () const
 Retrieve an iterator pointing to the first implicit lambda capture.
capture_iterator implicit_capture_end () const
 Retrieve an iterator pointing past the end of the sequence of implicit lambda captures.
llvm::iterator_range
< capture_init_iterator
capture_inits () const
 Retrieve the initialization expressions for this lambda's captures.
capture_init_iterator capture_init_begin () const
 Retrieve the first initialization argument for this lambda expression (which initializes the first capture field).
capture_init_iterator capture_init_end () const
 Retrieve the iterator pointing one past the last initialization argument for this lambda expression.
ArrayRef< VarDecl * > getCaptureInitIndexVars (capture_init_iterator Iter) const
 Retrieve the set of index variables used in the capture initializer of an array captured by copy.
SourceRange getIntroducerRange () const
 Retrieve the source range covering the lambda introducer, which contains the explicit capture list surrounded by square brackets ([...]).
CXXRecordDeclgetLambdaClass () const
 Retrieve the class that corresponds to the lambda.
CXXMethodDeclgetCallOperator () const
 Retrieve the function call operator associated with this lambda expression.
TemplateParameterListgetTemplateParameterList () const
 If this is a generic lambda expression, retrieve the template parameter list associated with it, or else return null.
bool isGenericLambda () const
 Whether this is a generic lambda.
CompoundStmtgetBody () const
 Retrieve the body of the lambda.
bool isMutable () const
 Determine whether the lambda is mutable, meaning that any captures values can be modified.
bool hasExplicitParameters () const
 Determine whether this lambda has an explicit parameter list vs. an implicit (empty) parameter list.
bool hasExplicitResultType () const
 Whether this lambda had its result type explicitly specified.
SourceLocation getLocStart () const LLVM_READONLY
SourceLocation getLocEnd () const LLVM_READONLY
child_range children ()

Static Public Member Functions

static LambdaExprCreate (const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< Capture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, ArrayRef< VarDecl * > ArrayIndexVars, ArrayRef< unsigned > ArrayIndexStarts, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
 Construct a new lambda expression.
static LambdaExprCreateDeserialized (const ASTContext &C, unsigned NumCaptures, unsigned NumArrayIndexVars)
 Construct a new lambda expression that will be deserialized from an external source.
static bool classof (const Stmt *T)

Friends

class ASTStmtReader
class ASTStmtWriter

Detailed Description

A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked later.

Example:

 void low_pass_filter(std::vector<double> &values, double cutoff) {
   values.erase(std::remove_if(values.begin(), values.end(),
                               [=](double value) { return value > cutoff; });
 }

C++11 lambda expressions can capture local variables, either by copying the values of those local variables at the time the function object is constructed (not when it is called!) or by holding a reference to the local variable. These captures can occur either implicitly or can be written explicitly between the square brackets ([...]) that start the lambda expression.

C++1y introduces a new form of "capture" called an init-capture that includes an initializing expression (rather than capturing a variable), and which can never occur implicitly.

Definition at line 1336 of file ExprCXX.h.


Member Typedef Documentation

Iterator that walks over the capture initialization arguments.

Definition at line 1493 of file ExprCXX.h.

An iterator that walks over the captures of the lambda, both implicit and explicit.

Definition at line 1451 of file ExprCXX.h.

typedef llvm::iterator_range<capture_iterator> clang::LambdaExpr::capture_range

An iterator over a range of lambda captures.

Definition at line 1454 of file ExprCXX.h.


Member Function Documentation

Retrieve an iterator pointing to the first lambda capture.

Definition at line 1034 of file ExprCXX.cpp.

References getLambdaClass().

Referenced by capture_end(), captures(), explicit_capture_begin(), clang::Expr::HasSideEffects(), and clang::TreeTransform< Derived >::TransformLambdaScope().

Retrieve an iterator pointing past the end of the sequence of lambda captures.

Definition at line 1038 of file ExprCXX.cpp.

References capture_begin().

Referenced by captures(), clang::Expr::HasSideEffects(), implicit_capture_end(), and clang::TreeTransform< Derived >::TransformLambdaScope().

Retrieve the first initialization argument for this lambda expression (which initializes the first capture field).

Definition at line 1503 of file ExprCXX.h.

Referenced by clang::Sema::canThrow(), capture_init_end(), capture_inits(), clang::CodeGen::CodeGenFunction::EmitLambdaExpr(), getCaptureInitIndexVars(), and clang::EvaluatedExprVisitor< ImplClass >::VisitLambdaExpr().

Retrieve the iterator pointing one past the last initialization argument for this lambda expression.

Definition at line 1509 of file ExprCXX.h.

References capture_init_begin().

Referenced by clang::Sema::canThrow(), capture_inits(), clang::CodeGen::CodeGenFunction::EmitLambdaExpr(), and clang::EvaluatedExprVisitor< ImplClass >::VisitLambdaExpr().

llvm::iterator_range<capture_init_iterator> clang::LambdaExpr::capture_inits ( ) const [inline]

Retrieve the initialization expressions for this lambda's captures.

Definition at line 1496 of file ExprCXX.h.

References capture_init_begin(), and capture_init_end().

Determine the number of captures in this lambda.

Definition at line 1467 of file ExprCXX.h.

Retrieve this lambda's captures.

Definition at line 1042 of file ExprCXX.cpp.

References capture_begin(), and capture_end().

Reimplemented from clang::Stmt.

Definition at line 1566 of file ExprCXX.h.

static bool clang::LambdaExpr::classof ( const Stmt T) [inline, static]

Reimplemented from clang::Expr.

Definition at line 1557 of file ExprCXX.h.

References clang::Stmt::getStmtClass().

LambdaExpr * LambdaExpr::Create ( const ASTContext C,
CXXRecordDecl Class,
SourceRange  IntroducerRange,
LambdaCaptureDefault  CaptureDefault,
SourceLocation  CaptureDefaultLoc,
ArrayRef< Capture Captures,
bool  ExplicitParams,
bool  ExplicitResultType,
ArrayRef< Expr * >  CaptureInits,
ArrayRef< VarDecl * >  ArrayIndexVars,
ArrayRef< unsigned ArrayIndexStarts,
SourceLocation  ClosingBrace,
bool  ContainsUnexpandedParameterPack 
) [static]

Construct a new lambda expression.

Definition at line 991 of file ExprCXX.cpp.

References clang::ASTContext::Allocate(), and clang::ASTContext::getTypeDeclType().

Referenced by clang::Sema::ActOnLambdaExpr().

LambdaExpr * LambdaExpr::CreateDeserialized ( const ASTContext C,
unsigned  NumCaptures,
unsigned  NumArrayIndexVars 
) [static]

Construct a new lambda expression that will be deserialized from an external source.

Definition at line 1023 of file ExprCXX.cpp.

References clang::ASTContext::Allocate().

Retrieve an iterator pointing to the first explicit lambda capture.

Definition at line 1046 of file ExprCXX.cpp.

References capture_begin().

Referenced by explicit_captures().

Retrieve an iterator pointing past the end of the sequence of explicit lambda captures.

Definition at line 1050 of file ExprCXX.cpp.

References getLambdaClass().

Referenced by explicit_captures(), and implicit_capture_begin().

Retrieve this lambda's explicit captures.

Definition at line 1056 of file ExprCXX.cpp.

References explicit_capture_begin(), and explicit_capture_end().

Retrieve the function call operator associated with this lambda expression.

Definition at line 1089 of file ExprCXX.cpp.

References clang::CXXRecordDecl::getLambdaCallOperator(), getLambdaClass(), and Record.

Referenced by getBody(), and isMutable().

Determine the default capture kind for this lambda.

Definition at line 1440 of file ExprCXX.h.

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().

Retrieve the location of this lambda's capture-default, if any.

Definition at line 1445 of file ExprCXX.h.

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().

Retrieve the set of index variables used in the capture initializer of an array captured by copy.

Parameters:
IterThe iterator that points at the capture initializer for which we are extracting the corresponding index variables.

Definition at line 1073 of file ExprCXX.cpp.

References capture_init_begin(), and getLambdaClass().

Referenced by clang::CodeGen::CodeGenFunction::EmitLambdaExpr().

Retrieve the source range covering the lambda introducer, which contains the explicit capture list surrounded by square brackets ([...]).

Definition at line 1523 of file ExprCXX.h.

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().

Retrieve the class that corresponds to the lambda.

This is the "closure type" (C++1y [expr.prim.lambda]), and stores the captures in its fields and provides the various operations permitted on a lambda (copying, calling).

Definition at line 1085 of file ExprCXX.cpp.

References clang::Type::getAsCXXRecordDecl(), and clang::Expr::getType().

Referenced by capture_begin(), clang::CodeGen::CodeGenFunction::EmitLambdaExpr(), explicit_capture_end(), getCallOperator(), getCaptureInitIndexVars(), and getTemplateParameterList().

Reimplemented from clang::Stmt.

Definition at line 1564 of file ExprCXX.h.

Reimplemented from clang::Stmt.

Definition at line 1561 of file ExprCXX.h.

References clang::SourceRange::getBegin().

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().

If this is a generic lambda expression, retrieve the template parameter list associated with it, or else return null.

Definition at line 1094 of file ExprCXX.cpp.

References clang::CXXRecordDecl::getGenericLambdaTemplateParameterList(), getLambdaClass(), and Record.

Referenced by isGenericLambda().

Determine whether this lambda has an explicit parameter list vs. an implicit (empty) parameter list.

Definition at line 1552 of file ExprCXX.h.

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().

Whether this lambda had its result type explicitly specified.

Definition at line 1555 of file ExprCXX.h.

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().

Retrieve an iterator pointing to the first implicit lambda capture.

Definition at line 1060 of file ExprCXX.cpp.

References explicit_capture_end().

Referenced by implicit_captures().

Retrieve an iterator pointing past the end of the sequence of implicit lambda captures.

Definition at line 1064 of file ExprCXX.cpp.

References capture_end().

Referenced by implicit_captures().

Retrieve this lambda's implicit captures.

Definition at line 1068 of file ExprCXX.cpp.

References implicit_capture_begin(), and implicit_capture_end().

Whether this is a generic lambda.

Definition at line 1541 of file ExprCXX.h.

References getTemplateParameterList().

Determine whether the lambda is mutable, meaning that any captures values can be modified.

Definition at line 1107 of file ExprCXX.cpp.

References getCallOperator(), and clang::CXXMethodDecl::isConst().

Referenced by clang::TreeTransform< Derived >::TransformLambdaScope().


Friends And Related Function Documentation

friend class ASTStmtReader [friend]

Reimplemented from clang::Stmt.

Definition at line 1570 of file ExprCXX.h.

friend class ASTStmtWriter [friend]

Reimplemented from clang::Stmt.

Definition at line 1571 of file ExprCXX.h.


The documentation for this class was generated from the following files: