]> granicus.if.org Git - clang/commitdiff
Add parsing support for Microsoft attributes. MS attributes will just be skipped...
authorFrancois Pichet <pichet2000@gmail.com>
Mon, 11 Oct 2010 12:59:39 +0000 (12:59 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Mon, 11 Oct 2010 12:59:39 +0000 (12:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116203 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseDeclCXX.cpp
lib/Parse/ParseTentative.cpp
lib/Parse/Parser.cpp
test/Parser/MicrosoftExtensions.c
test/Parser/MicrosoftExtensions.cpp [new file with mode: 0644]

index f1548460e340465019cb17c1bbb411a3d7a57e81..cb28bde8d3145187b93474be778a1aab6dc3ce8d 100644 (file)
@@ -1399,6 +1399,7 @@ private:
   // EndLoc, if non-NULL, is filled with the location of the last token of
   // the attribute list.
   CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0);
+  void ParseMicrosoftAttributes();
   AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0);
   AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0);
   AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0);
index 3d29e9e702e0b4f54ea0a47183981fc399183bfd..e4c7569b61db338d109cbc9006df4a772e366118 100644 (file)
@@ -3182,6 +3182,10 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
       EllipsisLoc = ConsumeToken();     // Consume the ellipsis.
       break;
     }
+       
+    // Skip any Microsoft attributes before a param.
+    if (getLang().Microsoft && Tok.is(tok::l_square))
+      ParseMicrosoftAttributes();
 
     SourceLocation DSStart = Tok.getLocation();
 
index e1a97da9c2e8b49bec88fa325c4e9ba97431686a..c02f41a26816e1a4aeb93ca91c0b049d24446bc9 100644 (file)
@@ -121,6 +121,8 @@ Decl *Parser::ParseNamespace(unsigned Context,
     CXX0XAttributeList Attr;
     if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
       Attr = ParseCXX0XAttributes();
+    if (getLang().Microsoft && Tok.is(tok::l_square))
+      ParseMicrosoftAttributes();
     ParseExternalDeclaration(Attr);
   }
 
@@ -205,6 +207,8 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS,
   if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) {
     Attr = ParseCXX0XAttributes();
   }
+  if (getLang().Microsoft && Tok.is(tok::l_square))
+    ParseMicrosoftAttributes();
 
   if (Tok.isNot(tok::l_brace)) {
     DS.setExternInLinkageSpec(true);
@@ -224,6 +228,8 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS,
     CXX0XAttributeList Attr;
     if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
       Attr = ParseCXX0XAttributes();
+    if (getLang().Microsoft && Tok.is(tok::l_square))
+      ParseMicrosoftAttributes();
     ParseExternalDeclaration(Attr);
   }
 
@@ -1321,6 +1327,8 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   // Optional C++0x attribute-specifier
   if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
     AttrList = ParseCXX0XAttributes();
+  if (getLang().Microsoft && Tok.is(tok::l_square))
+    ParseMicrosoftAttributes();
 
   if (Tok.is(tok::kw_using)) {
     // FIXME: Check for template aliases
@@ -2116,3 +2124,21 @@ ExprResult Parser::ParseCXX0XAlignArgument(SourceLocation Start) {
   } else
     return ParseConstantExpression();
 }
+
+/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr]
+///
+/// [MS] ms-attribute:
+///             '[' token-seq ']'
+///
+/// [MS] ms-attribute-seq:
+///             ms-attribute[opt]
+///             ms-attribute ms-attribute-seq
+void Parser::ParseMicrosoftAttributes() {
+  assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
+
+  while (Tok.is(tok::l_square)) {
+    ConsumeBracket();
+    SkipUntil(tok::r_square, true, true);
+    ExpectAndConsume(tok::r_square, diag::err_expected_rsquare);
+  }
+}
index 43d856d85f360f6702e668f671d0e760e57e61e4..731822ecddd1265edfc7b1a2b9e64c1427516133 100644 (file)
@@ -972,6 +972,9 @@ Parser::TPResult Parser::TryParseParameterDeclarationClause() {
       return TPResult::True(); // '...' is a sign of a function declarator.
     }
 
+    if (getLang().Microsoft && Tok.is(tok::l_square))
+      ParseMicrosoftAttributes();
+
     // decl-specifier-seq
     TPResult TPR = TryParseDeclarationSpecifier();
     if (TPR != TPResult::Ambiguous())
index 8084088afcad5d7affa7e5dff9a07315419d9698..13c25f478dbfb4102005064ad99c63a8e1c8db17 100644 (file)
@@ -406,6 +406,9 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) {
   CXX0XAttributeList Attr;
   if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
     Attr = ParseCXX0XAttributes();
+  if (getLang().Microsoft && Tok.is(tok::l_square))
+    ParseMicrosoftAttributes();
+  
   Result = ParseExternalDeclaration(Attr);
   return false;
 }
index 58f5879c30293786ea42d6fe2993ef7b4377dc44..d90378136887a39004caf636b5773805a8c5d9d0 100644 (file)
@@ -79,6 +79,14 @@ void uuidof_test2()
   _uuidof(c);
 }
 
+/* Microsoft attribute tests */
+[repeatable][source_annotation_attribute( Parameter|ReturnValue )]
+struct SA_Post{ SA_Post(); int attr; };
+
+[returnvalue:SA_Post( attr=1)] 
+int foo1([SA_Post(attr=1)] void *param);
+
+
 
 void ms_intrinsics(int a)
 {
diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp
new file mode 100644 (file)
index 0000000..9f64b3f
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions\r
+\r
+/* Microsoft attribute tests */\r
+[repeatable][source_annotation_attribute( Parameter|ReturnValue )]\r
+struct SA_Post{ SA_Post(); int attr; };\r
+\r
+[returnvalue:SA_Post( attr=1)] \r
+int foo1([SA_Post(attr=1)] void *param);\r
+\r
+namespace {\r
+  [returnvalue:SA_Post(attr=1)] \r
+  int foo2([SA_Post(attr=1)] void *param);\r
+}\r
+\r
+class T {\r
+  [returnvalue:SA_Post(attr=1)] \r
+  int foo3([SA_Post(attr=1)] void *param);\r
+};\r
+\r
+extern "C" {\r
+  [returnvalue:SA_Post(attr=1)] \r
+  int foo5([SA_Post(attr=1)] void *param);\r
+}\r
+\r
+\r