cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
json_symbol_table.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: JSON symbol table deserialization
4
5
Author: Chris Smowton, chris.smowton@diffblue.com
6
7
\*******************************************************************/
8
9
#include "
json_symbol_table.h
"
10
11
#include <
util/exception_utils.h
>
12
#include <
util/json.h
>
13
#include <
util/symbol_table_base.h
>
14
15
#include "
json_symbol.h
"
16
17
void
symbol_table_from_json
(
const
jsont
&in,
symbol_table_baset
&symbol_table)
18
{
19
if
(!in.
is_object
())
20
{
21
throw
deserialization_exceptiont
(
22
"symbol_table_from_json: JSON input must be an object"
);
23
}
24
25
const
json_objectt
&json_object =
to_json_object
(in);
26
const
auto
it = json_object.
find
(
"symbolTable"
);
27
28
if
(it == json_object.
end
())
29
{
30
throw
deserialization_exceptiont
(
31
"symbol_table_from_json: JSON object must have key `symbolTable`"
);
32
}
33
34
if
(!it->second.is_object())
35
{
36
throw
deserialization_exceptiont
(
37
"symbol_table_from_json: JSON symbol table must be an object"
);
38
}
39
40
const
json_objectt
&json_symbol_table =
to_json_object
(it->second);
41
42
for
(
const
auto
&pair : json_symbol_table)
43
{
44
const
jsont
&json_symbol = pair.second;
45
46
symbolt
symbol =
symbol_from_json
(json_symbol);
47
48
if
(symbol_table.
add
(symbol))
49
throw
deserialization_exceptiont
(
50
"symbol_table_from_json: duplicate symbol name `"
+
51
id2string
(symbol.
name
) +
"`"
);
52
}
53
54
symbol_table.
validate
(
validation_modet::EXCEPTION
);
55
}
deserialization_exceptiont
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
Definition
exception_utils.h:80
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
jsont::is_object
bool is_object() const
Definition
json.h:56
symbol_table_baset
The symbol table base class interface.
Definition
symbol_table_base.h:23
symbol_table_baset::validate
virtual void validate(const validation_modet vm=validation_modet::INVARIANT) const =0
symbol_table_baset::add
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Definition
symbol_table_base.cpp:18
symbolt
Symbol table entry.
Definition
symbol.h:28
symbolt::name
irep_idt name
The unique identifier.
Definition
symbol.h:40
exception_utils.h
id2string
const std::string & id2string(const irep_idt &d)
Definition
irep.h:44
json.h
to_json_object
json_objectt & to_json_object(jsont &json)
Definition
json.h:442
symbol_from_json
symbolt symbol_from_json(const jsont &in)
Deserialise a json object to a symbolt.
Definition
json_symbol.cpp:140
json_symbol.h
symbol_table_from_json
void symbol_table_from_json(const jsont &in, symbol_table_baset &symbol_table)
Definition
json_symbol_table.cpp:17
json_symbol_table.h
symbol_table_base.h
Author: Diffblue Ltd.
validation_modet::EXCEPTION
@ EXCEPTION
Definition
validation_mode.h:15
json-symtab-language
json_symbol_table.cpp
Generated by
1.17.0