blob: cc7c8e21705c14adeefc3a8f29ad386c18b53f79 [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
Chris Lattner500d3292009-01-29 05:15:15 +000017#include "clang/Parse/ParseDiagnostic.h"
Chris Lattnerc46d1a12008-10-20 06:45:43 +000018
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;
Chris Lattnerc46d1a12008-10-20 06:45:43 +000029 public:
30 ExtensionRAIIObject(Diagnostic &diags) : Diags(diags) {
Chris Lattner27ceb9d2009-04-15 07:01:18 +000031 Diags.IncrementAllExtensionsSilenced();
Chris Lattnerc46d1a12008-10-20 06:45:43 +000032 }
Mike Stump1eb44332009-09-09 15:08:12 +000033
Chris Lattnerc46d1a12008-10-20 06:45:43 +000034 ~ExtensionRAIIObject() {
Chris Lattner27ceb9d2009-04-15 07:01:18 +000035 Diags.DecrementAllExtensionsSilenced();
Chris Lattnerc46d1a12008-10-20 06:45:43 +000036 }
37 };
38}
39
40#endif