blob: d642da58d5031d300c54c9865a9535d23d655c6a [file] [log] [blame]
Chris Lattnerd167ca02009-12-10 00:21:05 +00001//===--- RAIIObjectsForParser.h - RAII helpers for the parser ---*- C++ -*-===//
Chris Lattnerc46d1a12008-10-20 06:45:43 +00002//
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//
Chris Lattnerd167ca02009-12-10 00:21:05 +000010// This file defines and implements the some simple RAII objects that are used
11// by the parser to manage bits in recursion.
Chris Lattnerc46d1a12008-10-20 06:45:43 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattnerd167ca02009-12-10 00:21:05 +000015#ifndef LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
16#define LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
Chris Lattnerc46d1a12008-10-20 06:45:43 +000017
Chris Lattner500d3292009-01-29 05:15:15 +000018#include "clang/Parse/ParseDiagnostic.h"
Chris Lattnerc46d1a12008-10-20 06:45:43 +000019
20namespace clang {
21
22 /// ExtensionRAIIObject - This saves the state of extension warnings when
23 /// constructed and disables them. When destructed, it restores them back to
24 /// the way they used to be. This is used to handle __extension__ in the
25 /// parser.
26 class ExtensionRAIIObject {
27 void operator=(const ExtensionRAIIObject &); // DO NOT IMPLEMENT
28 ExtensionRAIIObject(const ExtensionRAIIObject&); // DO NOT IMPLEMENT
29 Diagnostic &Diags;
Chris Lattnerc46d1a12008-10-20 06:45:43 +000030 public:
31 ExtensionRAIIObject(Diagnostic &diags) : Diags(diags) {
Chris Lattner27ceb9d2009-04-15 07:01:18 +000032 Diags.IncrementAllExtensionsSilenced();
Chris Lattnerc46d1a12008-10-20 06:45:43 +000033 }
Mike Stump1eb44332009-09-09 15:08:12 +000034
Chris Lattnerc46d1a12008-10-20 06:45:43 +000035 ~ExtensionRAIIObject() {
Chris Lattner27ceb9d2009-04-15 07:01:18 +000036 Diags.DecrementAllExtensionsSilenced();
Chris Lattnerc46d1a12008-10-20 06:45:43 +000037 }
38 };
39}
40
41#endif