Skip to content

Commit f87b8e9

Browse files
author
thk123
committed
Use format rather than from_expr for output
1 parent 407f908 commit f87b8e9

File tree

5 files changed

+117
-29
lines changed

5 files changed

+117
-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.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: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "symex_target_equation.h"
1313

14+
#include <util/format.h>
15+
#include <util/format_expr.h>
1416
#include <util/std_expr.h>
1517
#include <util/throw_with_nested.h>
1618
#include <util/unwrap_nested_exception.h>
1719

20+
// Can be removed once deprecated SSA_stept::output is removed
1821
#include <langapi/language_util.h>
22+
1923
#include <solvers/flattening/bv_conversion_exceptions.h>
2024
#include <solvers/prop/literal_expr.h>
2125
#include <solvers/prop/prop.h>
@@ -423,7 +427,7 @@ void symex_target_equationt::convert_decls(
423427
{
424428
util_throw_with_nested(
425429
equation_conversion_exceptiont(
426-
"Error converting decls for step", step, ns));
430+
"Error converting decls for step", step));
427431
}
428432
}
429433
}
@@ -448,7 +452,7 @@ void symex_target_equationt::convert_guards(
448452
{
449453
util_throw_with_nested(
450454
equation_conversion_exceptiont(
451-
"Error converting guard for step", step, ns));
455+
"Error converting guard for step", step));
452456
}
453457
}
454458
}
@@ -475,7 +479,7 @@ void symex_target_equationt::convert_assumptions(
475479
{
476480
util_throw_with_nested(
477481
equation_conversion_exceptiont(
478-
"Error converting assumptions for step", step, ns));
482+
"Error converting assumptions for step", step));
479483
}
480484
}
481485
}
@@ -503,7 +507,7 @@ void symex_target_equationt::convert_goto_instructions(
503507
{
504508
util_throw_with_nested(
505509
equation_conversion_exceptiont(
506-
"Error converting goto instructions for step", step, ns));
510+
"Error converting goto instructions for step", step));
507511
}
508512
}
509513
}
@@ -582,7 +586,7 @@ void symex_target_equationt::convert_assertions(
582586
{
583587
util_throw_with_nested(
584588
equation_conversion_exceptiont(
585-
"Error converting assertions for step", step, ns));
589+
"Error converting assertions for step", step));
586590
}
587591

588592
// store disjunct
@@ -767,3 +771,101 @@ void symex_target_equationt::SSA_stept::output(
767771

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

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)