blob: e7d44464b5858c95ef9c5e106efd0fc3d17a2b5e [file] [log] [blame]
Chris Lattnerc46d1a12008-10-20 06:45:43 +00001//===--- 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
19namespace 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