@@ -20,16 +20,12 @@ Date: June 2006
2020#include " goto_functions.h"
2121#include " write_goto_binary.h"
2222
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 (
2724 std::istream &in,
2825 symbol_table_baset &symbol_table,
29- goto_functionst &functions,
3026 irep_serializationt &irepconverter)
3127{
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
3329
3430 for (std::size_t i=0 ; i<count; i++)
3531 {
@@ -69,17 +65,42 @@ static bool read_bin_goto_object(
6965 sym.is_extern = (flags &(1 << 1 ))!=0 ;
7066 sym.is_volatile = (flags &1 )!=0 ;
7167
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-
7968 symbol_table.add (sym);
8069 }
70+ }
8171
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
83104
84105 for (std::size_t fct_index = 0 ; fct_index < count; ++fct_index)
85106 {
@@ -166,8 +187,19 @@ static bool read_bin_goto_object(
166187 }
167188
168189 functions.compute_location_numbers ();
190+ }
169191
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);
171203}
172204
173205// / reads a goto binary file back into a symbol and a function table
@@ -224,7 +256,7 @@ bool read_bin_goto_object(
224256 // symbol_serializationt symbolconverter(ic);
225257
226258 {
227- std::size_t version= irepconverter.read_gb_word (in);
259+ const std::size_t version = irepconverter.read_gb_word (in);
228260
229261 if (version < GOTO_BINARY_VERSION)
230262 {
@@ -235,7 +267,8 @@ bool read_bin_goto_object(
235267 }
236268 else if (version == GOTO_BINARY_VERSION)
237269 {
238- return read_bin_goto_object (in, symbol_table, functions, irepconverter);
270+ read_bin_goto_object (in, symbol_table, functions, irepconverter);
271+ return false ;
239272 }
240273 else
241274 {
@@ -246,5 +279,5 @@ bool read_bin_goto_object(
246279 }
247280 }
248281
249- return false ;
282+ UNREACHABLE ;
250283}
0 commit comments