Skip to content

Commit 6b6098c

Browse files
committed
Update html_goto_trace to use trace_configurationt
The HTML trace now has the same configuration options as the standard trace, and uses the global trace_config variable. This commit also modernises some for loops used in case INPUT and case OUTPUT
1 parent a097f26 commit 6b6098c

File tree

2 files changed

+97
-100
lines changed

2 files changed

+97
-100
lines changed

src/goto-programs/html_goto_trace.cpp

Lines changed: 97 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: [email protected]
1717
#include <ostream>
1818

1919
#include <util/arith_tools.h>
20+
#include <util/config.h>
2021
#include <util/symbol.h>
2122

2223
#include <ansi-c/printf_formatter.h>
@@ -61,22 +62,25 @@ void output_html_footer(std::ostream &out)
6162

6263

6364
void show_html_state_header(
64-
std::ostream &out,
65-
const goto_trace_stept &state,
66-
const source_locationt &source_location,
67-
unsigned step_nr)
65+
std::ostream &out,
66+
const namespacet &ns,
67+
const goto_trace_stept &state)
6868
{
6969
out << "\n<hr />\n";
7070
out << "<p><strong><span style=\"color: Indigo;\">";
7171

72-
if(step_nr==0)
72+
if(state.step_nr==0)
7373
out << "Initial State";
7474
else
75-
out << "State " << step_nr << "</span>";
75+
out << "State " << state.step_nr << "</span>";
7676

77-
out << " " << source_location
77+
out << " " << state.pc->source_location
7878
<< " thread " << state.thread_nr
7979
<< "</strong>></p>\n";
80+
81+
if(config.trace_config.show_source_code)
82+
out << "<p><span style=\"color: DarkGray;\">Code:<em> "
83+
<< as_string(ns, *state.pc) << "</em></span></p>\n";
8084
}
8185

8286

