]> granicus.if.org Git - clang/commitdiff
Refactor ParseFunctionDeclaratorIdentifierList to have the first
authorChris Lattner <sabre@nondot.org>
Fri, 14 May 2010 17:23:36 +0000 (17:23 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 14 May 2010 17:23:36 +0000 (17:23 +0000)
identifier in the identifier list consumed before it is called.
No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103781 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp

index 530570913246510a6aab313ab25e32d71b1d04ff..b640d36525f5057f10ff6a20c4089e7538850436 100644 (file)
@@ -1351,6 +1351,8 @@ private:
                                AttributeList *AttrList = 0,
                                bool RequiresArg = false);
   void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
+                                             IdentifierInfo *FirstIdent,
+                                             SourceLocation FirstIdentLoc,
                                              Declarator &D);
   void ParseBracketDeclarator(Declarator &D);
 
index 91050e0a4cf9c271f6e2ad5e02689b4840262778..9b4264db022f4b39cbe411e12ca961eb279cfd94 100644 (file)
@@ -2937,9 +2937,16 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
         Diag(Tok, diag::err_argument_required_after_attribute);
         delete AttrList;
       }
+      
       // Identifier list.  Note that '(' identifier-list ')' is only allowed for
-      // normal declarators, not for abstract-declarators.
-      return ParseFunctionDeclaratorIdentifierList(LParenLoc, D);
+      // normal declarators, not for abstract-declarators.  Get the first
+      // identifier.
+      IdentifierInfo *FirstIdent = Tok.getIdentifierInfo();
+      SourceLocation FirstIdentLoc = Tok.getLocation();
+      ConsumeToken();  // eat the first identifier.
+
+      return ParseFunctionDeclaratorIdentifierList(LParenLoc, FirstIdent,
+                                                   FirstIdentLoc, D);
     }
   }
 
@@ -3122,13 +3129,16 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
 
 /// ParseFunctionDeclaratorIdentifierList - While parsing a function declarator
 /// we found a K&R-style identifier list instead of a type argument list.  The
-/// current token is known to be the first identifier in the list.
+/// first identifier has already been consumed, and the current token is the
+/// token right after it.
 ///
 ///       identifier-list: [C99 6.7.5]
 ///         identifier
 ///         identifier-list ',' identifier
 ///
 void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
+                                                   IdentifierInfo *FirstIdent,
+                                                   SourceLocation FirstIdentLoc,
                                                    Declarator &D) {
   // Build up an array of information about the parsed arguments.
   llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
@@ -3139,17 +3149,14 @@ void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
   // to be abstract.  In abstract-declarators, identifier lists are not valid:
   // diagnose this.
   if (!D.getIdentifier())
-    Diag(Tok, diag::ext_ident_list_in_param);
+    Diag(FirstIdentLoc, diag::ext_ident_list_in_param);
 
-  // Tok is known to be the first identifier in the list.  Remember this
-  // identifier in ParamInfo.
-  ParamsSoFar.insert(Tok.getIdentifierInfo());
-  ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(),
-                                                 Tok.getLocation(),
+  // The first identifier was already read, and is known to be the first
+  // identifier in the list.  Remember this identifier in ParamInfo.
+  ParamsSoFar.insert(FirstIdent);
+  ParamInfo.push_back(DeclaratorChunk::ParamInfo(FirstIdent, FirstIdentLoc,
                                                  DeclPtrTy()));
 
-  ConsumeToken();  // eat the first identifier.
-
   while (Tok.is(tok::comma)) {
     // Eat the comma.
     ConsumeToken();