Skip to content

Commit dcf92fe

Browse files
authored
Merge pull request #5595 from tautschnig/messaget-interpreter
interpretert isn't a messaget
2 parents 48af472 + a17bbfa commit dcf92fe

File tree

4 files changed

+69
-72
lines changed

4 files changed

+69
-72
lines changed

src/goto-programs/interpreter.cpp

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ const std::size_t interpretert::npos=std::numeric_limits<size_t>::max();
3939

4040
void interpretert::operator()()
4141
{
42-
status() << "0- Initialize:" << eom;
42+
output.status() << "0- Initialize:" << messaget::eom;
4343
initialize(true);
4444
try
4545
{
46-
status() << "Type h for help\n" << eom;
46+
output.status() << "Type h for help\n" << messaget::eom;
4747

4848
while(!done)
4949
command();
5050

51-
status() << total_steps << "- Program End.\n" << eom;
51+
output.status() << total_steps << "- Program End.\n" << messaget::eom;
5252
}
5353
catch (const char *e)
5454
{
55-
error() << e << "\n" << eom;
55+
output.error() << e << "\n" << messaget::eom;
5656
}
5757

5858
while(!done)
@@ -113,22 +113,19 @@ void interpretert::show_state()
113113
{
114114
if(!show)
115115
return;
116-
status() << "\n"
117-
<< total_steps+1
118-
<< " ----------------------------------------------------\n";
116+
output.status() << "\n"
117+
<< total_steps + 1
118+
<< " ----------------------------------------------------\n";
119119

120120
if(pc==function->second.body.instructions.end())
121121
{
122-
status() << "End of function '" << function->first << "'\n";
122+
output.status() << "End of function '" << function->first << "'\n";
123123
}
124124
else
125125
function->second.body.output_instruction(
126-
ns,
127-
function->first,
128-
status(),
129-
*pc);
126+
ns, function->first, output.status(), *pc);
130127

131-
status() << eom;
128+
output.status() << messaget::eom;
132129
}
133130

134131
/// reads a user command and executes it.
@@ -147,18 +144,18 @@ void interpretert::command()
147144
done=true;
148145
else if(ch=='h')
149146
{
150-
status() << "Interpreter help\n"
151-
<< "h: display this menu\n"
152-
<< "j: output json trace\n"
153-
<< "m: output memory dump\n"
154-
<< "o: output goto trace\n"
155-
<< "q: quit\n"
156-
<< "r: run up to entry point\n"
157-
<< "s#: step a number of instructions\n"
158-
<< "sa: step across a function\n"
159-
<< "so: step out of a function\n"
160-
<< "se: step until end of program\n"
161-
<< eom;
147+
output.status() << "Interpreter help\n"
148+
<< "h: display this menu\n"
149+
<< "j: output json trace\n"
150+
<< "m: output memory dump\n"
151+
<< "o: output goto trace\n"
152+
<< "q: quit\n"
153+
<< "r: run up to entry point\n"
154+
<< "s#: step a number of instructions\n"
155+
<< "sa: step across a function\n"
156+
<< "so: step out of a function\n"
157+
<< "se: step until end of program\n"
158+
<< messaget::eom;
162159
}
163160
else if(ch=='j')
164161
{
@@ -176,7 +173,7 @@ void interpretert::command()
176173
return;
177174
}
178175
}
179-
json_steps.output(result());
176+
json_steps.output(output.result());
180177
}
181178
else if(ch=='m')
182179
{
@@ -197,7 +194,7 @@ void interpretert::command()
197194
return;
198195
}
199196
}
200-
steps.output(ns, result());
197+
steps.output(ns, output.result());
201198
}
202199
else if(ch=='r')
203200
{
@@ -408,8 +405,9 @@ void interpretert::execute_other()
408405
mp_integer size=get_size(pc->code.op0().type());
409406
while(rhs.size()<size) rhs.insert(rhs.end(), tmp.begin(), tmp.end());
410407
if(size!=rhs.size())
411-
error() << "!! failed to obtain rhs (" << rhs.size() << " vs. "
412-
<< size << ")\n" << eom;
408+
output.error() << "!! failed to obtain rhs (" << rhs.size() << " vs. "
409+
<< size << ")\n"
410+
<< messaget::eom;
413411
else
414412
{
415413
assign(address, rhs);
@@ -637,9 +635,9 @@ exprt interpretert::get_value(
637635
symbol_expr, from_integer(offset_from_address, integer_typet()));
638636
}
639637

640-
error() << "interpreter: invalid pointer "
641-
<< rhs[numeric_cast_v<std::size_t>(offset)] << " > object count "
642-
<< memory.size() << eom;
638+
output.error() << "interpreter: invalid pointer "
639+
<< rhs[numeric_cast_v<std::size_t>(offset)]
640+
<< " > object count " << memory.size() << messaget::eom;
643641

644642
throw "interpreter: reading from invalid pointer";
645643
}
@@ -671,10 +669,9 @@ void interpretert::execute_assign()
671669
mp_integer size=get_size(code_assign.lhs().type());
672670

