[cfe-commits] r61430 - in /cfe/trunk: include/clang/Basic/TokenKinds.def lib/Lex/Preprocessor.cpp lib/Parse/ParseDecl.cpp test/Parser/MicrosoftExtensions.c

Steve Naroff snaroff at apple.com
Thu Dec 25 06:16:41 PST 2008


Author: snaroff
Date: Thu Dec 25 08:16:32 2008
New Revision: 61430

URL: http://llvm.org/viewvc/llvm-project?rev=61430&view=rev
Log:
Add parser support for __cdecl, __stdcall, and __fastcall.
Change preprocessor implementation of _cdecl to reference __cdecl.

Added:
    cfe/trunk/test/Parser/MicrosoftExtensions.c
Modified:
    cfe/trunk/include/clang/Basic/TokenKinds.def
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/lib/Parse/ParseDecl.cpp

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

==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Thu Dec 25 08:16:32 2008
@@ -309,6 +309,9 @@
 
 // Microsoft Extension.
 KEYWORD(__declspec                  , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__cdecl                     , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__stdcall                   , EXTC90|EXTC99|EXTCPP|EXTCPP0x)
+KEYWORD(__fastcall                  , 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.

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

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Dec 25 08:16:32 2008
@@ -483,9 +483,7 @@
   // Filter out some microsoft extensions when trying to parse in ms-compat
   // mode. 
   if (PP.getLangOptions().Microsoft) {
-    DefineBuiltinMacro(Buf, "__stdcall=");
-    DefineBuiltinMacro(Buf, "__cdecl=");
-    DefineBuiltinMacro(Buf, "_cdecl=");
+    DefineBuiltinMacro(Buf, "_cdecl=__cdecl");
     DefineBuiltinMacro(Buf, "__ptr64=");
     DefineBuiltinMacro(Buf, "__w64=");
     DefineBuiltinMacro(Buf, "__forceinline=");

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Dec 25 08:16:32 2008
@@ -560,6 +560,15 @@
       FuzzyParseMicrosoftDeclSpec();
       continue;
       
+    // Microsoft single token adornments.
+    case tok::kw___cdecl:
+    case tok::kw___stdcall:
+    case tok::kw___fastcall:
+      if (!PP.getLangOptions().Microsoft)
+        goto DoneWithDeclSpec;
+      // Just ignore it.
+      break;
+      
     // storage-class-specifier
     case tok::kw_typedef:
       isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec);
@@ -798,6 +807,11 @@
     ParseTypeofSpecifier(DS);
     return true;
 
+  case tok::kw___cdecl:
+  case tok::kw___stdcall:
+  case tok::kw___fastcall:
+    return PP.getLangOptions().Microsoft;
+
   default:
     // Not a type-specifier; do nothing.
     return false;
@@ -1199,6 +1213,11 @@
     // GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'.
   case tok::less:
     return getLang().ObjC1;
+  
+  case tok::kw___cdecl:
+  case tok::kw___stdcall:
+  case tok::kw___fastcall:
+    return PP.getLangOptions().Microsoft;
   }
 }
 
@@ -1268,6 +1287,11 @@
     // GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'.
   case tok::less:
     return getLang().ObjC1;
+    
+  case tok::kw___cdecl:
+  case tok::kw___stdcall:
+  case tok::kw___fastcall:
+    return PP.getLangOptions().Microsoft;
   }
 }
 
@@ -1298,6 +1322,13 @@
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
                                  getLang())*2;
       break;
+    case tok::kw___cdecl:
+    case tok::kw___stdcall:
+    case tok::kw___fastcall:
+      if (!PP.getLangOptions().Microsoft)
+        goto DoneWithTypeQuals;
+      // Just ignore it.
+      break;
     case tok::kw___attribute:
       if (AttributesAllowed) {
         DS.AddAttributes(ParseAttributes());
@@ -1305,6 +1336,7 @@
       }
       // otherwise, FALL THROUGH!
     default:
+      DoneWithTypeQuals:
       // If this is not a type-qualifier token, we're done reading type
       // qualifiers.  First verify that DeclSpec's are consistent.
       DS.Finish(Diags, PP.getSourceManager(), getLang());
@@ -1632,6 +1664,10 @@
     // present even if the attribute list was empty.
     RequiresArg = true;
   }
+  // Eat any Microsoft extensions.
+  if ((Tok.is(tok::kw___cdecl) || Tok.is(tok::kw___stdcall) ||
+      (Tok.is(tok::kw___fastcall))) && PP.getLangOptions().Microsoft)
+    ConsumeToken();
   
   // If we haven't past the identifier yet (or where the identifier would be
   // stored, if this is an abstract declarator), then this is probably just

Added: cfe/trunk/test/Parser/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=61430&view=auto

==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.c (added)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.c Thu Dec 25 08:16:32 2008
@@ -0,0 +1,8 @@
+// RUN: clang -fsyntax-only -verify -fms-extensions %s
+__stdcall int func0();
+int __stdcall func();
+typedef int (__cdecl *tptr)();
+void (*__fastcall fastpfunc)();
+extern __declspec(dllimport) void __stdcall VarR4FromDec();
+__declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix);
+__declspec(noalias) __declspec(restrict) void * __cdecl xxx( void * _Memory );





More information about the cfe-commits mailing list