fixed bug with incorrect copy of pseudocode part
(was noticeable in doTestCopy4 example) labels after part should be repeated as well
This commit is contained in:
@@ -483,16 +483,12 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
}
|
||||
}
|
||||
for (int index = startIndex; index < finishIndex; index++) {
|
||||
Instruction oldInstruction = mutableInstructionList.get(index);
|
||||
Instruction newInstruction = copyInstruction(oldInstruction, originalToCopy);
|
||||
if (originalLabelsForInstruction.containsKey(oldInstruction)) {
|
||||
Collection<Label> oldLabels = originalLabelsForInstruction.get(oldInstruction);
|
||||
for (Label oldLabel : oldLabels) {
|
||||
bindLabel(originalToCopy.get(oldLabel));
|
||||
}
|
||||
}
|
||||
addInstruction(newInstruction);
|
||||
Instruction originalInstruction = mutableInstructionList.get(index);
|
||||
repeatLabelsBindingForInstruction(originalInstruction, originalToCopy, originalLabelsForInstruction);
|
||||
addInstruction(copyInstruction(originalInstruction, originalToCopy));
|
||||
}
|
||||
repeatLabelsBindingForInstruction(mutableInstructionList.get(finishIndex), originalToCopy, originalLabelsForInstruction);
|
||||
|
||||
for (Map.Entry<Label, Label> entry : originalToCopy.entrySet()) {
|
||||
Label oldLabel = entry.getKey();
|
||||
Label newLabel = entry.getValue();
|
||||
@@ -503,6 +499,16 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
}
|
||||
}
|
||||
|
||||
private void repeatLabelsBindingForInstruction(
|
||||
@NotNull Instruction originalInstruction,
|
||||
@NotNull Map<Label, Label> originalToCopy,
|
||||
@NotNull Multimap<Instruction, Label> originalLabelsForInstruction
|
||||
) {
|
||||
for (Label originalLabel : originalLabelsForInstruction.get(originalInstruction)) {
|
||||
bindLabel(originalToCopy.get(originalLabel));
|
||||
}
|
||||
}
|
||||
|
||||
private Instruction copyInstruction(@NotNull Instruction instruction, @NotNull Map<Label, Label> originalToCopy) {
|
||||
if (instruction instanceof AbstractJumpInstruction) {
|
||||
Label originalTarget = ((AbstractJumpInstruction) instruction).getTargetLabel();
|
||||
|
||||
@@ -163,7 +163,7 @@ L10 [skipFinallyToErrorBlock]:
|
||||
r(cond()) NEXT:[jf(copy L12)] PREV:[r(cond)]
|
||||
jf(copy L12) NEXT:[jmp(L2 [loop entry point]), ret L1] PREV:[r(cond())]
|
||||
ret L1 NEXT:[<END>] PREV:[jf(copy L12)]
|
||||
- jmp(L13) NEXT:[jmp(error)] PREV:[]
|
||||
- jmp(copy L13) NEXT:[jmp(L2 [loop entry point])] PREV:[]
|
||||
jmp(L2 [loop entry point]) NEXT:[r(cond)] PREV:[jf(copy L12)]
|
||||
L15 [stop [d0, d1, d2]]:
|
||||
- jmp(L2 [loop entry point]) NEXT:[r(cond)] PREV:[]
|
||||
@@ -258,3 +258,59 @@ error:
|
||||
sink:
|
||||
<SINK> NEXT:[] PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
== doTestCopy4 ==
|
||||
fun doTestCopy4() : Int {
|
||||
try {
|
||||
doSmth()
|
||||
}
|
||||
finally {
|
||||
if(list != null) {
|
||||
}
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
L0:
|
||||
<START> NEXT:[r(try { doSmth() } finally {..)] PREV:[]
|
||||
r(try {
|
||||
doSmth()
|
||||
}
|
||||
finally {
|
||||
if(list != null) {
|
||||
}
|
||||
}) NEXT:[jmp?(L2 [onExceptionToFinallyBlock])] PREV:[<START>]
|
||||
jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[r(list), r(doSmth)] PREV:[r(try { doSmth() } finally {..)]
|
||||
r(doSmth) NEXT:[r(doSmth())] PREV:[jmp?(L2 [onExceptionToFinallyBlock])]
|
||||
r(doSmth()) NEXT:[jmp(L3 [skipFinallyToErrorBlock])] PREV:[r(doSmth)]
|
||||
d0:
|
||||
jmp(L3 [skipFinallyToErrorBlock]) NEXT:[r(list)] PREV:[r(doSmth())]
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
L4 [start finally]:
|
||||
r(list) NEXT:[r(null)] PREV:[jmp?(L2 [onExceptionToFinallyBlock])]
|
||||
r(null) NEXT:[r(!=)] PREV:[r(list)]
|
||||
r(!=) NEXT:[r(list != null)] PREV:[r(null)]
|
||||
r(list != null) NEXT:[jf(L5)] PREV:[r(!=)]
|
||||
jf(L5) NEXT:[read (Unit), read (Unit)] PREV:[r(list != null)]
|
||||
read (Unit) NEXT:[jmp(L6)] PREV:[jf(L5)]
|
||||
jmp(L6) NEXT:[jmp(error)] PREV:[read (Unit)]
|
||||
L5:
|
||||
read (Unit) NEXT:[jmp(error)] PREV:[jf(L5)]
|
||||
L6:
|
||||
L7 [finish finally]:
|
||||
jmp(error) NEXT:[<ERROR>] PREV:[jmp(L6), read (Unit)]
|
||||
L3 [skipFinallyToErrorBlock]:
|
||||
r(list) NEXT:[r(null)] PREV:[jmp(L3 [skipFinallyToErrorBlock])]
|
||||
r(null) NEXT:[r(!=)] PREV:[r(list)]
|
||||
r(!=) NEXT:[r(list != null)] PREV:[r(null)]
|
||||
r(list != null) NEXT:[jf(copy L5)] PREV:[r(!=)]
|
||||
jf(copy L5) NEXT:[read (Unit), read (Unit)] PREV:[r(list != null)]
|
||||
read (Unit) NEXT:[jmp(copy L6)] PREV:[jf(copy L5)]
|
||||
jmp(copy L6) NEXT:[<END>] PREV:[read (Unit)]
|
||||
read (Unit) NEXT:[<END>] PREV:[jf(copy L5)]
|
||||
L1:
|
||||
L8 [stop [d0]]:
|
||||
<END> NEXT:[<SINK>] PREV:[jmp(copy L6), read (Unit)]
|
||||
error:
|
||||
<ERROR> NEXT:[<SINK>] PREV:[jmp(error)]
|
||||
sink:
|
||||
<SINK> NEXT:[] PREV:[<ERROR>, <END>]
|
||||
=====================
|
||||
|
||||
@@ -45,3 +45,13 @@ fun testCopy3() {
|
||||
while (cond());
|
||||
}
|
||||
}
|
||||
|
||||
fun doTestCopy4() : Int {
|
||||
try {
|
||||
doSmth()
|
||||
}
|
||||
finally {
|
||||
if(list != null) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user