Skip to content

Commit 54fb9ab

Browse files
author
thk123
committed
Use format rather than from_expr for output
1 parent 781bf7c commit 54fb9ab

File tree

5 files changed

+116
-29
lines changed

5 files changed

+116
-29
lines changed

src/cbmc/bmc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class bmct:public safety_checkert
7878
options(_options),
7979
outer_symbol_table(outer_symbol_table),
8080
ns(outer_symbol_table, symex_symbol_table),
81-
equation(ns),
81+
equation(),
8282
branch_worklist(_branch_worklist),
8383
symex(_message_handler, outer_symbol_table, equation, branch_worklist),
8484
prop_conv(_prop_conv),

src/goto-instrument/accelerate/scratch_program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class scratch_programt:public goto_programt
4040
symbol_table(_symbol_table),
4141
symex_symbol_table(),
4242
ns(symbol_table, symex_symbol_table),
43-
equation(ns),
43+
equation(),
4444
branch_worklist(),
4545
symex(mh, symbol_table, equation, branch_worklist),
4646
satcheck(util_make_unique<satcheckt>()),

src/goto-symex/equation_conversion_exceptions.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ Author: Diffblue Ltd.
1414

1515
#include <ostream>
1616

17-
#include <util/namespace.h>
18-
19-
#include <langapi/language_util.h>
17+
#include <util/format_expr.h>
2018

2119
#include "symex_target_equation.h"
2220

@@ -25,26 +23,17 @@ class equation_conversion_exceptiont : public std::runtime_error
2523
public:
2624
equation_conversion_exceptiont(
2725
const std::string &message,
28-
const symex_target_equationt::SSA_stept &step,
29-
const namespacet &ns)
26+
const symex_target_equationt::SSA_stept &step)
3027
: runtime_error(message), step(step)
3128
{
3229
std::ostringstream error_msg;
3330
error_msg << runtime_error::what();
34-
error_msg << "\nSource GOTO statement: "
35-
<< from_expr(ns, "java", step.source.pc->code);
31+
error_msg << "\nSource GOTO statement: " << format(step.source.pc->code);
3632
error_msg << "\nStep:\n";
37-
step.output(ns, error_msg);
33+
step.output(error_msg);
3834
error_message = error_msg.str();
3935
}
4036

41-
explicit equation_conversion_exceptiont(
42-
const std::string &message,
43-
const symex_target_equationt::SSA_stept &step)
44-
: equation_conversion_exceptiont(message, step, namespacet{symbol_tablet{}})
45-
{
46-
}
47-
4837
const char *what() const optional_noexcept override
4938
{
5039
return error_message.c_str();

src/goto-symex/symex_target_equation.cpp

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "symex_target_equation.h"
1313

14+
#include <util/format_expr.h>
1415
#include <util/std_expr.h>
1516
#include <util/throw_with_nested.h>
1617
#include <util/unwrap_nested_exception.h>
1718

19+
// Can be removed once deprecated SSA_stept::output is removed
1820
#include <langapi/language_util.h>
21+
1922
#include <solvers/flattening/bv_conversion_exceptions.h>
2023
#include <solvers/prop/literal_expr.h>
2124
#include <solvers/prop/prop.h>
@@ -423,7 +426,7 @@ void symex_target_equationt::convert_decls(
423426
{
424427
util_throw_with_nested(
425428
equation_conversion_exceptiont(
426-
"Error converting decls for step", step, ns));
429+
"Error converting decls for step", step));
427430
}
428431
}
429432
}
@@ -448,7 +451,7 @@ void symex_target_equationt::convert_guards(
448451
{
449452
util_throw_with_nested(
450453
equation_conversion_exceptiont(
451-
"Error converting guard for step", step, ns));
454+
"Error converting guard for step", step));
452455
}
453456
}
454457
}
@@ -475,7 +478,7 @@ void symex_target_equationt::convert_assumptions(
475478
{
476479
util_throw_with_nested(
477480
equation_conversion_exceptiont(
478-
"Error converting assumptions for step", step, ns));
481+
"Error converting assumptions for step", step));
479482
}
480483
}
481484
}
@@ -503,7 +506,7 @@ void symex_target_equationt::convert_goto_instructions(
503506
{
504507
util_throw_with_nested(
505508
equation_conversion_exceptiont(
506-
"Error converting goto instructions for step", step, ns));
509+
"Error converting goto instructions for step", step));
507510
}
508511
}
509512
}
@@ -582,7 +585,7 @@ void symex_target_equationt::convert_assertions(
582585
{
583586
util_throw_with_nested(
584587
equation_conversion_exceptiont(
585-
"Error converting assertions for step", step, ns));
588+
"Error converting assertions for step", step));
586589
}
587590

