zcov: / lib/Parse/RAIIObjectsForParser.h


Files: 1 Branches Taken: 0.0% 0 / 0
Generated: 2010-02-10 01:31 Branches Executed: 0.0% 0 / 0
Line Coverage: 100.0% 23 / 23


Programs: 12 Runs 18108


       1                 : //===--- RAIIObjectsForParser.h - RAII helpers for the parser ---*- 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 some simple RAII objects that are used
      11                 : // by the parser to manage bits in recursion.
      12                 : //
      13                 : //===----------------------------------------------------------------------===//
      14                 : 
      15                 : #ifndef LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
      16                 : #define LLVM_CLANG_PARSE_RAII_OBJECTS_FOR_PARSER_H
      17                 : 
      18                 : #include "clang/Parse/ParseDiagnostic.h"
      19                 : 
      20                 : namespace clang {
      21                 :   // TODO: move ParsingDeclRAIIObject here.
      22                 :   // TODO: move ParsingClassDefinition here.
      23                 :   // TODO: move TentativeParsingAction here.
      24                 :   
      25                 :   
      26                 :   /// ExtensionRAIIObject - This saves the state of extension warnings when
      27                 :   /// constructed and disables them.  When destructed, it restores them back to
      28                 :   /// the way they used to be.  This is used to handle __extension__ in the
      29                 :   /// parser.
      30                 :   class ExtensionRAIIObject {
      31                 :     void operator=(const ExtensionRAIIObject &);     // DO NOT IMPLEMENT
      32                 :     ExtensionRAIIObject(const ExtensionRAIIObject&); // DO NOT IMPLEMENT
      33                 :     Diagnostic &Diags;
      34                 :   public:
      35              549:     ExtensionRAIIObject(Diagnostic &diags) : Diags(diags) {
      36              549:       Diags.IncrementAllExtensionsSilenced();
      37              549:     }
      38                 : 
      39              549:     ~ExtensionRAIIObject() {
      40              549:       Diags.DecrementAllExtensionsSilenced();
      41              549:     }
      42                 :   };
      43                 :   
      44                 :   /// ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and
      45                 :   /// restores it when destroyed.  This says that "foo:" should not be
      46                 :   /// considered a possible typo for "foo::" for error recovery purposes.
      47                 :   class ColonProtectionRAIIObject {
      48                 :     Parser &P;
      49                 :     bool OldVal;
      50                 :   public:
      51            27424:     ColonProtectionRAIIObject(Parser &p, bool Value = true)
      52            27424:       : P(p), OldVal(P.ColonIsSacred) {
      53            27424:       P.ColonIsSacred = Value;
      54            27424:     }
      55                 :     
      56                 :     /// restore - This can be used to restore the state early, before the dtor
      57                 :     /// is run.
      58            27724:     void restore() {
      59            27724:       P.ColonIsSacred = OldVal;
      60            27724:     }
      61                 :     
      62            27424:     ~ColonProtectionRAIIObject() {
      63            27424:       restore();
      64            27424:     }
      65                 :   };
      66                 :   
      67                 :   /// \brief RAII object that makes '>' behave either as an operator
      68                 :   /// or as the closing angle bracket for a template argument list.
      69                 :   class GreaterThanIsOperatorScope {
      70                 :     bool &GreaterThanIsOperator;
      71                 :     bool OldGreaterThanIsOperator;
      72                 :   public:
      73            12080:     GreaterThanIsOperatorScope(bool &GTIO, bool Val)
      74            12080:     : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
      75            12080:       GreaterThanIsOperator = Val;
      76            12080:     }
      77                 :     
      78            12080:     ~GreaterThanIsOperatorScope() {
      79            12080:       GreaterThanIsOperator = OldGreaterThanIsOperator;
      80            12080:     }
      81                 :   };
      82                 :   
      83                 : } // end namespace clang
      84                 : 
      85                 : #endif

Generated: 2010-02-10 01:31 by zcov