26 auto code_it =
json.find(
"code");
27 if(code_it ==
json.end())
29 "instruction_from_json: key 'code' not found"};
47 "instruction_from_json: expected '" +
id2string(code_id) +
"', got '" +
58 auto guard_it =
json.find(
"guard");
59 if(guard_it ==
json.end())
61 "instruction_from_json: key 'guard' not found"};
65 return static_cast<exprt &
>(guard_irep);
74 auto id_it =
json.find(
"instructionId");
75 if(id_it ==
json.end())
78 "instruction_from_json: key 'instructionId' not found"};
80 auto instruction_type =
try_get_string(id_it->second,
"instructionId");
83 auto location_it =
json.find(
"sourceLocation");
84 if(location_it !=
json.end())
87 if(instruction_type ==
"GOTO")
92 else if(instruction_type ==
"ASSUME")
96 else if(instruction_type ==
"ASSERT")
100 else if(instruction_type ==
"OTHER")
104 else if(instruction_type ==
"SKIP")
108 else if(instruction_type ==
"START_THREAD")
117 else if(instruction_type ==
"END_THREAD")
126 else if(instruction_type ==
"LOCATION")
130 else if(instruction_type ==
"END_FUNCTION")
134 else if(instruction_type ==
"ATOMIC_BEGIN")
138 else if(instruction_type ==
"ATOMIC_END")
142 else if(instruction_type ==
"SET_RETURN_VALUE")
148 else if(instruction_type ==
"ASSIGN")
153 else if(instruction_type ==
"DECL")
158 else if(instruction_type ==
"DEAD")
167 else if(instruction_type ==
"FUNCTION_CALL")
173 else if(instruction_type ==
"THROW")
177 else if(instruction_type ==
"CATCH")
184 "instruction_from_json: got unexpected instructionId '" +
185 instruction_type +
"'"};
200 std::map<unsigned, goto_programt::targett> target_map;
203 if(!instruction_json.is_object())
207 auto location_number_it = json_object.
find(
"locationNumber");
208 std::optional<unsigned> loc_unsigned;
210 location_number_it != json_object.
end() &&
211 location_number_it->second.is_number())
215 if(!loc_unsigned.has_value())
218 "goto_program_from_json: key 'locationNumber' not found or does not "
219 "map to an unsigned number"};
224 target_map.insert({*loc_unsigned, std::prev(program.
instructions.end())})
229 "goto_program_from_json: duplicate locationNumber " +
230 location_number_it->second.value};
241 kv.first ==
"code" || kv.first ==
"guard" ||
242 kv.first ==
"instruction" || kv.first ==
"instructionId" ||
243 kv.first ==
"locationNumber" || kv.first ==
"sourceLocation")
247 else if(kv.first ==
"labels")
249 if(!kv.second.is_array())
254 if(!label.is_string())
256 instruction_it->labels.push_back(label.value);
259 else if(kv.first ==
"targets")
261 if(!kv.second.is_array())
266 std::optional<unsigned> target_unsigned =
268 if(!target.is_number() || !target_unsigned.has_value())
270 "target must be an unsigned number"};
271 auto target_it = target_map.find(*target_unsigned);
272 if(target_it == target_map.end())
274 instruction_it->targets.push_back(target_it->second);
278 !instruction_it->is_incomplete_goto() ||
279 instruction_it->targets.empty())
282 "goto_program_from_json: invalid targets entry"};
285 instruction_it->targets.pop_back();
286 instruction_it->complete_goto(target);
291 "goto_program_from_json: unexpected key '" + kv.first +
"'"};
305 for(
const auto &kv :
json)
307 if(kv.first ==
"instructions")
311 else if(kv.first ==
"parameterIdentifiers")
313 if(!kv.second.is_array())
316 "parameterIdentifiers must be an array"};
321 if(!param.is_string())
324 "parameter identifier must be a string"};
329 else if(kv.first ==
"isHidden")
334 else if(kv.first ==
"name")
338 else if(kv.first ==
"isBodyAvailable" || kv.first ==
"isInternal")
345 "goto_function_from_json: unexpected key '" + kv.first +
"'"};
const irep_idt & get_statement() const
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
Base class for all expressions.
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
parameter_identifierst parameter_identifiers
The identifiers of the parameters of this function.
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
static instructiont make_set_return_value(exprt return_value, const source_locationt &l=source_locationt::nil())
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
instructionst::iterator targett
static instructiont make_atomic_end(const source_locationt &l=source_locationt::nil())
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
static instructiont make_throw(const source_locationt &l=source_locationt::nil())
static instructiont make_other(const goto_instruction_codet &_code, const source_locationt &l=source_locationt::nil())
static instructiont make_catch(const source_locationt &l=source_locationt::nil())
static instructiont make_atomic_begin(const source_locationt &l=source_locationt::nil())
static instructiont make_location(const source_locationt &l)
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
There are a large number of kinds of tree structured or tree-like data in CPROVER.
irept convert_from_json(const jsont &) const
Deserialize a JSON irep representation.
iterator find(const std::string &key)
static const source_locationt & nil()
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
const code_deadt & to_code_dead(const goto_instruction_codet &code)
codet goto_instruction_codet
const code_assignt & to_code_assign(const goto_instruction_codet &code)
const code_declt & to_code_decl(const goto_instruction_codet &code)
const code_returnt & to_code_return(const goto_instruction_codet &code)
const irept & get_nil_irep()
const std::string & id2string(const irep_idt &d)
json_objectt & to_json_object(jsont &json)
json_arrayt & to_json_array(jsont &json)
static goto_instruction_codet try_get_code(const json_objectt &json)
Return code at "code" key in a JSON object, if any.
goto_functiont goto_function_from_json(const json_objectt &json)
Deserialize a goto_functiont from JSON.
static exprt try_get_guard(const json_objectt &json)
Return expression at "guard" key in a JSON object, if any.
static goto_programt goto_program_from_json(const jsont &json)
Deserialize a goto_programt from JSON.
static goto_programt::instructiont instruction_from_json(const json_objectt &json)
Deserialize a goto_programt::instructiont from JSON.
JSON goto_function deserialization.
bool try_get_bool(const jsont &in, const std::string &key)
Return boolean value for a given key if present in the json object.
source_locationt try_get_source_location(const jsont &json)
Return a source_locationt from the given JSON object.
const std::string & try_get_string(const jsont &in, const std::string &key)
Return string value for a given key if present in the json object.
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
std::optional< unsigned > string2optional_unsigned(const std::string &str, int base)
Convert string to unsigned similar to the stoul or stoull functions, return nullopt when the conversi...