diff options
author | Steve Naroff <snaroff@apple.com> | 2009-01-28 19:16:40 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-01-28 19:16:40 +0000 |
commit | 2d081c47cdaa2fa37848bddb0062e61c4607cb0b (patch) | |
tree | 2dfe0646664a018eaa16cdf5e022b2963f22431b /lib/Parse/ParseDecl.cpp | |
parent | 46b86c610ede6d9abdec254f39663db86c9c88e0 (diff) |
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).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63219 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDecl.cpp')
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 89e0f10d74..dc6768f999 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -1992,18 +1992,30 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, // 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. |