673671
if(size!=rhs.size())
674-
error() << "!! failed to obtain rhs ("
675-
<< rhs.size() << " vs. "
676-
<< size << ")\n"
677-
<< eom;
672+
output.error() << "!! failed to obtain rhs (" << rhs.size() << " vs. "
673+
<< size << ")\n"
674+
<< messaget::eom;
678675
else
679676
{
680677
goto_trace_stept &trace_step=steps.get_last_step();
@@ -716,11 +713,11 @@ void interpretert::assign(
716713
memory_cellt &cell = memory[numeric_cast_v<std::size_t>(address_val)];
717714
if(show)
718715
{
719-
status() << total_steps << " ** assigning "
720-
<< address_to_symbol(address_val).get_identifier() << "["
721-
<< address_to_offset(address_val)
722-
<< "]:=" << rhs[numeric_cast_v<std::size_t>(i)] << "\n"
723-
<< eom;
716+
output.status() << total_steps << " ** assigning "
717+
<< address_to_symbol(address_val).get_identifier()
718+
<< "[" << address_to_offset(address_val)
719+
<< "]:=" << rhs[numeric_cast_v<std::size_t>(i)] << "\n"
720+
<< messaget::eom;
724721
}
725722
cell.value = rhs[numeric_cast_v<std::size_t>(i)];
726723
if(cell.initialized==memory_cellt::initializedt::UNKNOWN)
@@ -740,8 +737,8 @@ void interpretert::execute_assert()
740737
if(!evaluate_boolean(pc->get_condition()))
741738
{
742739
if(show)
743-
error() << "assertion failed at " << pc->location_number
744-
<< "\n" << eom;
740+
output.error() << "assertion failed at " << pc->location_number << "\n"
741+
<< messaget::eom;
745742
}
746743
}
747744

@@ -847,7 +844,7 @@ void interpretert::execute_function_call()
847844
}
848845

849846
if(show)
850-
error() << "no body for "+id2string(identifier) << eom;
847+
output.error() << "no body for " << identifier << messaget::eom;
851848
}
852849
}
853850

@@ -903,16 +900,17 @@ typet interpretert::concretize_type(const typet &type)
903900
if(computed_size.size()==1 &&
904901
computed_size[0]>=0)
905902
{
906-
result() << "Concretized array with size " << computed_size[0]
907-
<< eom;
903+
output.result() << "Concretized array with size " << computed_size[0]
904+
<< messaget::eom;
908905
return
909906
array_typet(
910907
type.subtype(),
911908
from_integer(computed_size[0], integer_typet()));
912909
}
913910
else
914911
{
915-
warning() << "Failed to concretize variable array" << eom;
912+
output.warning() << "Failed to concretize variable array"
913+
<< messaget::eom;
916914
}
917915
}
918916
return type;
@@ -1067,11 +1065,12 @@ void interpretert::print_memory(bool input_flags)
10671065
const memory_cellt &cell=cell_address.second;
10681066
const auto identifier = address_to_symbol(i).get_identifier();
10691067
const auto offset=address_to_offset(i);
1070-
status() << identifier << "[" << offset << "]"
1071-
<< "=" << cell.value << eom;
1068+
output.status() << identifier << "[" << offset << "]"
1069+
<< "=" << cell.value << messaget::eom;
10721070
if(input_flags)
1073-
status() << "(" << static_cast<int>(cell.initialized) << ")" << eom;
1074-
status() << eom;
1071+
output.status() << "(" << static_cast<int>(cell.initialized) << ")"
1072+
<< messaget::eom;
1073+
output.status() << messaget::eom;
10751074
}
10761075
}
10771076

