CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
json_irep.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Util
4
5Author: Thomas Kiley, thomas.kiley@diffblue.com
6
7\*******************************************************************/
8
11
12#include "json_irep.h"
13
14#include "exception_utils.h"
15#include "irep.h"
16#include "json.h"
17
26
32{
34
35 irep_object["id"] = json_stringt(irep.id_string());
36
37 convert_sub_tree("sub", irep.get_sub(), irep_object);
39
40 return irep_object;
41}
42
49
51 const std::string &sub_tree_id,
53 json_objectt &parent) const
54{
55 if(!sub_trees.empty())
56 {
58 for(const irept &sub_tree : sub_trees)
59 {
61 sub_objects.push_back(sub_object);
62 }
64 }
65}
66
75 const std::string &sub_tree_id,
77 json_objectt &parent) const
78{
79 if(!sub_trees.empty())
80 {
82 for(const auto &sub_tree : sub_trees)
84 {
87 }
89 }
90}
91
96{
97 if(!in.is_object())
98 {
100 "irep JSON representation must be an object");
101 }
102
104
105 irept out;
106
107 {
108 const auto it = json_object.find("id");
109
110 if(it != json_object.end())
111 {
112 out.id(it->second.value);
113 }
114 }
115
116 {
117 const auto it = json_object.find("sub");
118
119 if(it != json_object.end())
120 {
121 for(const auto &sub : to_json_array(it->second))
122 out.get_sub().push_back(convert_from_json(sub));
123 }
124 }
125
126 {
127 const auto it = json_object.find("namedSub");
128
129 if(it != json_object.end())
130 {
131 for(const auto &named_sub : to_json_object(it->second))
132 out.add(named_sub.first) = convert_from_json(named_sub.second);
133 }
134 }
135
136 return out;
137}
138
140{
141 json_objectt result;
142
143 if(!location.get_working_directory().empty())
144 result["workingDirectory"] = json_stringt(location.get_working_directory());
145
146 if(!location.get_file().empty())
147 result["file"] = json_stringt(location.get_file());
148
149 if(!location.get_line().empty())
150 result["line"] = json_stringt(location.get_line());
151
152 if(!location.get_column().empty())
153 result["column"] = json_stringt(location.get_column());
154
155 if(!location.get_function().empty())
156 result["function"] = json_stringt(location.get_function());
157
158 if(!location.get_java_bytecode_index().empty())
159 result["bytecodeIndex"] = json_stringt(location.get_java_bytecode_index());
160
161 return result;
162}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition irep.h:364
const std::string & id_string() const
Definition irep.h:391
subt & get_sub()
Definition irep.h:448
static bool is_comment(const irep_idt &name)
Definition irep.h:460
const irep_idt & id() const
Definition irep.h:388
irept & add(const irep_idt &name)
Definition irep.cpp:103
named_subt & get_named_sub()
Definition irep.h:450
json_irept(bool include_comments)
To convert to JSON from an irep structure by recursively generating JSON for the different sub trees.
Definition json_irep.cpp:22
bool include_comments
Definition json_irep.h:38
irept convert_from_json(const jsont &) const
Deserialize a JSON irep representation.
Definition json_irep.cpp:95
json_objectt convert_from_irep(const irept &) const
To convert to JSON from an irep structure by recursively generating JSON for the different sub trees.
Definition json_irep.cpp:31
void convert_sub_tree(const std::string &sub_tree_id, const irept::subt &sub_trees, json_objectt &parent) const
To convert to JSON from a list of ireps that are in an unlabelled subtree.
Definition json_irep.cpp:50
void convert_named_sub_tree(const std::string &sub_tree_id, const irept::named_subt &sub_trees, json_objectt &parent) const
To convert to JSON from a map of ireps that are in a named subtree.
Definition json_irep.cpp:74
Definition json.h:27
bool is_object() const
Definition json.h:56
const irep_idt & get_java_bytecode_index() const
const irep_idt & get_column() const
const irep_idt & get_function() const
const irep_idt & get_working_directory() const
const irep_idt & get_file() const
const irep_idt & get_line() const
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
json_objectt & to_json_object(jsont &json)
Definition json.h:442
json_arrayt & to_json_array(jsont &json)
Definition json.h:424
json_objectt json(const source_locationt &location)