#349 AS3 - better handling of declarations

This commit is contained in:
Jindra Petřík
2021-02-08 20:15:19 +01:00
parent 6f19d50572
commit 43885a1a40
28 changed files with 397 additions and 105 deletions
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -534,12 +535,30 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
});
}
public final void visitRecursivelyNoBlock(GraphTargetVisitorInterface visitor) {
Set<GraphTargetItem> visitedItems = new HashSet<>();
visitNoBlock(new AbstractGraphTargetVisitor() {
@Override
public void visit(GraphTargetItem item) {
if (item != null && !visitedItems.contains(item)) {
visitedItems.add(item);
visitor.visit(item);
item.visitNoBlock(this);
}
}
});
}
public void visit(GraphTargetVisitorInterface visitor) {
if (value != null) {
visitor.visit(value);
}
}
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
visit(visitor);
}
public abstract GraphTargetItem returnType();
@Override
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -69,6 +70,14 @@ public class DoWhileItem extends LoopItem implements Block {
}
}
@Override
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
if (expression != null) {
visitor.visitAll(expression);
}
}
public DoWhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> commands, List<GraphTargetItem> expression) {
super(src, lineStartIns, loop);
this.expression = expression;
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -75,6 +76,12 @@ public class ForItem extends LoopItem implements Block {
}
}
@Override
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
visitor.visit(expression);
}
public ForItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> firstCommands, GraphTargetItem expression, List<GraphTargetItem> finalCommands, List<GraphTargetItem> commands) {
super(src, lineStartIns, loop);
this.firstCommands = firstCommands;
@@ -12,13 +12,15 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.GraphTargetVisitorInterface;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
@@ -106,4 +108,15 @@ public class GotoItem extends GraphTargetItem implements Block {
}
return ret;
}
@Override
public void visit(GraphTargetVisitorInterface visitor) {
if (targetCommands != null) {
visitor.visitAll(targetCommands);
}
}
@Override
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
}
}
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -72,6 +73,12 @@ public class IfItem extends GraphTargetItem implements Block {
}
}
@Override
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
visitor.visit(expression);
}
public IfItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem expression, List<GraphTargetItem> onTrue, List<GraphTargetItem> onFalse) {
super(src, lineStartIns, NOPRECEDENCE);
this.expression = expression;
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -62,6 +63,13 @@ public class SwitchItem extends LoopItem implements Block {
}
}
@Override
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
visitor.visit(switchedObject);
visitor.visitAll(caseValues);
}
public SwitchItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, Loop loop, GraphTargetItem switchedObject, List<GraphTargetItem> caseValues, List<List<GraphTargetItem>> caseCommands, List<Integer> valuesMapping) {
super(instruction, lineStartIns, loop);
this.switchedObject = switchedObject;
@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.␍ */
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -64,6 +65,14 @@ public class WhileItem extends LoopItem implements Block {
}
}
@Override
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
if (expression != null) {
visitor.visitAll(expression);
}
}
public WhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> expression, List<GraphTargetItem> commands) {
super(src, lineStartIns, loop);
this.expression = expression;