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
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index aa24e9b..b65daa5 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -969,6 +969,35 @@
   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))