@@ -1452,18 +1452,22 @@ public void remapClashingNames(Statement root, StructMethod mt) {
1452
1452
start += (md .params [i ].stackSize - 1 );
1453
1453
}
1454
1454
1455
- iterateClashingNames (root , mt , varDefinitions , liveVarDefs , nameMap );
1455
+ Set <String > seenMethods = new HashSet <>();
1456
+ seenMethods .add (InterpreterUtil .makeUniqueKey (mt .getName (), mt .getDescriptor ()));
1457
+
1458
+ iterateClashingNames (root , mt , varDefinitions , liveVarDefs , nameMap , seenMethods );
1456
1459
}
1457
1460
1458
- private void iterateClashingNames (Statement stat , StructMethod mt , Map <Statement , Set <VarInMethod >> varDefinitions , Set <VarInMethod > liveVarDefs , Map <VarInMethod , String > nameMap ) {
1461
+ private void iterateClashingNames (Statement stat , StructMethod mt , Map <Statement , Set <VarInMethod >> varDefinitions ,
1462
+ Set <VarInMethod > liveVarDefs , Map <VarInMethod , String > nameMap , Set <String > seenMethods ) {
1459
1463
Set <VarInMethod > curVarDefs = new HashSet <>();
1460
1464
1461
1465
boolean shouldRemoveAtEnd = false ;
1462
1466
1463
1467
// Process var definitions as owned by the parent- they come before the statement, and so their scope extends past the actual statement.
1464
1468
for (Exprent exprent : stat .getVarDefinitions ()) {
1465
1469
Set <VarInMethod > upDefs = new HashSet <>();
1466
- iterateClashingExprent (stat , mt , varDefinitions , exprent , liveVarDefs , upDefs , nameMap );
1470
+ iterateClashingExprent (stat , mt , varDefinitions , exprent , liveVarDefs , upDefs , nameMap , seenMethods );
1467
1471
liveVarDefs .addAll (upDefs );
1468
1472
varDefinitions .put (stat .getParent (), upDefs );
1469
1473
}
@@ -1474,7 +1478,7 @@ private void iterateClashingNames(Statement stat, StructMethod mt, Map<Statement
1474
1478
BasicBlockStatement basic = stat .getBasichead ();
1475
1479
for (Exprent exprent : basic .getExprents ()) {
1476
1480
for (Exprent ex : exprent .getAllExprents (true , true )) {
1477
- iterateClashingExprent (basic , mt , varDefinitions , ex , liveVarDefs , upDefs , nameMap );
1481
+ iterateClashingExprent (basic , mt , varDefinitions , ex , liveVarDefs , upDefs , nameMap , seenMethods );
1478
1482
}
1479
1483
}
1480
1484
@@ -1489,7 +1493,7 @@ private void iterateClashingNames(Statement stat, StructMethod mt, Map<Statement
1489
1493
// Sort order from getAllExprents here is crucial!
1490
1494
// Say, for example, "MyType t = method(t -> ....);"
1491
1495
// It is imperative that the lhs of the assign comes first, so that any defs in the rhs can be properly seen.
1492
- iterateClashingExprent (stat , mt , varDefinitions , ex , liveVarDefs , curVarDefs , nameMap );
1496
+ iterateClashingExprent (stat , mt , varDefinitions , ex , liveVarDefs , curVarDefs , nameMap , seenMethods );
1493
1497
}
1494
1498
}
1495
1499
} else {
@@ -1499,7 +1503,7 @@ private void iterateClashingNames(Statement stat, StructMethod mt, Map<Statement
1499
1503
List <Exprent > exprents = ((Exprent ) obj ).getAllExprents (true , true );
1500
1504
1501
1505
for (Exprent exprent : exprents ) {
1502
- iterateClashingExprent (stat , mt , varDefinitions , exprent , liveVarDefs , curVarDefs , nameMap );
1506
+ iterateClashingExprent (stat , mt , varDefinitions , exprent , liveVarDefs , curVarDefs , nameMap , seenMethods );
1503
1507
}
1504
1508
}
1505
1509
}
@@ -1538,7 +1542,7 @@ private void iterateClashingNames(Statement stat, StructMethod mt, Map<Statement
1538
1542
}
1539
1543
}
1540
1544
1541
- iterateClashingNames (st , mt , varDefinitions , liveVarDefs , nameMap );
1545
+ iterateClashingNames (st , mt , varDefinitions , liveVarDefs , nameMap , seenMethods );
1542
1546
}
1543
1547
}
1544
1548
@@ -1555,7 +1559,7 @@ private void iterateClashingNames(Statement stat, StructMethod mt, Map<Statement
1555
1559
// Process deferred statements
1556
1560
if (iterate ) {
1557
1561
for (Statement st : deferred ) {
1558
- iterateClashingNames (st , mt , varDefinitions , liveVarDefs , nameMap );
1562
+ iterateClashingNames (st , mt , varDefinitions , liveVarDefs , nameMap , seenMethods );
1559
1563
}
1560
1564
}
1561
1565
@@ -1575,7 +1579,8 @@ private void clearStatement(Map<Statement, Set<VarInMethod>> varDefinitions, Set
1575
1579
}
1576
1580
}
1577
1581
1578
- private void iterateClashingExprent (Statement stat , StructMethod mt , Map <Statement , Set <VarInMethod >> varDefinitions , Exprent exprent , Set <VarInMethod > liveVarDefs , Set <VarInMethod > curVarDefs , Map <VarInMethod , String > nameMap ) {
1582
+ private void iterateClashingExprent (Statement stat , StructMethod mt , Map <Statement , Set <VarInMethod >> varDefinitions , Exprent exprent ,
1583
+ Set <VarInMethod > liveVarDefs , Set <VarInMethod > curVarDefs , Map <VarInMethod , String > nameMap , Set <String > seenMethods ) {
1579
1584
if (exprent instanceof NewExprent ) {
1580
1585
NewExprent newExprent = (NewExprent ) exprent ;
1581
1586
// Check if this is a lambda with a body
@@ -1584,7 +1589,8 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme
1584
1589
if (node != null && node .getWrapper () != null ) {
1585
1590
MethodWrapper mw = node .getWrapper ().getMethods ().getWithKey (node .lambdaInformation .content_method_key );
1586
1591
StructMethod mt2 = node .getWrapper ().getClassStruct ().getMethod (node .lambdaInformation .content_method_key );
1587
- if (mt2 != null && mw != null ) {
1592
+ if (mt2 != null && mw != null && !seenMethods .contains (InterpreterUtil .makeUniqueKey (mt2 .getName (), mt2 .getDescriptor ()))) {
1593
+ seenMethods .add (InterpreterUtil .makeUniqueKey (mt2 .getName (), mt2 .getDescriptor ()));
1588
1594
// Propagate current data through to lambda
1589
1595
VarDefinitionHelper vardef = new VarDefinitionHelper (mw .root , mt2 , mw .varproc , false );
1590
1596
@@ -1616,7 +1622,7 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme
1616
1622
}
1617
1623
1618
1624
// Iterate clashing names with the lambda's body, with the context of the outer method
1619
- vardef .iterateClashingNames (mw .root , mt2 , varDefinitions , liveVarDefs , nameMap );
1625
+ vardef .iterateClashingNames (mw .root , mt2 , varDefinitions , liveVarDefs , nameMap , seenMethods );
1620
1626
1621
1627
for (Entry <VarVersionPair , String > e : vardef .getClashingNames ().entrySet ()) {
1622
1628
mw .varproc .setClashingName (e .getKey (), e .getValue ());
@@ -1636,7 +1642,8 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme
1636
1642
for (String mthKey : node .getWrapper ().getMethods ().getLstKeys ()) {
1637
1643
MethodWrapper mw = node .getWrapper ().getMethods ().getWithKey (mthKey );
1638
1644
StructMethod mt2 = node .getWrapper ().getClassStruct ().getMethod (mthKey );
1639
- if (mt2 != null && mw != null && !mt2 .hasModifier (CodeConstants .ACC_SYNTHETIC )) {
1645
+ if (mt2 != null && mw != null && !mt2 .hasModifier (CodeConstants .ACC_SYNTHETIC ) && !seenMethods .contains (InterpreterUtil .makeUniqueKey (mt2 .getName (), mt2 .getDescriptor ()))) {
1646
+ seenMethods .add (InterpreterUtil .makeUniqueKey (mt2 .getName (), mt2 .getDescriptor ()));
1640
1647
// Propagate current data through to method
1641
1648
VarDefinitionHelper vardef = new VarDefinitionHelper (mw .root , mt2 , mw .varproc , false );
1642
1649
@@ -1669,7 +1676,7 @@ private void iterateClashingExprent(Statement stat, StructMethod mt, Map<Stateme
1669
1676
}
1670
1677
1671
1678
// Iterate clashing names with the lambda's body, with the context of the outer method
1672
- vardef .iterateClashingNames (mw .root , mt2 , varDefinitions , liveVarDefs , nameMap );
1679
+ vardef .iterateClashingNames (mw .root , mt2 , varDefinitions , liveVarDefs , nameMap , seenMethods );
1673
1680
1674
1681
for (Entry <VarVersionPair , String > e : vardef .getClashingNames ().entrySet ()) {
1675
1682
mw .varproc .setClashingName (e .getKey (), e .getValue ());
0 commit comments