[cfe-commits] r61422 - in /cfe/trunk: include/clang/Basic/TokenKinds.def include/clang/Parse/Parser.h lib/Lex/Preprocessor.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp

Steve Naroff snaroff at apple.com
Wed Dec 24 12:59:22 PST 2008


Author: snaroff
Date: Wed Dec 24 14:59:21 2008
New Revision: 61422

URL: http://llvm.org/viewvc/llvm-project?rev=61422&view=rev
Log:
Add explicit "fuzzy" parse support for Microsoft declspec.
Remove previous __declspec macro that would effectively erase the construct prior to parsing.


Modified:
    cfe/trunk/include/clang/Basic/TokenKinds.def
    cfe/trunk/include/clang/Parse/Parser.h
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=61422&r1=61421&r2=61422&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Wed Dec 24 14:59:21 2008
@@ -307,6 +307,9 @@
 // Apple Extension.
 KEYWORD(__private_extern__          , EXTC90|EXTC99|NOTCPP)
 
+// Microsoft Extension.
+KEYWORD(__declspec                  , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+
 // Alternate spelling for various tokens.  There are GCC extensions in all
 // languages, but should not be disabled in strict conformance mode.
 ALIAS("__attribute__", __attribute)

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Dec 24 14:59:21 2008
@@ -887,6 +887,7 @@
 
   TypeTy *ParseTypeName();
   AttributeList *ParseAttributes();
+  void FuzzyParseMicrosoftDeclSpec();
   void ParseTypeofSpecifier(DeclSpec &DS);
 
   /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=61422&r1=61421&r2=61422&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Dec 24 14:59:21 2008
@@ -493,7 +493,6 @@
     DefineBuiltinMacro(Buf, "__int16=short");
     DefineBuiltinMacro(Buf, "__int32=int");
     DefineBuiltinMacro(Buf, "__int64=long long");
-    DefineBuiltinMacro(Buf, "__declspec(X)=");
   }
   
   

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Dec 24 14:59:21 2008
@@ -192,6 +192,20 @@
   return CurrAttr;
 }
 
+/// FuzzyParseMicrosoftDeclSpec. When -fms-extensions is enabled, this
+/// routine is called to skip/ignore tokens that comprise the MS declspec.
+void Parser::FuzzyParseMicrosoftDeclSpec() {
+  assert(Tok.is(tok::kw___declspec) && "Not a declspec!");
+  ConsumeToken();
+  if (Tok.is(tok::l_paren)) {
+    unsigned short savedParenCount = ParenCount;
+    do {
+      ConsumeAnyToken();
+    } while (ParenCount > savedParenCount && Tok.isNot(tok::eof));
+  } 
+  return;
+}
+
 /// ParseDeclaration - Parse a full 'declaration', which consists of
 /// declaration-specifiers, some number of declarators, and a semicolon.
 /// 'Context' should be a Declarator::TheContext value.
@@ -538,6 +552,13 @@
     case tok::kw___attribute:
       DS.AddAttributes(ParseAttributes());
       continue;
+
+    // Microsoft declspec support.
+    case tok::kw___declspec:
+      if (!PP.getLangOptions().Microsoft)
+        goto DoneWithDeclSpec;
+      FuzzyParseMicrosoftDeclSpec();
+      continue;
       
     // storage-class-specifier
     case tok::kw_typedef:

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Dec 24 14:59:21 2008
@@ -220,6 +220,10 @@
   if (Tok.is(tok::kw___attribute))
     Attr = ParseAttributes();
 
+  // If declspecs exist after tag, parse them.
+  if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft)
+    FuzzyParseMicrosoftDeclSpec();
+  
   // Parse the (optional) nested-name-specifier.
   CXXScopeSpec SS;
   if (getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) {





More information about the cfe-commits mailing list