[cfe-commits] r61657 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDecl.cpp lib/Parse/Parser.cpp

Chris Lattner sabre at nondot.org
Sun Jan 4 16:07:26 PST 2009


Author: lattner
Date: Sun Jan  4 18:07:25 2009
New Revision: 61657

URL: http://llvm.org/viewvc/llvm-project?rev=61657&view=rev
Log:
sink a call to TryAnnotateCXXScopeToken down into the
applicable cases in ParseDeclarationSpecifiers. 

Modified:
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=61657&r1=61656&r2=61657&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sun Jan  4 18:07:25 2009
@@ -272,8 +272,9 @@
   bool TryAnnotateTypeOrScopeToken(const Token *GlobalQualifier = 0);
 
   /// TryAnnotateCXXScopeToken - Like TryAnnotateTypeOrScopeToken but only
-  /// annotates C++ scope specifiers.
-  void TryAnnotateCXXScopeToken();
+  /// annotates C++ scope specifiers.  This returns true if the token was
+  /// annotated.
+  bool TryAnnotateCXXScopeToken();
 
   /// TentativeParsingAction - An object that is used as a kind of "tentative
   /// parsing transaction". It gets instantiated to mark the token position and

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Jan  4 18:07:25 2009
@@ -438,32 +438,31 @@
 /// [C++]   'explicit'
 ///
 void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
-                                        TemplateParameterLists *TemplateParams)
-{
+                                        TemplateParameterLists *TemplateParams){
   DS.SetRangeStart(Tok.getLocation());
   while (1) {
     int isInvalid = false;
     const char *PrevSpec = 0;
     SourceLocation Loc = Tok.getLocation();
 
-    // Only annotate C++ scope. Allow class-name as an identifier in case
-    // it's a constructor.
-    if (getLang().CPlusPlus)
-      TryAnnotateCXXScopeToken();
-    
     switch (Tok.getKind()) {
     default: 
       // Try to parse a type-specifier; if we found one, continue. If it's not
       // a type, this falls through.
-      if (MaybeParseTypeSpecifier(DS, isInvalid, PrevSpec, TemplateParams)) {
+      if (MaybeParseTypeSpecifier(DS, isInvalid, PrevSpec, TemplateParams))
         continue;
-      }
 
     DoneWithDeclSpec:
       // If this is not a declaration specifier token, we're done reading decl
       // specifiers.  First verify that DeclSpec's are consistent.
       DS.Finish(Diags, PP.getSourceManager(), getLang());
       return;
+        
+    case tok::coloncolon: // ::foo::bar
+      // Annotate C++ scope specifiers.  If we get one, loop.
+      if (TryAnnotateCXXScopeToken())
+        continue;
+      goto DoneWithDeclSpec;
 
     case tok::annot_cxxscope: {
       if (DS.hasTypeSpecifier())
@@ -505,6 +504,12 @@
 
       // typedef-name
     case tok::identifier: {
+      // In C++, check to see if this is a scope specifier like foo::bar::, if
+      // so handle it as such.  This is important for ctor parsing.
+      if (getLang().CPlusPlus &&
+        TryAnnotateCXXScopeToken())
+          continue;
+      
       // This identifier can only be a typedef name if we haven't already seen
       // a type-specifier.  Without this check we misparse:
       //  typedef int X; struct Y { short X; };  as 'short int'.

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

==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sun Jan  4 18:07:25 2009
@@ -807,17 +807,18 @@
 }
 
 /// TryAnnotateScopeToken - Like TryAnnotateTypeOrScopeToken but only
-/// annotates C++ scope specifiers.
-void Parser::TryAnnotateCXXScopeToken() {
+/// annotates C++ scope specifiers.  This returns true if the token was
+/// annotated.
+bool Parser::TryAnnotateCXXScopeToken() {
   assert(getLang().CPlusPlus &&
          "Call sites of this function should be guarded by checking for C++");
 
   if (Tok.is(tok::annot_cxxscope))
-    return;
+    return false;
 
   CXXScopeSpec SS;
   if (!MaybeParseCXXScopeSpecifier(SS))
-    return;
+    return false;
 
   // Push the current token back into the token stream (or revert it if it is
   // cached) and use an annotation scope token for current token.
@@ -832,4 +833,5 @@
   // In case the tokens were cached, have Preprocessor replace them with the
   // annotation token.
   PP.AnnotateCachedTokens(Tok);
+  return true;
 }





More information about the cfe-commits mailing list