blob: d18d2f802633aa967260cf9924e95a954ac564ed [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 };
Chris Lattner08d92ec2009-12-10 00:32:41 +000039
40 // TODO: move GreaterThanIsOperatorScope here.
41
42 /// ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and
43 /// restores it when destroyed. This says that "foo:" should not be
44 /// considered a possible typo for "foo::" for error recovery purposes.
45 class ColonProtectionRAIIObject {
46 Parser &P;
47 bool OldVal;
48 public:
49 ColonProtectionRAIIObject(Parser &p) : P(p), OldVal(P.ColonIsSacred) {
50 P.ColonIsSacred = true;
51 }
52
53 ~ColonProtectionRAIIObject() {
54 P.ColonIsSacred = OldVal;
55 }
56 };
57
58} // end namespace clang
Chris Lattnerc46d1a12008-10-20 06:45:43 +000059
60#endif