Added Checkstyle to build process and fixing checkstyle to all com.src.jpexs classes

This commit is contained in:
Jindra Petřík
2023-10-16 09:36:06 +02:00
parent b6e8ca0d67
commit dc5e50813f
789 changed files with 23773 additions and 22843 deletions
@@ -86,10 +86,10 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
} else if (name.isEmpty()) {
return DottedChain.TOPLEVEL;
} else {
String parts[] = name.split("\\.");
String[] parts = name.split("\\.");
List<PathPart> newParts = new ArrayList<>();
for (String part : parts) {
newParts.add(new PathPart(part, false, ""));
newParts.add(new PathPart(part, false, ""));
}
return new DottedChain(newParts, false);
@@ -102,7 +102,7 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
} else if (name.isEmpty()) {
return DottedChain.TOPLEVEL;
} else {
String parts[] = name.split("\\.");
String[] parts = name.split("\\.");
List<PathPart> newParts = new ArrayList<>();
for (String part : parts) {
String nameNoSuffix = part;
@@ -111,7 +111,7 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
nameNoSuffix = part.substring(0, part.lastIndexOf("#"));
namespaceSuffix = part.substring(part.lastIndexOf("#"));
}
newParts.add(new PathPart(nameNoSuffix, false, namespaceSuffix));
newParts.add(new PathPart(nameNoSuffix, false, namespaceSuffix));
}
return new DottedChain(newParts, false);
@@ -149,7 +149,7 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
this(new boolean[parts.length], parts, namespaceSuffixes);
}
public DottedChain(boolean attributes[], String[] parts, String[] namespaceSuffixes) {
public DottedChain(boolean[] attributes, String[] parts, String[] namespaceSuffixes) {
List<PathPart> newParts = new ArrayList<>();
for (int i = 0; i < attributes.length; i++) {
newParts.add(new PathPart(parts[i], attributes[i], namespaceSuffixes[i]));
@@ -248,11 +248,11 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
newParts.add(new PathPart(name, attribute, namespaceSuffix));
return new DottedChain(newParts, false);
}
public DottedChain preAdd(String name, String namespaceSuffix) {
return preAdd(false, name, namespaceSuffix);
}
public DottedChain preAdd(boolean attribute, String name, String namespaceSuffix) {
if (name == null) {
return new DottedChain(this);
@@ -262,6 +262,11 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
return new DottedChain(newParts, false);
}
@Override
public String toString() {
return toRawString();
}
protected String toString(boolean as3, boolean raw, boolean withSuffix) {
if (isNull) {
return "";
@@ -324,11 +329,6 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
return toString(false/*ignored*/, true, true);
}
@Override
public String toString() {
return toRawString();
}
@Override
public int hashCode() {
int hash = 7;
@@ -400,6 +400,6 @@ public class DottedChain implements Serializable, Comparable<DottedChain> {
return false;
}
return Objects.equals(this.namespaceSuffix, other.namespaceSuffix);
}
}
}
}
@@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.FinalProcessLocalData;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BinaryOpItem;
@@ -63,7 +62,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -390,7 +388,7 @@ public class Graph {
return null;
}
List<GraphPart> loopContinues = new ArrayList<>();//getLoopsContinues(loops);
List<GraphPart> loopContinues = new ArrayList<>();
for (Loop l : loops) {
if (l.phase == 1) {
loopContinues.add(l.loopContinue);
@@ -452,7 +450,7 @@ public class Graph {
Set<GraphPart> s = new HashSet<>(parts); //unique
parts = new ArrayList<>(s); //make local copy
List<GraphPart> loopContinues = new ArrayList<>();//getLoopsContinues(loops);
List<GraphPart> loopContinues = new ArrayList<>();
for (Loop l : loops) {
if (l.phase == 1) {
loopContinues.add(l.loopContinue);
@@ -643,7 +641,7 @@ public class Graph {
int ret = o.level - level;
if (ret == 0) {
ret = part.closedTime - o.part.closedTime;
if (ret == 0) { //some nodes may be split in half and thus have same closedTime - like in try..catch
return part.start - o.part.start;
}
@@ -826,16 +824,16 @@ public class Graph {
makeAllCommands(ret, stack);
finalProcessAll(ret, 0, getFinalData(localData, loops, throwStates), path);
return ret;
}
protected SecondPassData prepareSecondPass(List<GraphTargetItem> list) {
return null;
}
protected void processSwitches(List<GraphTargetItem> list) {
processSwitches(list, -1);
}
protected SecondPassData prepareSecondPass(List<GraphTargetItem> list) {
return null;
}
/*
while(something){
@@ -1517,33 +1515,7 @@ public class Graph {
}
return ret;
}
protected GraphTargetItem checkLoop(List<GraphTargetItem> output, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, List<ThrowState> throwStates) {
if (stopPart.contains(part)) {
return null;
}
GraphSourceItem firstIns = null;
if (part != null) {
if (part.start >= 0 && part.start < code.size()) {
firstIns = code.get(part.start);
}
}
for (Loop l : loops) {
if (l.phase == 2) {
continue;
}
if (l.loopContinue == part) {
return (new ContinueItem(null, firstIns, l.id));
}
if (l.loopBreak == part) {
return (new BreakItem(null, firstIns, l.id));
}
}
return null;
}
private void checkContinueAtTheEnd(List<GraphTargetItem> commands, Loop loop) {
if (!commands.isEmpty()) {
int i = commands.size() - 1;
@@ -1661,10 +1633,32 @@ public class Graph {
list.remove(list.size() - 1);
}
protected 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);
}
protected GraphTargetItem checkLoop(List<GraphTargetItem> output, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, List<ThrowState> throwStates) {
if (stopPart.contains(part)) {
return null;
}
GraphSourceItem firstIns = null;
if (part != null) {
if (part.start >= 0 && part.start < code.size()) {
firstIns = code.get(part.start);
}
}
for (Loop l : loops) {
if (l.phase == 2) {
continue;
}
if (l.loopContinue == part) {
return (new ContinueItem(null, firstIns, l.id));
}
if (l.loopBreak == part) {
return (new BreakItem(null, firstIns, l.id));
}
}
return null;
}
protected GraphTargetItem checkLoop(List<GraphTargetItem> output, LoopItem loopItem, BaseLocalData localData, List<Loop> loops, List<ThrowState> throwStates, TranslateStack stack) {
return loopItem;
}
@@ -1814,13 +1808,7 @@ public class Graph {
if (part.nextParts.size() == 2 && !partIsSwitch(part)) {
List<GraphPart> nps;/* = new ArrayList<>(part.nextParts);
for(int i=0;i<nps.size();i++){
nps.set(i,getNextNoJump(nps.get(i),localData));
}
if(nps.get(0) == nps.get(1)){
nps = part.nextParts;
}*/
List<GraphPart> nps;
nps = part.nextParts;
GraphPart next = getCommonPart(localData, part, nps, loops, throwStates);
@@ -2055,6 +2043,7 @@ public class Graph {
}
}
if (otherBreakCandidate) {
//empty
} else if (count.get(cand) > winnerCount) {
winnerCount = count.get(cand);
winner = cand;
@@ -2171,6 +2160,10 @@ public class Graph {
return true;
}
protected 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);
}
protected 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:
while (true) {
@@ -2445,7 +2438,7 @@ public class Graph {
currentRet.addAll(output);
}
}
//********************************END PART DECOMPILING
//********************************END PART DECOMPILING
if (parseNext) {
if (getNextParts(localData, part).size() > 2 || partIsSwitch(part)) {
@@ -2934,8 +2927,9 @@ public class Graph {
if (continueCommands.isEmpty()) {
commands.addAll(precoCommands);
precoCommands = new ArrayList<>();
} //Single continue and there is break/continue/return/throw at end of the commands
else if (!commands.isEmpty() && continueCommands.size() == 1) {
//Single continue and there is break/continue/return/throw at end of the commands
} else if (!commands.isEmpty() && continueCommands.size() == 1) {
GraphTargetItem lastItem = commands.get(commands.size() - 1);
if ((lastItem instanceof BreakItem) || (lastItem instanceof ContinueItem) || (lastItem instanceof ExitItem)) {
continueCommands.get(0).addAll(continueCommands.get(0).size() - 1, precoCommands);
@@ -3093,6 +3087,22 @@ public class Graph {
}
protected void checkGraph(List<GraphPart> allBlocks) {
}
protected int checkIp(int ip) {
return ip;
}
public GraphPart searchPart(int ip, Collection<? extends GraphPart> allParts) {
if (ip < 0) {
return null;
}
for (GraphPart p : allParts) {
if (ip >= p.start && ip <= p.end) {
return p;
}
}
return null;
}
public List<GraphPart> makeGraph(GraphSource code, List<GraphPart> allBlocks, List<GraphException> exceptions) throws InterruptedException {
@@ -3115,22 +3125,6 @@ public class Graph {
return ret;
}
protected int checkIp(int ip) {
return ip;
}
public GraphPart searchPart(int ip, Collection<? extends GraphPart> allParts) {
if (ip < 0) {
return null;
}
for (GraphPart p : allParts) {
if (ip >= p.start && ip <= p.end) {
return p;
}
}
return null;
}
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();
@@ -3366,7 +3360,7 @@ public class Graph {
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,
List<GraphTargetItem> caseValuesMap, GraphPart defaultPart, List<GraphPart> caseBodyParts, Reference<GraphPart> nextRef, Reference<GraphTargetItem> tiRef) throws InterruptedException {
List<GraphTargetItem> caseValuesMap, GraphPart defaultPart, List<GraphPart> caseBodyParts, Reference<GraphPart> nextRef, Reference<GraphTargetItem> tiRef) throws InterruptedException {
boolean hasDefault = false;
/*
case 4:
@@ -21,6 +21,7 @@ package com.jpexs.decompiler.graph;
* @author JPEXS
*/
public class GraphExceptionParts {
public GraphPart start;
public GraphPart end;
public GraphPart target;
@@ -64,13 +64,13 @@ public class GraphPart implements Serializable {
public List<GraphPart> refs = new ArrayList<>();
public boolean ignored = false;
public int level;
public int discoveredTime;
public int finishedTime;
public int closedTime;
public int order;
@@ -134,77 +134,9 @@ public class GraphPart implements Serializable {
next.setNumblocks(numBlocks);
}
}
}
}
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
Stack<GraphPart> todo = new Stack<>();
todo.push(this);
looptodo:while (!todo.isEmpty()) {
GraphPart thisPart = todo.pop();
GraphPart tpart = gr.checkPart(null, localData, prev, thisPart, null);
if (tpart == null) {
continue;
}
if (tpart != thisPart) {
todo.push(tpart);
continue;
}
for (Loop l : loops) {
if (l.phase == 1) {
if (l.loopContinue == thisPart) {
continue looptodo;
}
if (l.loopPreContinue == thisPart) {
continue looptodo;
}
if (l.loopBreak == thisPart) {
//return false; //?
}
}
}
if (visited.contains(thisPart)) {
continue;
}
visited.add(thisPart);
if (thisPart.end < code.size() && code.get(thisPart.end).isBranch() && (code.get(thisPart.end).ignoredLoops())) {
continue;
}
for (GraphPart p : thisPart.nextParts) {
if (p == part) {
return true;
}
if (visited.contains(p)) {
continue;
}
todo.push(p);
}
for (ThrowState ts : throwStates) {
if (ts.state != 1) {
if (ts.throwingParts.contains(thisPart)) {
GraphPart p = ts.targetPart;
if (p == part) {
return true;
}
if (visited.contains(p)) {
continue;
}
todo.push(p);
}
}
}
}
return false;
}
private boolean leadsToRecursive(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
private boolean leadsToRecursive(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
@@ -270,6 +202,75 @@ public class GraphPart implements Serializable {
return false;
}
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
Stack<GraphPart> todo = new Stack<>();
todo.push(this);
looptodo:
while (!todo.isEmpty()) {
GraphPart thisPart = todo.pop();
GraphPart tpart = gr.checkPart(null, localData, prev, thisPart, null);
if (tpart == null) {
continue;
}
if (tpart != thisPart) {
todo.push(tpart);
continue;
}
for (Loop l : loops) {
if (l.phase == 1) {
if (l.loopContinue == thisPart) {
continue looptodo;
}
if (l.loopPreContinue == thisPart) {
continue looptodo;
}
if (l.loopBreak == thisPart) {
//return false; //?
}
}
}
if (visited.contains(thisPart)) {
continue;
}
visited.add(thisPart);
if (thisPart.end < code.size() && code.get(thisPart.end).isBranch() && (code.get(thisPart.end).ignoredLoops())) {
continue;
}
for (GraphPart p : thisPart.nextParts) {
if (p == part) {
return true;
}
if (visited.contains(p)) {
continue;
}
todo.push(p);
}
for (ThrowState ts : throwStates) {
if (ts.state != 1) {
if (ts.throwingParts.contains(thisPart)) {
GraphPart p = ts.targetPart;
if (p == part) {
return true;
}
if (visited.contains(p)) {
continue;
}
todo.push(p);
}
}
}
}
return false;
}
public boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
for (Loop l : loops) {
l.leadsToMark = 0;
@@ -351,11 +352,19 @@ public class GraphPart implements Serializable {
int printEnd = end + 1;
return "" + (printStart < 0 ? "(" : "") + printStart + (printStart < 0 ? ")" : "")
+ "-" + (printEnd < 0 ? "(" : "") + printEnd + (printEnd < 0 ? ")" : "") + (instanceCount > 1 ? "(" + instanceCount + " links)" : "");// + " p" + path;
+ "-" + (printEnd < 0 ? "(" : "") + printEnd + (printEnd < 0 ? ")" : "") + (instanceCount > 1 ? "(" + instanceCount + " links)" : "");
}
public boolean containsIP(int ip) {
return (ip >= start) && (ip <= end);
}
public int getHeight() {
return end - start + 1;
}
public int getPosAt(int offset) {
return start + offset;
}
private boolean containsPart(GraphPart part, GraphPart what, List<GraphPart> used) {
@@ -374,14 +383,6 @@ public class GraphPart implements Serializable {
return false;
}
public int getHeight() {
return end - start + 1;
}
public int getPosAt(int offset) {
return start + offset;
}
public boolean containsPart(GraphPart what) {
return containsPart(this, what, new ArrayList<>());
}
@@ -23,6 +23,7 @@ import java.util.List;
* @author JPEXS
*/
public class GraphPartChangeException extends Exception {
private final int ip;
private final List<GraphTargetItem> output;
@@ -39,5 +40,4 @@ public class GraphPartChangeException extends Exception {
return output;
}
}
@@ -23,6 +23,7 @@ import java.util.Objects;
* @author JPEXS
*/
public class GraphPartDecision {
public GraphPart part;
public int way;
@@ -23,6 +23,7 @@ import java.util.Objects;
* @author JPEXS
*/
public class GraphPartEdge {
public GraphPart from;
public GraphPart to;
@@ -93,7 +93,7 @@ public abstract class GraphSource implements Serializable {
break;
}
ip++;
};
}
}
public HashMap<Integer, List<Integer>> visitCode(List<Integer> alternateEntries) throws InterruptedException {
@@ -113,9 +113,7 @@ public abstract class GraphSource implements Serializable {
public abstract int adr2pos(long adr);
public abstract int adr2pos(long adr, boolean nearest);
public abstract long pos2adr(int pos);
public abstract int adr2pos(long adr, boolean nearest);
public long getAddressAfterCode() {
if (isEmpty()) {
@@ -124,6 +122,8 @@ public abstract class GraphSource implements Serializable {
long lastAddr = pos2adr(size() - 1);
return lastAddr + get(size() - 1).getBytesLength();
}
public abstract long pos2adr(int pos);
public final long pos2adr(int pos, boolean allowPosAfterCode) {
if (pos == size() && allowPosAfterCode) {
@@ -131,5 +131,4 @@ public abstract class GraphSource implements Serializable {
}
return pos2adr(pos);
}
;
}
@@ -180,7 +180,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
case "Boolean":
r = EcmaScript.toBoolean(r);
break;
}
}
GraphTargetItem it2 = valToItem(r);
if (it2 == null) {
@@ -287,12 +287,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
public boolean needsSemicolon() {
return true;
}
@Override
public String toString() {
return getClass().getName();
}
}
public GraphTextWriter toStringBoolean(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData, "Boolean");
@@ -310,6 +305,11 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
return toString(writer, localData, "Number");
}
@Override
public String toString() {
return getClass().getName();
}
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData, String implicitCoerce) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
@@ -325,6 +325,12 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
return toString(writer, localData, "");
}
public String toString(LocalData localData) throws InterruptedException {
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toString(writer, localData);
return writer.toString();
}
public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException;
public GraphTextWriter appendTry(GraphTextWriter writer, LocalData localData) throws InterruptedException {
@@ -342,13 +348,12 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
if (localData.abc != null) { //its AS3
List<String> numberTypes = Arrays.asList("int", "uint", "Number");
String returnTypeStr = t.returnType().toString();
//To avoid Error: Implicit coercion of a value of type XXX to an unrelated type YYY
if (!t.returnType().equals(TypeItem.UNBOUNDED) &&
!implicitCoerce.equals(returnTypeStr) &&
!(numberTypes.contains(implicitCoerce) && numberTypes.contains(returnTypeStr)) &&
!(implicitCoerce.equals("Boolean") && !returnTypeStr.equals("Function"))
) {
if (!t.returnType().equals(TypeItem.UNBOUNDED)
&& !implicitCoerce.equals(returnTypeStr)
&& !(numberTypes.contains(implicitCoerce) && numberTypes.contains(returnTypeStr))
&& !(implicitCoerce.equals("Boolean") && !returnTypeStr.equals("Function"))) {
t = new ConvertAVM2Item(null, null, t, new TypeItem(implicitCoerce));
}
}
@@ -360,19 +365,13 @@ public abstract class GraphTargetItem implements Serializable, Cloneable {
}
public String toString(LocalData localData) throws InterruptedException {
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toString(writer, localData);
return writer.toString();
}
public int getPrecedence() {
return precedence;
}
public boolean isCompileTime() {
Set<GraphTargetItem> dependencies = new HashSet<>();
if (!((this instanceof SimpleValue) && ((SimpleValue)this).isSimpleValue())) {
if (!((this instanceof SimpleValue) && ((SimpleValue) this).isSimpleValue())) {
dependencies.add(this);
}
return isCompileTime(dependencies);
@@ -67,7 +67,7 @@ public class Loop implements Serializable {
}
Set<String> bcAsStr = new LinkedHashSet<>();
for (int i = 0; i < breakCandidates.size(); i++) {
bcAsStr.add(breakCandidates.get(i) + " - level " + breakCandidatesLevels.get(i) +" - numblocks " + breakCandidates.get(i).numBlocks);
bcAsStr.add(breakCandidates.get(i) + " - level " + breakCandidatesLevels.get(i) + " - numblocks " + breakCandidates.get(i).numBlocks);
}
return "loop(id:" + id + (loopPreContinue != null ? ",precontinue:" + loopPreContinue : "") + ",continue:" + loopContinue + ", break:" + loopBreak + ", phase:" + phase + ", backedges: " + String.join(",", edgesAsStr) + ", breakCandidates: " + String.join(",", bcAsStr) + ")";
@@ -24,5 +24,6 @@ import java.util.Set;
* @author JPEXS
*/
public class SecondPassData {
public Set<GraphPart> allSwitchParts = new HashSet<>();
public Set<GraphPart> allSwitchParts = new HashSet<>();
}
@@ -21,6 +21,7 @@ package com.jpexs.decompiler.graph;
* @author JPEXS
*/
public class SecondPassException extends RuntimeException {
private final SecondPassData data;
public SecondPassException(SecondPassData data) {
@@ -41,7 +41,7 @@ import java.util.List;
* @author JPEXS
*/
public interface SourceGenerator {
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PushItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, PopItem item) throws CompilationException;
@@ -24,6 +24,7 @@ import java.util.Set;
* @author JPEXS
*/
public class ThrowState {
public int exceptionId;
public int state;
@@ -47,7 +47,7 @@ public class TranslateStack extends Stack<GraphTargetItem> {
private PopItem getPop() {
if (pop == null) {
pop = new PopItem(null, null);//TODO: linestart?
pop = new PopItem(null, null); //TODO: linestart?
}
return pop;
@@ -35,40 +35,42 @@ public class TypeItem extends GraphTargetItem {
public static TypeItem BOOLEAN = new TypeItem(DottedChain.BOOLEAN);
public static TypeItem STRING = new TypeItem(DottedChain.STRING);
public static TypeItem NUMBER = new TypeItem(DottedChain.NUMBER);
public static TypeItem INT = new TypeItem(DottedChain.INT);
public static TypeItem UINT = new TypeItem(DottedChain.UINT);
public static TypeItem UNDEFINED = new TypeItem(DottedChain.UNDEFINED);
public static TypeItem ARRAY = new TypeItem(DottedChain.ARRAY);
public static UnboundedTypeItem UNBOUNDED = new UnboundedTypeItem();
public static TypeItem UNKNOWN = new TypeItem("--UNKNOWN--");
public final DottedChain fullTypeName;
public boolean printRaw = false;
public String ns;
public TypeItem(String s) {
this(s, null);
}
public TypeItem(String s, String ns) {
this(s == null ? new DottedChain(new String[]{}, new String[]{""}) : DottedChain.parseWithSuffix(s), ns);
}
public TypeItem(DottedChain fullTypeName) {
this(fullTypeName, (String)null);
}
this(fullTypeName, (String) null);
}
public TypeItem(DottedChain fullTypeName, String ns) {
this(fullTypeName, new ArrayList<>(), ns);
}
}
public TypeItem(DottedChain fullTypeName, List<GraphTargetItem> subtypes, String ns) {
super(null, null, NOPRECEDENCE);
@@ -102,8 +104,6 @@ public class TypeItem extends GraphTargetItem {
return Objects.equals(this.fullTypeName, other.fullTypeName);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
boolean as3 = localData.constantsAvm2 != null;
@@ -107,13 +107,13 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
if (dependencies.contains(leftSide)) {
return false;
}
if (!((leftSide instanceof SimpleValue) && ((SimpleValue)leftSide).isSimpleValue())) {
if (!((leftSide instanceof SimpleValue) && ((SimpleValue) leftSide).isSimpleValue())) {
dependencies.add(leftSide);
}
if (leftSide != rightSide && dependencies.contains(rightSide)) {
return false;
}
if (!((rightSide instanceof SimpleValue) && ((SimpleValue)rightSide).isSimpleValue())) {
if (!((rightSide instanceof SimpleValue) && ((SimpleValue) rightSide).isSimpleValue())) {
dependencies.add(rightSide);
}
return leftSide.isConvertedCompileTime(dependencies) && rightSide.isConvertedCompileTime(dependencies);
@@ -70,7 +70,6 @@ public class CommaExpressionItem extends GraphTargetItem {
return generator.generate(localData, this, false);
}
@Override
public boolean hasReturnValue() {
return false;
@@ -77,7 +77,6 @@ public class DoWhileItem extends LoopItem implements Block {
}
}
public DoWhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> commands, List<GraphTargetItem> expression) {
super(src, lineStartIns, loop);
this.expression = expression;
@@ -109,7 +108,7 @@ public class DoWhileItem extends LoopItem implements Block {
if (!first) {
writer.append(", ");
}
first = false;
first = false;
if (i == expression.size() - 1) {
expression.get(i).toStringBoolean(writer, localData);
} else {
@@ -82,7 +82,7 @@ public class DuplicateItem extends GraphTargetItem implements SimpleValue {
if (dependencies.contains(value)) {
return false;
}
if (!((value instanceof SimpleValue) && ((SimpleValue)value).isSimpleValue())) {
if (!((value instanceof SimpleValue) && ((SimpleValue) value).isSimpleValue())) {
dependencies.add(value);
}
return value.isCompileTime(dependencies);
@@ -40,5 +40,5 @@ public class EmptyCommand extends GraphTargetItem {
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -81,7 +81,6 @@ public class ForItem extends LoopItem implements Block {
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;
@@ -52,7 +52,7 @@ public class IfItem extends GraphTargetItem implements Block {
if (dependencies.contains(expression)) {
return false;
}
if (!((expression instanceof SimpleValue) && ((SimpleValue)expression).isSimpleValue())) {
if (!((expression instanceof SimpleValue) && ((SimpleValue) expression).isSimpleValue())) {
dependencies.add(expression);
}
return expression.isCompileTime(dependencies);
@@ -86,7 +86,6 @@ public class IfItem extends GraphTargetItem implements Block {
visitor.visit(expression);
}
public IfItem(GraphSourceItem src, GraphSourceItem lineStartIns, GraphTargetItem expression, List<GraphTargetItem> onTrue, List<GraphTargetItem> onFalse) {
super(src, lineStartIns, NOPRECEDENCE);
this.expression = expression;
@@ -38,9 +38,9 @@ public class LocalData {
public ConstantPool constants;
public AVM2ConstantPool constantsAvm2;
public AbcIndexing abcIndex;
public List<MethodBody> callStack;
public HashMap<Integer, String> localRegNames;
@@ -33,8 +33,8 @@ public abstract class LoopItem extends GraphTargetItem {
super(src, lineStartItem, NOPRECEDENCE);
this.loop = loop;
}
public abstract boolean hasBaseBody();
public abstract List<GraphTargetItem> getBaseBodyCommands();
}
@@ -58,7 +58,7 @@ public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
if (dependencies.contains(value)) {
return false;
}
if (!((value instanceof SimpleValue) && ((SimpleValue)value).isSimpleValue())) {
if (!((value instanceof SimpleValue) && ((SimpleValue) value).isSimpleValue())) {
dependencies.add(value);
}
return value.isCompileTime(dependencies);
@@ -66,5 +66,5 @@ public class PopItem extends GraphTargetItem {
@Override
public boolean hasSideEffect() {
return true; //?
}
}
}
@@ -69,7 +69,6 @@ public class SwitchItem extends LoopItem implements Block {
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;
@@ -72,7 +72,6 @@ public class WhileItem extends LoopItem implements Block {
}
}
public WhileItem(GraphSourceItem src, GraphSourceItem lineStartIns, Loop loop, List<GraphTargetItem> expression, List<GraphTargetItem> commands) {
super(src, lineStartIns, loop);
this.expression = expression;
@@ -21,6 +21,7 @@ package com.jpexs.decompiler.graph.precontinues;
* @author JPEXS
*/
public class DoWhileNode extends Node {
public Node body;
@Override
@@ -205,29 +205,7 @@ public class GraphPrecontinueDetector {
for (Node n : node.next) {
populateNodes(n, populated);
}
}
private boolean checkIfs(List<Node> headNodes) {
Set<Node> visited = new HashSet<>();
Reference<Integer> numChanged = new Reference<>(0);
for (int h = 0; h < headNodes.size(); h++) {
Node newHeadNode;
newHeadNode = checkIfs(headNodes.get(h), visited, numChanged);
headNodes.set(h, newHeadNode);
}
return numChanged.getVal() > 0;
}
private boolean joinNodes(List<Node> headNodes) {
Set<Node> visited = new HashSet<>();
Reference<Integer> numChanged = new Reference<>(0);
for (int h = 0; h < headNodes.size(); h++) {
Node newHeadNode;
newHeadNode = joinNodes(headNodes.get(h), visited, numChanged);
headNodes.set(h, newHeadNode);
}
return numChanged.getVal() > 0;
}
}
private boolean handleWhile(List<Node> headNodes) {
Set<Node> visited = new HashSet<>();
@@ -312,6 +290,17 @@ public class GraphPrecontinueDetector {
}
return result;
}
private boolean joinNodes(List<Node> headNodes) {
Set<Node> visited = new HashSet<>();
Reference<Integer> numChanged = new Reference<>(0);
for (int h = 0; h < headNodes.size(); h++) {
Node newHeadNode;
newHeadNode = joinNodes(headNodes.get(h), visited, numChanged);
headNodes.set(h, newHeadNode);
}
return numChanged.getVal() > 0;
}
private Node joinNodes(Node node, Set<Node> visited, Reference<Integer> numJoined) {
if (visited.contains(node)) {
@@ -365,6 +354,17 @@ public class GraphPrecontinueDetector {
return result;
}
private boolean checkIfs(List<Node> headNodes) {
Set<Node> visited = new HashSet<>();
Reference<Integer> numChanged = new Reference<>(0);
for (int h = 0; h < headNodes.size(); h++) {
Node newHeadNode;
newHeadNode = checkIfs(headNodes.get(h), visited, numChanged);
headNodes.set(h, newHeadNode);
}
return numChanged.getVal() > 0;
}
private Node checkIfs(Node node, Set<Node> visited, Reference<Integer> numIfs) {
if (visited.contains(node)) {
@@ -21,6 +21,7 @@ package com.jpexs.decompiler.graph.precontinues;
* @author JPEXS
*/
public class IfNode extends Node {
public Node onTrue;
public Node onFalse;
@@ -24,6 +24,7 @@ import java.util.List;
* @author JPEXS
*/
public class JoinedNode extends Node {
public List<Node> nodes = new ArrayList<>();
@Override
@@ -25,6 +25,7 @@ import java.util.List;
* @author JPEXS
*/
public class Node {
public List<Node> next = new ArrayList<>();
public List<Node> prev = new ArrayList<Node>();
public GraphPart graphPart;
@@ -71,7 +72,6 @@ public class Node {
return true;
}
public void replacePrevs(Node newNode) {
for (Node p : this.prev) {
for (int i = 0; i < p.next.size(); i++) {
@@ -21,6 +21,7 @@ package com.jpexs.decompiler.graph.precontinues;
* @author JPEXS
*/
public class WhileNode extends Node {
public Node body;
@Override
@@ -28,5 +29,4 @@ public class WhileNode extends Node {
return "while" + super.toString();
}
}