blob: d18d2f802633aa967260cf9924e95a954ac564ed [file] [log] [blame]
//===--- RAIIObjectsForParser.h - RAII helpers for the parser ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines and implements the some simple RAII objects that are used
// by the parser to manage bits in recursion.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
#define LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
#include "clang/Parse/ParseDiagnostic.h"
namespace clang {
/// ExtensionRAIIObject - This saves the state of extension warnings when
/// constructed and disables them. When destructed, it restores them back to
/// the way they used to be. This is used to handle __extension__ in the
/// parser.
class ExtensionRAIIObject {
void operator=(const ExtensionRAIIObject &); // DO NOT IMPLEMENT
ExtensionRAIIObject(const ExtensionRAIIObject&); // DO NOT IMPLEMENT
Diagnostic &Diags;
public:
ExtensionRAIIObject(Diagnostic &diags) : Diags(diags) {
Diags.IncrementAllExtensionsSilenced();
}
~ExtensionRAIIObject() {
Diags.DecrementAllExtensionsSilenced();
}
};
// TODO: move GreaterThanIsOperatorScope here.
/// ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and
/// restores it when destroyed. This says that "foo:" should not be
/// considered a possible typo for "foo::" for error recovery purposes.
class ColonProtectionRAIIObject {
Parser &P;
bool OldVal;
public:
ColonProtectionRAIIObject(Parser &p) : P(p), OldVal(P.ColonIsSacred) {
P.ColonIsSacred = true;
}
~ColonProtectionRAIIObject() {
P.ColonIsSacred = OldVal;
}
};
} // end namespace clang
#endif