@@ -88,7 +92,6 @@ void show_html_goto_trace(
8892
unsigned prev_step_nr=0;
8993
bool first_step=true;
9094
bool use_panel1=true;
91-
bool use_hex=true; // at some point this will become a cmd line argument
9295
output_html_header(out);
9396

9497
for(const auto &step : goto_trace.steps)
@@ -110,8 +113,8 @@ void show_html_goto_trace(
110113
out << "<p> " << step.comment << "</p>\n";
111114

112115
if(step.pc->is_assert())
113-
out << "<p> " << from_expr(ns, "", step.pc->guard) << "\n";
114-
out<<"</p></div>\n";
116+
out << "<p> " << from_expr(ns, "", step.pc->guard) << '\n';
117+
out << "</p></div>\n";
115118
}
116119
break;
117120

@@ -137,125 +140,120 @@ void show_html_goto_trace(
137140
break;
138141

139142
case goto_trace_stept::typet::ASSIGNMENT:
140-
if(step.pc->is_assign() ||
141-
step.pc->is_return() || // returns have a lhs!
142-
step.pc->is_function_call() ||
143-
(step.pc->is_other() && step.lhs_object.is_not_nil()))
143+
if(config.trace_config.show_value_assignments)
144144
{
145-
if(prev_step_nr!=step.step_nr || first_step)
145+
if(step.pc->is_assign() || step.pc->is_return()
146+
|| // returns have a lhs!
147+
step.pc->is_function_call()
148+
|| (step.pc->is_other() && step.lhs_object.is_not_nil()))
146149
{
147-
first_step=false;
148-
prev_step_nr=step.step_nr;
149-
show_html_state_header(
150-
out, step, step.pc->source_location, step.step_nr);
151-
out << "<p><span style=\"color: DarkGray;\">Code:<em> "
152-
<< as_string(ns, *step.pc) << "</em></p>\n";
150+
if(prev_step_nr != step.step_nr || first_step)
151+
{
152+
first_step = false;
153+
prev_step_nr = step.step_nr;
154+
show_html_state_header(out, ns, step);
155+
}
156+
157+
trace_value(out, ns, step);
158+
out << "</p>\n";
153159
}
154-
155-
// see if the full lhs is something clean
156-
if(is_index_member_symbol(step.full_lhs))
157-
trace_value(
158-
out, ns, step.lhs_object, step.full_lhs,
159-
step.full_lhs_value, use_hex);
160-
else
161-
trace_value(
162-
out, ns, step.lhs_object, step.lhs_object,
163-
step.lhs_object_value, use_hex);
164-
out<<"</span></p>\n";
165160
}
166-
167161
break;
168162

169163
case goto_trace_stept::typet::DECL:
170-
if(prev_step_nr!=step.step_nr || first_step)
164+
if(config.trace_config.show_value_assignments)
171165
{
172-
first_step=false;
173-
prev_step_nr=step.step_nr;
174-
show_html_state_header(
175-
out, step, step.pc->source_location, step.step_nr);
176-
out << "<p><span style=\"color: DarkGray;\">Code:<em> "
177-
<< as_string(ns, *step.pc) << "</em></p>\n";
178-
}
166+
if(prev_step_nr != step.step_nr || first_step)
167+
{
168+
first_step = false;
169+
prev_step_nr = step.step_nr;
170+
show_html_state_header(out, ns, step);
171+
}
179172

180-
trace_value(
181-
out, ns, step.lhs_object, step.full_lhs,
182-
step.full_lhs_value, use_hex);
183-
out<<"</span></p>\n";
173+
trace_value(out, ns, step);
174+
out << "</span></p>\n";
175+
}
184176
break;
185177

186178
case goto_trace_stept::typet::OUTPUT:
187-
if(step.formatted)
188-
{
189-
printf_formattert printf_formatter(ns);
190-
printf_formatter(id2string(step.format_string), step.io_args);
191-
printf_formatter.print(out);
192-
}
193-
else
179+
if(config.trace_config.show_outputs)
194180
{
195-
show_html_state_header(
196-
out, step, step.pc->source_location, step.step_nr);
197-
out << "<p><span style=\"color: DarkGray;\">Code:<em> "
198-
<< as_string(ns, *step.pc) << "</em></p>\n";
199-
200-
out << "<p> OUTPUT " << step.io_id << ":";
201-
202-
for(std::list<exprt>::const_iterator
203-
l_it=step.io_args.begin();
204-
l_it!=step.io_args.end();
205-
l_it++)
181+
if(step.formatted)
206182
{
207-
if(l_it!=step.io_args.begin())
208-
out << ";";
209-
out << " " << from_expr(ns, "", *l_it);
210-
211-
// the hex representation
212-
out << " (" << trace_value_hex(*l_it, ns) << ")";
183+
printf_formattert printf_formatter(ns);
184+
printf_formatter(id2string(step.format_string), step.io_args);
185+
printf_formatter.print(out);
186+
}
187+
else
188+
{
189+
show_html_state_header(out, ns, step);
190+
out << "<p> OUTPUT " << step.io_id << ":";
191+
192+
bool first_output = true;
193+
for(const auto &arg : step.io_args)
194+
{
195+
if(!first_output)
196+
out << ";";
197+
out << " " << from_expr(ns, "", arg);
198+
199+
if(config.trace_config.numeric_representation ==
200+
configt::numeric_representationt::HEX)
201+
out << " (" << trace_value_hex(arg, ns) << ")</p>\n";
202+
else
203+
out << " (" << trace_value_binary(arg, ns) << ")</p>\n";
204+
first_output = false;
205+
}
213206
}
214207
}
215-
out<<"</span></p>\n";
216208
break;
217209

218210
case goto_trace_stept::typet::INPUT:
219-
show_html_state_header(out, step, step.pc->source_location, step.step_nr);
220-
out << "<p><span style=\"color: DarkGray;\">Code:<em> "
221-
<< as_string(ns, *step.pc) << "</em></p>\n";
222-
out << " <p> INPUT " << step.io_id << ":";
223-
224-
for(std::list<exprt>::const_iterator
225-
l_it=step.io_args.begin();
226-
l_it!=step.io_args.end();
227-
l_it++)
211+
if(!config.trace_config.show_inputs)
228212
{
229-
if(l_it!=step.io_args.begin())
230-
out << ";";
231-
out << " " << from_expr(ns, "", *l_it);
213+
show_html_state_header(out, ns, step);
214+
out << " <p> INPUT " << step.io_id << ":";
232215

233-
// the binary representation
234-
out << " (" << trace_value_hex(*l_it, ns) << ")";
235-
}
216+
bool first_input = true;
217+
for(const auto &arg : step.io_args)
218+
{
219+
if(!first_input)
220+
out << ";";
221+
out << " " << from_expr(ns, "", arg);
222+
223+
if(config.trace_config.numeric_representation ==
224+
configt::numeric_representationt::HEX)
225+
out << " (" << trace_value_hex(arg, ns) << ")";
226+
else
227+
out << " (" << trace_value_binary(arg, ns) << ")";
228+
first_input = false;
229+
}
236230

237-
out<<"</span></p>\n";
231+
out << "</span></p>\n";
232+
}
238233
break;
239234

240235
case goto_trace_stept::typet::FUNCTION_CALL:
241-
out << "\n";
242-
out << "<button class=\"function_call\">";
243-
out << "<strong>FUNCTION CALL: </strong>" << as_string(ns, *step.pc);
244-
if(use_panel1)
236+
if(config.trace_config.show_function_calls)
245237
{
246-
out <<"</button>\n<div class=\"panel1\">\n";
247-
use_panel1=false;
248-
}
249-
else
250-
{
251-
out <<"</button>\n<div class=\"panel2\">\n";
252-
use_panel1=true;
238+
out << '\n';
239+
out << "<button class=\"function_call\">";
240+
out << "<strong>FUNCTION CALL: </strong>" << as_string(ns, *step.pc);
241+
if(use_panel1)
242+
{
243+
out << "</button>\n<div class=\"panel1\">\n";
244+
use_panel1 = false;
245+
}
246+
else
247+
{
248+
out << "</button>\n<div class=\"panel2\">\n";
249+
use_panel1 = true;
250+
}
253251
}
254-
255252
break;
256253

257254
case goto_trace_stept::typet::FUNCTION_RETURN:
258-
out<<"</div>\n";
255+
if(config.trace_config.show_function_calls)
256+
out << "</div>\n";
259257
break;
260258

261259
case goto_trace_stept::typet::SPAWN:

src/goto-programs/html_goto_trace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Author: [email protected]
1414
#ifndef CPROVER_GOTO_PROGRAMS_HTML_GOTO_TRACE_H_
1515
#define CPROVER_GOTO_PROGRAMS_HTML_GOTO_TRACE_H_
1616

17-
#include <util/config.h>
1817

1918
void show_html_goto_trace(
2019
std::ostream &,

0 commit comments

Comments
 (0)