Chris Lattner | c46d1a1 | 2008-10-20 06:45:43 +0000 | [diff] [blame] | 1 | //===--- ExtensionRAIIObject.h - Use RAII for __extension__ -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines and implements the ExtensionRAIIObject class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_PARSE_EXTENSION_RAII_OBJECT_H |
| 15 | #define LLVM_CLANG_PARSE_EXTENSION_RAII_OBJECT_H |
| 16 | |
| 17 | #include "clang/Basic/Diagnostic.h" |
| 18 | |
| 19 | namespace clang { |
| 20 | |
| 21 | /// ExtensionRAIIObject - This saves the state of extension warnings when |
| 22 | /// constructed and disables them. When destructed, it restores them back to |
| 23 | /// the way they used to be. This is used to handle __extension__ in the |
| 24 | /// parser. |
| 25 | class ExtensionRAIIObject { |
| 26 | void operator=(const ExtensionRAIIObject &); // DO NOT IMPLEMENT |
| 27 | ExtensionRAIIObject(const ExtensionRAIIObject&); // DO NOT IMPLEMENT |
| 28 | Diagnostic &Diags; |
| 29 | bool OldState; |
| 30 | public: |
| 31 | ExtensionRAIIObject(Diagnostic &diags) : Diags(diags) { |
| 32 | OldState = Diags.getWarnOnExtensions(); |
| 33 | Diags.setWarnOnExtensions(false); |
| 34 | } |
| 35 | |
| 36 | ~ExtensionRAIIObject() { |
| 37 | Diags.setWarnOnExtensions(OldState); |
| 38 | } |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | #endif |