@@ -421,7 +421,7 @@ void linkingt::link_warning(
421421 << type_to_string_verbose (new_symbol) << eom;
422422}
423423
424- irep_idt linkingt::rename (const irep_idt id)
424+ irep_idt linkingt::rename (const irep_idt & id)
425425{
426426 unsigned cnt=0 ;
427427
@@ -1313,14 +1313,15 @@ void linkingt::do_type_dependencies(
13131313 }
13141314}
13151315
1316- void linkingt::rename_symbols (
1316+ std::unordered_map<irep_idt, irep_idt> linkingt::rename_symbols (
13171317 const std::unordered_set<irep_idt> &needs_to_be_renamed)
13181318{
1319+ std::unordered_map<irep_idt, irep_idt> new_identifiers;
13191320 namespacet src_ns (src_symbol_table);
13201321
13211322 for (const irep_idt &id : needs_to_be_renamed)
13221323 {
1323- symbolt &new_symbol = src_symbol_table. get_writeable_ref (id);
1324+ const symbolt &new_symbol = src_ns. lookup (id);
13241325
13251326 irep_idt new_identifier;
13261327
@@ -1329,21 +1330,24 @@ void linkingt::rename_symbols(
13291330 else
13301331 new_identifier=rename (id);
13311332
1332- new_symbol. name = new_identifier;
1333+ new_identifiers. emplace (id, new_identifier) ;
13331334
1334- #ifdef DEBUG
1335+ #ifdef DEBUG
13351336 debug () << " LINKING: renaming " << id << " to "
13361337 << new_identifier << eom;
1337- #endif
1338+ #endif
13381339
13391340 if (new_symbol.is_type )
13401341 rename_symbol.insert_type (id, new_identifier);
13411342 else
13421343 rename_symbol.insert_expr (id, new_identifier);
13431344 }
1345+
1346+ return new_identifiers;
13441347}
13451348
1346- void linkingt::copy_symbols ()
1349+ void linkingt::copy_symbols (
1350+ const std::unordered_map<irep_idt, irep_idt> &new_identifiers)
13471351{
13481352 std::map<irep_idt, symbolt> src_symbols;
13491353 // First apply the renaming
@@ -1353,7 +1357,10 @@ void linkingt::copy_symbols()
13531357 // apply the renaming
13541358 rename_symbol (symbol.type );
13551359 rename_symbol (symbol.value );
1356- // Add to vector
1360+ auto it = new_identifiers.find (named_symbol.first );
1361+ if (it != new_identifiers.end ())
1362+ symbol.name = it->second ;
1363+
13571364 src_symbols.emplace (named_symbol.first , std::move (symbol));
13581365 }
13591366
@@ -1435,15 +1442,15 @@ void linkingt::typecheck()
14351442 do_type_dependencies (needs_to_be_renamed);
14361443
14371444 // PHASE 2: actually rename them
1438- rename_symbols (needs_to_be_renamed);
1445+ auto new_identifiers = rename_symbols (needs_to_be_renamed);
14391446
14401447 // PHASE 3: copy new symbols to main table
1441- copy_symbols ();
1448+ copy_symbols (new_identifiers );
14421449}
14431450
14441451bool linking (
14451452 symbol_tablet &dest_symbol_table,
1446- symbol_tablet &new_symbol_table,
1453+ const symbol_tablet &new_symbol_table,
14471454 message_handlert &message_handler)
14481455{
14491456 linkingt linking (
0 commit comments