[cfe-commits] r39602 - in /cfe/cfe/trunk: Parse/ParseDecl.cpp include/clang/Lex/LexerToken.h

Steve Naroff snaroff at apple.com
Wed Jul 11 09:46:08 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:46:08 2007
New Revision: 39602

URL: http://llvm.org/viewvc/llvm-project?rev=39602&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:

Fixed a bug in the parser's handling of attributes on pointer declarators.

For example, the following code was producing a syntax error...

int *__attribute(()) foo;

attrib.c:10:25: error: expected identifier or '('
int *__attribute(()) foo;
                        ^
Changed Parser::ParseTypeQualifierListOpt to not consume the token following
an attribute declaration.

Also added LexerToken::getName() convenience method...useful when tracking
down errors like this.

Modified:
    cfe/cfe/trunk/Parse/ParseDecl.cpp
    cfe/cfe/trunk/include/clang/Lex/LexerToken.h

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

==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:46:08 2007
@@ -181,8 +181,10 @@
         CurrAttr = Actions.ParseAttribute(AttrName, AttrNameLoc, CurrAttr);
       }
     }
-    SkipUntil(tok::r_paren, false);
-    SkipUntil(tok::r_paren, false);
+    if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
+      SkipUntil(tok::r_paren, false); 
+    if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
+      SkipUntil(tok::r_paren, false);
   }
   return CurrAttr;
 }
@@ -929,7 +931,7 @@
       break;
     case tok::kw___attribute:
       ParseAttributes();
-      break;
+      continue; // do *not* consume the next token!
     }
     
     // If the specifier combination wasn't legal, issue a diagnostic.
@@ -979,6 +981,7 @@
   if (Kind == tok::star) {
     // Is a pointer
     DeclSpec DS;
+    
     ParseTypeQualifierListOpt(DS);
   
     // Recursively parse the declarator.

Modified: cfe/cfe/trunk/include/clang/Lex/LexerToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/LexerToken.h?rev=39602&r1=39601&r2=39602&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/LexerToken.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/LexerToken.h Wed Jul 11 11:46:08 2007
@@ -62,6 +62,8 @@
   void setLocation(SourceLocation L) { Loc = L; }
   void setLength(unsigned Len) { Length = Len; }
   
+  const char *getName() const { return getTokenName(Kind); }
+  
   /// startToken - Reset all flags to cleared.
   ///
   void startToken() {





More information about the cfe-commits mailing list