Skip to content

Commit

Permalink
Fix var clashing not processing foreach properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Aug 1, 2023
1 parent eb95dad commit 7f65ce7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public boolean allowNewlineAfterQualifier() {

@Override
public String toString() {
return "VarExprent[" + index + ',' + version +"]: {" + super.toString() + "}";
return "VarExprent[" + index + ',' + version + (definition ? " Def" : "") + "]: {" + super.toString() + "}";
}

// *****************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1355,15 +1355,13 @@ public void remapClashingNames(Statement root) {
Set<VarVersionPair> liveVarDefs = new HashSet<>();
Map<VarVersionPair, String> nameMap = new HashMap<>();

if (root instanceof RootStatement) {
StructMethodParametersAttribute paramAttribute = ((RootStatement) root).mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_METHOD_PARAMETERS);
StructLocalVariableTableAttribute lvtAttribute = ((RootStatement) root).mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
if (paramAttribute != null && lvtAttribute != null) {
for (StructMethodParametersAttribute.Entry entry : paramAttribute.getEntries()) {
// for every method param, find lvt entry and put it into the name map
Optional<LocalVariable> lvtEntry = lvtAttribute.getVariables().filter(s -> s.getName().equals(entry.myName)).findFirst();
lvtEntry.ifPresent(localVariable -> nameMap.put(localVariable.getVersion(), entry.myName));
}
StructMethodParametersAttribute paramAttribute = ((RootStatement) root).mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_METHOD_PARAMETERS);
StructLocalVariableTableAttribute lvtAttribute = ((RootStatement) root).mt.getAttribute(StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
if (paramAttribute != null && lvtAttribute != null) {
for (StructMethodParametersAttribute.Entry entry : paramAttribute.getEntries()) {
// for every method param, find lvt entry and put it into the name map
Optional<LocalVariable> lvtEntry = lvtAttribute.getVariables().filter(s -> s.getName().equals(entry.myName)).findFirst();
lvtEntry.ifPresent(localVariable -> nameMap.put(localVariable.getVersion(), entry.myName));
}
}

Expand All @@ -1389,7 +1387,7 @@ private void iterateClashingNames(Statement stat, Map<Statement, Set<VarVersionP
// Process var definitions in statement head
for (Object obj : stat.getSequentialObjects()) {
if (obj instanceof Exprent) {
List<Exprent> exprents = ((Exprent) obj).getAllExprents(true);
List<Exprent> exprents = ((Exprent) obj).getAllExprents(true, true);

for (Exprent exprent : exprents) {
iterateClashingExprent(stat, varDefinitions, exprent, curVarDefs, nameMap);
Expand Down
6 changes: 3 additions & 3 deletions testData/results/TestJadLvtCollision.dec
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class TestJadLvtCollision implements Iterable<TestJadLvtCollision> {
}// 10

public void testLoop(TestJadLvtCollision testjadlvtcollision) {
for(TestJadLvtCollision testjadlvtcollision : testjadlvtcollision) {// 13
System.out.println(testjadlvtcollision.toString() + testjadlvtcollision.toString());// 14
for(TestJadLvtCollision testjadlvtcollisionx : testjadlvtcollision) {// 13
System.out.println(testjadlvtcollision.toString() + testjadlvtcollisionx.toString());// 14
}
}// 16

Expand Down Expand Up @@ -91,4 +91,4 @@ Lines mapping:
16 <-> 13
20 <-> 16
Not mapped:
15
15

0 comments on commit 7f65ce7

Please sign in to comment.