cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
json_goto_functions.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: JSON goto_functions deserialization
4
5
Author: Michael Tautschnig
6
7
\*******************************************************************/
8
11
12
#include "
json_goto_functions.h
"
13
14
#include <
util/exception_utils.h
>
15
#include <
util/json.h
>
16
17
#include <
goto-programs/goto_functions.h
>
18
19
#include "
json_goto_function.h
"
20
21
void
goto_functions_from_json
(
22
const
jsont
&
json
,
23
goto_functionst
&goto_functions)
24
{
25
if
(!
json
.is_object())
26
{
27
throw
deserialization_exceptiont
{
28
"goto_functions_from_json: JSON input must be an object"
};
29
}
30
31
const
json_objectt
&json_object =
to_json_object
(
json
);
32
const
auto
it = json_object.
find
(
"functions"
);
33
34
if
(it == json_object.
end
())
35
{
36
throw
deserialization_exceptiont
{
37
"goto_functions_from_json: JSON object must have key 'functions'"
};
38
}
39
40
if
(!it->second.is_array())
41
{
42
throw
deserialization_exceptiont
{
43
"goto_functions_from_json: JSON functions must be an array"
};
44
}
45
46
const
json_arrayt
&json_functions =
to_json_array
(it->second);
47
48
for
(
const
auto
&function : json_functions)
49
{
50
if
(!function.is_object())
51
{
52
throw
deserialization_exceptiont
{
53
"goto_functions_from_json: JSON function must be an object"
};
54
}
55
56
const
json_objectt
&json_function =
to_json_object
(function);
57
auto
name_it = json_function.
find
(
"name"
);
58
59
if
(name_it == json_function.
end
() || !name_it->second.is_string())
60
{
61
throw
deserialization_exceptiont
{
62
"goto_functions_from_json: JSON function object must have key 'name' "
63
"mapping to a string"
};
64
}
65
const
auto
function_name = name_it->second.value;
66
67
goto_functiont
goto_function =
goto_function_from_json
(json_function);
68
goto_functions.
function_map
[function_name] = std::move(goto_function);
69
}
70
71
goto_functions.
update
();
72
}
deserialization_exceptiont
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
Definition
exception_utils.h:80
goto_functionst
A collection of goto functions.
Definition
goto_functions.h:25
goto_functionst::function_map
function_mapt function_map
Definition
goto_functions.h:29
goto_functionst::update
void update()
Definition
goto_functions.h:88
goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition
goto_function.h:24
json_arrayt
Definition
json.h:165
json_objectt
Definition
json.h:298
json_objectt::find
iterator find(const std::string &key)
Definition
json.h:354
json_objectt::end
iterator end()
Definition
json.h:384
jsont
Definition
json.h:27
exception_utils.h
goto_functions.h
Goto Programs with Functions.
json.h
to_json_object
json_objectt & to_json_object(jsont &json)
Definition
json.h:442
to_json_array
json_arrayt & to_json_array(jsont &json)
Definition
json.h:424
goto_function_from_json
goto_functiont goto_function_from_json(const json_objectt &json)
Deserialize a goto_functiont from JSON.
Definition
json_goto_function.cpp:301
json_goto_function.h
JSON goto_function deserialization.
goto_functions_from_json
void goto_functions_from_json(const jsont &json, goto_functionst &goto_functions)
Deserialize goto_functionst from JSON.
Definition
json_goto_functions.cpp:21
json_goto_functions.h
JSON goto_functions deserialization.
json
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
Definition
properties.cpp:120
json-symtab-language
json_goto_functions.cpp
Generated by
1.17.0