diff options
author | Steve Naroff <snaroff@apple.com> | 2008-12-24 20:59:21 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-12-24 20:59:21 +0000 |
commit | 3a9b7e0cffae23feefa46d46629e8921f8beb0f6 (patch) | |
tree | 36c15f2db609f3e8bb9dedf7f71c2cc85eefad2e /clang/lib | |
parent | 068b13d62aa0d65a8de10bf30a70c5a7e57d6c5d (diff) | |
download | bcm5719-llvm-3a9b7e0cffae23feefa46d46629e8921f8beb0f6.tar.gz bcm5719-llvm-3a9b7e0cffae23feefa46d46629e8921f8beb0f6.zip |
Add explicit "fuzzy" parse support for Microsoft declspec.
Remove previous __declspec macro that would effectively erase the construct prior to parsing.
llvm-svn: 61422
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 21 | ||||
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 4 |
3 files changed, 25 insertions, 1 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 7800fb51894..97ff07049f9 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -493,7 +493,6 @@ static void InitializePredefinedMacros(Preprocessor &PP, DefineBuiltinMacro(Buf, "__int16=short"); DefineBuiltinMacro(Buf, "__int32=int"); DefineBuiltinMacro(Buf, "__int64=long long"); - DefineBuiltinMacro(Buf, "__declspec(X)="); } diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index c7f92cf014d..a8052dc2904 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -192,6 +192,20 @@ AttributeList *Parser::ParseAttributes() { return CurrAttr; } +/// FuzzyParseMicrosoftDeclSpec. When -fms-extensions is enabled, this +/// routine is called to skip/ignore tokens that comprise the MS declspec. +void Parser::FuzzyParseMicrosoftDeclSpec() { + assert(Tok.is(tok::kw___declspec) && "Not a declspec!"); + ConsumeToken(); + if (Tok.is(tok::l_paren)) { + unsigned short savedParenCount = ParenCount; + do { + ConsumeAnyToken(); + } while (ParenCount > savedParenCount && Tok.isNot(tok::eof)); + } + return; +} + /// ParseDeclaration - Parse a full 'declaration', which consists of /// declaration-specifiers, some number of declarators, and a semicolon. /// 'Context' should be a Declarator::TheContext value. @@ -538,6 +552,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, case tok::kw___attribute: DS.AddAttributes(ParseAttributes()); continue; + + // Microsoft declspec support. + case tok::kw___declspec: + if (!PP.getLangOptions().Microsoft) + goto DoneWithDeclSpec; + FuzzyParseMicrosoftDeclSpec(); + continue; // storage-class-specifier case tok::kw_typedef: diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 1b0b811c88f..1d3de90060b 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -220,6 +220,10 @@ void Parser::ParseClassSpecifier(DeclSpec &DS, if (Tok.is(tok::kw___attribute)) Attr = ParseAttributes(); + // If declspecs exist after tag, parse them. + if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft) + FuzzyParseMicrosoftDeclSpec(); + // Parse the (optional) nested-name-specifier. CXXScopeSpec SS; if (getLang().CPlusPlus && MaybeParseCXXScopeSpecifier(SS)) { |