Implement some suggestions by Daniel:

-Change Parser::ParseCXXScopeSpecifier to MaybeParseCXXScopeSpecifier
-Remove Parser::isTokenCXXScopeSpecifier and fold it into MaybeParseCXXScopeSpecifier
-Rename Parser::TryAnnotateScopeToken to TryAnnotateCXXScopeToken and only allow it to be called when in C++

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60117 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index b4b6fb5..09aea03 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -17,7 +17,8 @@
 #include "AstGuard.h"
 using namespace clang;
 
-/// ParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
+/// MaybeParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
+/// Returns true if a nested-name-specifier was parsed from the token stream.
 ///
 ///       '::'[opt] nested-name-specifier
 ///       '::'
@@ -28,14 +29,20 @@
 ///         nested-name-specifier identifier '::'
 ///         nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
 ///
-void Parser::ParseCXXScopeSpecifier(CXXScopeSpec &SS) {
-  assert(isTokenCXXScopeSpecifier() && "Not scope specifier!");
+bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS) {
+  assert(getLang().CPlusPlus &&
+         "Call sites of this function should be guarded by checking for C++.");
+
+  if (Tok.isNot(tok::coloncolon)     &&
+      Tok.isNot(tok::annot_cxxscope) &&
+      (Tok.isNot(tok::identifier) || NextToken().isNot(tok::coloncolon)))
+    return false;
 
   if (Tok.is(tok::annot_cxxscope)) {
     SS.setScopeRep(Tok.getAnnotationValue());
     SS.setRange(Tok.getAnnotationRange());
     ConsumeToken();
-    return;
+    return true;
   }
 
   SS.setBeginLoc(Tok.getLocation());
@@ -68,6 +75,8 @@
          Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II) );
     SS.setEndLoc(CCLoc);
   }
+
+  return true;
 }
 
 /// ParseCXXIdExpression - Handle id-expression.
@@ -126,8 +135,7 @@
   //   '::' unqualified-id
   //
   CXXScopeSpec SS;
-  if (isTokenCXXScopeSpecifier())
-    ParseCXXScopeSpecifier(SS);
+  MaybeParseCXXScopeSpecifier(SS);
 
   // unqualified-id:
   //   identifier