ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
threeval.h
Go to the documentation of this file.
1#ifndef CPROVER_THREEVAL_H
2#define CPROVER_THREEVAL_H
3#include <ostream>
4
5//
6// three valued logic
7//
8
9class tvt
10{
11public:
12 typedef enum
13 {
17 } tv_enumt;
18
19 bool is_true() const
20 {
21 return value == TV_TRUE;
22 }
23 bool is_false() const
24 {
25 return value == TV_FALSE;
26 }
27 bool is_unknown() const
28 {
29 return value == TV_UNKNOWN;
30 }
31 bool is_known() const
32 {
33 return value == TV_TRUE || value == TV_FALSE;
34 }
35
36 const char *to_string() const;
37
39 {
40 return value;
41 }
42
43 tvt() = default;
44
45 explicit tvt(bool b) : value(b ? TV_TRUE : TV_FALSE)
46 {
47 }
48
49 explicit tvt(tv_enumt v) : value(v)
50 {
51 }
52
54 {
55 if (value == TV_TRUE)
56 return tvt(TV_FALSE);
57 if (value == TV_FALSE)
58 return tvt(TV_TRUE);
59
60 return tvt(value);
61 }
62
63 friend bool operator==(const tvt a, const tvt b)
64 {
65 return a.value == b.value;
66 }
67
68 friend bool operator!=(const tvt a, const tvt b)
69 {
70 return a.value != b.value;
71 }
72
73 friend tvt operator&&(const tvt a, const tvt b)
74 {
75 if (a.value == TV_FALSE || b.value == TV_FALSE)
76 return tvt(TV_FALSE);
77 if (a.value == TV_TRUE && b.value == TV_TRUE)
78 return tvt(TV_TRUE);
79 return tvt(TV_UNKNOWN);
80 }
81
82 friend tvt operator||(const tvt a, const tvt b)
83 {
84 if (a.value == TV_TRUE || b.value == TV_TRUE)
85 return tvt(TV_TRUE);
86 if (a.value == TV_FALSE && b.value == TV_FALSE)
87 return tvt(TV_FALSE);
88 return tvt(TV_UNKNOWN);
89 }
90
91 friend tvt operator!(const tvt a)
92 {
93 if (a.value == TV_UNKNOWN)
94 return tvt(TV_UNKNOWN);
95 if (a.value == TV_TRUE)
96 return tvt(TV_FALSE);
97 return tvt(TV_TRUE);
98 }
99
100 friend std::ostream &operator<<(std::ostream &out, const tvt &a)
101 {
102 return out << a.to_string();
103 }
104
105protected:
107};
108
109#endif
tv_enumt value
Definition threeval.h:106
friend tvt operator!(const tvt a)
Definition threeval.h:91
tv_enumt
Definition threeval.h:13
@ TV_TRUE
Definition threeval.h:16
@ TV_UNKNOWN
Definition threeval.h:15
@ TV_FALSE
Definition threeval.h:14
friend bool operator!=(const tvt a, const tvt b)
Definition threeval.h:68
friend tvt operator||(const tvt a, const tvt b)
Definition threeval.h:82
bool is_known() const
Definition threeval.h:31
friend bool operator==(const tvt a, const tvt b)
Definition threeval.h:63
tvt(bool b)
Definition threeval.h:45
friend tvt operator&&(const tvt a, const tvt b)
Definition threeval.h:73
bool is_unknown() const
Definition threeval.h:27
const char * to_string() const
Definition threeval.cpp:3
bool is_false() const
Definition threeval.h:23
bool is_true() const
Definition threeval.h:19
friend std::ostream & operator<<(std::ostream &out, const tvt &a)
Definition threeval.h:100
tv_enumt get_value() const
Definition threeval.h:38
tvt invert()
Definition threeval.h:53
tvt()=default
tvt(tv_enumt v)
Definition threeval.h:49