Sema for Captured Statements

Add CapturedDecl to be the DeclContext for CapturedStmt, and perform semantic
analysis. Currently captures all variables by reference.

TODO: templates

Author: Ben Langmuir <ben.langmuir@intel.com>

Differential Revision: http://llvm-reviews.chandlerc.com/D433


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179618 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 3604482..d572335 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -3234,6 +3234,10 @@
                                   0, 0);
 }
 
+CapturedDecl *CapturedDecl::Create(ASTContext &C, DeclContext *DC) {
+  return new (C) CapturedDecl(DC);
+}
+
 EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
                                            SourceLocation L,
                                            IdentifierInfo *Id, QualType T,
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 3f23f3d..402d836 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -553,6 +553,7 @@
     case StaticAssert:
     case ObjCPropertyImpl:
     case Block:
+    case Captured:
     case TranslationUnit:
 
     case UsingDirective:
@@ -839,6 +840,7 @@
   case Decl::TranslationUnit:
   case Decl::LinkageSpec:
   case Decl::Block:
+  case Decl::Captured:
     // There is only one DeclContext for these entities.
     return this;
 
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index e120c6a..2a7b170 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -1038,12 +1038,12 @@
 
 CapturedStmt::CapturedStmt(Stmt *S, ArrayRef<Capture> Captures,
                            ArrayRef<Expr *> CaptureInits,
-                           FunctionDecl *FD,
+                           CapturedDecl *CD,
                            RecordDecl *RD)
   : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
-    TheFuncDecl(FD), TheRecordDecl(RD) {
+    TheCapturedDecl(CD), TheRecordDecl(RD) {
   assert( S && "null captured statement");
-  assert(FD && "null function declaration for captured statement");
+  assert(CD && "null captured declaration for captured statement");
   assert(RD && "null record declaration for captured statement");
 
   // Copy initialization expressions.
@@ -1061,14 +1061,14 @@
 
 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
   : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
-    TheFuncDecl(0), TheRecordDecl(0) {
+    TheCapturedDecl(0), TheRecordDecl(0) {
   getStoredStmts()[NumCaptures] = 0;
 }
 
 CapturedStmt *CapturedStmt::Create(ASTContext &Context, Stmt *S,
                                    ArrayRef<Capture> Captures,
                                    ArrayRef<Expr *> CaptureInits,
-                                   FunctionDecl *FD,
+                                   CapturedDecl *CD,
                                    RecordDecl *RD) {
   // The layout is
   //
@@ -1089,7 +1089,7 @@
   }
 
   void *Mem = Context.Allocate(Size);
-  return new (Mem) CapturedStmt(S, Captures, CaptureInits, FD, RD);
+  return new (Mem) CapturedStmt(S, Captures, CaptureInits, CD, RD);
 }
 
 CapturedStmt *CapturedStmt::CreateDeserialized(ASTContext &Context,
@@ -1106,8 +1106,8 @@
 }
 
 Stmt::child_range CapturedStmt::children() {
-  // Children are captured field initilizers and the statement being captured.
-  return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
+  // Children are captured field initilizers.
+  return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
 }
 
 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 469c284..1b2285c 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -451,7 +451,7 @@
 }
 
 void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) {
-  PrintStmt(Node->getCapturedStmt());
+  PrintStmt(Node->getCapturedDecl()->getBody());
 }
 
 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {