]> granicus.if.org Git - clang/commitdiff
Rearrange some code in TryAnnotateTypeOrScopeToken to make it
authorChris Lattner <sabre@nondot.org>
Mon, 5 Jan 2009 01:49:50 +0000 (01:49 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 5 Jan 2009 01:49:50 +0000 (01:49 +0000)
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

lib/Parse/Parser.cpp

index 16f0837240763ccce32c465917ca91b0ab47c402..1cd0b022b5da8085eea226731f73c89f5a372bd7 100644 (file)
@@ -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