@@ -20,16 +20,12 @@ Date: June 2006
20
20
#include " goto_functions.h"
21
21
#include " write_goto_binary.h"
22
22
23
- // / read goto binary format
24
- // / \par parameters: input stream, symbol_table, functions
25
- // / \return true on error, false otherwise
26
- static bool read_bin_goto_object (
23
+ static void read_bin_symbol_table_object (
27
24
std::istream &in,
28
25
symbol_table_baset &symbol_table,
29
- goto_functionst &functions,
30
26
irep_serializationt &irepconverter)
31
27
{
32
- std::size_t count = irepconverter.read_gb_word (in); // # of symbols
28
+ const std::size_t count = irepconverter.read_gb_word (in); // # of symbols
33
29
34
30
for (std::size_t i=0 ; i<count; i++)
35
31
{
@@ -69,17 +65,42 @@ static bool read_bin_goto_object(
69
65
sym.is_extern = (flags &(1 << 1 ))!=0 ;
70
66
sym.is_volatile = (flags &1 )!=0 ;
71
67
72
- if (!sym.is_type && sym.type .id ()==ID_code)
73
- {
74
- // makes sure there is an empty function for every function symbol
75
- auto entry = functions.function_map .emplace (sym.name , goto_functiont ());
76
- entry.first ->second .set_parameter_identifiers (to_code_type (sym.type ));
77
- }
78
-
79
68
symbol_table.add (sym);
80
69
}
70
+ }
81
71
82
- count=irepconverter.read_gb_word (in); // # of functions
72
+ // / The serialised form of the goto-model currently includes the parameter
73
+ // / identifiers in the symbol table attached to the types of function symbols.
74
+ // / However it is not included in the goto functions. Therefore this function is
75
+ // / needed to copy the parameter identifiers from the symbol table to the
76
+ // / functions.
77
+ static void copy_parameter_identifiers (
78
+ const symbol_table_baset &symbol_table,
79
+ goto_functionst &functions)
80
+ {
81
+ for (const auto &name_symbol : symbol_table)
82
+ {
83
+ const auto &symbol = name_symbol.second ;
84
+ if (symbol.is_type )
85
+ continue ;
86
+
87
+ const auto code_type = type_try_dynamic_cast<code_typet>(symbol.type );
88
+ if (!code_type)
89
+ continue ;
90
+
91
+ // Makes sure there is an empty function for every function symbol.
92
+ auto emplaced =
93
+ functions.function_map .emplace (symbol.name , goto_functiont ());
94
+ emplaced.first ->second .set_parameter_identifiers (*code_type);
95
+ }
96
+ }
97
+
98
+ static void read_bin_functions_object (
99
+ std::istream &in,
100
+ goto_functionst &functions,
101
+ irep_serializationt &irepconverter)
102
+ {
103
+ const std::size_t count = irepconverter.read_gb_word (in); // # of functions
83
104
84
105
for (std::size_t fct_index = 0 ; fct_index < count; ++fct_index)
85
106
{
@@ -166,8 +187,19 @@ static bool read_bin_goto_object(
166
187
}
167
188
168
189
functions.compute_location_numbers ();
190
+ }
169
191
170
- return false ;
192
+ // / read goto binary format
193
+ // / \par parameters: input stream, symbol_table, functions
194
+ static void read_bin_goto_object (
195
+ std::istream &in,
196
+ symbol_table_baset &symbol_table,
197
+ goto_functionst &functions,
198
+ irep_serializationt &irepconverter)
199
+ {
200
+ read_bin_symbol_table_object (in, symbol_table, irepconverter);
201
+ copy_parameter_identifiers (symbol_table, functions);
202
+ read_bin_functions_object (in, functions, irepconverter);
171
203
}
172
204
173
205
// / reads a goto binary file back into a symbol and a function table
@@ -224,7 +256,7 @@ bool read_bin_goto_object(
224
256
// symbol_serializationt symbolconverter(ic);
225
257
226
258
{
227
- std::size_t version= irepconverter.read_gb_word (in);
259
+ const std::size_t version = irepconverter.read_gb_word (in);
228
260
229
261
if (version < GOTO_BINARY_VERSION)
230
262
{
@@ -235,7 +267,8 @@ bool read_bin_goto_object(
235
267
}
236
268
else if (version == GOTO_BINARY_VERSION)
237
269
{
238
- return read_bin_goto_object (in, symbol_table, functions, irepconverter);
270
+ read_bin_goto_object (in, symbol_table, functions, irepconverter);
271
+ return false ;
239
272
}
240
273
else
241
274
{
@@ -246,5 +279,5 @@ bool read_bin_goto_object(
246
279
}
247
280
}
248
281
249
- return false ;
282
+ UNREACHABLE ;
250
283
}
0 commit comments