CBMC
Loading...
Searching...
No Matches
show_goto_functions_json.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Goto Program
4
5Author: Thomas Kiley
6
7\*******************************************************************/
8
11
13
14#include <util/cprover_prefix.h>
15#include <util/json_irep.h>
16
17#include "goto_functions.h"
18
24
29 const goto_functionst &goto_functions)
30{
33
34 const auto sorted = goto_functions.sorted();
35
36 for(const auto &function_entry : sorted)
37 {
38 const irep_idt &function_name = function_entry->first;
39 const goto_functionst::goto_functiont &function = function_entry->second;
40
42 json_functions.push_back(jsont()).make_object();
43 json_function["name"] = json_stringt(function_name);
44 json_function["isBodyAvailable"]=
45 jsont::json_boolean(function.body_available());
46 bool is_internal = function_name.starts_with(CPROVER_PREFIX) ||
47 function_name.starts_with("java::array[") ||
48 function_name.starts_with("java::org.cprover") ||
49 function_name.starts_with("java::java");
50 json_function["isInternal"]=jsont::json_boolean(is_internal);
51
52 if(list_only)
53 continue;
54
55 if(function.body_available())
56 {
58
59 for(const goto_programt::instructiont &instruction :
60 function.body.instructions)
61 {
63 {"instructionId", json_stringt(instruction.to_string())}};
64
65 if(instruction.code().source_location().is_not_nil())
66 {
67 instruction_entry["sourceLocation"] =
68 json(instruction.code().source_location());
69 }
70
71 std::ostringstream instruction_builder;
72 instruction.output(instruction_builder);
73
74 instruction_entry["instruction"]=
76
77 if(!instruction.code().operands().empty())
78 {
80 for(const exprt &operand : instruction.code().operands())
81 {
83 no_comments_irep_converter.convert_from_irep(
84 operand);
86 }
87 instruction_entry["operands"] = std::move(operand_array);
88 }
89
90 if(instruction.has_condition())
91 {
93 no_comments_irep_converter.convert_from_irep(
94 instruction.condition());
95
96 instruction_entry["guard"] = std::move(guard_object);
97 }
98
99 json_instruction_array.push_back(std::move(instruction_entry));
100 }
101
102 json_function["instructions"] = std::move(json_instruction_array);
103 }
104 }
105
106 return json_objectt({{"functions", json_functions}});
107}
108
117 const goto_functionst &goto_functions,
118 std::ostream &out,
119 bool append)
120{
121 if(append)
122 {
123 out << ",\n";
124 }
125 out << convert(goto_functions);
126}
virtual void output(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
Output the abstract states for a single function.
Definition ai.cpp:39
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Definition dstring.h:95
Base class for all expressions.
Definition expr.h:56
A collection of goto functions.
::goto_functiont goto_functiont
std::vector< function_mapt::const_iterator > sorted() const
returns a vector of the iterators in alphabetical order
This class represents an instruction in the GOTO intermediate representation.
Definition json.h:27
static jsont json_boolean(bool value)
Definition json.h:97
void operator()(const goto_functionst &goto_functions, std::ostream &out, bool append=true)
Print the json object generated by show_goto_functions_jsont::show_goto_functions to the provided str...
json_objectt convert(const goto_functionst &goto_functions)
Walks through all of the functions in the program and returns a JSON object representing all their fu...
show_goto_functions_jsont(bool _list_only=false)
For outputting the GOTO program in a readable JSON format.
#define CPROVER_PREFIX
Goto Programs with Functions.
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)