@@ -421,7 +421,7 @@ void linkingt::link_warning(
421
421
<< type_to_string_verbose (new_symbol) << eom;
422
422
}
423
423
424
- irep_idt linkingt::rename (const irep_idt id)
424
+ irep_idt linkingt::rename (const irep_idt & id)
425
425
{
426
426
unsigned cnt=0 ;
427
427
@@ -1313,14 +1313,15 @@ void linkingt::do_type_dependencies(
1313
1313
}
1314
1314
}
1315
1315
1316
- void linkingt::rename_symbols (
1316
+ std::unordered_map<irep_idt, irep_idt> linkingt::rename_symbols (
1317
1317
const std::unordered_set<irep_idt> &needs_to_be_renamed)
1318
1318
{
1319
+ std::unordered_map<irep_idt, irep_idt> new_identifiers;
1319
1320
namespacet src_ns (src_symbol_table);
1320
1321
1321
1322
for (const irep_idt &id : needs_to_be_renamed)
1322
1323
{
1323
- symbolt &new_symbol = src_symbol_table. get_writeable_ref (id);
1324
+ const symbolt &new_symbol = src_ns. lookup (id);
1324
1325
1325
1326
irep_idt new_identifier;
1326
1327
@@ -1329,21 +1330,24 @@ void linkingt::rename_symbols(
1329
1330
else
1330
1331
new_identifier=rename (id);
1331
1332
1332
- new_symbol. name = new_identifier;
1333
+ new_identifiers. emplace (id, new_identifier) ;
1333
1334
1334
- #ifdef DEBUG
1335
+ #ifdef DEBUG
1335
1336
debug () << " LINKING: renaming " << id << " to "
1336
1337
<< new_identifier << eom;
1337
- #endif
1338
+ #endif
1338
1339
1339
1340
if (new_symbol.is_type )
1340
1341
rename_symbol.insert_type (id, new_identifier);
1341
1342
else
1342
1343
rename_symbol.insert_expr (id, new_identifier);
1343
1344
}
1345
+
1346
+ return new_identifiers;
1344
1347
}
1345
1348
1346
- void linkingt::copy_symbols ()
1349
+ void linkingt::copy_symbols (
1350
+ const std::unordered_map<irep_idt, irep_idt> &new_identifiers)
1347
1351
{
1348
1352
std::map<irep_idt, symbolt> src_symbols;
1349
1353
// First apply the renaming
@@ -1353,7 +1357,10 @@ void linkingt::copy_symbols()
1353
1357
// apply the renaming
1354
1358
rename_symbol (symbol.type );
1355
1359
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
+
1357
1364
src_symbols.emplace (named_symbol.first , std::move (symbol));
1358
1365
}
1359
1366
@@ -1435,15 +1442,15 @@ void linkingt::typecheck()
1435
1442
do_type_dependencies (needs_to_be_renamed);
1436
1443
1437
1444
// PHASE 2: actually rename them
1438
- rename_symbols (needs_to_be_renamed);
1445
+ auto new_identifiers = rename_symbols (needs_to_be_renamed);
1439
1446
1440
1447
// PHASE 3: copy new symbols to main table
1441
- copy_symbols ();
1448
+ copy_symbols (new_identifiers );
1442
1449
}
1443
1450
1444
1451
bool linking (
1445
1452
symbol_tablet &dest_symbol_table,
1446
- symbol_tablet &new_symbol_table,
1453
+ const symbol_tablet &new_symbol_table,
1447
1454
message_handlert &message_handler)
1448
1455
{
1449
1456
linkingt linking (
0 commit comments