-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathjson_goto_trace.h
201 lines (173 loc) · 6.49 KB
/
json_goto_trace.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*******************************************************************\
Module: Traces of GOTO Programs
Author: Daniel Kroening
Date: November 2005
\*******************************************************************/
/// \file
/// Traces of GOTO Programs
#ifndef CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H
#define CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H
#include "goto_trace.h"
#include "structured_trace_util.h"
#include <util/json.h>
#include <util/json_irep.h>
/// This is structure is here to facilitate
/// passing arguments to the conversion
/// functions.
typedef struct
{
const jsont &location;
const goto_trace_stept &step;
const namespacet &ns;
} conversion_dependenciest;
/// Convert an ASSERT goto_trace step.
/// \param [out] json_failure: The JSON object that
/// will contain the information about the step
/// after this function has run.
/// \param conversion_dependencies: A structure
/// that contains information the conversion function
/// needs.
void convert_assert(
json_objectt &json_failure,
const conversion_dependenciest &conversion_dependencies);
/// Convert a DECL goto_trace step.
/// \param [out] json_assignment: The JSON object that
/// will contain the information about the step
/// after this function has run.
/// \param conversion_dependencies: A structure
/// that contains information the conversion function
/// needs.
/// \param trace_options: Extra information used by this
/// particular conversion function.
void convert_decl(
json_objectt &json_assignment,
const conversion_dependenciest &conversion_dependencies,
const trace_optionst &trace_options);
/// Convert an OUTPUT goto_trace step.
/// \param [out] json_output: The JSON object that
/// will contain the information about the step
/// after this function has run.
/// \param conversion_dependencies: A structure
/// that contains information the conversion function
/// needs.
void convert_output(
json_objectt &json_output,
const conversion_dependenciest &conversion_dependencies);
/// Convert an INPUT goto_trace step.
/// \param [out] json_input: The JSON object that
/// will contain the information about the step
/// after this function has run.
/// \param conversion_dependencies: A structure
/// that contains information the conversion function
/// needs.
void convert_input(
json_objectt &json_input,
const conversion_dependenciest &conversion_dependencies);
/// Convert a FUNCTION_RETURN goto_trace step.
/// \param [out] json_call_return: The JSON object that
/// will contain the information about the step
/// after this function has run.
/// \param conversion_dependencies: A structure
/// that contains information the conversion function
/// needs.
void convert_return(
json_objectt &json_call_return,
const conversion_dependenciest &conversion_dependencies);
/// Convert all other types of steps not already handled
/// by the other conversion functions.
/// \param [out] json_location_only: The JSON object that
/// will contain the information about the step
/// after this function has run.
/// \param default_step: The procesed details about this step, see \ref
/// default_step_kind
void convert_default(
json_objectt &json_location_only,
const default_trace_stept &default_step);
/// Templated version of the conversion method.
/// Works by dispatching to the more specialised
/// conversion functions based on the type of the
/// step that is being handled.
/// \param ns: The namespace used for resolution of symbols.
/// \param goto_trace: The goto_trace from which we are
/// going to convert the steps from.
/// \param dest_array: The JSON object that we are going
/// to append the step information to.
/// \param trace_options: A list of trace options
template <typename json_arrayT>
void convert(
const namespacet &ns,
const goto_tracet &goto_trace,
json_arrayT &dest_array,
trace_optionst trace_options = trace_optionst::default_options)
{
source_locationt previous_source_location;
for(const auto &step : goto_trace.steps)
{
const source_locationt &source_location = step.pc->source_location();
jsont json_location;
source_location.is_not_nil() && !source_location.get_file().empty()
? json_location = json(source_location)
: json_location = json_nullt();
// NOLINTNEXTLINE(whitespace/braces)
conversion_dependenciest conversion_dependencies = {
json_location, step, ns};
switch(step.type)
{
case goto_trace_stept::typet::ASSERT:
if(!step.cond_value)
{
json_objectt &json_failure = dest_array.push_back().make_object();
convert_assert(json_failure, conversion_dependencies);
}
break;
case goto_trace_stept::typet::ASSIGNMENT:
case goto_trace_stept::typet::DECL:
{
json_objectt &json_assignment = dest_array.push_back().make_object();
convert_decl(json_assignment, conversion_dependencies, trace_options);
}
break;
case goto_trace_stept::typet::OUTPUT:
{
json_objectt &json_output = dest_array.push_back().make_object();
convert_output(json_output, conversion_dependencies);
}
break;
case goto_trace_stept::typet::INPUT:
{
json_objectt &json_input = dest_array.push_back().make_object();
convert_input(json_input, conversion_dependencies);
}
break;
case goto_trace_stept::typet::FUNCTION_CALL:
case goto_trace_stept::typet::FUNCTION_RETURN:
{
json_objectt &json_call_return = dest_array.push_back().make_object();
convert_return(json_call_return, conversion_dependencies);
}
break;
case goto_trace_stept::typet::ATOMIC_BEGIN:
case goto_trace_stept::typet::ATOMIC_END:
case goto_trace_stept::typet::DEAD:
case goto_trace_stept::typet::LOCATION:
case goto_trace_stept::typet::GOTO:
case goto_trace_stept::typet::ASSUME:
case goto_trace_stept::typet::MEMORY_BARRIER:
case goto_trace_stept::typet::SPAWN:
case goto_trace_stept::typet::SHARED_READ:
case goto_trace_stept::typet::SHARED_WRITE:
case goto_trace_stept::typet::CONSTRAINT:
case goto_trace_stept::typet::NONE:
const auto default_step = ::default_step(step, previous_source_location);
if(default_step)
{
json_objectt &json_location_only = dest_array.push_back().make_object();
convert_default(json_location_only, *default_step);
}
break;
}
if(source_location.is_not_nil() && !source_location.get_file().empty())
previous_source_location = source_location;
}
}
#endif // CPROVER_GOTO_PROGRAMS_JSON_GOTO_TRACE_H