[cfe-commits] r63219 - /cfe/trunk/lib/Parse/ParseDecl.cpp

Steve Naroff snaroff at apple.com
Wed Jan 28 11:16:40 PST 2009


Author: snaroff
Date: Wed Jan 28 13:16:40 2009
New Revision: 63219

URL: http://llvm.org/viewvc/llvm-project?rev=63219&view=rev
Log:
Change Parser::ParseFunctionDeclarator() to annotate typename tokens.

This removes ~10% of the calls to Sema::isTypeName(), which amount to a little less than a 1% reduction in usertime (for Cocoa.h).

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=63219&r1=63218&r2=63219&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Jan 28 13:16:40 2009
@@ -1992,18 +1992,30 @@
   
   // Alternatively, this parameter list may be an identifier list form for a
   // K&R-style function:  void foo(a,b,c)
-  if (!getLang().CPlusPlus && Tok.is(tok::identifier) &&
+  if (!getLang().CPlusPlus && Tok.is(tok::identifier)) {
+
+    TypeTy *TypeRep = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope);
+    if (TypeRep) {
+      // This is a typename. Replace the current token in-place with an
+      // annotation type token.
+      Tok.setKind(tok::annot_typename);
+      Tok.setAnnotationValue(TypeRep);
+      Tok.setAnnotationEndLoc(Tok.getLocation());
+      // In case the tokens were cached, have Preprocessor replace
+      // them with the annotation token.
+      PP.AnnotateCachedTokens(Tok);
+    } else {
       // K&R identifier lists can't have typedefs as identifiers, per
       // C99 6.7.5.3p11.
-      !Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) {
-    if (RequiresArg) {
-      Diag(Tok, diag::err_argument_required_after_attribute);
-      delete AttrList;
+      if (RequiresArg) {
+        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);
     }
-    
-    // Identifier list.  Note that '(' identifier-list ')' is only allowed for
-    // normal declarators, not for abstract-declarators.
-    return ParseFunctionDeclaratorIdentifierList(LParenLoc, D);
   }
   
   // Finally, a normal, non-empty parameter type list.





More information about the cfe-commits mailing list