diff --git a/src/com/jpexs/decompiler/flash/abc/avm2/model/WithAVM2Item.java b/src/com/jpexs/decompiler/flash/abc/avm2/model/WithAVM2Item.java index 57c861989..6c92fabcb 100644 --- a/src/com/jpexs/decompiler/flash/abc/avm2/model/WithAVM2Item.java +++ b/src/com/jpexs/decompiler/flash/abc/avm2/model/WithAVM2Item.java @@ -56,14 +56,9 @@ public class WithAVM2Item extends AVM2Item { } writer.append("("); scope.toString(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); - /*for (GraphTargetItem ti : items) { - ret += ti.toString(constants, localRegNames, fullyQualifiedNames) + "\r\n"; - }*/ - writer.unindent(); - return writer.append("}"); + writer.append(")").startBlock(); + //NOTE: endBlock is added with WithEndAVM2Item + return writer; } @Override diff --git a/src/com/jpexs/decompiler/flash/abc/avm2/model/WithEndAVM2Item.java b/src/com/jpexs/decompiler/flash/abc/avm2/model/WithEndAVM2Item.java index bc29d1f5f..173553b5f 100644 --- a/src/com/jpexs/decompiler/flash/abc/avm2/model/WithEndAVM2Item.java +++ b/src/com/jpexs/decompiler/flash/abc/avm2/model/WithEndAVM2Item.java @@ -1,53 +1,53 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.abc.avm2.model; - -import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.helpers.GraphTextWriter; -import com.jpexs.decompiler.graph.GraphTargetItem; -import com.jpexs.decompiler.graph.TypeItem; -import com.jpexs.decompiler.graph.model.LocalData; - -public class WithEndAVM2Item extends AVM2Item { - - public GraphTargetItem scope; - - public WithEndAVM2Item(AVM2Instruction instruction, GraphTargetItem scope) { - super(instruction, PRECEDENCE_PRIMARY); - this.scope = scope; - } - - @Override - public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { - return writer.append("}"); - } - - @Override - public boolean needsSemicolon() { - return false; - } - - @Override - public GraphTargetItem returnType() { - return TypeItem.UNBOUNDED; - } - - @Override - public boolean hasReturnValue() { - return false; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.abc.avm2.model; + +import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.TypeItem; +import com.jpexs.decompiler.graph.model.LocalData; + +public class WithEndAVM2Item extends AVM2Item { + + public GraphTargetItem scope; + + public WithEndAVM2Item(AVM2Instruction instruction, GraphTargetItem scope) { + super(instruction, PRECEDENCE_PRIMARY); + this.scope = scope; + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { + return writer.endBlock(); + } + + @Override + public boolean needsSemicolon() { + return false; + } + + @Override + public GraphTargetItem returnType() { + return TypeItem.UNBOUNDED; + } + + @Override + public boolean hasReturnValue() { + return false; + } +} diff --git a/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java b/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java index 02f14a92f..3d7aaea3a 100644 --- a/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java +++ b/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java @@ -1,193 +1,184 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.action.model.clauses; - -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.SourceGeneratorLocalData; -import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.model.ActionItem; -import com.jpexs.decompiler.flash.action.model.ConstantPool; -import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; -import com.jpexs.decompiler.flash.action.swf4.ActionJump; -import com.jpexs.decompiler.flash.action.swf7.ActionTry; -import com.jpexs.decompiler.flash.helpers.GraphTextWriter; -import com.jpexs.decompiler.graph.Block; -import com.jpexs.decompiler.graph.CompilationException; -import com.jpexs.decompiler.graph.GraphSourceItem; -import com.jpexs.decompiler.graph.GraphTargetItem; -import com.jpexs.decompiler.graph.SourceGenerator; -import com.jpexs.decompiler.graph.model.ContinueItem; -import com.jpexs.decompiler.graph.model.LocalData; -import java.util.ArrayList; -import java.util.List; - -public class TryActionItem extends ActionItem implements Block { - - public List tryCommands; - public List catchExceptions; - public List> catchCommands; - public List finallyCommands; - - @Override - public List> getSubs() { - List> ret = new ArrayList<>(); - if (tryCommands != null) { - ret.add(tryCommands); - } - ret.addAll(catchCommands); - if (finallyCommands != null) { - ret.add(finallyCommands); - } - return ret; - } - - public TryActionItem(List tryCommands, List catchExceptions, List> catchCommands, List finallyCommands) { - super(null, NOPRECEDENCE); - this.tryCommands = tryCommands; - this.catchExceptions = catchExceptions; - this.catchCommands = catchCommands; - this.finallyCommands = finallyCommands; - } - - @Override - public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.append("try").newLine(); - writer.append("{").newLine(); - writer.indent(); - for (GraphTargetItem ti : tryCommands) { - if (!ti.isEmpty()) { - ti.toStringSemicoloned(writer, localData).newLine(); - } - } - writer.unindent(); - writer.append("}"); - for (int e = 0; e < catchExceptions.size(); e++) { - writer.newLine(); - writer.append("catch"); - if (writer.getFormatting().spaceBeforeParenthesesCatchParentheses) { - writer.append(" "); - } - writer.append("("); - catchExceptions.get(e).toStringNoQuotes(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); - List commands = catchCommands.get(e); - for (GraphTargetItem ti : commands) { - if (!ti.isEmpty()) { - ti.toStringSemicoloned(writer, localData).newLine(); - } - } - writer.unindent(); - writer.append("}"); - } - if (finallyCommands.size() > 0) { - writer.newLine(); - writer.append("finally").newLine(); - writer.append("{").newLine(); - writer.indent(); - for (GraphTargetItem ti : finallyCommands) { - if (!ti.isEmpty()) { - ti.toStringSemicoloned(writer, localData).newLine(); - } - } - writer.unindent(); - writer.append("}"); - } - return writer; - } - - @Override - public List getContinues() { - List ret = new ArrayList<>(); - for (GraphTargetItem ti : tryCommands) { - if (ti instanceof ContinueItem) { - ret.add((ContinueItem) ti); - } - if (ti instanceof Block) { - ret.addAll(((Block) ti).getContinues()); - } - } - if (finallyCommands != null) { - for (GraphTargetItem ti : finallyCommands) { - if (ti instanceof ContinueItem) { - ret.add((ContinueItem) ti); - } - if (ti instanceof Block) { - ret.addAll(((Block) ti).getContinues()); - } - } - } - for (List commands : catchCommands) { - for (GraphTargetItem ti : commands) { - if (ti instanceof ContinueItem) { - ret.add((ContinueItem) ti); - } - if (ti instanceof Block) { - ret.addAll(((Block) ti).getContinues()); - } - } - } - return ret; - } - - @Override - public boolean needsSemicolon() { - return false; - } - - @Override - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - List ret = new ArrayList<>(); - ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; - List tryCommandsA = asGenerator.toActionList(asGenerator.generate(localData, tryCommands)); - List finallyCommandsA = finallyCommands == null ? null : asGenerator.toActionList(asGenerator.generate(localData, finallyCommands)); - List catchCommandsA = null; - String catchName = null; - if (catchExceptions != null) { - if (!catchExceptions.isEmpty()) { - catchName = catchExceptions.get(0).toStringNoQuotes(LocalData.create(new ConstantPool(asGenerator.getConstantPool()))); - } - - } - int catchSize = 0; - if (catchCommands != null && !catchCommands.isEmpty()) { - catchCommandsA = asGenerator.toActionList(asGenerator.generate(localData, catchCommands.get(0))); - catchSize = Action.actionsToBytes(catchCommandsA, false, SWF.DEFAULT_VERSION).length; - tryCommandsA.add(new ActionJump(catchSize)); - } - int finallySize = 0; - if (finallyCommandsA != null) { - finallySize = Action.actionsToBytes(finallyCommandsA, false, SWF.DEFAULT_VERSION).length; - } - int trySize = Action.actionsToBytes(tryCommandsA, false, SWF.DEFAULT_VERSION).length; - ret.add(new ActionTry(false, finallyCommands != null, catchCommands != null, catchName, 0, trySize, catchSize, finallySize, SWF.DEFAULT_VERSION)); - ret.addAll(tryCommandsA); - if (catchCommandsA != null) { - ret.addAll(catchCommandsA); - } - if (finallyCommandsA != null) { - ret.addAll(finallyCommandsA); - } - return ret; - } - - @Override - public boolean hasReturnValue() { - return false; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.action.model.clauses; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.model.ActionItem; +import com.jpexs.decompiler.flash.action.model.ConstantPool; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; +import com.jpexs.decompiler.flash.action.swf4.ActionJump; +import com.jpexs.decompiler.flash.action.swf7.ActionTry; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.Block; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.SourceGenerator; +import com.jpexs.decompiler.graph.model.ContinueItem; +import com.jpexs.decompiler.graph.model.LocalData; +import java.util.ArrayList; +import java.util.List; + +public class TryActionItem extends ActionItem implements Block { + + public List tryCommands; + public List catchExceptions; + public List> catchCommands; + public List finallyCommands; + + @Override + public List> getSubs() { + List> ret = new ArrayList<>(); + if (tryCommands != null) { + ret.add(tryCommands); + } + ret.addAll(catchCommands); + if (finallyCommands != null) { + ret.add(finallyCommands); + } + return ret; + } + + public TryActionItem(List tryCommands, List catchExceptions, List> catchCommands, List finallyCommands) { + super(null, NOPRECEDENCE); + this.tryCommands = tryCommands; + this.catchExceptions = catchExceptions; + this.catchCommands = catchCommands; + this.finallyCommands = finallyCommands; + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.append("try").startBlock(); + for (GraphTargetItem ti : tryCommands) { + if (!ti.isEmpty()) { + ti.toStringSemicoloned(writer, localData).newLine(); + } + } + writer.endBlock(); + for (int e = 0; e < catchExceptions.size(); e++) { + writer.newLine(); + writer.append("catch"); + if (writer.getFormatting().spaceBeforeParenthesesCatchParentheses) { + writer.append(" "); + } + writer.append("("); + catchExceptions.get(e).toStringNoQuotes(writer, localData); + writer.append(")").startBlock(); + List commands = catchCommands.get(e); + for (GraphTargetItem ti : commands) { + if (!ti.isEmpty()) { + ti.toStringSemicoloned(writer, localData).newLine(); + } + } + writer.endBlock(); + } + if (finallyCommands.size() > 0) { + writer.newLine(); + writer.append("finally").startBlock(); + for (GraphTargetItem ti : finallyCommands) { + if (!ti.isEmpty()) { + ti.toStringSemicoloned(writer, localData).newLine(); + } + } + writer.endBlock(); + } + return writer; + } + + @Override + public List getContinues() { + List ret = new ArrayList<>(); + for (GraphTargetItem ti : tryCommands) { + if (ti instanceof ContinueItem) { + ret.add((ContinueItem) ti); + } + if (ti instanceof Block) { + ret.addAll(((Block) ti).getContinues()); + } + } + if (finallyCommands != null) { + for (GraphTargetItem ti : finallyCommands) { + if (ti instanceof ContinueItem) { + ret.add((ContinueItem) ti); + } + if (ti instanceof Block) { + ret.addAll(((Block) ti).getContinues()); + } + } + } + for (List commands : catchCommands) { + for (GraphTargetItem ti : commands) { + if (ti instanceof ContinueItem) { + ret.add((ContinueItem) ti); + } + if (ti instanceof Block) { + ret.addAll(((Block) ti).getContinues()); + } + } + } + return ret; + } + + @Override + public boolean needsSemicolon() { + return false; + } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + List ret = new ArrayList<>(); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + List tryCommandsA = asGenerator.toActionList(asGenerator.generate(localData, tryCommands)); + List finallyCommandsA = finallyCommands == null ? null : asGenerator.toActionList(asGenerator.generate(localData, finallyCommands)); + List catchCommandsA = null; + String catchName = null; + if (catchExceptions != null) { + if (!catchExceptions.isEmpty()) { + catchName = catchExceptions.get(0).toStringNoQuotes(LocalData.create(new ConstantPool(asGenerator.getConstantPool()))); + } + + } + int catchSize = 0; + if (catchCommands != null && !catchCommands.isEmpty()) { + catchCommandsA = asGenerator.toActionList(asGenerator.generate(localData, catchCommands.get(0))); + catchSize = Action.actionsToBytes(catchCommandsA, false, SWF.DEFAULT_VERSION).length; + tryCommandsA.add(new ActionJump(catchSize)); + } + int finallySize = 0; + if (finallyCommandsA != null) { + finallySize = Action.actionsToBytes(finallyCommandsA, false, SWF.DEFAULT_VERSION).length; + } + int trySize = Action.actionsToBytes(tryCommandsA, false, SWF.DEFAULT_VERSION).length; + ret.add(new ActionTry(false, finallyCommands != null, catchCommands != null, catchName, 0, trySize, catchSize, finallySize, SWF.DEFAULT_VERSION)); + ret.addAll(tryCommandsA); + if (catchCommandsA != null) { + ret.addAll(catchCommandsA); + } + if (finallyCommandsA != null) { + ret.addAll(finallyCommandsA); + } + return ret; + } + + @Override + public boolean hasReturnValue() { + return false; + } +} diff --git a/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java b/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java index af8c8efe5..2b9959999 100644 --- a/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java +++ b/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java @@ -1,85 +1,82 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.action.model.clauses; - -import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.SourceGeneratorLocalData; -import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.model.ActionItem; -import com.jpexs.decompiler.flash.action.swf5.ActionWith; -import com.jpexs.decompiler.flash.helpers.GraphTextWriter; -import com.jpexs.decompiler.graph.CompilationException; -import com.jpexs.decompiler.graph.GraphSourceItem; -import com.jpexs.decompiler.graph.GraphTargetItem; -import com.jpexs.decompiler.graph.SourceGenerator; -import com.jpexs.decompiler.graph.model.LocalData; -import java.util.ArrayList; -import java.util.List; - -public class WithActionItem extends ActionItem { - - public GraphTargetItem scope; - public List items; - - public WithActionItem(Action instruction, GraphTargetItem scope, List items) { - super(instruction, NOPRECEDENCE); - this.scope = scope; - this.items = items; - } - - public WithActionItem(Action instruction, ActionItem scope) { - super(instruction, NOPRECEDENCE); - this.scope = scope; - this.items = new ArrayList<>(); - } - - @Override - public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - writer.append("with"); - if (writer.getFormatting().spaceBeforeParenthesesWithParentheses) { - writer.append(" "); - } - writer.append("("); - scope.toString(writer, localData); - writer.append(")").newLine(); - writer.append("{").newLine(); - writer.indent(); - for (GraphTargetItem ti : items) { - ti.toString(writer, localData).newLine(); - } - writer.unindent(); - return writer.append("}"); - } - - @Override - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - List data = generator.generate(localData, items); - List dataA = new ArrayList<>(); - for (GraphSourceItem s : data) { - if (s instanceof Action) { - dataA.add((Action) s); - } - } - int codeLen = Action.actionsToBytes(dataA, false, SWF.DEFAULT_VERSION).length; - return toSourceMerge(localData, generator, scope, new ActionWith(codeLen), data); - } - - @Override - public boolean hasReturnValue() { - return false; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.action.model.clauses; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.model.ActionItem; +import com.jpexs.decompiler.flash.action.swf5.ActionWith; +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphSourceItem; +import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.SourceGenerator; +import com.jpexs.decompiler.graph.model.LocalData; +import java.util.ArrayList; +import java.util.List; + +public class WithActionItem extends ActionItem { + + public GraphTargetItem scope; + public List items; + + public WithActionItem(Action instruction, GraphTargetItem scope, List items) { + super(instruction, NOPRECEDENCE); + this.scope = scope; + this.items = items; + } + + public WithActionItem(Action instruction, ActionItem scope) { + super(instruction, NOPRECEDENCE); + this.scope = scope; + this.items = new ArrayList<>(); + } + + @Override + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + writer.append("with"); + if (writer.getFormatting().spaceBeforeParenthesesWithParentheses) { + writer.append(" "); + } + writer.append("("); + scope.toString(writer, localData); + writer.append(")").startBlock(); + for (GraphTargetItem ti : items) { + ti.toString(writer, localData).newLine(); + } + return writer.endBlock(); + } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + List data = generator.generate(localData, items); + List dataA = new ArrayList<>(); + for (GraphSourceItem s : data) { + if (s instanceof Action) { + dataA.add((Action) s); + } + } + int codeLen = Action.actionsToBytes(dataA, false, SWF.DEFAULT_VERSION).length; + return toSourceMerge(localData, generator, scope, new ActionWith(codeLen), data); + } + + @Override + public boolean hasReturnValue() { + return false; + } +}