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
default_step
optionalt< default_trace_stept > default_step(const goto_trace_stept &step, const source_locationt &previous_source_location)
Definition: structured_trace_util.cpp:39
convert_assert
void convert_assert(json_objectt &json_failure, const conversion_dependenciest &conversion_dependencies)
Convert an ASSERT goto_trace step.
Definition: json_goto_trace.cpp:32
goto_trace_stept::typet::LOCATION
@ LOCATION
goto_trace_stept::typet::ASSUME
@ ASSUME
goto_tracet::steps
stepst steps
Definition: goto_trace.h:178
convert_return
void convert_return(json_objectt &json_call_return, const conversion_dependenciest &conversion_dependencies)
Convert a FUNCTION_RETURN goto_trace step.
Definition: json_goto_trace.cpp:250
goto_trace_stept
Step of the trace of a GOTO program.
Definition: goto_trace.h:49
jsont::make_object
json_objectt & make_object()
Definition: json.h:438
jsont
Definition: json.h:26
json_irep.h
json_objectt
Definition: json.h:299
goto_trace.h
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:380
convert_decl
void convert_decl(json_objectt &json_assignment, const conversion_dependenciest &conversion_dependencies, const trace_optionst &trace_options)
Convert a DECL goto_trace step.
Definition: json_goto_trace.cpp:59
goto_trace_stept::typet::OUTPUT
@ OUTPUT
goto_trace_stept::typet::FUNCTION_RETURN
@ FUNCTION_RETURN
goto_trace_stept::typet::DECL
@ DECL
goto_trace_stept::typet::ASSERT
@ ASSERT
goto_trace_stept::typet::NONE
@ NONE
json
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:120
convert_default
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.
Definition: json_goto_trace.cpp:279
goto_trace_stept::typet::ASSIGNMENT
@ ASSIGNMENT
conversion_dependenciest::step
const goto_trace_stept & step
Definition: json_goto_trace.h:29
conversion_dependenciest
This is structure is here to facilitate passing arguments to the conversion functions.
Definition: json_goto_trace.h:26
dstringt::empty
bool empty() const
Definition: dstring.h:88
goto_trace_stept::typet::INPUT
@ INPUT
goto_trace_stept::typet::ATOMIC_END
@ ATOMIC_END
goto_trace_stept::typet::SPAWN
@ SPAWN
conversion_dependenciest::ns
const namespacet & ns
Definition: json_goto_trace.h:30
source_locationt
Definition: source_location.h:18
convert_output
void convert_output(json_objectt &json_output, const conversion_dependenciest &conversion_dependencies)
Convert an OUTPUT goto_trace step.
Definition: json_goto_trace.cpp:166
goto_trace_stept::typet::MEMORY_BARRIER
@ MEMORY_BARRIER
goto_trace_stept::typet::SHARED_WRITE
@ SHARED_WRITE
default_trace_stept
Definition: structured_trace_util.h:40
goto_trace_stept::typet::GOTO
@ GOTO
convert_input
void convert_input(json_objectt &json_input, const conversion_dependenciest &conversion_dependencies)
Convert an INPUT goto_trace step.
Definition: json_goto_trace.cpp:208
trace_optionst
Options for printing the trace using show_goto_trace.
Definition: goto_trace.h:218
trace_optionst::default_options
static const trace_optionst default_options
Definition: goto_trace.h:236
goto_trace_stept::typet::ATOMIC_BEGIN
@ ATOMIC_BEGIN
json.h
goto_tracet
Trace of a GOTO program.
Definition: goto_trace.h:174
conversion_dependenciest::location
const jsont & location
Definition: json_goto_trace.h:28
source_locationt::get_file
const irep_idt & get_file() const
Definition: source_location.h:35
convert
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.
Definition: json_goto_trace.h:113
goto_trace_stept::typet::SHARED_READ
@ SHARED_READ
structured_trace_util.h
goto_trace_stept::typet::FUNCTION_CALL
@ FUNCTION_CALL
json_nullt
Definition: json.h:414
goto_trace_stept::typet::DEAD
@ DEAD
goto_trace_stept::typet::CONSTRAINT
@ CONSTRAINT