diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-05 01:49:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-05 01:49:50 +0000 |
commit | 608d1fc9c4db3e3769f03a4f989d7692aefbf073 (patch) | |
tree | 336145d859939e9259a418694698d6be1dd5615f /lib/Parse/Parser.cpp | |
parent | 83cf05a3b0e655dc8ea1cb4c4e1eef541b770992 (diff) |
Rearrange some code in TryAnnotateTypeOrScopeToken to make it
early exit for C and avoid template lookup for C.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61667 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r-- | lib/Parse/Parser.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 16f0837240..1cd0b022b5 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -756,30 +756,33 @@ bool Parser::TryAnnotateTypeOrScopeToken(const Token *GlobalQualifier) { MaybeParseCXXScopeSpecifier(SS, GlobalQualifier); if (Tok.is(tok::identifier)) { - DeclTy *Template = 0; - // If this is a template-id, annotate the template-id token. - if (getLang().CPlusPlus && NextToken().is(tok::less) && - (Template = Actions.isTemplateName(*Tok.getIdentifierInfo(), CurScope, - &SS))) - AnnotateTemplateIdToken(Template, &SS); - else { - // Determine whether the identifier is a type name. - TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, &SS); - if (Ty) { - // This is a typename. Replace the current token in-place with an - // annotation type token. - Tok.setKind(tok::annot_qualtypename); - Tok.setAnnotationValue(Ty); - Tok.setAnnotationEndLoc(Tok.getLocation()); - if (SS.isNotEmpty()) // it was a C++ qualified type name. - Tok.setLocation(SS.getBeginLoc()); - - // In case the tokens were cached, have Preprocessor replace - // them with the annotation token. - PP.AnnotateCachedTokens(Tok); - return true; - } + // Determine whether the identifier is a type name. + if (TypeTy *Ty = Actions.isTypeName(*Tok.getIdentifierInfo(), + CurScope, &SS)) { + // This is a typename. Replace the current token in-place with an + // annotation type token. + Tok.setKind(tok::annot_qualtypename); + Tok.setAnnotationValue(Ty); + Tok.setAnnotationEndLoc(Tok.getLocation()); + if (SS.isNotEmpty()) // it was a C++ qualified type name. + Tok.setLocation(SS.getBeginLoc()); + + // In case the tokens were cached, have Preprocessor replace + // them with the annotation token. + PP.AnnotateCachedTokens(Tok); + return true; + } else if (!getLang().CPlusPlus) { + // If we're in C, we can't have :: tokens at all (the lexer won't return + // them). If the identifier is not a type, then it can't be scope either, + // just early exit. + return false; } + + // If this is a template-id, annotate the template-id token. + if (NextToken().is(tok::less)) + if (DeclTy *Template = + Actions.isTemplateName(*Tok.getIdentifierInfo(), CurScope, &SS)) + AnnotateTemplateIdToken(Template, &SS); // We either have an identifier that is not a type name or we have // just created a template-id that might be a type name. Both |