diff --git a/CHANGELOG.md b/CHANGELOG.md index f0c5c2adb..458df1eaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file. - AS3 direct editation - coerce in setproperty - AS3 direct editation - unary minus (negate) compiled as 0 - value - AS3 direct editation - using finally clause for continue and break +- AS3 direct editation - popscope in catch on continue and break - #1159, #1608 Regexp syntax hilight when not a regexp (only division) again - Graphviz Graph not showing AS3 exception end - #1609 First frame missing in frame to PDF export diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java index a6239d157..ee5076110 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SourceGeneratorLocalData.java @@ -82,6 +82,9 @@ public class SourceGeneratorLocalData implements Serializable { public List openedLoops = new ArrayList<>(); + public List> catchesOpenedLoops = new ArrayList<>(); + public List catchesTempRegs = new ArrayList<>(); + public String getFullClass() { return pkg == null ? currentClass : pkg.addWithSuffix(currentClass).toRawString(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index f7702465f..829cc37e4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -27,8 +27,10 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructSuperIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.JumpIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.KillIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnValueIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnVoidIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopScopeIns; import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ApplyTypeAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item; @@ -723,6 +725,16 @@ public class AVM2SourceGenerator implements SourceGenerator { } ret.add(ins(AVM2Instructions.Label)); } + + for (int i = 0; i < localData.catchesOpenedLoops.size(); i++) { + List openedLoops = localData.catchesOpenedLoops.get(i); + + if (openedLoops.contains(item.loopId)) { + ret.add(ins(new PopScopeIns())); + } + ret.add(ins(new KillIns(), localData.catchesTempRegs.get(i))); + } + AVM2Instruction abreak = ins(new BreakJumpIns(item.loopId), 0); ret.add(abreak); return ret; @@ -830,9 +842,13 @@ public class AVM2SourceGenerator implements SourceGenerator { } } } + localData.catchesTempRegs.add(tempReg.getVal()); localData.scopeStack.add(new LocalRegAVM2Item(null, null, tempReg.getVal(), null)); + localData.catchesOpenedLoops.add(new ArrayList<>(localData.openedLoops)); catchCmd.addAll(generateToInsList(localData, item.catchCommands.get(c))); + localData.catchesOpenedLoops.remove(localData.catchesOpenedLoops.size() - 1); localData.scopeStack.remove(localData.scopeStack.size() - 1); + localData.catchesTempRegs.remove(localData.catchesTempRegs.size() - 1); catchCmd.add(ins(AVM2Instructions.PopScope)); catchCmd.addAll(toInsList(AssignableAVM2Item.killTemp(localData, this, Arrays.asList(tempReg)))); catchCmds.add(catchCmd); @@ -1090,6 +1106,15 @@ public class AVM2SourceGenerator implements SourceGenerator { ret.add(ins(AVM2Instructions.Label)); } + for (int i = 0; i < localData.catchesOpenedLoops.size(); i++) { + List openedLoops = localData.catchesOpenedLoops.get(i); + + if (openedLoops.contains(item.loopId)) { + ret.add(ins(new PopScopeIns())); + } + ret.add(ins(new KillIns(), localData.catchesTempRegs.get(i))); + } + AVM2Instruction acontinue = ins(new ContinueJumpIns(item.loopId), 0); ret.add(acontinue); return ret; diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.air.swf b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.air.swf index bcc074905..4226b39d1 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.air.swf and b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.air.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex.swf b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex.swf index e1f77262b..30fe4d1c4 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex.swf and b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex_apache.swf b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex_apache.swf index 55b2038ee..02e63822e 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex_apache.swf and b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.flex_apache.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.swftools.swf b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.swftools.swf index e8e46f686..db2513655 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.swftools.swf and b/libsrc/ffdec_lib/testdata/as3_cross_compile/bin/as3_cross_compile.swftools.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.old b/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.old index 8bd4a91f5..7c7c25007 100644 --- a/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.old +++ b/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.old @@ -16,7 +16,7 @@ CONFIG::timeStamp - '09.02.2021' + '20.02.2021' CONFIG::air diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.xml b/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.xml index 8bd4a91f5..7c7c25007 100644 --- a/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.xml +++ b/libsrc/ffdec_lib/testdata/as3_cross_compile/obj/as3_cross_compileConfig.xml @@ -16,7 +16,7 @@ CONFIG::timeStamp - '09.02.2021' + '20.02.2021' CONFIG::air diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/src/Main.as b/libsrc/ffdec_lib/testdata/as3_cross_compile/src/Main.as index db5b45843..83afa9c8f 100644 --- a/libsrc/ffdec_lib/testdata/as3_cross_compile/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_cross_compile/src/Main.as @@ -25,6 +25,8 @@ package TestTryCatchLoopBreak3; TestTryCatchLoopBreak4; TestTryCatchLoopBreak5; + TestTryCatchLoopBreak6; + TestTryCatchReturn; TestTryCatchExceptionUsage TestTryFinally; TestTryFinallyDirectReturnInFinally; diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/src/tests/TestTryCatchLoopBreak6.as b/libsrc/ffdec_lib/testdata/as3_cross_compile/src/tests/TestTryCatchLoopBreak6.as new file mode 100644 index 000000000..ca17ed542 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_cross_compile/src/tests/TestTryCatchLoopBreak6.as @@ -0,0 +1,50 @@ +package tests +{ + import flash.errors.EOFError; + /** + * ... + * @author JPEXS + */ + public class TestTryCatchLoopBreak6 + { + + + public function run() : void + { + var a:int; + a = 0; + trace("before loop"); + while (a < 10) { + try + { + trace("in try"); + } + catch(e:Error) + { + trace("in catch1"); + if (a > 3) + { + break; + } + try + { + trace("in try2"); + } + catch(e:Error) + { + trace("in catch2"); + if (a > 4) + { + break; + } + } + } + a++; + } + trace("after"); + + } + + } + +} \ No newline at end of file diff --git a/libsrc/ffdec_lib/testdata/as3_cross_compile/src/tests/TestTryCatchReturn.as b/libsrc/ffdec_lib/testdata/as3_cross_compile/src/tests/TestTryCatchReturn.as new file mode 100644 index 000000000..781d32637 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_cross_compile/src/tests/TestTryCatchReturn.as @@ -0,0 +1,33 @@ +package tests +{ + /** + * ... + * @author JPEXS + */ + public class TestTryCatchReturn + { + + public function run() : int + { + var a:int = 5; + trace("before try"); + try + { + trace("in try"); + } + catch (e:Error) + { + trace("in catch"); + if (a == 5) + { + return a; + } + trace("in catch2"); + } + trace("after"); + return -1; + } + + } + +} \ No newline at end of file