1111#include " goto_convert_functions.h"
1212#include < util/message.h>
1313#include < util/language_file.h>
14-
14+ # include < util/journalling_symbol_table.h >
1515
1616// / Provides a wrapper for a map of lazily loaded goto_functiont.
1717// / This incrementally builds a goto-functions object, while permitting
@@ -48,7 +48,9 @@ class lazy_goto_functions_mapt final
4848 typedef std::size_t size_type;
4949
5050 typedef
51- std::function<void (goto_functionst::goto_functiont &function)>
51+ std::function<void (
52+ goto_functionst::goto_functiont &function,
53+ journalling_symbol_tablet &function_symbols)>
5254 post_process_functiont;
5355
5456private:
@@ -61,11 +63,8 @@ class lazy_goto_functions_mapt final
6163
6264 language_filest &language_files;
6365 symbol_tablet &symbol_table;
64- // This is mutable because it has internal state that it changes during the
65- // course of conversion. Strictly it should make that state mutable or
66- // recreate it for each conversion, but it's easier just to store it mutable.
67- mutable goto_convert_functionst convert_functions;
6866 const post_process_functiont post_process_function;
67+ message_handlert &message_handler;
6968
7069public:
7170 // / Creates a lazy_goto_functions_mapt.
@@ -78,8 +77,8 @@ class lazy_goto_functions_mapt final
7877 : goto_functions(goto_functions),
7978 language_files (language_files),
8079 symbol_table(symbol_table),
81- convert_functions(symbol_table, message_handler ),
82- post_process_function(std::move(post_process_function) )
80+ post_process_function(std::move(post_process_function) ),
81+ message_handler(message_handler )
8382 {
8483 }
8584
@@ -122,29 +121,43 @@ class lazy_goto_functions_mapt final
122121 // const first
123122 reference ensure_function_loaded_internal (const key_type &name) const
124123 {
125- reference named_function=ensure_entry_converted (name);
124+ journalling_symbol_tablet journalling_table =
125+ journalling_symbol_tablet::wrap (symbol_table);
126+ reference named_function=ensure_entry_converted (name, journalling_table);
126127 mapped_type function=named_function.second ;
127128 if (processed_functions.count (name)==0 )
128129 {
129130 // Run function-pass conversions
130- post_process_function (function);
131+ post_process_function (function, journalling_table );
131132 // Assign procedure-local location numbers for now
132133 function.body .compute_location_numbers ();
133134 processed_functions.insert (name);
134135 }
135136 return named_function;
136137 }
137138
138- reference ensure_entry_converted (const key_type &name) const
139+ // / Convert a function if not already converted, then return a reference to
140+ // / its goto_functionst map entry.
141+ // / \param name: ID of the function to convert
142+ // / \param function_symbol_table: mutable symbol table reference to be used
143+ // / when converting the function (e.g. to add new local variables).
144+ // / Note we should not use a global pre-cached symbol table reference for
145+ // / this so that our callers can insert a journalling table here if needed.
146+ // / \return reference to the new or existing goto_functions map entry.
147+ reference ensure_entry_converted (
148+ const key_type &name,
149+ symbol_table_baset &function_symbol_table) const
139150 {
140151 typename underlying_mapt::iterator it=goto_functions.find (name);
141152 if (it!=goto_functions.end ())
142153 return *it;
143154 // Fill in symbol table entry body if not already done
144155 // If this returns false then it's a stub
145- language_files.convert_lazy_method (name, symbol_table );
156+ language_files.convert_lazy_method (name, function_symbol_table );
146157 // Create goto_functiont
147158 goto_functionst::goto_functiont function;
159+ goto_convert_functionst convert_functions (
160+ function_symbol_table, message_handler);
148161 convert_functions.convert_function (name, function);
149162 // Add to map
150163 return *goto_functions.emplace (name, std::move (function)).first ;
0 commit comments