From: Francois Pichet Date: Mon, 11 Oct 2010 12:59:39 +0000 (+0000) Subject: Add parsing support for Microsoft attributes. MS attributes will just be skipped... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=334d47e92e9f241576fdeb7477b69a03136ba854;p=clang Add parsing support for Microsoft attributes. MS attributes will just be skipped and not inserted into the AST for now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116203 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index f1548460e3..cb28bde8d3 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -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); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 3d29e9e702..e4c7569b61 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -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(); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index e1a97da9c2..c02f41a268 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -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); + } +} diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp index 43d856d85f..731822ecdd 100644 --- a/lib/Parse/ParseTentative.cpp +++ b/lib/Parse/ParseTentative.cpp @@ -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()) diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 8084088afc..13c25f478d 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -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; } diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c index 58f5879c30..d903781368 100644 --- a/test/Parser/MicrosoftExtensions.c +++ b/test/Parser/MicrosoftExtensions.c @@ -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 index 0000000000..9f64b3fe42 --- /dev/null +++ b/test/Parser/MicrosoftExtensions.cpp @@ -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); +} + +