More documentation.

This commit is contained in:
Jindra Petřík
2024-08-08 19:27:14 +02:00
parent 38bcab878b
commit 5c1811582a
677 changed files with 7393 additions and 343 deletions
@@ -25,6 +25,12 @@ import java.util.Collection;
*/
public abstract class AbstractGraphTargetVisitor implements GraphTargetVisitorInterface {
/**
* Constructs new AbstractGraphTargetVisitor
*/
public AbstractGraphTargetVisitor() {
}
/**
* Visits a graph target item.
*
@@ -134,7 +134,7 @@ public class Graph {
/**
* Gets sub-graphs
*
* @return
* @return Sub-graphs
*/
public LinkedHashMap<String, Graph> getSubGraphs() {
return new LinkedHashMap<>();
@@ -155,7 +155,7 @@ public class Graph {
* Initializes the graph.
*
* @param localData Local data
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public void init(BaseLocalData localData) throws InterruptedException {
if (heads != null) {
@@ -508,7 +508,7 @@ public class Graph {
* @param loops Loops
* @param throwStates Throw states
* @return Common successor
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphPart getNextCommonPart(BaseLocalData localData, GraphPart part, List<Loop> loops, List<ThrowState> throwStates) throws InterruptedException {
return getCommonPart(localData, part, getNextParts(localData, part), loops, throwStates);
@@ -525,7 +525,7 @@ public class Graph {
* @param loops Loops
* @param throwStates Throw states
* @return Common successor
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphPart getCommonPart(BaseLocalData localData, GraphPart prev, List<GraphPart> parts, List<Loop> loops, List<ThrowState> throwStates) throws InterruptedException {
if (parts.isEmpty()) {
@@ -597,7 +597,7 @@ public class Graph {
* @param throwStates Throw states
* @param stopPart Stop part
* @return Most common successor
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphPart getMostCommonPart(BaseLocalData localData, List<GraphPart> parts, List<Loop> loops, List<ThrowState> throwStates, List<GraphPart> stopPart) throws InterruptedException {
if (parts.isEmpty()) {
@@ -903,7 +903,7 @@ public class Graph {
* @param staticOperation Unused
* @param path Path
* @return List of GraphTargetItems
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public List<GraphTargetItem> translate(BaseLocalData localData, int staticOperation, String path) throws InterruptedException {
@@ -1029,7 +1029,7 @@ public class Graph {
/**
* Process switches.
*
* @param list
* @param list List of GraphTargetItems
*/
protected final void processSwitches(List<GraphTargetItem> list) {
processSwitches(list, -1);
@@ -1200,10 +1200,10 @@ public class Graph {
* Gets data for final process. Override this method to provide data for
* final process.
*
* @param localData
* @param loops
* @param throwStates
* @return
* @param localData Local data
* @param loops Loops
* @param throwStates Throw states
* @return Final process local data
*/
protected FinalProcessLocalData getFinalData(BaseLocalData localData, List<Loop> loops, List<ThrowState> throwStates) {
return new FinalProcessLocalData(loops);
@@ -1217,7 +1217,7 @@ public class Graph {
* @param path Path
* @param allParts All parts
* @param throwStates Throw states
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected void beforeGetLoops(BaseLocalData localData, String path, Set<GraphPart> allParts, List<ThrowState> throwStates) throws InterruptedException {
@@ -1230,7 +1230,7 @@ public class Graph {
* @param localData Local data
* @param path Path
* @param allParts All parts
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected void afterGetLoops(BaseLocalData localData, String path, Set<GraphPart> allParts) throws InterruptedException {
@@ -1302,7 +1302,7 @@ public class Graph {
* @param localData Local data
* @param loops Loops
* @param throwStates Throw states
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
private void getBackEdges(BaseLocalData localData, List<Loop> loops, List<ThrowState> throwStates) throws InterruptedException {
clearLoops(loops);
@@ -1336,7 +1336,7 @@ public class Graph {
* @param level Level
* @param localData Local data
* @param path Path
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
private void finalProcessAll(List<GraphTargetItem> list, int level, FinalProcessLocalData localData, String path) throws InterruptedException {
if (debugDoNotProcess) {
@@ -1432,7 +1432,7 @@ public class Graph {
* @param level Level
* @param localData Local data
* @param path Path
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData, String path) throws InterruptedException {
@@ -1925,7 +1925,7 @@ public class Graph {
* @param path Path
* @return List of GraphTargetItems to replace current output and stop
* further processing. Null to continue.
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected List<GraphTargetItem> check(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, GraphSource code, BaseLocalData localData, Set<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<StopPartKind> stopPartKind, List<Loop> loops, List<ThrowState> throwStates, List<GraphTargetItem> output, Loop currentLoop, int staticOperation, String path) throws InterruptedException {
return null;
@@ -1971,8 +1971,8 @@ public class Graph {
* @param stack Translate stack
* @param staticOperation Unused
* @return Top of the stack
* @throws InterruptedException
* @throws GraphPartChangeException
* @throws InterruptedException On interrupt
* @throws GraphPartChangeException On graph part change
*/
//@SuppressWarnings("unchecked")
protected final GraphTargetItem translatePartGetStack(BaseLocalData localData, GraphPart part, TranslateStack stack, int staticOperation) throws InterruptedException, GraphPartChangeException {
@@ -1990,8 +1990,8 @@ public class Graph {
* @param staticOperation Unused
* @param path Path
* @return List of GraphTargetItems
* @throws InterruptedException
* @throws GraphPartChangeException
* @throws InterruptedException On interrupt
* @throws GraphPartChangeException On graph part change
*/
protected final List<GraphTargetItem> translatePart(BaseLocalData localData, GraphPart part, TranslateStack stack, int staticOperation, String path) throws InterruptedException, GraphPartChangeException {
List<GraphPart> sub = part.getSubParts();
@@ -2094,7 +2094,7 @@ public class Graph {
* @param loops List of loops
* @param throwStates List of throw states
* @param stopPart Stop part
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
private void getLoops(BaseLocalData localData, GraphPart part, List<Loop> loops, List<ThrowState> throwStates, List<GraphPart> stopPart) throws InterruptedException {
clearLoops(loops);
@@ -2160,7 +2160,7 @@ public class Graph {
* @param first First
* @param visited Set of Graph parts
* @param level Level
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
private void getLoopsWalk(BaseLocalData localData, GraphPart part, List<Loop> loops, List<ThrowState> throwStates, List<GraphPart> stopPart, boolean first, List<GraphPart> visited, int level) throws InterruptedException {
@@ -2616,7 +2616,7 @@ public class Graph {
* @param path Path
* @param recursionLevel Recursion level
* @return True to stop processing. False to continue.
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected boolean checkPartOutput(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, GraphSource code, BaseLocalData localData, Set<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<StopPartKind> stopPartKind, List<Loop> loops, List<ThrowState> throwStates, Loop currentLoop, int staticOperation, String path, int recursionLevel) throws InterruptedException {
return false;
@@ -2709,7 +2709,7 @@ public class Graph {
* @param staticOperation Unused
* @param path Path
* @return List of GraphTargetItems
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected final List<GraphTargetItem> printGraph(List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, BaseLocalData localData, TranslateStack stack, Set<GraphPart> allParts, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<StopPartKind> stopPartKind, List<Loop> loops, List<ThrowState> throwStates, int staticOperation, String path) throws InterruptedException {
return printGraph(foundGotos, partCodes, partCodePos, visited, localData, stack, allParts, parent, part, stopPart, stopPartKind, loops, throwStates, null, staticOperation, path, 0);
@@ -2736,7 +2736,7 @@ public class Graph {
* @param path Path
* @param recursionLevel Recursion level
* @return List of GraphTargetItems
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected final List<GraphTargetItem> printGraph(List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, BaseLocalData localData, TranslateStack stack, Set<GraphPart> allParts, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<StopPartKind> stopPartKind, List<Loop> loops, List<ThrowState> throwStates, List<GraphTargetItem> ret, int staticOperation, String path, int recursionLevel) throws InterruptedException {
loopPrintGraph:
@@ -3660,7 +3660,7 @@ public class Graph {
*
* @param ip IP
* @param allParts All parts
* @return
* @return Part
*/
public GraphPart searchPart(int ip, Collection<? extends GraphPart> allParts) {
if (ip < 0) {
@@ -3681,7 +3681,7 @@ public class Graph {
* @param allBlocks All blocks to populate parts into.
* @param exceptions Exceptions
* @return List of entry points
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public List<GraphPart> makeGraph(GraphSource code, List<GraphPart> allBlocks, List<GraphException> exceptions) throws InterruptedException {
List<Integer> alternateEntries = new ArrayList<>();
@@ -3709,20 +3709,20 @@ public class Graph {
* @param parent Parent part
* @param path Path
* @param code Graph source
* @param startip Start IP
* @param startIp Start IP
* @param lastIp Last IP
* @param allBlocks All blocks
* @param refs References
* @param visited Visited
* @return Entry point
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
private GraphPart makeGraph(GraphPart parent, GraphPath path, GraphSource code, int startip, int lastIp, List<GraphPart> allBlocks, HashMap<Integer, List<Integer>> refs, boolean[] visited) throws InterruptedException {
private GraphPart makeGraph(GraphPart parent, GraphPath path, GraphSource code, int startIp, int lastIp, List<GraphPart> allBlocks, HashMap<Integer, List<Integer>> refs, boolean[] visited) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
int ip = startip;
int ip = startIp;
GraphPart existingPart = searchPart(ip, allBlocks);
if (existingPart != null) {
if (parent != null) {
@@ -3743,7 +3743,7 @@ public class Graph {
if (ip >= code.size()) {
break;
}
if (visited[ip] || ((ip != startip) && (refs.get(ip).size() > 1))) {
if (visited[ip] || ((ip != startIp) && (refs.get(ip).size() > 1))) {
part.end = lastIp;
GraphPart found = searchPart(ip, allBlocks);
@@ -3842,7 +3842,7 @@ public class Graph {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws java.lang.InterruptedException
* @throws InterruptedException On interrupt
*/
public static GraphTextWriter graphToString(List<GraphTargetItem> tree, GraphTextWriter writer, LocalData localData) throws InterruptedException {
for (GraphTargetItem ti : tree) {
@@ -3990,7 +3990,7 @@ public class Graph {
* @param nextRef Next reference
* @param tiRef Target item reference
* @return Switch item
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
protected SwitchItem handleSwitch(GraphTargetItem switchedObject,
GraphSourceItem switchStartItem, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, Set<GraphPart> allParts, TranslateStack stack, List<GraphPart> stopPart, List<StopPartKind> stopPartKind, List<Loop> loops, List<ThrowState> throwStates, BaseLocalData localData, int staticOperation, String path,
@@ -24,6 +24,7 @@ import java.util.List;
* List which can store parts of the graph for each element.
*
* @author JPEXS
* @param <E> Element type
*/
public class GraphPartMarkedArrayList<E> extends ArrayList<E> {
@@ -65,8 +65,8 @@ public abstract class GraphSource implements Serializable {
* @param staticOperation Unused
* @param path Path
* @return List of graph target items
* @throws InterruptedException
* @throws GraphPartChangeException
* @throws InterruptedException On interrupt
* @throws GraphPartChangeException On graph part change
*/
public abstract List<GraphTargetItem> translatePart(Graph graph, GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException, GraphPartChangeException;
@@ -92,7 +92,7 @@ public abstract class GraphSource implements Serializable {
* @param lastIp Last position
* @param refs References
* @param endIp End position
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
private void visitCode(int ip, int lastIp, HashMap<Integer, List<Integer>> refs, int endIp) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
@@ -153,7 +153,7 @@ public abstract class GraphSource implements Serializable {
*
* @param alternateEntries Alternate entries
* @return References
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public HashMap<Integer, List<Integer>> visitCode(List<Integer> alternateEntries) throws InterruptedException {
HashMap<Integer, List<Integer>> refs = new HashMap<>();
@@ -35,7 +35,7 @@ public interface GraphSourceItem extends Serializable, Cloneable {
* @param output Output list
* @param staticOperation Unused
* @param path Path
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public void translate(BaseLocalData localData, TranslateStack stack, List<GraphTargetItem> output, int staticOperation, String path) throws InterruptedException;
@@ -62,7 +62,7 @@ public interface GraphSourceItemContainer {
*
* @param size Size up to this point
* @param lexer Lexer
* @return
* @return True if the division was parsed successfully
*/
public boolean parseDivision(long size, FlasmLexer lexer);
@@ -339,7 +339,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
/**
* Gets highlight src data
*
* @return
* @return Highlight src data
*/
protected HighlightData getSrcData() {
if (srcData == null) {
@@ -383,7 +383,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
@@ -414,7 +414,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringBoolean(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData, "Boolean");
@@ -426,7 +426,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData, "String");
@@ -438,7 +438,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringInt(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData, "int");
@@ -450,7 +450,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringNumber(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData, "Number");
@@ -471,8 +471,9 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
*
* @param writer Writer
* @param localData Local data
* @param implicitCoerce Implicit coerce
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData, String implicitCoerce) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
@@ -488,9 +489,10 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
/**
* Converts this to string.
*
* @param writer Writer
* @param localData Local data
* @return String
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData, "");
@@ -501,7 +503,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
*
* @param localData Local data
* @return String
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public String toString(LocalData localData) throws InterruptedException {
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
@@ -516,7 +518,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException;
@@ -526,7 +528,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter appendTry(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return appendTry(writer, localData, "");
@@ -539,7 +541,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param localData Local data
* @param implicitCoerce Implicit coerce
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter appendTry(GraphTextWriter writer, LocalData localData, String implicitCoerce) throws InterruptedException {
GraphTargetItem t = this;
@@ -699,7 +701,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, getLineStartItem(), getPos(), srcData);
@@ -714,7 +716,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData);
@@ -771,7 +773,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param writer Writer
* @param localData Local data
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, getLineStartItem(), getPos(), srcData);
@@ -826,7 +828,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param localData Local data
* @param generator Source generator
* @return Source
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
@@ -838,7 +840,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param localData Local data
* @param generator Source generator
* @return Source
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if (!hasReturnValue()) {
@@ -867,7 +869,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param gen Source generator
* @param tar Objects
* @return List of GraphTargetItems
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public static List<GraphSourceItem> toSourceMerge(SourceGeneratorLocalData localData, SourceGenerator gen, Object... tar) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
@@ -989,7 +991,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
/**
* Visits this without using Blocks.
*
* @param visitor
* @param visitor Visitor
*/
public void visitNoBlock(GraphTargetVisitorInterface visitor) {
visit(visitor);
@@ -998,7 +1000,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
/**
* Gets return type.
*
* @return
* @return Return type
*/
public abstract GraphTargetItem returnType();
@@ -1035,7 +1037,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
* @param commands Commands
* @param asBlock As block
* @return Writer
* @throws InterruptedException
* @throws InterruptedException On interrupt
*/
public GraphTextWriter appendCommands(GraphTargetItem prevLineItem, GraphTextWriter writer, LocalData localData, List<GraphTargetItem> commands, boolean asBlock) throws InterruptedException {
@@ -1071,12 +1073,12 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
/**
* Append this to a writer as a Block.
*
* @param prevLineItem
* @param writer
* @param localData
* @param commands
* @return
* @throws InterruptedException
* @param prevLineItem Previous line item
* @param writer Writer
* @param localData Local data
* @param commands Commands
* @return Writer
* @throws InterruptedException On interrupt
*/
public GraphTextWriter appendBlock(GraphTargetItem prevLineItem, GraphTextWriter writer, LocalData localData, List<GraphTargetItem> commands) throws InterruptedException {
appendCommands(prevLineItem, writer, localData, commands, true);
@@ -1086,7 +1088,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
/**
* Gets this as long.
*
* @return
* @return This as long
*/
public long getAsLong() {
if (this instanceof DirectValueActionItem) {
@@ -49,7 +49,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item PushItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PushItem item) throws CompilationException;
@@ -59,7 +59,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item PopItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PopItem item) throws CompilationException;
@@ -69,7 +69,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item TrueItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TrueItem item) throws CompilationException;
@@ -79,7 +79,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item FalseItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, FalseItem item) throws CompilationException;
@@ -89,7 +89,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item AndItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, AndItem item) throws CompilationException;
@@ -99,7 +99,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item OrItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, OrItem item) throws CompilationException;
@@ -109,7 +109,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item IfItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, IfItem item) throws CompilationException;
@@ -119,7 +119,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item TernarOpItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TernarOpItem item) throws CompilationException;
@@ -129,7 +129,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item WhileItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, WhileItem item) throws CompilationException;
@@ -139,7 +139,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item DoWhileItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, DoWhileItem item) throws CompilationException;
@@ -149,7 +149,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item ForItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, ForItem item) throws CompilationException;
@@ -159,7 +159,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item SwitchItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, SwitchItem item) throws CompilationException;
@@ -169,7 +169,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item NotItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, NotItem item) throws CompilationException;
@@ -179,7 +179,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item DuplicateItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, DuplicateItem item) throws CompilationException;
@@ -189,7 +189,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item BreakItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, BreakItem item) throws CompilationException;
@@ -199,7 +199,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item ContinueItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, ContinueItem item) throws CompilationException;
@@ -209,7 +209,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param commands List of GraphTargetItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, List<GraphTargetItem> commands) throws CompilationException;
@@ -220,7 +220,7 @@ public interface SourceGenerator {
* @param item CommaExpressionItem
* @param withReturnValue If true, the return value is used
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item, boolean withReturnValue) throws CompilationException;
@@ -230,7 +230,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item TypeItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException;
@@ -240,7 +240,7 @@ public interface SourceGenerator {
* @param localData Local data
* @param item GraphTargetItem
* @return List of GraphSourceItem
* @throws CompilationException
* @throws CompilationException On compilation error
*/
public List<GraphSourceItem> generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException;
}
@@ -41,6 +41,13 @@ public class AndItem extends BinaryOpItem implements CompoundableBinaryOp {
return ret;
}
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
* @param leftSide Left side
* @param rightSide Right side
*/
public AndItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, lineStartIns, PRECEDENCE_LOGICALAND, leftSide, rightSide, "&&", "Boolean", "Boolean");
this.leftSide = leftSide;
@@ -27,19 +27,51 @@ import java.util.List;
*/
public interface BinaryOp {
/**
* Gets left side.
* @return Left side
*/
public GraphTargetItem getLeftSide();
/**
* Gets right side.
* @return Right side
*/
public GraphTargetItem getRightSide();
/**
* Sets left side.
* @param value Left side
*/
public void setLeftSide(GraphTargetItem value);
/**
* Sets right side.
* @param value Right side
*/
public void setRightSide(GraphTargetItem value);
/**
* Gets precedence.
* @return Precedence
*/
public int getPrecedence();
/**
* Gets all sub items.
* @return All sub items
*/
public List<GraphTargetItem> getAllSubItems();
/**
* Gets operator.
* @return Operator
*/
public String getOperator();
/**
* Gets operator instruction.
* @return Operator instruction
*/
public List<GraphSourceItem> getOperatorInstruction();
}
@@ -34,13 +34,29 @@ import java.util.Set;
*/
public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
/**
* Left side of the operation
*/
public GraphTargetItem leftSide;
/**
* Right side of the operation
*/
public GraphTargetItem rightSide;
/**
* Operator
*/
protected final String operator;
/**
* Coerce left side to this type
*/
protected String coerceLeft;
/**
* Coerce right side to this type
*/
protected String coerceRight;
@Override
@@ -52,6 +68,18 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
return fp;
}
/**
* Constructor.
*
* @param instruction Instruction
* @param lineStartItem Line start item
* @param precedence Precedence
* @param leftSide Left side
* @param rightSide Right side
* @param operator Operator
* @param coerceLeft Coerce left
* @param coerceRight Coerce right
*/
public BinaryOpItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator, String coerceLeft, String coerceRight) {
super(instruction, lineStartItem, precedence);
this.leftSide = leftSide;
@@ -95,6 +123,14 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
return writer;
}
/**
* Converts operand to string
*
* @param operand Operand
* @param writer Writer
* @param localData Local data
* @throws InterruptedException On interrupt
*/
protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException {
operand.toString(writer, localData, "");
}
@@ -143,6 +179,12 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
return hash;
}
/**
* Gets left most item
*
* @param item Item
* @return Left most item
*/
public GraphTargetItem getLeftMostItem(GraphTargetItem item) {
GraphTargetItem ret = item;
if (ret instanceof BinaryOpItem) {
@@ -151,6 +193,11 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
return ret;
}
/**
* Gets left most item
*
* @return Left most item
*/
public GraphTargetItem getLeftMostItem() {
GraphTargetItem ret = leftSide;
if (ret instanceof BinaryOpItem) {
@@ -34,8 +34,18 @@ import java.util.List;
*/
public class BlockItem extends GraphTargetItem {
/**
* Commands
*/
List<GraphTargetItem> commands;
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param commands Commands
*/
public BlockItem(GraphSourceItem src, GraphSourceItem lineStartIns, List<GraphTargetItem> commands) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
this.commands = commands;
@@ -33,10 +33,23 @@ import java.util.List;
*/
public class BreakItem extends GraphTargetItem {
/**
* Loop id
*/
public long loopId;
/**
* Label required
*/
private boolean labelRequired;
/**
* Constructor.
*
* @param src Source item
* @param lineStartIns Line start instruction
* @param loopId Loop id
*/
public BreakItem(GraphSourceItem src, GraphSourceItem lineStartIns, long loopId) {
super(src, lineStartIns, NOPRECEDENCE);
this.loopId = loopId;
@@ -25,7 +25,18 @@ import java.util.List;
*/
public interface Callable {
/**
* Call a method with a name and arguments.
* @param methodName Method name
* @param args Arguments
* @return Result of the method call
*/
public Object call(String methodName, List<Object> args);
/**
* Call with arguments.
* @param args Arguments
* @return Result of the call
*/
public Object call(List<Object> args);
}
@@ -33,8 +33,18 @@ import java.util.List;
*/
public class CommaExpressionItem extends GraphTargetItem {
/**
* Commands
*/
public List<GraphTargetItem> commands;
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param commands Commands
*/
public CommaExpressionItem(GraphSourceItem src, GraphSourceItem lineStartIns, List<GraphTargetItem> commands) {
super(src, lineStartIns, PRECEDENCE_COMMA);
this.commands = commands;
@@ -27,13 +27,24 @@ import com.jpexs.decompiler.graph.TypeItem;
*/
public class CommentItem extends GraphTargetItem {
/**
* Comment lines.
*/
private final String[] commentLines;
/**
* Constructor.
* @param comment Comment
*/
public CommentItem(String comment) {
super(null, null, NOPRECEDENCE);
this.commentLines = new String[]{comment};
}
/**
* Constructor.
* @param commentLines Comment lines
*/
public CommentItem(String[] commentLines) {
super(null, null, NOPRECEDENCE);
this.commentLines = commentLines;
@@ -54,6 +65,10 @@ public class CommentItem extends GraphTargetItem {
return writer.append(" */");
}
/**
* Gets comment lines.
* @return Comment lines
*/
public String[] getCommentLines() {
return commentLines;
}
@@ -33,10 +33,23 @@ import java.util.List;
*/
public class ContinueItem extends GraphTargetItem {
/**
* Loop id
*/
public long loopId;
/**
* Label required
*/
private boolean labelRequired;
/**
* Constructor.
*
* @param src Source item
* @param lineStartIns Line start instruction
* @param loopId Loop id
*/
public ContinueItem(GraphSourceItem src, GraphSourceItem lineStartIns, long loopId) {
super(src, lineStartIns, NOPRECEDENCE);
this.loopId = loopId;
@@ -38,10 +38,19 @@ import java.util.List;
*/
public class DoWhileItem extends LoopItem implements Block {
/**
* Commands
*/
public List<GraphTargetItem> commands;
/**
* Expression
*/
public List<GraphTargetItem> expression;
/**
* Label used
*/
private boolean labelUsed;
@Override
@@ -78,6 +87,15 @@ public class DoWhileItem extends LoopItem implements Block {
}
}
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param loop Loop
* @param commands Commands
* @param expression Expression
*/
public DoWhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> commands, List<GraphTargetItem> expression) {
super(src, lineStartIns, loop);
this.expression = expression;
@@ -34,6 +34,12 @@ import java.util.Set;
*/
public class DuplicateItem extends GraphTargetItem implements SimpleValue {
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start item
* @param value Value
*/
public DuplicateItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem value) {
super(src, lineStartIns, value.getPrecedence(), value);
}
@@ -34,6 +34,11 @@ import java.util.Set;
*/
public class FalseItem extends GraphTargetItem implements LogicalOpItem, SimpleValue {
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
*/
public FalseItem(GraphSourceItem src, GraphSourceItem lineStartIns) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
}
@@ -38,14 +38,29 @@ import java.util.List;
*/
public class ForItem extends LoopItem implements Block {
/**
* First commands
*/
public List<GraphTargetItem> firstCommands;
/**
* Expression
*/
public GraphTargetItem expression;
/**
* Final commands
*/
public List<GraphTargetItem> finalCommands;
/**
* Commands
*/
public List<GraphTargetItem> commands;
/**
* Label used
*/
private boolean labelUsed;
@Override
@@ -82,6 +97,17 @@ public class ForItem extends LoopItem implements Block {
visitor.visit(expression);
}
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param loop Loop
* @param firstCommands First commands
* @param expression Expression
* @param finalCommands Final commands
* @param commands Commands
*/
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;
@@ -32,10 +32,23 @@ import java.util.List;
*/
public class GotoItem extends GraphTargetItem implements Block {
/**
* Label name
*/
public String labelName;
/**
* Target commands
*/
public List<GraphTargetItem> targetCommands = null;
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param labelName Label name
*/
public GotoItem(GraphSourceItem src, GraphSourceItem lineStartIns, String labelName) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
this.labelName = labelName;
@@ -38,14 +38,34 @@ import java.util.Set;
*/
public class IfItem extends GraphTargetItem implements Block {
/**
* Expression
*/
public GraphTargetItem expression;
/**
* On true
*/
public List<GraphTargetItem> onTrue;
/**
* On false
*/
public List<GraphTargetItem> onFalse;
/**
* Decision part
*/
public GraphPart decisionPart;
/**
* On true part
*/
public GraphPart onTruePart;
/**
* On false part
*/
public GraphPart onFalsePart;
@Override
@@ -87,6 +107,15 @@ public class IfItem extends GraphTargetItem implements Block {
visitor.visit(expression);
}
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param expression Expression
* @param onTrue On true
* @param onFalse On false
*/
public IfItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem expression, List<GraphTargetItem> onTrue, List<GraphTargetItem> onFalse) {
super(src, lineStartIns, NOPRECEDENCE);
this.expression = expression;
@@ -29,8 +29,17 @@ import java.util.Set;
*/
public class IntegerValueItem extends GraphTargetItem implements IntegerValueTypeItem {
/**
* Integer value
*/
private final int intValue;
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
* @param value Value
*/
public IntegerValueItem(GraphSourceItem src, GraphSourceItem lineStartIns, int value) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
this.intValue = value;
@@ -23,5 +23,9 @@ package com.jpexs.decompiler.graph.model;
*/
public interface IntegerValueTypeItem {
/**
* Gets the integer value of this item.
* @return Integer value
*/
public int intValue();
}
@@ -28,8 +28,17 @@ import com.jpexs.decompiler.graph.TypeItem;
*/
public class LabelItem extends GraphTargetItem {
/**
* Label name.
*/
public String labelName;
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
* @param labelName Label name
*/
public LabelItem(GraphSourceItem src, GraphSourceItem lineStartIns, String labelName) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
this.labelName = labelName;
@@ -34,30 +34,73 @@ import java.util.Set;
*/
public class LocalData {
/**
* Empty local data
*/
public static LocalData empty = new LocalData();
/**
* Constant pool
*/
public ConstantPool constants;
/**
* AVM2 constant pool
*/
public AVM2ConstantPool constantsAvm2;
/**
* ABC indexing
*/
public AbcIndexing abcIndex;
/**
* Call stack
*/
public List<MethodBody> callStack;
/**
* Local register names
*/
public HashMap<Integer, String> localRegNames;
/**
* Fully qualified names
*/
public List<DottedChain> fullyQualifiedNames;
/**
* Seen methods
*/
public Set<Integer> seenMethods = new HashSet<>();
/**
* ABC
*/
public ABC abc;
/**
* Creates a new local data
*
* @param constants Constant pool
* @return Local data
*/
public static LocalData create(ConstantPool constants) {
LocalData localData = new LocalData();
localData.constants = constants;
return localData;
}
/**
* Creates a new local data
* @param callStack Call stack
* @param abcIndex ABC indexing
* @param abc ABC
* @param localRegNames Local register names
* @param fullyQualifiedNames Fully qualified names
* @param seenMethods Seen methods
* @return Local data
*/
public static LocalData create(List<MethodBody> callStack, AbcIndexing abcIndex, ABC abc, HashMap<Integer, String> localRegNames, List<DottedChain> fullyQualifiedNames, Set<Integer> seenMethods) {
LocalData localData = new LocalData();
localData.abc = abc;
@@ -26,5 +26,11 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
*/
public interface LogicalOpItem {
/**
* Inverts the logical operation.
*
* @param src Source item
* @return Inverted target item
*/
public GraphTargetItem invert(GraphSourceItem src);
}
@@ -28,14 +28,32 @@ import java.util.List;
*/
public abstract class LoopItem extends GraphTargetItem {
/**
* Loop
*/
public Loop loop;
/**
* Constructor.
*
* @param src Source item
* @param lineStartItem Line start item
* @param loop Loop
*/
public LoopItem(GraphSourceItem src, GraphSourceItem lineStartItem, Loop loop) {
super(src, lineStartItem, NOPRECEDENCE);
this.loop = loop;
}
/**
* Checks if loop has base body.
* @return True if loop has base body
*/
public abstract boolean hasBaseBody();
/**
* Gets base body commands.
* @return List of base body commands
*/
public abstract List<GraphTargetItem> getBaseBodyCommands();
}
@@ -36,6 +36,12 @@ import java.util.Set;
*/
public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
/**
* Constructor.
* @param instruction Instruction
* @param lineStartIns Line start instruction
* @param value Value
*/
public NotItem(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem value) {
super(instruction, lineStartIns, PRECEDENCE_UNARY, value, "!", "Boolean");
}
@@ -65,6 +71,10 @@ public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
return value.isCompileTime(dependencies);
}
/**
* Gets the original value.
* @return Original value
*/
public GraphTargetItem getOriginal() {
return value;
}
@@ -33,6 +33,13 @@ import java.util.List;
*/
public class OrItem extends BinaryOpItem implements CompoundableBinaryOp {
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
* @param leftSide Left side
* @param rightSide Right side
*/
public OrItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, lineStartIns, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||", "Boolean", "Boolean");
this.leftSide = leftSide;
@@ -31,6 +31,12 @@ import java.util.List;
*/
public class ParenthesisItem extends GraphTargetItem {
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
* @param value Value
*/
public ParenthesisItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem value) {
super(src, lineStartIns, PRECEDENCE_PRIMARY, value);
}
@@ -33,6 +33,11 @@ import java.util.List;
*/
public class PopItem extends GraphTargetItem {
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
*/
public PopItem(GraphSourceItem src, GraphSourceItem lineStartIns) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
}
@@ -33,6 +33,10 @@ import java.util.Objects;
*/
public class PushItem extends GraphTargetItem {
/**
* Constructor.
* @param value Value to push
*/
public PushItem(GraphTargetItem value) {
super(value.getSrc(), value.getLineStartItem(), value.getPrecedence(), value);
}
@@ -27,6 +27,9 @@ import com.jpexs.decompiler.graph.TypeItem;
*/
public class ScriptEndItem extends GraphTargetItem implements ExitItem {
/**
* Constructor.
*/
public ScriptEndItem() {
super(null, null, NOPRECEDENCE);
}
@@ -38,14 +38,29 @@ import java.util.List;
*/
public class SwitchItem extends LoopItem implements Block {
/**
* Switched object
*/
public GraphTargetItem switchedObject;
/**
* Case values
*/
public List<GraphTargetItem> caseValues;
/**
* Case commands
*/
public List<List<GraphTargetItem>> caseCommands;
/**
* Values mapping
*/
public List<Integer> valuesMapping;
/**
* Label used
*/
private boolean labelUsed;
@Override
@@ -70,6 +85,16 @@ public class SwitchItem extends LoopItem implements Block {
visitor.visitAll(caseValues);
}
/**
* Constructor.
* @param instruction Instruction
* @param lineStartIns Line start instruction
* @param loop Loop
* @param switchedObject Switched object
* @param caseValues Case values
* @param caseCommands Case commands
* @param valuesMapping Values mapping
*/
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;
@@ -34,12 +34,30 @@ import java.util.Objects;
*/
public class TernarOpItem extends GraphTargetItem {
/**
* Expression
*/
public GraphTargetItem expression;
/**
* On true
*/
public GraphTargetItem onTrue;
/**
* On false
*/
public GraphTargetItem onFalse;
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param expression Expression
* @param onTrue On true
* @param onFalse On false
*/
public TernarOpItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem expression, GraphTargetItem onTrue, GraphTargetItem onFalse) {
super(src, lineStartIns, PRECEDENCE_CONDITIONAL);
this.expression = expression;
@@ -34,6 +34,11 @@ import java.util.Set;
*/
public class TrueItem extends GraphTargetItem implements LogicalOpItem, SimpleValue {
/**
* Constructor.
* @param src Source
* @param lineStartIns Line start instruction
*/
public TrueItem(GraphSourceItem src, GraphSourceItem lineStartIns) {
super(src, lineStartIns, PRECEDENCE_PRIMARY);
}
@@ -25,7 +25,15 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
*/
public interface UnaryOp {
/**
* Gets value
* @return Value
*/
public GraphTargetItem getValue();
/**
* Gets precedence
* @return Precedence
*/
public int getPrecedence();
}
@@ -31,10 +31,26 @@ import java.util.Set;
*/
public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
/**
* Operator
*/
public String operator;
/**
* Coerce value to this type
*/
protected String coerce;
/**
* Constructor.
*
* @param instruction Instruction
* @param lineStartItem Line start item
* @param precedence Precedence
* @param value Value
* @param operator Operator
* @param coerce Coerce
*/
public UnaryOpItem(GraphSourceItem instruction, GraphSourceItem lineStartItem, int precedence, GraphTargetItem value, String operator, String coerce) {
super(instruction, lineStartItem, precedence, value);
this.operator = operator;
@@ -148,6 +164,14 @@ public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
return hash;
}
/**
* Converts operand to string.
*
* @param operand Operand
* @param writer Writer
* @param localData Local data
* @throws InterruptedException On interrupt
*/
protected void operandToString(GraphTargetItem operand, GraphTextWriter writer, LocalData localData) throws InterruptedException {
operand.toString(writer, localData, "");
}
@@ -27,6 +27,9 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
*/
public class UnboundedTypeItem extends AVM2Item {
/**
* Constructor.
*/
public UnboundedTypeItem() {
super(null, null, NOPRECEDENCE);
}
@@ -30,12 +30,23 @@ import java.util.List;
*/
public class UniversalLoopItem extends WhileItem implements Block {
/**
* True expression.
*/
static final List<GraphTargetItem> TRUE_EXPRESSION = new ArrayList<>();
static {
TRUE_EXPRESSION.add(new TrueItem(null, null));
}
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param loop Loop
* @param commands Commands
*/
public UniversalLoopItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> commands) {
super(src, lineStartIns, loop, TRUE_EXPRESSION, commands);
}
@@ -38,10 +38,19 @@ import java.util.List;
*/
public class WhileItem extends LoopItem implements Block {
/**
* Expression
*/
public List<GraphTargetItem> expression;
/**
* Commands
*/
public List<GraphTargetItem> commands;
/**
* Label used
*/
private boolean labelUsed;
@Override
@@ -73,6 +82,15 @@ public class WhileItem extends LoopItem implements Block {
}
}
/**
* Constructor.
*
* @param src Source
* @param lineStartIns Line start instruction
* @param loop Loop
* @param expression Expression
* @param commands Commands
*/
public WhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> expression, List<GraphTargetItem> commands) {
super(src, lineStartIns, loop);
this.expression = expression;
@@ -23,6 +23,9 @@ package com.jpexs.decompiler.graph.precontinues;
*/
public class DoWhileNode extends Node {
/**
* Body
*/
public Node body;
@Override
@@ -40,6 +40,13 @@ import java.util.Set;
*/
public class GraphPrecontinueDetector {
/**
* Detects precontinues in graph.
* @param heads Heads
* @param allParts All parts
* @param loops Loops
* @param throwStates Throw states
*/
public void detectPrecontinues(List<GraphPart> heads, Set<GraphPart> allParts, List<Loop> loops, List<ThrowState> throwStates) {
boolean isSomethingTodo = false;
for (Loop el : loops) {
@@ -169,7 +176,7 @@ public class GraphPrecontinueDetector {
/**
* Converts node graph to graphviz for easily display.
*
* @param headNodes
* @param headNodes Head nodes
*/
public void printGraph(List<Node> headNodes) {
Set<Node> allNodes = new LinkedHashSet<>();
@@ -23,7 +23,14 @@ package com.jpexs.decompiler.graph.precontinues;
*/
public class IfNode extends Node {
/**
* On true
*/
public Node onTrue;
/**
* On false
*/
public Node onFalse;
@Override
@@ -26,6 +26,9 @@ import java.util.List;
*/
public class JoinedNode extends Node {
/**
* Nodes
*/
public List<Node> nodes = new ArrayList<>();
@Override
@@ -27,18 +27,43 @@ import java.util.List;
*/
public class Node {
/**
* Next nodes
*/
public List<Node> next = new ArrayList<>();
/**
* Previous nodes
*/
public List<Node> prev = new ArrayList<Node>();
/**
* Graph part
*/
public GraphPart graphPart;
/**
* Current id
*/
private static int CURRENT_ID = 0;
/**
* Id
*/
private int id;
/**
* Parent node
*/
public Node parentNode;
/**
* Constructor.
*/
public Node() {
this.id = ++CURRENT_ID;
}
/**
* Gets id.
* @return Id
*/
public int getId() {
return id;
}
@@ -73,6 +98,10 @@ public class Node {
return true;
}
/**
* Replces previous node.
* @param newNode New node
*/
public void replacePrevs(Node newNode) {
for (Node p : this.prev) {
for (int i = 0; i < p.next.size(); i++) {
@@ -83,6 +112,10 @@ public class Node {
}
}
/**
* Replaces next node.
* @param newNode New node
*/
public void replaceNexts(Node newNode) {
for (Node n : this.next) {
for (int i = 0; i < n.prev.size(); i++) {
@@ -93,6 +126,9 @@ public class Node {
}
}
/**
* Removes node from graph.
*/
public void removeFromGraph() {
for (Node p : this.prev) {
for (int i = p.next.size() - 1; i >= 0; i--) {
@@ -23,6 +23,9 @@ package com.jpexs.decompiler.graph.precontinues;
*/
public class WhileNode extends Node {
/**
* Body
*/
public Node body;
@Override