GCC Middle and Back End API Reference
tristate.h
Go to the documentation of this file.
1/* "True" vs "False" vs "Unknown".
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
26class tristate {
27 public:
33
34 tristate (enum value val) : m_value (val) {}
35 tristate (bool val) : m_value (val ? TS_TRUE : TS_FALSE) {}
36 static tristate unknown () { return tristate (TS_UNKNOWN); }
37
38 const char *as_string () const;
39
40 bool is_known () const { return m_value != TS_UNKNOWN; }
41 bool is_unknown () const { return m_value == TS_UNKNOWN; }
42 bool is_true () const { return m_value == TS_TRUE; }
43 bool is_false () const { return m_value == TS_FALSE; }
44
45 tristate not_ () const;
46 tristate or_ (tristate other) const;
47 tristate and_ (tristate other) const;
48
49 bool operator== (const tristate &other) const
50 {
51 return m_value == other.m_value;
52 }
53
54 bool operator!= (const tristate &other) const
55 {
56 return m_value != other.m_value;
57 }
58
59 enum value get_value () const { return m_value; }
60
61 private:
63};
64
65/* Overloaded boolean operators on tristates. */
66
67inline tristate
69{
70 return t.not_ ();
71}
72
73inline tristate
75{
76 return a.or_ (b);
77}
78
79inline tristate
81{
82 return a.and_ (b);
83}
84
85#endif /* GCC_TRISTATE_H */
Definition tristate.h:26
tristate(enum value val)
Definition tristate.h:34
enum value m_value
Definition tristate.h:62
bool is_unknown() const
Definition tristate.h:41
const char * as_string() const
Definition tristate.cc:28
bool operator==(const tristate &other) const
Definition tristate.h:49
tristate(bool val)
Definition tristate.h:35
value
Definition tristate.h:28
@ TS_FALSE
Definition tristate.h:31
@ TS_TRUE
Definition tristate.h:30
@ TS_UNKNOWN
Definition tristate.h:29
bool is_false() const
Definition tristate.h:43
enum value get_value() const
Definition tristate.h:59
static tristate unknown()
Definition tristate.h:36
bool is_true() const
Definition tristate.h:42
tristate and_(tristate other) const
Definition tristate.cc:79
tristate not_() const
Definition tristate.cc:44
tristate or_(tristate other) const
Definition tristate.cc:60
bool is_known() const
Definition tristate.h:40
bool operator!=(const tristate &other) const
Definition tristate.h:54
Ca const poly_int< N, Cb > & b
Definition poly-int.h:767
Ca & a
Definition poly-int.h:766
tristate operator||(tristate a, tristate b)
Definition tristate.h:74
tristate operator&&(tristate a, tristate b)
Definition tristate.h:80
tristate operator!(tristate t)
Definition tristate.h:68