LCOV - code coverage report
Current view: top level - gcc - tristate.h (source / functions) Hit Total Coverage
Test: gcc.info Lines: 16 16 100.0 %
Date: 2020-04-04 11:58:09 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* "True" vs "False" vs "Unknown".
       2                 :            :    Copyright (C) 2019-2020 Free Software Foundation, Inc.
       3                 :            :    Contributed by David Malcolm <dmalcolm@redhat.com>.
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify it
       8                 :            : under the terms of the GNU General Public License as published by
       9                 :            : the Free Software Foundation; either version 3, or (at your option)
      10                 :            : any later version.
      11                 :            : 
      12                 :            : GCC is distributed in the hope that it will be useful, but
      13                 :            : WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :            : General Public License for more details.
      16                 :            : 
      17                 :            : You should have received a copy of the GNU General Public License
      18                 :            : along with GCC; see the file COPYING3.  If not see
      19                 :            : <http://www.gnu.org/licenses/>.  */
      20                 :            : 
      21                 :            : #ifndef GCC_TRISTATE_H
      22                 :            : #define GCC_TRISTATE_H
      23                 :            : 
      24                 :            : /* "True" vs "False" vs "Unknown".  */
      25                 :            : 
      26                 :            : class tristate {
      27                 :            :  public:
      28                 :            :   enum value {
      29                 :            :     TS_UNKNOWN,
      30                 :            :     TS_TRUE,
      31                 :            :     TS_FALSE
      32                 :            :   };
      33                 :            : 
      34                 :     202453 :   tristate (enum value val) : m_value (val) {}
      35                 :          4 :   tristate (bool val) : m_value (val ? TS_TRUE : TS_FALSE) {}
      36                 :         62 :   static tristate unknown () { return tristate (TS_UNKNOWN); }
      37                 :            : 
      38                 :            :   const char *as_string () const;
      39                 :            : 
      40                 :      44349 :   bool is_known () const { return m_value != TS_UNKNOWN; }
      41                 :     190052 :   bool is_true () const { return m_value == TS_TRUE; }
      42                 :      43129 :   bool is_false () const { return m_value == TS_FALSE; }
      43                 :            : 
      44                 :            :   tristate not_ () const;
      45                 :            :   tristate or_ (tristate other) const;
      46                 :            :   tristate and_ (tristate other) const;
      47                 :            : 
      48                 :       1522 :   bool operator== (const tristate &other) const
      49                 :            :   {
      50                 :       1518 :     return m_value == other.m_value;
      51                 :            :   }
      52                 :            : 
      53                 :          6 :   bool operator!= (const tristate &other) const
      54                 :            :   {
      55                 :          6 :     return m_value != other.m_value;
      56                 :            :   }
      57                 :            : 
      58                 :            :  private:
      59                 :            :   enum value m_value;
      60                 :            : };
      61                 :            : 
      62                 :            : /* Overloaded boolean operators on tristates.  */
      63                 :            : 
      64                 :            : inline tristate
      65                 :          6 : operator ! (tristate t)
      66                 :            : {
      67                 :          6 :   return t.not_ ();
      68                 :            : }
      69                 :            : 
      70                 :            : inline tristate
      71                 :         18 : operator || (tristate a, tristate b)
      72                 :            : {
      73                 :         18 :   return a.or_ (b);
      74                 :            : }
      75                 :            : 
      76                 :            : inline tristate
      77                 :         18 : operator && (tristate a, tristate b)
      78                 :            : {
      79                 :         18 :   return a.and_ (b);
      80                 :            : }
      81                 :            : 
      82                 :            : #endif /* GCC_TRISTATE_H */

Generated by: LCOV version 1.0

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto --enable-host-shared. GCC test suite is run with the built compiler.