@@ -16,12 +16,13 @@ Author: Daniel Kroening, kroening@kroening.com
1616#include < fstream>
1717#include < iostream>
1818
19- #include < util/string2int.h>
20- #include < util/simplify_expr.h>
2119#include < util/arith_tools.h>
22- #include < util/std_expr.h>
23- #include < util/guard.h>
20+ #include < util/exception_utils.h>
2421#include < util/format_expr.h>
22+ #include < util/guard.h>
23+ #include < util/simplify_expr.h>
24+ #include < util/std_expr.h>
25+ #include < util/string2int.h>
2526
2627void symex_slice_by_tracet::slice_by_trace (
2728 std::string trace_files,
@@ -79,6 +80,11 @@ void symex_slice_by_tracet::slice_by_trace(
7980 {
8081 exprt g_copy (*i);
8182
83+ DATA_INVARIANT (
84+ g_copy.id () == ID_symbol || g_copy.id () == ID_not ||
85+ g_copy.id () == ID_and || g_copy.id () == ID_constant,
86+ " guards should only be and, symbol, constant, or `not'" );
87+
8288 if (g_copy.id ()==ID_symbol || g_copy.id () == ID_not)
8389 {
8490 g_copy.make_not ();
@@ -92,10 +98,6 @@ void symex_slice_by_tracet::slice_by_trace(
9298 simplify (copy_last, ns);
9399 implications.insert (copy_last);
94100 }
95- else if (!(g_copy.id ()==ID_constant))
96- {
97- throw " guards should only be and, symbol, constant, or `not'" ;
98- }
99101 }
100102
101103 slice_SSA_steps (equation, implications); // Slice based on implications
@@ -122,7 +124,8 @@ void symex_slice_by_tracet::read_trace(std::string filename)
122124 std::cout << " Reading trace from file " << filename << ' \n ' ;
123125 std::ifstream file (filename);
124126 if (file.fail ())
125- throw " failed to read from trace file" ;
127+ throw invalid_user_input_exceptiont (
128+ " invalid file to read trace from: " + filename, " " );
126129
127130 // In case not the first trace read
128131 alphabet.clear ();
@@ -219,9 +222,10 @@ void symex_slice_by_tracet::parse_events(std::string read_line)
219222 const std::string::size_type vnext=read_line.find (" ," , vidx);
220223 std::string event=read_line.substr (vidx, vnext - vidx);
221224 eis.insert (event);
222- if ((!alphabet.empty ()) &&
223- ((alphabet.count (event)!=0 )!=alphabet_parity))
224- throw " trace uses symbol not in alphabet: " +event;
225+ PRECONDITION (!alphabet.empty ());
226+ INVARIANT (
227+ (alphabet.count (event) != 0 ) == alphabet_parity,
228+ " trace uses symbol not in alphabet: " + event);
225229 if (vnext==std::string::npos)
226230 break ;
227231 vidx=vnext;
0 commit comments