CBMC
json_goto_trace.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Traces of GOTO Programs
4 
5 Author: Daniel Kroening
6 
7 Date: November 2005
8 
9 \*******************************************************************/
10 
13 
14 #ifndef CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H
15 #define CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H
16 
17 #include "goto_trace.h"
18 #include "structured_trace_util.h"
19 
20 #include <util/json.h>
21 #include <util/json_irep.h>
22 
26 typedef struct
27 {
28  const jsont &location;
30  const namespacet &ns;
32 
40 void convert_assert(
41  json_objectt &json_failure,
42  const conversion_dependenciest &conversion_dependencies);
43 
53 void convert_decl(
54  json_objectt &json_assignment,
55  const conversion_dependenciest &conversion_dependencies,
56  const trace_optionst &trace_options);
57 
65 void convert_output(
66  json_objectt &json_output,
67  const conversion_dependenciest &conversion_dependencies);
68 
76 void convert_input(
77  json_objectt &json_input,
78  const conversion_dependenciest &conversion_dependencies);
79 
87 void convert_return(
88  json_objectt &json_call_return,
89  const conversion_dependenciest &conversion_dependencies);
90 
98 void convert_default(
99  json_objectt &json_location_only,
101 
112 template <typename json_arrayT>
113 void convert(
114  const namespacet &ns,
115  const goto_tracet &goto_trace,
116  json_arrayT &dest_array,
118 {
119  source_locationt previous_source_location;
120 
121  for(const auto &step : goto_trace.steps)
122  {
123  const source_locationt &source_location = step.pc->source_location();
124 
125  jsont json_location;
126 
127  source_location.is_not_nil() && !source_location.get_file().empty()
128  ? json_location = json(source_location)
129  : json_location = json_nullt();
130 
131  // NOLINTNEXTLINE(whitespace/braces)
132  conversion_dependenciest conversion_dependencies = {
133  json_location, step, ns};
134 
135  switch(step.type)
136  {
138  if(!step.cond_value)
139  {
140  json_objectt &json_failure = dest_array.push_back().make_object();
141  convert_assert(json_failure, conversion_dependencies);
142  }
143  break;
144 
147  {
148  json_objectt &json_assignment = dest_array.push_back().make_object();
149  convert_decl(json_assignment, conversion_dependencies, trace_options);
150  }
151  break;
152 
154  {
155  json_objectt &json_output = dest_array.push_back().make_object();
156  convert_output(json_output, conversion_dependencies);
157  }
158  break;
159 
161  {
162  json_objectt &json_input = dest_array.push_back().make_object();
163  convert_input(json_input, conversion_dependencies);
164  }
165  break;
166 
169  {
170  json_objectt &json_call_return = dest_array.push_back().make_object();
171  convert_return(json_call_return, conversion_dependencies);
172  }
173  break;
174 
187  const auto default_step = ::default_step(step, previous_source_location);
188  if(default_step)
189  {
190  json_objectt &json_location_only = dest_array.push_back().make_object();
191  convert_default(json_location_only, *default_step);
192  }
193  break;
194  }
195 
196  if(source_location.is_not_nil() && !source_location.get_file().empty())
197  previous_source_location = source_location;
198  }
199 }
200 
201 #endif // CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H
bool empty() const
Definition: dstring.h:89
Step of the trace of a GOTO program.
Definition: goto_trace.h:50
Trace of a GOTO program.
Definition: goto_trace.h:177
stepst steps
Definition: goto_trace.h:180
bool is_not_nil() const
Definition: irep.h:368
Definition: json.h:27
json_objectt & make_object()
Definition: json.h:436
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
const irep_idt & get_file() const
Traces of GOTO Programs.
void convert_assert(json_objectt &json_failure, const conversion_dependenciest &conversion_dependencies)
Convert an ASSERT goto_trace step.
void convert_output(json_objectt &json_output, const conversion_dependenciest &conversion_dependencies)
Convert an OUTPUT goto_trace step.
void convert(const namespacet &ns, const goto_tracet &goto_trace, json_arrayT &dest_array, trace_optionst trace_options=trace_optionst::default_options)
Templated version of the conversion method.
void convert_input(json_objectt &json_input, const conversion_dependenciest &conversion_dependencies)
Convert an INPUT goto_trace step.
void convert_decl(json_objectt &json_assignment, const conversion_dependenciest &conversion_dependencies, const trace_optionst &trace_options)
Convert a DECL goto_trace step.
void convert_return(json_objectt &json_call_return, const conversion_dependenciest &conversion_dependencies)
Convert a FUNCTION_RETURN goto_trace step.
void convert_default(json_objectt &json_location_only, const default_trace_stept &default_step)
Convert all other types of steps not already handled by the other conversion functions.
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:120
This is structure is here to facilitate passing arguments to the conversion functions.
const goto_trace_stept & step
const namespacet & ns
Options for printing the trace using show_goto_trace.
Definition: goto_trace.h:221
static const trace_optionst default_options
Definition: goto_trace.h:238
std::optional< default_trace_stept > default_step(const goto_trace_stept &step, const source_locationt &previous_source_location)
Utilities for printing location info steps in the trace in a format agnostic way.