]> granicus.if.org Git - clang/commitdiff
Add explicit "fuzzy" parse support for Microsoft declspec.
authorSteve Naroff <snaroff@apple.com>
Wed, 24 Dec 2008 20:59:21 +0000 (20:59 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 24 Dec 2008 20:59:21 +0000 (20:59 +0000)
Remove previous __declspec macro that would effectively erase the construct prior to parsing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61422 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 150a2eb13c6d27f5f3ca9f70a0d92376a1427048..c0a448dfa771194e20443d596bfce297188e048c 100644 (file)
@@ -307,6 +307,9 @@ KEYWORD(__thread                    , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
 // 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)
index df6f895e49dcad12a48f659bc92e120e5425aa0e..28aed8b58a6da344e599d4838ccd2fec6fc31962 100644 (file)
@@ -887,6 +887,7 @@ private:
 
   TypeTy *ParseTypeName();
   AttributeList *ParseAttributes();
+  void FuzzyParseMicrosoftDeclSpec();
   void ParseTypeofSpecifier(DeclSpec &DS);
 
   /// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
index 7800fb5189449d2cae53a9ebbc5a766ce4102b11..97ff07049f97b474583c44bef340b98980e19f9d 100644 (file)
@@ -493,7 +493,6 @@ static void InitializePredefinedMacros(Preprocessor &PP,
     DefineBuiltinMacro(Buf, "__int16=short");
     DefineBuiltinMacro(Buf, "__int32=int");
     DefineBuiltinMacro(Buf, "__int64=long long");
-    DefineBuiltinMacro(Buf, "__declspec(X)=");
   }
   
   
index c7f92cf014db033ff3feac36dfcd3d0580085ca8..a8052dc2904292573d1626f70976d4cdfcae065e 100644 (file)
@@ -192,6 +192,20 @@ AttributeList *Parser::ParseAttributes() {
   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 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
     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:
index 1b0b811c88f36a3358729699b6fe4a1a1064a632..1d3de90060b7ca1e58a37fd60132e5b95d4c7c24 100644 (file)
@@ -220,6 +220,10 @@ void Parser::ParseClassSpecifier(DeclSpec &DS,
   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)) {