LCOV - code coverage report
Current view: top level - include/llvm/Support - SaveAndRestore.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 4 4 100.0 %
Date: 2017-09-14 15:23:50 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- SaveAndRestore.h - Utility  -------------------------------*- 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             : /// \file
      11             : /// This file provides utility classes that use RAII to save and restore
      12             : /// values.
      13             : ///
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_SUPPORT_SAVEANDRESTORE_H
      17             : #define LLVM_SUPPORT_SAVEANDRESTORE_H
      18             : 
      19             : namespace llvm {
      20             : 
      21             : /// A utility class that uses RAII to save and restore the value of a variable.
      22             : template <typename T> struct SaveAndRestore {
      23     2098119 :   SaveAndRestore(T &X) : X(X), OldValue(X) {}
      24     4704486 :   SaveAndRestore(T &X, const T &NewValue) : X(X), OldValue(X) {
      25     4704486 :     X = NewValue;
      26             :   }
      27     6795362 :   ~SaveAndRestore() { X = OldValue; }
      28             :   T get() { return OldValue; }
      29             : 
      30             : private:
      31             :   T &X;
      32             :   T OldValue;
      33             : };
      34             : 
      35             : /// Similar to \c SaveAndRestore.  Operates only on bools; the old value of a
      36             : /// variable is saved, and during the dstor the old value is or'ed with the new
      37             : /// value.
      38             : struct SaveOr {
      39             :   SaveOr(bool &X) : X(X), OldValue(X) { X = false; }
      40             :   ~SaveOr() { X |= OldValue; }
      41             : 
      42             : private:
      43             :   bool &X;
      44             :   const bool OldValue;
      45             : };
      46             : 
      47             : } // namespace llvm
      48             : 
      49             : #endif

Generated by: LCOV version 1.13