aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-10 07:45:31 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-10 07:45:31 +0000
commit4d8d22bfaed6e5d7da6b5556415b18c43b44e36c (patch)
treee426e3c83c502004ea93b36f96ae13503f7f3566 /lib
parent864b1cf13b288c5099911e1265431ffdcac060a4 (diff)
Extend CXXRecordDecl with a function that determines the mapping from
the variables captured by a lambda to the fields that store the captured values. To be used in IRgen. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150235 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/DeclCXX.cpp29
-rw-r--r--lib/Sema/SemaLambda.cpp3
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index aa24e9b625..b65daa5e5e 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -969,6 +969,35 @@ bool CXXRecordDecl::isCLike() const {
return isPOD() && data().HasOnlyCMembers;
}
+void CXXRecordDecl::setLambda(LambdaExpr *Lambda) {
+ if (!Lambda)
+ return;
+
+ data().IsLambda = true;
+ getASTContext().Lambdas[this] = Lambda;
+}
+
+void CXXRecordDecl::getCaptureFields(
+ llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
+ FieldDecl *&ThisCapture) {
+ Captures.clear();
+ ThisCapture = 0;
+
+ LambdaExpr *Lambda = getASTContext().Lambdas[this];
+ RecordDecl::field_iterator Field = field_begin();
+ for (LambdaExpr::capture_iterator C = Lambda->capture_begin(),
+ CEnd = Lambda->capture_end();
+ C != CEnd; ++C, ++Field) {
+ if (C->capturesThis()) {
+ ThisCapture = *Field;
+ continue;
+ }
+
+ Captures[C->getCapturedVar()] = *Field;
+ }
+}
+
+
static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
QualType T;
if (isa<UsingShadowDecl>(Conv))
diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp
index 73ef229a6b..6e9bea781d 100644
--- a/lib/Sema/SemaLambda.cpp
+++ b/lib/Sema/SemaLambda.cpp
@@ -32,7 +32,7 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro,
/*IdLoc=*/Intro.Range.getBegin(),
/*Id=*/0);
Class->startDefinition();
- Class->setLambda(true);
+ Class->makeLambda();
CurContext->addDecl(Class);
// Build the call operator; we don't really have all the relevant information
@@ -408,6 +408,7 @@ ExprResult Sema::ActOnLambdaExpr(SourceLocation StartLoc,
CaptureDefault, Captures,
ExplicitParams, CaptureInits,
Body->getLocEnd());
+ Class->setLambda(Lambda);
// C++11 [expr.prim.lambda]p2:
// A lambda-expression shall not appear in an unevaluated operand