diff options
author | Chris Lattner <sabre@nondot.org> | 2008-10-20 06:45:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-10-20 06:45:43 +0000 |
commit | c46d1a1f8af67a87689d7db9eaf96027282ccaea (patch) | |
tree | e5a1cf61f756b78e1107f53230d9cb8b0e58175b /lib/Parse | |
parent | da3253d8a97981257185c89ced71ce137278b121 (diff) |
implement a couple fixme's by implementing __extension__ properly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57806 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse')
-rw-r--r-- | lib/Parse/ExtensionRAIIObject.h | 42 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 10 | ||||
-rw-r--r-- | lib/Parse/ParseExpr.cpp | 6 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 9 |
4 files changed, 54 insertions, 13 deletions
diff --git a/lib/Parse/ExtensionRAIIObject.h b/lib/Parse/ExtensionRAIIObject.h new file mode 100644 index 0000000000..e7d44464b5 --- /dev/null +++ b/lib/Parse/ExtensionRAIIObject.h @@ -0,0 +1,42 @@ +//===--- ExtensionRAIIObject.h - Use RAII for __extension__ -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines and implements the ExtensionRAIIObject class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_PARSE_EXTENSION_RAII_OBJECT_H +#define LLVM_CLANG_PARSE_EXTENSION_RAII_OBJECT_H + +#include "clang/Basic/Diagnostic.h" + +namespace clang { + + /// ExtensionRAIIObject - This saves the state of extension warnings when + /// constructed and disables them. When destructed, it restores them back to + /// the way they used to be. This is used to handle __extension__ in the + /// parser. + class ExtensionRAIIObject { + void operator=(const ExtensionRAIIObject &); // DO NOT IMPLEMENT + ExtensionRAIIObject(const ExtensionRAIIObject&); // DO NOT IMPLEMENT + Diagnostic &Diags; + bool OldState; + public: + ExtensionRAIIObject(Diagnostic &diags) : Diags(diags) { + OldState = Diags.getWarnOnExtensions(); + Diags.setWarnOnExtensions(false); + } + + ~ExtensionRAIIObject() { + Diags.setWarnOnExtensions(OldState); + } + }; +} + +#endif diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 041d876f56..27133d683c 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Parse/DeclSpec.h" #include "clang/Parse/Scope.h" +#include "ExtensionRAIIObject.h" #include "llvm/ADT/SmallSet.h" using namespace clang; @@ -659,15 +660,16 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { void Parser:: ParseStructDeclaration(DeclSpec &DS, llvm::SmallVectorImpl<FieldDeclarator> &Fields) { - // FIXME: When __extension__ is specified, disable extension diagnostics. - while (Tok.is(tok::kw___extension__)) + if (Tok.is(tok::kw___extension__)) { + // __extension__ silences extension warnings in the subexpression. + ExtensionRAIIObject O(Diags); // Use RAII to do this. ConsumeToken(); + return ParseStructDeclaration(DS, Fields); + } // Parse the common specifier-qualifiers-list piece. SourceLocation DSStart = Tok.getLocation(); ParseSpecifierQualifierList(DS); - // TODO: Does specifier-qualifier list correctly check that *something* is - // specified? // If there are no declarators, issue a warning. if (Tok.is(tok::semi)) { diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index d0f5eb2607..f6d7037ad1 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -22,7 +22,7 @@ #include "clang/Parse/Parser.h" #include "clang/Parse/DeclSpec.h" #include "clang/Parse/Scope.h" -#include "clang/Basic/Diagnostic.h" +#include "ExtensionRAIIObject.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallString.h" using namespace clang; @@ -521,13 +521,11 @@ Parser::ExprResult Parser::ParseCastExpression(bool isUnaryExpression) { case tok::kw___extension__:{//unary-expression:'__extension__' cast-expr [GNU] // __extension__ silences extension warnings in the subexpression. - bool SavedExtWarn = Diags.getWarnOnExtensions(); - Diags.setWarnOnExtensions(false); + ExtensionRAIIObject O(Diags); // Use RAII to do this. SourceLocation SavedLoc = ConsumeToken(); Res = ParseCastExpression(false); if (!Res.isInvalid) Res = Actions.ActOnUnaryOp(SavedLoc, SavedKind, Res.Val); - Diags.setWarnOnExtensions(SavedExtWarn); return Res; } case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 1b3adb95c0..e30e4f4fa8 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Parse/DeclSpec.h" #include "clang/Parse/Scope.h" +#include "ExtensionRAIIObject.h" #include "ParsePragma.h" using namespace clang; @@ -341,11 +342,9 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { // TODO: Invoke action for top-level semicolon. return 0; case tok::kw___extension__: { - ConsumeToken(); - // FIXME: Disable extension warnings. - DeclTy *RV = ParseExternalDeclaration(); - // FIXME: Restore extension warnings. - return RV; + // __extension__ silences extension warnings in the subexpression. + ExtensionRAIIObject O(Diags); // Use RAII to do this. + return ParseExternalDeclaration(); } case tok::kw_asm: { ExprResult Result = ParseSimpleAsm(); |