mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 22:00:45 +00:00
GraphTargetVisitorInterface for visiting model
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2018 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public abstract class AbstractGraphTargetVisitor implements GraphTargetVisitorInterface {
|
||||
|
||||
@Override
|
||||
public abstract void visit(GraphTargetItem item);
|
||||
|
||||
@Override
|
||||
public final void visitAll(Collection<GraphTargetItem> items) {
|
||||
for (GraphTargetItem item : items) {
|
||||
visit(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -42,6 +43,7 @@ import com.jpexs.decompiler.graph.model.NotItem;
|
||||
import com.jpexs.decompiler.graph.model.TrueItem;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -498,12 +500,21 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
|
||||
|
||||
public List<GraphTargetItem> getAllSubItems() {
|
||||
List<GraphTargetItem> ret = new ArrayList<>();
|
||||
if (value != null) {
|
||||
ret.add(value);
|
||||
}
|
||||
visit(new AbstractGraphTargetVisitor() {
|
||||
@Override
|
||||
public void visit(GraphTargetItem item) {
|
||||
ret.add(item);
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
if (value != null) {
|
||||
visitor.visit(value);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract GraphTargetItem returnType();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2018 JPEXS, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface GraphTargetVisitorInterface {
|
||||
|
||||
public void visit(GraphTargetItem item);
|
||||
|
||||
public void visitAll(Collection<GraphTargetItem> items);
|
||||
}
|
||||
@@ -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.helpers.GraphTextWriter;
|
||||
@@ -20,6 +21,7 @@ import com.jpexs.decompiler.graph.GraphPart;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItemPos;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetVisitorInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -208,10 +210,8 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphTargetItem> getAllSubItems() {
|
||||
List<GraphTargetItem> ret = new ArrayList<>();
|
||||
ret.add(getLeftSide());
|
||||
ret.add(getRightSide());
|
||||
return ret;
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visit(getLeftSide());
|
||||
visitor.visit(getRightSide());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -21,6 +22,7 @@ import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import java.util.List;
|
||||
@@ -38,6 +40,11 @@ public class BlockItem extends GraphTargetItem {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visitAll(commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
writer.startBlock();
|
||||
|
||||
@@ -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;
|
||||
@@ -20,6 +21,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import java.util.List;
|
||||
@@ -37,6 +39,11 @@ public class CommaExpressionItem extends GraphTargetItem {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visitAll(commands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
boolean first = true;
|
||||
|
||||
@@ -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;
|
||||
@@ -23,6 +24,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.Loop;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
@@ -58,6 +60,16 @@ public class DoWhileItem extends LoopItem implements Block {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
if (commands != null) {
|
||||
visitor.visitAll(commands);
|
||||
}
|
||||
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;
|
||||
@@ -23,6 +24,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.Loop;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
@@ -60,6 +62,20 @@ public class ForItem extends LoopItem implements Block {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
if (firstCommands != null) {
|
||||
visitor.visitAll(firstCommands);
|
||||
}
|
||||
visitor.visit(expression);
|
||||
if (commands != null) {
|
||||
visitor.visitAll(commands);
|
||||
}
|
||||
if (finalCommands != null) {
|
||||
visitor.visitAll(finalCommands);
|
||||
}
|
||||
}
|
||||
|
||||
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,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;
|
||||
@@ -21,6 +22,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import java.util.ArrayList;
|
||||
@@ -60,6 +62,17 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visit(expression);
|
||||
if (onTrue != null) {
|
||||
visitor.visitAll(onTrue);
|
||||
}
|
||||
if (onFalse != null) {
|
||||
visitor.visitAll(onFalse);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -23,6 +24,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.Loop;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
@@ -52,6 +54,15 @@ public class SwitchItem extends LoopItem implements Block {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visit(switchedObject);
|
||||
visitor.visitAll(caseValues);
|
||||
for (List<GraphTargetItem> c : caseCommands) {
|
||||
visitor.visitAll(c);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -20,6 +21,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,6 +44,12 @@ public class TernarOpItem extends GraphTargetItem {
|
||||
this.onFalse = onFalse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
visitor.visit(onTrue);
|
||||
visitor.visit(onFalse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
expression.toString(writer, localData);
|
||||
|
||||
@@ -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;
|
||||
@@ -23,6 +24,7 @@ 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.GraphTargetVisitorInterface;
|
||||
import com.jpexs.decompiler.graph.Loop;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
@@ -53,6 +55,16 @@ public class WhileItem extends LoopItem implements Block {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GraphTargetVisitorInterface visitor) {
|
||||
if (expression != null) {
|
||||
visitor.visitAll(expression);
|
||||
}
|
||||
if (commands != null) {
|
||||
visitor.visitAll(commands);
|
||||
}
|
||||
}
|
||||
|
||||
public WhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> expression, List<GraphTargetItem> commands) {
|
||||
super(src, lineStartIns, loop);
|
||||
this.expression = expression;
|
||||
|
||||
Reference in New Issue
Block a user