src/goto-programs/interpreter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_GOTO_PROGRAMS_INTERPRETER_H
1313
#define CPROVER_GOTO_PROGRAMS_INTERPRETER_H
1414

15-
#include <util/message.h>
16-
1715
#include "goto_model.h"
1816

17+
class message_handlert;
18+
1919
void interpreter(
2020
const goto_modelt &,
2121
message_handlert &);

src/goto-programs/interpreter_class.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Author: Daniel Kroening, [email protected]
2424
#include "goto_trace.h"
2525
#include "json_goto_trace.h"
2626

27-
class interpretert:public messaget
27+
class interpretert
2828
{
2929
public:
3030
interpretert(
3131
const symbol_tablet &_symbol_table,
3232
const goto_functionst &_goto_functions,
3333
message_handlert &_message_handler)
34-
: messaget(_message_handler),
34+
: output(_message_handler),
3535
symbol_table(_symbol_table),
3636
ns(_symbol_table),
3737
goto_functions(_goto_functions),
@@ -97,6 +97,7 @@ class interpretert:public messaget
9797
const dynamic_typest &get_dynamic_types() { return dynamic_types; }
9898

9999
protected:
100+
messaget output;
100101
const symbol_tablet &symbol_table;
101102

102103
// This is a cache so that we don't have to create it when a call needs it

src/goto-programs/interpreter_evaluate.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ void interpretert::evaluate(
404404
{
405405
const std::string &value = id2string(to_constant_expr(expr).get_value());
406406
if(show)
407-
warning() << "string decoding not fully implemented "
408-
<< value.size() + 1 << eom;
407+
output.warning() << "string decoding not fully implemented "
408+
<< value.size() + 1 << messaget::eom;
409409
dest.push_back(get_string_container()[value]);
410410
return;
411411
}
@@ -457,15 +457,14 @@ void interpretert::evaluate(
457457
if(side_effect.get_statement()==ID_nondet)
458458
{
459459
if(show)
460-
error() << "nondet not implemented" << eom;
460+
output.error() << "nondet not implemented" << messaget::eom;
461461
return;
462462
}
463463
else if(side_effect.get_statement()==ID_allocate)
464464
{
465465
if(show)
466-
error() << "heap memory allocation not fully implemented "
467-
<< expr.type().subtype().pretty()
468-
<< eom;
466+
output.error() << "heap memory allocation not fully implemented "
467+
<< expr.type().subtype().pretty() << messaget::eom;
469468
std::stringstream buffer;
470469
num_dynamic_objects++;
471470
buffer << "interpreter::dynamic_object" << num_dynamic_objects;
@@ -478,9 +477,8 @@ void interpretert::evaluate(
478477
return;
479478
}
480479
if(show)
481-
error() << "side effect not implemented "
482-
<< side_effect.get_statement()
483-
<< eom;
480+
output.error() << "side effect not implemented "
481+
<< side_effect.get_statement() << messaget::eom;
484482
}
485483
else if(expr.id()==ID_bitor)
486484
{
@@ -1041,14 +1039,14 @@ void interpretert::evaluate(
10411039
{
10421040
if(expr.type().id()==ID_signedbv)
10431041
{
1044-
warning() << "Infinite size arrays not supported" << eom;
1042+
output.warning() << "Infinite size arrays not supported" << messaget::eom;
10451043
return;
10461044
}
10471045
}
1048-
error() << "!! failed to evaluate expression: "
1049-
<< from_expr(ns, function->first, expr) << "\n"
1050-
<< expr.id() << "[" << expr.type().id() << "]"
1051-
<< eom;
1046+
output.error() << "!! failed to evaluate expression: "
1047+
<< from_expr(ns, function->first, expr) << "\n"
1048+
<< expr.id() << "[" << expr.type().id() << "]"
1049+
<< messaget::eom;
10521050
}
10531051

10541052
mp_integer interpretert::evaluate_address(
@@ -1157,9 +1155,8 @@ mp_integer interpretert::evaluate_address(
11571155

11581156
if(!fail_quietly)
11591157
{
1160-
error() << "!! failed to evaluate address: "
1161-
<< from_expr(ns, function->first, expr)
1162-
<< eom;
1158+
output.error() << "!! failed to evaluate address: "
1159+
<< from_expr(ns, function->first, expr) << messaget::eom;
11631160
}
11641161

11651162
return 0;

0 commit comments

Comments
 (0)