clang API Documentation

Classes | 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.

Classes

class  Capture
 Describes the capture of either a variable or 'this'. More...

Public Types

typedef const Capturecapture_iterator
 An iterator that walks over the captures of the lambda, both implicit and explicit.
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.
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_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_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.
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, which stores the captures in its fields and provides the various operations permitted on a lambda (copying, calling).
CXXMethodDeclgetCallOperator () const
 Retrieve the function call operator associated with this lambda expression.
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.
SourceRange getSourceRange () const LLVM_READONLY
child_range children ()

Static Public Member Functions

static LambdaExprCreate (ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, ArrayRef< Capture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, ArrayRef< VarDecl * > ArrayIndexVars, ArrayRef< unsigned > ArrayIndexStarts, SourceLocation ClosingBrace)
 Construct a new lambda expression.
static LambdaExprCreateDeserialized (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)
static bool classof (const LambdaExpr *)

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; });
 }

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.

Definition at line 1119 of file ExprCXX.h.


Member Typedef Documentation

Iterator that walks over the capture initialization arguments.

Definition at line 1333 of file ExprCXX.h.

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

Definition at line 1303 of file ExprCXX.h.


Member Function Documentation

LambdaExpr::capture_iterator LambdaExpr::capture_begin ( ) const

Retrieve an iterator pointing to the first lambda capture.

Definition at line 882 of file ExprCXX.cpp.

References getLambdaClass().

Referenced by capture_end(), and explicit_capture_begin().

LambdaExpr::capture_iterator LambdaExpr::capture_end ( ) const

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

Definition at line 886 of file ExprCXX.cpp.

References capture_begin().

Referenced by implicit_capture_end().

capture_init_iterator clang::LambdaExpr::capture_init_begin ( ) const [inline]

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

Definition at line 1337 of file ExprCXX.h.

Referenced by clang::Sema::canThrow(), capture_init_end(), clang::CodeGen::CodeGenFunction::EmitLambdaExpr(), getCaptureInitIndexVars(), and clang::Sema::PopExpressionEvaluationContext().

capture_init_iterator clang::LambdaExpr::capture_init_end ( ) const [inline]

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

Definition at line 1343 of file ExprCXX.h.

References capture_init_begin().

Referenced by clang::Sema::canThrow(), clang::CodeGen::CodeGenFunction::EmitLambdaExpr(), and clang::Sema::PopExpressionEvaluationContext().

unsigned clang::LambdaExpr::capture_size ( ) const [inline]

Determine the number of captures in this lambda.

Definition at line 1313 of file ExprCXX.h.

child_range clang::LambdaExpr::children ( ) [inline]

Reimplemented from clang::Stmt.

Definition at line 1391 of file ExprCXX.h.

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

Reimplemented from clang::Expr.

Definition at line 1382 of file ExprCXX.h.

References clang::Stmt::getStmtClass().

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

Definition at line 1385 of file ExprCXX.h.

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

Construct a new lambda expression.

Definition at line 846 of file ExprCXX.cpp.

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

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

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

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

Definition at line 872 of file ExprCXX.cpp.

References clang::ASTContext::Allocate().

LambdaExpr::capture_iterator LambdaExpr::explicit_capture_begin ( ) const

Retrieve an iterator pointing to the first explicit lambda capture.

Definition at line 890 of file ExprCXX.cpp.

References capture_begin().

LambdaExpr::capture_iterator LambdaExpr::explicit_capture_end ( ) const

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

Definition at line 894 of file ExprCXX.cpp.

References getLambdaClass().

Referenced by implicit_capture_begin().

CompoundStmt * LambdaExpr::getBody ( ) const

Retrieve the body of the lambda.

Definition at line 936 of file ExprCXX.cpp.

References clang::FunctionDecl::getBody(), and getCallOperator().

CXXMethodDecl * LambdaExpr::getCallOperator ( ) const

Retrieve the function call operator associated with this lambda expression.

Definition at line 925 of file ExprCXX.cpp.

References clang::ASTContext::DeclarationNames, clang::Decl::getASTContext(), clang::DeclarationNameTable::getCXXOperatorName(), getLambdaClass(), and clang::DeclContext::lookup().

Referenced by getBody(), and isMutable().

LambdaCaptureDefault clang::LambdaExpr::getCaptureDefault ( ) const [inline]

Determine the default capture kind for this lambda.

Definition at line 1297 of file ExprCXX.h.

ArrayRef< VarDecl * > LambdaExpr::getCaptureInitIndexVars ( capture_init_iterator  Iter) const

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 909 of file ExprCXX.cpp.

References capture_init_begin(), getLambdaClass(), and Index.

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

SourceRange clang::LambdaExpr::getIntroducerRange ( ) const [inline]

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

Definition at line 1357 of file ExprCXX.h.

CXXRecordDecl * LambdaExpr::getLambdaClass ( ) const

Retrieve the class that corresponds to the lambda, which stores the captures in its fields and provides the various operations permitted on a lambda (copying, calling).

Definition at line 921 of file ExprCXX.cpp.

References clang::Expr::getType().

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

SourceRange clang::LambdaExpr::getSourceRange ( ) const [inline]

SourceLocation tokens are not useful in isolation - they are low level value objects created/interpreted by SourceManager. We assume AST clients will have a pointer to the respective SourceManager.

Reimplemented from clang::Stmt.

Definition at line 1387 of file ExprCXX.h.

References clang::SourceRange::getBegin().

bool clang::LambdaExpr::hasExplicitParameters ( ) const [inline]

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

Definition at line 1377 of file ExprCXX.h.

bool clang::LambdaExpr::hasExplicitResultType ( ) const [inline]

Whether this lambda had its result type explicitly specified.

Definition at line 1380 of file ExprCXX.h.

LambdaExpr::capture_iterator LambdaExpr::implicit_capture_begin ( ) const

Retrieve an iterator pointing to the first implicit lambda capture.

Definition at line 900 of file ExprCXX.cpp.

References explicit_capture_end().

LambdaExpr::capture_iterator LambdaExpr::implicit_capture_end ( ) const

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

Definition at line 904 of file ExprCXX.cpp.

References capture_end().

bool LambdaExpr::isMutable ( ) const

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

Definition at line 943 of file ExprCXX.cpp.

References clang::Qualifiers::Const, and getCallOperator().


Friends And Related Function Documentation

friend class ASTStmtReader [friend]

Reimplemented from clang::Stmt.

Definition at line 1395 of file ExprCXX.h.

friend class ASTStmtWriter [friend]

Reimplemented from clang::Stmt.

Definition at line 1396 of file ExprCXX.h.


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