[cfe-commits] r73056 - in /cfe/trunk: include/clang/Parse/AttributeList.h include/clang/Parse/Parser.h lib/Parse/AttributeList.cpp lib/Parse/ParseDecl.cpp lib/Parse/ParseDeclCXX.cpp
Eli Friedman
eli.friedman at gmail.com
Mon Jun 8 00:21:15 PDT 2009
Author: efriedma
Date: Mon Jun 8 02:21:15 2009
New Revision: 73056
URL: http://llvm.org/viewvc/llvm-project?rev=73056&view=rev
Log:
Add real parsing for __declspec. It doesn't make much of a difference
at the moment because we ignore the result.
Modified:
cfe/trunk/include/clang/Parse/AttributeList.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/AttributeList.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=73056&r1=73055&r2=73056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Mon Jun 8 02:21:15 2009
@@ -38,13 +38,14 @@
ActionBase::ExprTy **Args;
unsigned NumArgs;
AttributeList *Next;
+ bool DeclspecAttribute;
AttributeList(const AttributeList &); // DO NOT IMPLEMENT
void operator=(const AttributeList &); // DO NOT IMPLEMENT
public:
AttributeList(IdentifierInfo *AttrName, SourceLocation AttrLoc,
IdentifierInfo *ParmName, SourceLocation ParmLoc,
ActionBase::ExprTy **args, unsigned numargs,
- AttributeList *Next);
+ AttributeList *Next, bool declspec = false);
~AttributeList();
enum Kind { // Please keep this list alphabetized.
@@ -103,6 +104,7 @@
IdentifierInfo *getName() const { return AttrName; }
SourceLocation getLoc() const { return AttrLoc; }
IdentifierInfo *getParameterName() const { return ParmName; }
+ bool isDeclspecAttribute() const { return DeclspecAttribute; }
Kind getKind() const { return getKind(getName()); }
static Kind getKind(const IdentifierInfo *Name);
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=73056&r1=73055&r2=73056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Jun 8 02:21:15 2009
@@ -1064,7 +1064,7 @@
// EndLoc, if non-NULL, is filled with the location of the last token of
// the attribute list.
AttributeList *ParseAttributes(SourceLocation *EndLoc = 0);
- void FuzzyParseMicrosoftDeclSpec();
+ AttributeList *ParseMicrosoftDeclSpec();
void ParseTypeofSpecifier(DeclSpec &DS);
/// DeclaratorScopeObj - RAII object used in Parser::ParseDirectDeclarator to
Modified: cfe/trunk/lib/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/AttributeList.cpp?rev=73056&r1=73055&r2=73056&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/AttributeList.cpp (original)
+++ cfe/trunk/lib/Parse/AttributeList.cpp Mon Jun 8 02:21:15 2009
@@ -18,9 +18,9 @@
AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
IdentifierInfo *pName, SourceLocation pLoc,
ActionBase::ExprTy **ExprList, unsigned numArgs,
- AttributeList *n)
+ AttributeList *n, bool declspec)
: AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
- NumArgs(numArgs), Next(n) {
+ NumArgs(numArgs), Next(n), DeclspecAttribute(declspec) {
if (numArgs == 0)
Args = 0;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=73056&r1=73055&r2=73056&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Jun 8 02:21:15 2009
@@ -200,18 +200,50 @@
return CurrAttr;
}
-/// FuzzyParseMicrosoftDeclSpec. When -fms-extensions is enabled, this
-/// routine is called to skip/ignore tokens that comprise the MS declspec.
-void Parser::FuzzyParseMicrosoftDeclSpec() {
+/// ParseMicrosoftDeclSpec - Parse an __declspec construct
+///
+/// [MS] decl-specifier:
+/// __declspec ( extended-decl-modifier-seq )
+///
+/// [MS] extended-decl-modifier-seq:
+/// extended-decl-modifier[opt]
+/// extended-decl-modifier extended-decl-modifier-seq
+
+AttributeList* Parser::ParseMicrosoftDeclSpec() {
assert(Tok.is(tok::kw___declspec) && "Not a declspec!");
+
+ AttributeList *CurrAttr = 0;
ConsumeToken();
- if (Tok.is(tok::l_paren)) {
- unsigned short savedParenCount = ParenCount;
- do {
- ConsumeAnyToken();
- } while (ParenCount > savedParenCount && Tok.isNot(tok::eof));
- }
- return;
+ if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
+ "declspec")) {
+ SkipUntil(tok::r_paren, true); // skip until ) or ;
+ return CurrAttr;
+ }
+ while (Tok.is(tok::identifier) || Tok.is(tok::kw_restrict)) {
+ IdentifierInfo *AttrName = Tok.getIdentifierInfo();
+ SourceLocation AttrNameLoc = ConsumeToken();
+ if (Tok.is(tok::l_paren)) {
+ ConsumeParen();
+ // FIXME: This doesn't parse __declspec(property(get=get_func_name))
+ // correctly.
+ OwningExprResult ArgExpr(ParseAssignmentExpression());
+ if (!ArgExpr.isInvalid()) {
+ ExprTy* ExprList = ArgExpr.take();
+ CurrAttr = new AttributeList(AttrName, AttrNameLoc, 0,
+ SourceLocation(), &ExprList, 1,
+ CurrAttr, true);
+ }
+ if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
+ SkipUntil(tok::r_paren, false);
+ } else {
+ CurrAttr = new AttributeList(AttrName, AttrNameLoc, 0, SourceLocation(),
+ 0, 0, CurrAttr, true);
+ }
+ }
+ if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
+ SkipUntil(tok::r_paren, false);
+ // FIXME: Return the attributes once we have some Sema support!
+ return 0;
}
/// ParseDeclaration - Parse a full 'declaration', which consists of
@@ -809,7 +841,7 @@
case tok::kw___declspec:
if (!PP.getLangOptions().Microsoft)
goto DoneWithDeclSpec;
- FuzzyParseMicrosoftDeclSpec();
+ DS.AddAttributes(ParseMicrosoftDeclSpec());
continue;
// Microsoft single token adornments.
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=73056&r1=73055&r2=73056&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Jun 8 02:21:15 2009
@@ -410,7 +410,8 @@
// If declspecs exist after tag, parse them.
if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft)
- FuzzyParseMicrosoftDeclSpec();
+ // FIXME: Need to do something with the attributes!
+ ParseMicrosoftDeclSpec();
// Parse the (optional) nested-name-specifier.
CXXScopeSpec SS;
More information about the cfe-commits
mailing list