[cfe-commits] r116203 - in /cfe/trunk: 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
Francois Pichet
pichet2000 at gmail.com
Mon Oct 11 05:59:39 PDT 2010
Author: fpichet
Date: Mon Oct 11 07:59:39 2010
New Revision: 116203
URL: http://llvm.org/viewvc/llvm-project?rev=116203&view=rev
Log:
Add parsing support for Microsoft attributes. MS attributes will just be skipped and not inserted into the AST for now.
Added:
cfe/trunk/test/Parser/MicrosoftExtensions.cpp
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.c
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=116203&r1=116202&r2=116203&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Oct 11 07:59:39 2010
@@ -1399,6 +1399,7 @@
// 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);
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=116203&r1=116202&r2=116203&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Oct 11 07:59:39 2010
@@ -3182,6 +3182,10 @@
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();
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=116203&r1=116202&r2=116203&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Oct 11 07:59:39 2010
@@ -121,6 +121,8 @@
CXX0XAttributeList Attr;
if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
Attr = ParseCXX0XAttributes();
+ if (getLang().Microsoft && Tok.is(tok::l_square))
+ ParseMicrosoftAttributes();
ParseExternalDeclaration(Attr);
}
@@ -205,6 +207,8 @@
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 @@
CXX0XAttributeList Attr;
if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
Attr = ParseCXX0XAttributes();
+ if (getLang().Microsoft && Tok.is(tok::l_square))
+ ParseMicrosoftAttributes();
ParseExternalDeclaration(Attr);
}
@@ -1321,6 +1327,8 @@
// 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 @@
} 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);
+ }
+}
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=116203&r1=116202&r2=116203&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Mon Oct 11 07:59:39 2010
@@ -972,6 +972,9 @@
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())
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=116203&r1=116202&r2=116203&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Mon Oct 11 07:59:39 2010
@@ -406,6 +406,9 @@
CXX0XAttributeList Attr;
if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier())
Attr = ParseCXX0XAttributes();
+ if (getLang().Microsoft && Tok.is(tok::l_square))
+ ParseMicrosoftAttributes();
+
Result = ParseExternalDeclaration(Attr);
return false;
}
Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=116203&r1=116202&r2=116203&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.c Mon Oct 11 07:59:39 2010
@@ -79,6 +79,14 @@
_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)
{
Added: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=116203&view=auto
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (added)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Mon Oct 11 07:59:39 2010
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
+
+/* 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);
+
+namespace {
+ [returnvalue:SA_Post(attr=1)]
+ int foo2([SA_Post(attr=1)] void *param);
+}
+
+class T {
+ [returnvalue:SA_Post(attr=1)]
+ int foo3([SA_Post(attr=1)] void *param);
+};
+
+extern "C" {
+ [returnvalue:SA_Post(attr=1)]
+ int foo5([SA_Post(attr=1)] void *param);
+}
+
+
More information about the cfe-commits
mailing list