588591
// store disjunct
@@ -767,3 +770,101 @@ void symex_target_equationt::SSA_stept::output(
767770

768771
out << "Guard: " << from_expr(ns, source.pc->function, guard) << '\n';
769772
}
773+
774+
void symex_target_equationt::SSA_stept::output(std::ostream &out) const
775+
{
776+
if(source.is_set)
777+
{
778+
out << "Thread " << source.thread_nr;
779+
780+
if(source.pc->source_location.is_not_nil())
781+
out << " " << source.pc->source_location << '\n';
782+
else
783+
out << '\n';
784+
}
785+
786+
switch(type)
787+
{
788+
case goto_trace_stept::typet::ASSERT:
789+
out << "ASSERT " << format(cond_expr) << '\n'; break;
790+
case goto_trace_stept::typet::ASSUME:
791+
out << "ASSUME " << format(cond_expr) << '\n'; break;
792+
case goto_trace_stept::typet::LOCATION:
793+
out << "LOCATION" << '\n'; break;
794+
case goto_trace_stept::typet::INPUT:
795+
out << "INPUT" << '\n'; break;
796+
case goto_trace_stept::typet::OUTPUT:
797+
out << "OUTPUT" << '\n'; break;
798+
799+
case goto_trace_stept::typet::DECL:
800+
out << "DECL" << '\n';
801+
out << format(ssa_lhs) << '\n';
802+
break;
803+
804+
case goto_trace_stept::typet::ASSIGNMENT:
805+
out << "ASSIGNMENT (";
806+
switch(assignment_type)
807+
{
808+
case assignment_typet::HIDDEN:
809+
out << "HIDDEN";
810+
break;
811+
case assignment_typet::STATE:
812+
out << "STATE";
813+
break;
814+
case assignment_typet::VISIBLE_ACTUAL_PARAMETER:
815+
out << "VISIBLE_ACTUAL_PARAMETER";
816+
break;
817+
case assignment_typet::HIDDEN_ACTUAL_PARAMETER:
818+
out << "HIDDEN_ACTUAL_PARAMETER";
819+
break;
820+
case assignment_typet::PHI:
821+
out << "PHI";
822+
break;
823+
case assignment_typet::GUARD:
824+
out << "GUARD";
825+
break;
826+
default:
827+
{
828+
}
829+
}
830+
831+
out << ")\n";
832+
break;
833+
834+
case goto_trace_stept::typet::DEAD:
835+
out << "DEAD\n"; break;
836+
case goto_trace_stept::typet::FUNCTION_CALL:
837+
out << "FUNCTION_CALL\n"; break;
838+
case goto_trace_stept::typet::FUNCTION_RETURN:
839+
out << "FUNCTION_RETURN\n"; break;
840+
case goto_trace_stept::typet::CONSTRAINT:
841+
out << "CONSTRAINT\n"; break;
842+
case goto_trace_stept::typet::SHARED_READ:
843+
out << "SHARED READ\n"; break;
844+
case goto_trace_stept::typet::SHARED_WRITE:
845+
out << "SHARED WRITE\n"; break;
846+
case goto_trace_stept::typet::ATOMIC_BEGIN:
847+
out << "ATOMIC_BEGIN\n"; break;
848+
case goto_trace_stept::typet::ATOMIC_END:
849+
out << "AUTOMIC_END\n"; break;
850+
case goto_trace_stept::typet::SPAWN:
851+
out << "SPAWN\n"; break;
852+
case goto_trace_stept::typet::MEMORY_BARRIER:
853+
out << "MEMORY_BARRIER\n"; break;
854+
case goto_trace_stept::typet::GOTO:
855+
out << "IF " << format(cond_expr) << " GOTO\n"; break;
856+
857+
default: UNREACHABLE;
858+
}
859+
860+
if(is_assert() || is_assume() || is_assignment() || is_constraint())
861+
out << format(cond_expr) << '\n';
862+
863+
if(is_assert() || is_constraint())
864+
out << comment << '\n';
865+
866+
if(is_shared_read() || is_shared_write())
867+
out << format(ssa_lhs) << '\n';
868+
869+
out << "Guard: " << format(guard) << '\n';
870+
}

src/goto-symex/symex_target_equation.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class prop_convt;
3232
class symex_target_equationt:public symex_targett
3333
{
3434
public:
35-
explicit symex_target_equationt(const namespacet &ns) : ns(ns)
36-
{
37-
}
38-
35+
symex_target_equationt() = default;
3936
virtual ~symex_target_equationt() = default;
4037

4138
// read event
@@ -260,9 +257,12 @@ class symex_target_equationt:public symex_targett
260257
{
261258
}
262259

260+
DEPRECATED("Use output without ns param")
263261
void output(
264262
const namespacet &ns,
265263
std::ostream &out) const;
264+
265+
void output(std::ostream &out) const;
266266
};
267267

268268
std::size_t count_assertions() const
@@ -323,9 +323,6 @@ class symex_target_equationt:public symex_targett
323323
// for enforcing sharing in the expressions stored
324324
merge_irept merge_irep;
325325
void merge_ireps(SSA_stept &SSA_step);
326-
327-
private:
328-
const namespacet &ns;
329326
};
330327

331328
inline bool operator<(

0 commit comments

Comments
 (0)