Skip to content

Commit 4ee5f2d

Browse files
author
Thomas Kiley
committed
Add loopheads to the JSON output
1 parent 65c8fe2 commit 4ee5f2d

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CORE
2+
test.c
3+
--unwind 6 test.c --trace --json-ui --partial-loops --slice-formula
4+
activate-multi-line-match
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
\s*\{\n\s* .*\n\s* "sourceLocation": \{\n\s* .*,\n\s* .*,\n\s* "line": "5",\n\s* .*\n\s* \},\n\s* "stepType": "loop-head",\n\s* .*\n\s*\},\n\s*\{\n\s* .*\n\s* "sourceLocation": \{\n\s* .*,\n\s* .*,\n\s* "line": "5",\n\s* .*\n\s* \},\n\s* "stepType": "loop-head",\n\s* .*\n\s*\},
8+
--
9+
--
10+
Ensure even with sliced formulas, we get a location only step for
11+
each iteration of the loop (called loop-heads) when using partial loops.
12+
13+
This test is checking the following json:(deleting the new lines after each \n to obtain
14+
monster regex above).
15+
16+
\s*\{\n
17+
\s* .*\n
18+
\s* "sourceLocation": \{\n
19+
\s* .*,\n
20+
\s* .*,\n
21+
\s* "line": "5",\n
22+
\s* .*\n
23+
\s* \},\n
24+
\s* "stepType": "loop-head",\n
25+
\s* .*\n
26+
\s*\},\n
27+
\s*\{\n
28+
\s* .*\n
29+
\s* "sourceLocation": \{\n
30+
\s* .*,\n
31+
\s* .*,\n
32+
\s* "line": "5",\n
33+
\s* .*\n
34+
\s* \},\n
35+
\s* "stepType": "loop-head",\n
36+
\s* .*\n
37+
\s*\},

src/goto-programs/json_goto_trace.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,13 @@ void convert_return(
286286
/// needs.
287287
void convert_default(
288288
json_objectt &json_location_only,
289-
const conversion_dependenciest &conversion_dependencies)
289+
const conversion_dependenciest &conversion_dependencies,
290+
const std::string &step_type)
290291
{
291292
const goto_trace_stept &step = conversion_dependencies.step;
292293
const jsont &location = conversion_dependencies.location;
293294

294-
json_location_only["stepType"] = json_stringt("location-only");
295+
json_location_only["stepType"] = json_stringt(step_type);
295296
json_location_only["hidden"] = jsont::json_boolean(step.hidden);
296297
json_location_only["thread"] = json_numbert(std::to_string(step.thread_nr));
297298
json_location_only["sourceLocation"] = location;

src/goto-programs/json_goto_trace.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Date: November 2005
1616

1717
#include "goto_trace.h"
1818

19+
#include <algorithm>
1920
#include <util/invariant.h>
2021
#include <util/json.h>
2122
#include <util/json_irep.h>
@@ -99,7 +100,8 @@ void convert_return(
99100
/// needs.
100101
void convert_default(
101102
json_objectt &json_location_only,
102-
const conversion_dependenciest &conversion_dependencies);
103+
const conversion_dependenciest &conversion_dependencies,
104+
const std::string &step_type);
103105

104106
/// Templated version of the conversion method.
105107
/// Works by dispatching to the more specialised
@@ -186,10 +188,17 @@ void convert(
186188
case goto_trace_stept::typet::SHARED_WRITE:
187189
case goto_trace_stept::typet::CONSTRAINT:
188190
case goto_trace_stept::typet::NONE:
189-
if(source_location != previous_source_location)
191+
const bool is_loophead = std::any_of(
192+
step.pc->incoming_edges.begin(),
193+
step.pc->incoming_edges.end(),
194+
[](goto_programt::targett t) { return t->is_backwards_goto(); });
195+
if(source_location != previous_source_location || is_loophead)
190196
{
191197
json_objectt &json_location_only = dest_array.push_back().make_object();
192-
convert_default(json_location_only, conversion_dependencies);
198+
convert_default(
199+
json_location_only,
200+
conversion_dependencies,
201+
is_loophead ? "loop-head" : "location-only");
193202
}
194203
}
195204

0 commit comments

Comments
 (0)