Skip to content

Commit 96c8aa4

Browse files
author
Thomas Kiley
committed
Pull out function for processing the default trace step
This models the logic for whether a trace step should be included away from whether the format is json or XML
1 parent 1f1de48 commit 96c8aa4

File tree

5 files changed

+71
-43
lines changed

5 files changed

+71
-43
lines changed

src/goto-programs/json_goto_trace.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,12 @@ void convert_return(
278278

279279
void convert_default(
280280
json_objectt &json_location_only,
281-
const conversion_dependenciest &conversion_dependencies,
282-
const default_step_kindt &step_kind)
281+
const default_trace_stept &default_step)
283282
{
284-
const goto_trace_stept &step = conversion_dependencies.step;
285-
const jsont &location = conversion_dependencies.location;
286-
287-
json_location_only["stepType"] = json_stringt(default_step_name(step_kind));
288-
json_location_only["hidden"] = jsont::json_boolean(step.hidden);
289-
json_location_only["thread"] = json_numbert(std::to_string(step.thread_nr));
290-
json_location_only["sourceLocation"] = location;
283+
json_location_only["stepType"] =
284+
json_stringt(default_step_name(default_step.kind));
285+
json_location_only["hidden"] = jsont::json_boolean(default_step.hidden);
286+
json_location_only["thread"] =
287+
json_numbert(std::to_string(default_step.thread_number));
288+
json_location_only["sourceLocation"] = json(default_step.location);
291289
}

src/goto-programs/json_goto_trace.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ void convert_return(
9696
/// \param [out] json_location_only: The JSON object that
9797
/// will contain the information about the step
9898
/// after this function has run.
99-
/// \param conversion_dependencies: A structure
100-
/// that contains information the conversion function
101-
/// needs.
102-
/// \param step_kind: The kind of default step we are printing.
103-
/// See \ref default_step_kind
99+
/// \param default_step: The procesed details about this step, see \ref
100+
/// default_step_kind
104101
void convert_default(
105102
json_objectt &json_location_only,
106-
const conversion_dependenciest &conversion_dependencies,
107-
const default_step_kindt &step_kind);
103+
const default_trace_stept &default_step);
108104

109105
/// Templated version of the conversion method.
110106
/// Works by dispatching to the more specialised
@@ -191,15 +187,13 @@ void convert(
191187
case goto_trace_stept::typet::SHARED_WRITE:
192188
case goto_trace_stept::typet::CONSTRAINT:
193189
case goto_trace_stept::typet::NONE:
194-
const auto default_step_kind = ::default_step_kind(*step.pc);
195-
if(
196-
source_location != previous_source_location ||
197-
default_step_kind == default_step_kindt::LOOP_HEAD)
190+
const auto default_step = ::default_step(step, previous_source_location);
191+
if(default_step)
198192
{
199193
json_objectt &json_location_only = dest_array.push_back().make_object();
200-
convert_default(
201-
json_location_only, conversion_dependencies, default_step_kind);
194+
convert_default(json_location_only, *default_step);
202195
}
196+
break;
203197
}
204198

205199
if(source_location.is_not_nil() && !source_location.get_file().empty())

src/goto-programs/structured_trace_util.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Author: Diffblue
99
/// agnostic way
1010

1111
#include "structured_trace_util.h"
12+
#include "goto_trace.h"
13+
1214
#include <algorithm>
1315

1416
default_step_kindt
@@ -33,3 +35,33 @@ std::string default_step_name(const default_step_kindt &step_type)
3335
}
3436
UNREACHABLE;
3537
}
38+
39+
optionalt<default_trace_stept> default_step(
40+
const goto_trace_stept &step,
41+
const source_locationt &previous_source_location)
42+
{
43+
const source_locationt &source_location = step.pc->source_location;
44+
if(source_location.is_nil() || source_location.get_file().empty())
45+
return {};
46+
47+
const auto default_step_kind = ::default_step_kind(*step.pc);
48+
49+
// If this is just a source location then we output only the first
50+
// location of a sequence of same locations.
51+
// However, we don't want to suppress loop head locations because
52+
// they might come from different loop iterations. If we suppressed
53+
// them it would be impossible to know which loop iteration
54+
// we are in.
55+
if(
56+
source_location == previous_source_location &&
57+
default_step_kind == default_step_kindt::LOCATION_ONLY)
58+
{
59+
return {};
60+
}
61+
62+
return default_trace_stept{default_step_kind,
63+
step.hidden,
64+
step.thread_nr,
65+
step.step_nr,
66+
source_location};
67+
}

src/goto-programs/structured_trace_util.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Diffblue
1313

1414
#include "goto_program.h"
1515
#include <string>
16+
class goto_trace_stept;
1617

1718
/// There are two kinds of step for location markers - location-only and
1819
/// loop-head (for locations associated with the first step of a loop).
@@ -36,4 +37,17 @@ default_step_kind(const goto_programt::instructiont &instruction);
3637
/// \return Either "loop-head" or "location-only"
3738
std::string default_step_name(const default_step_kindt &step_type);
3839

40+
struct default_trace_stept
41+
{
42+
default_step_kindt kind;
43+
bool hidden;
44+
unsigned thread_number;
45+
std::size_t step_number;
46+
source_locationt location;
47+
};
48+
49+
optionalt<default_trace_stept> default_step(
50+
const goto_trace_stept &step,
51+
const source_locationt &previous_source_location);
52+
3953
#endif // CPROVER_GOTO_PROGRAMS_STRUCTURED_TRACE_UTIL_H

src/goto-programs/xml_goto_trace.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,31 +239,21 @@ void convert(
239239
case goto_trace_stept::typet::ASSUME:
240240
case goto_trace_stept::typet::NONE:
241241
{
242-
// If this is just a source location then we output only the first
243-
// location of a sequence of same locations.
244-
// However, we don't want to suppress loop head locations because
245-
// they might come from different loop iterations. If we suppressed
246-
// them it would be impossible to know in which loop iteration
247-
// we are in.
248-
const auto default_step_kind = ::default_step_kind(*step.pc);
249-
if(
250-
source_location != previous_source_location ||
251-
default_step_kind == default_step_kindt::LOOP_HEAD)
242+
const auto default_step = ::default_step(step, previous_source_location);
243+
if(default_step)
252244
{
253-
if(!xml_location.name.empty())
254-
{
255-
xmlt &xml_location_only =
256-
dest.new_element(default_step_name(default_step_kind));
245+
xmlt &xml_location_only =
246+
dest.new_element(default_step_name(default_step->kind));
257247

258-
xml_location_only.set_attribute_bool("hidden", step.hidden);
259-
xml_location_only.set_attribute(
260-
"thread", std::to_string(step.thread_nr));
261-
xml_location_only.set_attribute(
262-
"step_nr", std::to_string(step.step_nr));
248+
xml_location_only.set_attribute_bool("hidden", default_step->hidden);
249+
xml_location_only.set_attribute(
250+
"thread", std::to_string(default_step->thread_number));
251+
xml_location_only.set_attribute(
252+
"step_nr", std::to_string(default_step->step_number));
263253

264-
xml_location_only.new_element().swap(xml_location);
265-
}
254+
xml_location_only.new_element(xml(default_step->location));
266255
}
256+
267257
break;
268258
}
269259
}

0 commit comments

Comments
 (0)