21 #include <unordered_set>
27 for(
auto &identifier :
function.parameter_identifiers)
29 auto entry = rename_symbol.
expr_map.find(identifier);
30 if(entry != rename_symbol.
expr_map.end())
31 identifier = entry->second;
34 for(
auto &instruction :
function.body.instructions)
36 rename_symbol(instruction.code_nonconst());
38 if(instruction.has_condition())
39 rename_symbol(instruction.condition_nonconst());
52 const std::unordered_set<irep_idt> &weak_symbols)
58 for(
const auto &rename_entry : rename_dest_symbol.
expr_map)
60 auto fn_candidate = dest_functions.
function_map.find(rename_entry.first);
65 {rename_entry.second, std::move(fn_candidate->second)});
77 rename_symbolt::expr_mapt::const_iterator e_it =
78 rename_src_symbol.
expr_map.find(gf_entry.first);
82 if(e_it != rename_src_symbol.
expr_map.end())
83 final_id=e_it->second;
86 goto_functionst::function_mapt::iterator dest_f_it=
93 dest_functions.
function_map.emplace(final_id, std::move(src_func));
99 if(in_dest_symbol_table.body.instructions.empty() ||
100 weak_symbols.find(final_id)!=weak_symbols.end())
105 in_dest_symbol_table.body.swap(src_func.body);
106 in_dest_symbol_table.parameter_identifiers.swap(
107 src_func.parameter_identifiers);
110 src_func.body.instructions.empty() ||
111 src_ns.
lookup(gf_entry.first).is_weak)
130 std::unordered_set<irep_idt> weak_symbols;
134 if(symbol_pair.second.is_weak)
135 weak_symbols.insert(symbol_pair.first);
140 if(
linking.link(src.symbol_table))
161 return linking.object_type_updates.get_expr_map();
170 type_updates.begin(), type_updates.end());
178 for(
const auto &symbol_pair : dest_symbol_table.
symbols)
180 if(symbol_pair.second.is_macro && !symbol_pair.second.is_type)
182 const symbolt &symbol = symbol_pair.second;
188 if(!base_type_eq(symbol.
type, ns.lookup(
id).type, ns))
190 std::cerr << symbol <<
'\n';
191 std::cerr << ns.lookup(
id) <<
'\n';
201 if(!macro_application.
expr_map.empty())
207 if(!object_type_updates.
empty())
211 for(
auto &instruction : gf_entry.second.body.instructions)
213 if(instruction.is_function_call())
216 !object_type_updates.
replace(instruction.call_function());
217 if(changed && instruction.call_lhs().is_not_nil())
219 object_type_updates(instruction.call_lhs());
221 instruction.call_lhs().type() !=
225 instruction.call_lhs(),
232 instruction.transform([&object_type_updates](
exprt expr) {
233 const bool changed = !object_type_updates.
replace(expr);
234 return changed ? std::optional<exprt>{expr} : std::nullopt;
A variant of replace_symbolt that does not require types to match, but instead inserts type casts as ...
bool replace(exprt &dest) const override
const typet & return_type() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
A collection of goto functions.
function_mapt function_map
::goto_functiont goto_functiont
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
const irep_idt & id() const
Class that provides messages with a built-in verbosity 'level'.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void insert_expr(const irep_idt &old_id, const irep_idt &new_id)
const expr_mapt & get_expr_map() const
std::unordered_map< irep_idt, exprt > expr_mapt
const irep_idt & get_identifier() const
const symbolst & symbols
Read-only field, used to look up symbols given their names.
typet type
Type of symbol.
irep_idt name
The unique identifier.
exprt value
Initial value of symbol.
Semantic type conversion.
std::optional< replace_symbolt::expr_mapt > link_goto_model(goto_modelt &dest, goto_modelt &&src, message_handlert &message_handler)
Link goto model src into goto model dest, invalidating src in this process.
void finalize_linking(goto_modelt &dest, const replace_symbolt::expr_mapt &type_updates)
Apply type_updates to dest, where type_updates were constructed from one or more calls to link_goto_m...
static void rename_symbols_in_function(goto_functionst::goto_functiont &function, const rename_symbolt &rename_symbol)
static bool link_functions(symbol_tablet &dest_symbol_table, goto_functionst &dest_functions, const symbol_tablet &src_symbol_table, goto_functionst &src_functions, const rename_symbolt &rename_dest_symbol, const rename_symbolt &rename_src_symbol, const std::unordered_set< irep_idt > &weak_symbols)
Link a set of goto functions, considering weak symbols and symbol renaming.
bool linking(symbol_table_baset &dest_symbol_table, const symbol_table_baset &new_symbol_table, message_handlert &message_handler)
Merges the symbol table new_symbol_table into dest_symbol_table, renaming symbols from new_symbol_tab...
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.