Implementation of new and delete parsing and sema.
This version uses VLAs to represent arrays. I'll try an alternative way next, but I want this safe first.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59835 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 92a5fdb..3262c0d 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -25,7 +25,11 @@
 /// ParseTypeName
 ///       type-name: [C99 6.7.6]
 ///         specifier-qualifier-list abstract-declarator[opt]
-Parser::TypeTy *Parser::ParseTypeName() {
+///
+/// Called type-id in C++.
+/// CXXNewMode is a special flag used by the parser of C++ new-expressions. It
+/// is simply passed on to ActOnTypeName.
+Parser::TypeTy *Parser::ParseTypeName(bool CXXNewMode) {
   // Parse the common declaration-specifiers piece.
   DeclSpec DS;
   ParseSpecifierQualifierList(DS);
@@ -34,7 +38,7 @@
   Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
   ParseDeclarator(DeclaratorInfo);
   
-  return Actions.ActOnTypeName(CurScope, DeclaratorInfo).Val;
+  return Actions.ActOnTypeName(CurScope, DeclaratorInfo, CXXNewMode).Val;
 }
 
 /// ParseAttributes - Parse a non-empty attributes list.
@@ -1292,12 +1296,12 @@
 void Parser::ParseDeclarator(Declarator &D) {
   /// This implements the 'declarator' production in the C grammar, then checks
   /// for well-formedness and issues diagnostics.
-  ParseDeclaratorInternal(D);
+  ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
 }
 
-/// ParseDeclaratorInternal - Parse a C or C++ declarator. If
-/// PtrOperator is true, then this routine won't parse the final
-/// direct-declarator; therefore, it effectively parses the C++
+/// ParseDeclaratorInternal - Parse a C or C++ declarator. The direct-declarator
+/// is parsed by the function passed to it. Pass null, and the direct-declarator
+/// isn't parsed at all, making this function effectively parse the C++
 /// ptr-operator production.
 ///
 ///       declarator: [C99 6.7.5]
@@ -1314,14 +1318,15 @@
 ///         '&'
 /// [GNU]   '&' restrict[opt] attributes[opt]
 ///         '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt] [TODO]
-void Parser::ParseDeclaratorInternal(Declarator &D, bool PtrOperator) {
+void Parser::ParseDeclaratorInternal(Declarator &D,
+                                     DirectDeclParseFunction DirectDeclParser) {
   tok::TokenKind Kind = Tok.getKind();
 
   // Not a pointer, C++ reference, or block.
   if (Kind != tok::star && (Kind != tok::amp || !getLang().CPlusPlus) &&
       (Kind != tok::caret || !getLang().Blocks)) {
-    if (!PtrOperator)
-      ParseDirectDeclarator(D);
+    if (DirectDeclParser)
+      (this->*DirectDeclParser)(D);
     return;
   }
   
@@ -1335,7 +1340,7 @@
     ParseTypeQualifierListOpt(DS);
   
     // Recursively parse the declarator.
-    ParseDeclaratorInternal(D, PtrOperator);
+    ParseDeclaratorInternal(D, DirectDeclParser);
     if (Kind == tok::star)
       // Remember that we parsed a pointer type, and remember the type-quals.
       D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,
@@ -1366,7 +1371,7 @@
     }
 
     // Recursively parse the declarator.
-    ParseDeclaratorInternal(D, PtrOperator);
+    ParseDeclaratorInternal(D, DirectDeclParser);
 
     if (D.getNumTypeObjects() > 0) {
       // C++ [dcl.ref]p4: There shall be no references to references.
@@ -1379,7 +1384,7 @@
           Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference)
             << "type name";
 
-        // Once we've complained about the reference-to-referwnce, we
+        // Once we've complained about the reference-to-reference, we
         // can go ahead and build the (technically ill-formed)
         // declarator: reference collapsing will take care of it.
       }
@@ -1581,7 +1586,7 @@
     if (AttrList)
       D.AddAttributes(AttrList);
 
-    ParseDeclaratorInternal(D);
+    ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
     // Match the ')'.
     MatchRHSPunctuation(tok::r_paren, StartLoc);