Skip to content

Commit 1458009

Browse files
author
martin
committed
Move the result enum out so message can be used in _resultt
1 parent 81a0c57 commit 1458009

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

src/goto-analyzer/static_verifier.cpp

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,54 @@ Author: Martin Brain, [email protected]
1818

1919
#include <analyses/ai.h>
2020

21+
// clang-format off
22+
enum class statust { TRUE, FALSE, BOTTOM, UNKNOWN };
23+
// clang-format on
24+
25+
/// Makes a status message string from a status.
26+
static const char *message(const statust &status)
27+
{
28+
switch(status)
29+
{
30+
case statust::TRUE:
31+
return "SUCCESS";
32+
case statust::FALSE:
33+
return "FAILURE (if reachable)";
34+
case statust::BOTTOM:
35+
return "SUCCESS (unreachable)";
36+
case statust::UNKNOWN:
37+
return "UNKNOWN";
38+
}
39+
UNREACHABLE;
40+
}
41+
2142
struct static_verifier_resultt
2243
{
23-
// clang-format off
24-
enum statust { TRUE, FALSE, BOTTOM, UNKNOWN } status;
25-
// clang-format on
44+
statust status;
2645
source_locationt source_location;
2746
irep_idt function_id;
2847
};
2948

30-
static static_verifier_resultt::statust
49+
static statust
3150
check_assertion(const ai_domain_baset &domain, exprt e, const namespacet &ns)
3251
{
3352
if(domain.is_bottom())
3453
{
35-
return static_verifier_resultt::BOTTOM;
54+
return statust::BOTTOM;
3655
}
3756

3857
domain.ai_simplify(e, ns);
3958
if(e.is_true())
4059
{
41-
return static_verifier_resultt::TRUE;
60+
return statust::TRUE;
4261
}
4362
else if(e.is_false())
4463
{
45-
return static_verifier_resultt::FALSE;
64+
return statust::FALSE;
4665
}
4766
else
4867
{
49-
return static_verifier_resultt::UNKNOWN;
68+
return statust::UNKNOWN;
5069
}
5170

5271
UNREACHABLE;
@@ -72,7 +91,7 @@ static static_verifier_resultt check_assertion(
7291

7392
if(trace_set.size() == 0) // i.e. unreachable
7493
{
75-
result.status = static_verifier_resultt::BOTTOM;
94+
result.status = statust::BOTTOM;
7695
}
7796
else if(trace_set.size() == 1)
7897
{
@@ -95,16 +114,16 @@ static static_verifier_resultt check_assertion(
95114
result.status = check_assertion(*dp, e, ns);
96115
switch(result.status)
97116
{
98-
case static_verifier_resultt::BOTTOM:
117+
case statust::BOTTOM:
99118
++unreachable_traces;
100119
break;
101-
case static_verifier_resultt::TRUE:
120+
case statust::TRUE:
102121
++true_traces;
103122
break;
104-
case static_verifier_resultt::FALSE:
123+
case statust::FALSE:
105124
++false_traces;
106125
break;
107-
case static_verifier_resultt::UNKNOWN:
126+
case statust::UNKNOWN:
108127
++unknown_traces;
109128
break;
110129
default:
@@ -116,7 +135,7 @@ static static_verifier_resultt check_assertion(
116135
if(unknown_traces != 0)
117136
{
118137
// If any trace is unknown, the final result must be unknown
119-
result.status = static_verifier_resultt::UNKNOWN;
138+
result.status = statust::UNKNOWN;
120139
}
121140
else
122141
{
@@ -129,13 +148,13 @@ static static_verifier_resultt check_assertion(
129148
INVARIANT(
130149
unreachable_traces == trace_set.size(),
131150
"All traces must not reach the assertion");
132-
result.status = static_verifier_resultt::BOTTOM;
151+
result.status = statust::BOTTOM;
133152
}
134153
else
135154
{
136155
// At least one trace (may) reach it.
137156
// All traces that reach it are safe.
138-
result.status = static_verifier_resultt::TRUE;
157+
result.status = statust::TRUE;
139158
}
140159
}
141160
else
@@ -144,7 +163,7 @@ static static_verifier_resultt check_assertion(
144163
if(true_traces == 0)
145164
{
146165
// All traces that (may) reach it are false
147-
result.status = static_verifier_resultt::FALSE;
166+
result.status = statust::FALSE;
148167
}
149168
else
150169
{
@@ -156,7 +175,7 @@ static static_verifier_resultt check_assertion(
156175
// Given that all results of FAILURE from this analysis are
157176
// caveated with some reachability questions, the following is not
158177
// entirely unreasonable.
159-
result.status = static_verifier_resultt::FALSE;
178+
result.status = statust::FALSE;
160179
}
161180
}
162181
}
@@ -185,20 +204,20 @@ void static_verifier(
185204

186205
switch(result.status)
187206
{
188-
case static_verifier_resultt::TRUE:
207+
case statust::TRUE:
189208
// if the condition simplifies to true the assertion always succeeds
190209
property_status = property_statust::PASS;
191210
break;
192-
case static_verifier_resultt::FALSE:
211+
case statust::FALSE:
193212
// if the condition simplifies to false the assertion always fails
194213
property_status = property_statust::FAIL;
195214
break;
196-
case static_verifier_resultt::BOTTOM:
215+
case statust::BOTTOM:
197216
// if the domain state is bottom then the assertion is definitely
198217
// unreachable
199218
property_status = property_statust::NOT_REACHABLE;
200219
break;
201-
case static_verifier_resultt::UNKNOWN:
220+
case statust::UNKNOWN:
202221
// if the condition isn't definitely true, false or unreachable
203222
// we don't know whether or not it may fail
204223
property_status = property_statust::UNKNOWN;
@@ -209,23 +228,6 @@ void static_verifier(
209228
}
210229
}
211230

212-
/// Makes a status message string from a status.
213-
static const char *message(const static_verifier_resultt::statust &status)
214-
{
215-
switch(status)
216-
{
217-
case static_verifier_resultt::TRUE:
218-
return "SUCCESS";
219-
case static_verifier_resultt::FALSE:
220-
return "FAILURE (if reachable)";
221-
case static_verifier_resultt::BOTTOM:
222-
return "SUCCESS (unreachable)";
223-
case static_verifier_resultt::UNKNOWN:
224-
return "UNKNOWN";
225-
}
226-
UNREACHABLE;
227-
}
228-
229231
static void static_verifier_json(
230232
const std::vector<static_verifier_resultt> &results,
231233
messaget &m,
@@ -339,19 +341,19 @@ static void static_verifier_console(
339341

340342
switch(result.status)
341343
{
342-
case static_verifier_resultt::TRUE:
344+
case statust::TRUE:
343345
m.result() << m.green << "SUCCESS" << m.reset;
344346
break;
345347

346-
case static_verifier_resultt::FALSE:
348+
case statust::FALSE:
347349
m.result() << m.red << "FAILURE" << m.reset << " (if reachable)";
348350
break;
349351

350-
case static_verifier_resultt::BOTTOM:
352+
case statust::BOTTOM:
351353
m.result() << m.green << "SUCCESS" << m.reset << " (unreachable)";
352354
break;
353355

354-
case static_verifier_resultt::UNKNOWN:
356+
case statust::UNKNOWN:
355357
m.result() << m.yellow << "UNKNOWN" << m.reset;
356358
break;
357359
}
@@ -404,16 +406,16 @@ bool static_verifier(
404406

405407
switch(results.back().status)
406408
{
407-
case static_verifier_resultt::BOTTOM:
409+
case statust::BOTTOM:
408410
++pass;
409411
break;
410-
case static_verifier_resultt::TRUE:
412+
case statust::TRUE:
411413
++pass;
412414
break;
413-
case static_verifier_resultt::FALSE:
415+
case statust::FALSE:
414416
++fail;
415417
break;
416-
case static_verifier_resultt::UNKNOWN:
418+
case statust::UNKNOWN:
417419
++unknown;
418420
break;
419421
default:

0 commit comments

Comments
 (0)