[cfe-commits] r74261 - /cfe/trunk/lib/Parse/ParseExprCXX.cpp

Chris Lattner sabre at nondot.org
Thu Jun 25 20:52:38 PDT 2009


Author: lattner
Date: Thu Jun 25 22:52:38 2009
New Revision: 74261

URL: http://llvm.org/viewvc/llvm-project?rev=74261&view=rev
Log:
rearrange more code, this avoids a token lookahead for foo<


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

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Thu Jun 25 22:52:38 2009
@@ -90,50 +90,6 @@
       continue;
     }
     
-    // nested-name-specifier:
-    //   type-name '::'
-    //   namespace-name '::'
-    //   nested-name-specifier identifier '::'
-    if (Tok.is(tok::identifier) && NextToken().is(tok::coloncolon)) {
-      // We have an identifier followed by a '::'. Lookup this name
-      // as the name in a nested-name-specifier.
-      IdentifierInfo *II = Tok.getIdentifierInfo();
-      SourceLocation IdLoc = ConsumeToken();
-      assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
-      SourceLocation CCLoc = ConsumeToken();
-      
-      if (!HasScopeSpecifier) {
-        SS.setBeginLoc(IdLoc);
-        HasScopeSpecifier = true;
-      }
-      
-      if (SS.isInvalid())
-        continue;
-      
-      SS.setScopeRep(
-        Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II));
-      SS.setEndLoc(CCLoc);
-      continue;
-    }
-    
-    // nested-name-specifier:
-    //   type-name '::'
-    if (Tok.is(tok::identifier) && NextToken().is(tok::less)) {
-      TemplateTy Template;
-      TemplateNameKind TNK = Actions.isTemplateName(*Tok.getIdentifierInfo(),
-                                                    CurScope, Template, &SS);
-      if (TNK) {
-        // We have found a template name, so annotate this this token
-        // with a template-id annotation. We do not permit the
-        // template-id to be translated into a type annotation,
-        // because some clients (e.g., the parsing of class template
-        // specializations) still want to see the original template-id
-        // token.
-        AnnotateTemplateIdToken(Template, TNK, &SS, SourceLocation(), false);
-        continue;
-      }
-    }
-
     if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) {
       // We have 
       //
@@ -177,6 +133,57 @@
       assert(false && "FIXME: Only type template names supported here");
     }
 
+
+    // The rest of the nested-name-specifier possibilities start with
+    // tok::identifier.
+    if (Tok.isNot(tok::identifier))
+      break;
+
+    IdentifierInfo &II = *Tok.getIdentifierInfo();
+
+    // nested-name-specifier:
+    //   type-name '::'
+    //   namespace-name '::'
+    //   nested-name-specifier identifier '::'
+    Token Next = NextToken();
+    if (Next.is(tok::coloncolon)) {
+      // We have an identifier followed by a '::'. Lookup this name
+      // as the name in a nested-name-specifier.
+      SourceLocation IdLoc = ConsumeToken();
+      assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
+      SourceLocation CCLoc = ConsumeToken();
+      
+      if (!HasScopeSpecifier) {
+        SS.setBeginLoc(IdLoc);
+        HasScopeSpecifier = true;
+      }
+      
+      if (SS.isInvalid())
+        continue;
+      
+      SS.setScopeRep(
+        Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, II));
+      SS.setEndLoc(CCLoc);
+      continue;
+    }
+    
+    // nested-name-specifier:
+    //   type-name '<'
+    if (Next.is(tok::less)) {
+      TemplateTy Template;
+      if (TemplateNameKind TNK = Actions.isTemplateName(II, CurScope,
+                                                        Template, &SS)) {
+        // We have found a template name, so annotate this this token
+        // with a template-id annotation. We do not permit the
+        // template-id to be translated into a type annotation,
+        // because some clients (e.g., the parsing of class template
+        // specializations) still want to see the original template-id
+        // token.
+        AnnotateTemplateIdToken(Template, TNK, &SS, SourceLocation(), false);
+        continue;
+      }
+    }
+
     // We don't have any tokens that form the beginning of a
     // nested-name-specifier, so we're done.
     break;





More information about the cfe-commits mailing list