Skip to content

Commit d7a70e1

Browse files
committed
[path explore 3/7] Logical ops for resultt
The operators &= and |= can now be used between two safety_checkert::resultt objects. They return the "best" or "worst" of two results, and additionally assign that result to the LHS. The assignment operators are useful when repeatedly performing a safety check and wanting to return a single error code that either describes the best or worst outcome of all the safety checks combined.
1 parent c53d630 commit d7a70e1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/goto-programs/safety_checker.h

+36
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
// this is just an interface -- it won't actually do any checking!
1616

17+
#include <util/invariant.h>
1718
#include <util/message.h>
1819

1920
#include "goto_trace.h"
@@ -45,4 +46,39 @@ class safety_checkert:public messaget
4546
const namespacet &ns;
4647
};
4748

49+
/// \brief The worst of two results
50+
inline safety_checkert::resultt &
51+
operator&=(safety_checkert::resultt &a, safety_checkert::resultt const &b)
52+
{
53+
switch(a)
54+
{
55+
case safety_checkert::resultt::ERROR:
56+
return a;
57+
case safety_checkert::resultt::SAFE:
58+
a = b;
59+
return a;
60+
case safety_checkert::resultt::UNSAFE:
61+
a = b == safety_checkert::resultt::ERROR ? b : a;
62+
return a;
63+
}
64+
UNREACHABLE;
65+
}
66+
67+
/// \brief The best of two results
68+
inline safety_checkert::resultt &
69+
operator|=(safety_checkert::resultt &a, safety_checkert::resultt const &b)
70+
{
71+
switch(a)
72+
{
73+
case safety_checkert::resultt::SAFE:
74+
return a;
75+
case safety_checkert::resultt::ERROR:
76+
a = b;
77+
return a;
78+
case safety_checkert::resultt::UNSAFE:
79+
a = b == safety_checkert::resultt::SAFE ? b : a;
80+
return a;
81+
}
82+
UNREACHABLE;
83+
}
4884
#endif // CPROVER_GOTO_PROGRAMS_SAFETY_CHECKER_H

0 commit comments

Comments
 (0)