Separated FFDec core library and the rest (GUI).

FFDec Library is now LGPLv3, others stay GPLv3.
Version changed to 3.0.0 for FFDec, 1.0.0 for FFDec Library.
This commit is contained in:
Jindra Petřík
2014-08-24 17:55:42 +02:00
parent 2479c59b03
commit 04922aaf69
1323 changed files with 53605 additions and 52175 deletions
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.graph.model.ContinueItem;
import java.util.List;
public interface Block {
public List<ContinueItem> getContinues();
public List<List<GraphTargetItem>> getSubs();
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2014 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;
/**
*
* @author JPEXS
*/
public class CompilationException extends Exception {
public int line;
public String text;
public CompilationException(String message, int line) {
super("Compilation error on line " + line + ": " + message);
this.line = line;
this.text = message;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,269 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.BaseLocalData;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class GraphPart implements Serializable {
public int start = 0;
public int end = 0;
public int instanceCount = 0;
public List<GraphPart> nextParts = new ArrayList<>();
public int posX = -1;
public int posY = -1;
public GraphPath path = new GraphPath();
public List<GraphPart> refs = new ArrayList<>();
public boolean ignored = false;
public List<Object> forContinues = new ArrayList<>();
public int level;
public int discoveredTime;
public int finishedTime;
public int order;
public List<GraphPart> throwParts = new ArrayList<>();
public int setTime(int time, List<GraphPart> ordered, List<GraphPart> visited) {
if (visited.contains(this)) {
return time;
}
discoveredTime = time;
visited.add(this);
for (GraphPart next : nextParts) {
if (!visited.contains(next)) {
time = next.setTime(time + 1, ordered, visited);
}
}
time++;
finishedTime = time;
order = ordered.size();
ordered.add(this);
return time;
}
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<GraphPart> visited, List<Loop> loops) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
GraphPart tpart = gr.checkPart(null, localData, this, null);
if (tpart == null) {
return false;
}
if (tpart != this) {
return tpart.leadsTo(localData, gr, code, part, visited, loops);
}
Loop currentLoop = null;
for (Loop l : loops) {
/*if(l.phase==0){
if(l.loopContinue==this){
l.leadsToMark = 1;
next = l.loopBreak;
currentLoop = l;
continue;
}
}*/
if (l.phase == 1) {
if (l.loopContinue == this) {
return false;
}
if (l.loopPreContinue == this) {
return false;
}
if (l.loopBreak == this) {
//return false; //?
}
}
}
if (visited.contains(this)) {
return false;
}
/*if (loops.contains(this)) {
return false;
}*/
visited.add(this);
if (end < code.size() && code.get(end).isBranch() && (code.get(end).ignoredLoops())) {
return false;
}
for (GraphPart p : nextParts) {
if (p == part) {
return true;
} else {
if (p.leadsTo(localData, gr, code, part, visited, loops)) {
return true;
}
}
}
for (GraphPart p : throwParts) {
if (p == part) {
return true;
} else {
if (p.leadsTo(localData, gr, code, part, visited, loops)) {
return true;
}
}
}
return false;
}
public boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops) throws InterruptedException {
for (Loop l : loops) {
l.leadsToMark = 0;
}
return leadsTo(localData, gr, code, part, new ArrayList<GraphPart>(), loops);
}
public GraphPart(int start, int end) {
this.start = start;
this.end = end;
}
private GraphPart getNextPartPath(GraphPart original, GraphPath path, List<GraphPart> visited) {
if (visited.contains(this) && (this == original)) {
return null;
}
if (visited.contains(this) && (this != original)) {
return null;
}
visited.add(this);
for (GraphPart p : nextParts) {
if (p == original) {
continue;
}
if (p.path.equals(path)) {
return p;
} else if (p.path.length() >= path.length()) {
GraphPart gp = p.getNextPartPath(original, path, visited);
if (gp != null) {
return gp;
}
}
}
return null;
}
public GraphPart getNextPartPath(List<GraphPart> ignored) {
List<GraphPart> visited = new ArrayList<>();
visited.addAll(ignored);
if (visited.contains(this)) {
visited.remove(this);
}
return getNextPartPath(this, path, visited);
}
public GraphPart getNextSuperPartPath(List<GraphPart> ignored) {
List<GraphPart> visited = new ArrayList<>();
visited.addAll(ignored);
return getNextSuperPartPath(this, path, visited);
}
private GraphPart getNextSuperPartPath(GraphPart original, GraphPath path, List<GraphPart> visited) {
if (visited.contains(this)) {
return null;
}
visited.add(this);
for (GraphPart p : nextParts) {
if (p == original) {
continue;
}
if (p.path.length() < path.length()) {
return p;
} else {
GraphPart gp = p.getNextSuperPartPath(original, path, visited);
if (gp != null) {
return gp;
}
}
}
return null;
}
@Override
public String toString() {
if (end < start) {
return "<-> " + (start + 1) + "-" + (end + 1);
}
return "" + (start + 1) + "-" + (end + 1) + (instanceCount > 1 ? "(" + instanceCount + " links)" : "");// + " p" + path;
}
public boolean containsIP(int ip) {
return (ip >= start) && (ip <= end);
}
private boolean containsPart(GraphPart part, GraphPart what, List<GraphPart> used) {
if (used.contains(part)) {
return false;
}
used.add(part);
for (GraphPart subpart : part.nextParts) {
if (subpart == what) {
return true;
}
if (containsPart(subpart, what, used)) {
return true;
}
}
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<GraphPart>());
}
public List<GraphPart> getSubParts() {
List<GraphPart> ret = new ArrayList<>();
ret.add(this);
return ret;
}
@Override
public int hashCode() {
int hash = 7;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof GraphPart)) {
return false;
}
final GraphPart other = (GraphPart) obj;
if (this.start != other.start) {
return false;
}
if (this.end != other.end) {
return false;
}
return true;
}
}
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2010-2014 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.Collections;
import java.util.List;
/**
*
* @author JPEXS
*/
public class GraphPartMulti extends GraphPart {
public List<GraphPart> parts;
public GraphPartMulti(List<GraphPart> parts) {
super(parts.get(0).start, parts.get(parts.size() - 1).end);
this.parts = parts;
this.path = parts.get(0).path;
}
@Override
public String toString() {
String ret = "";
ret += "[multi ";
boolean first = true;
for (GraphPart g : parts) {
if (first) {
first = false;
} else {
ret += ", ";
}
ret += g.toString();
}
ret += "]";
return ret;
}
@Override
public int getHeight() {
int ret = 0;
for (GraphPart p : parts) {
ret += p.getHeight();
}
return ret;
}
@Override
public int getPosAt(int offset) {
int ofs = 0;
int pos = 0;
for (GraphPart p : parts) {
for (int i = 0; i < p.getHeight(); i++) {
pos = p.start + i;
ofs += 1;
if (ofs == offset) {
return pos;
}
}
}
return -1;
}
@Override
public List<GraphPart> getSubParts() {
return Collections.unmodifiableList(parts);
}
}
@@ -0,0 +1,157 @@
/*
* Copyright (C) 2010-2014 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.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class GraphPath implements Serializable {
private final List<Integer> keys = new ArrayList<>();
private final List<Integer> vals = new ArrayList<>();
public String rootName = "";
public GraphPath(String rootName, List<Integer> keys, List<Integer> vals) {
this.rootName = rootName;
this.keys.addAll(keys);
this.vals.addAll(vals);
}
public GraphPath(List<Integer> keys, List<Integer> vals) {
this.keys.addAll(keys);
this.vals.addAll(vals);
}
public boolean startsWith(GraphPath p) {
if (p.length() > length()) {
return false;
}
List<Integer> otherKeys = new ArrayList<>(p.keys);
List<Integer> otherVals = new ArrayList<>(p.vals);
for (int i = 0; i < p.length(); i++) {
if (keys.get(i) != otherKeys.get(i)) {
return false;
}
if (vals.get(i) != otherVals.get(i)) {
return false;
}
}
return true;
}
public GraphPath parent(int len) {
GraphPath par = new GraphPath(rootName);
for (int i = 0; i < len; i++) {
par.keys.add(keys.get(i));
par.vals.add(vals.get(i));
}
return par;
}
public GraphPath sub(int part, int codePos) {
GraphPath next = new GraphPath(rootName, this.keys, this.vals);
next.keys.add(codePos);
next.vals.add(part);
return next;
}
public GraphPath(String rootName) {
this.rootName = rootName;
}
public GraphPath() {
}
public int length() {
return vals.size();
}
public int get(int index) {
return vals.get(index);
}
public int getKey(int index) {
return keys.get(index);
}
@Override
public int hashCode() {
int hash = 5;
hash = 23 * hash + (this.keys != null ? this.keys.hashCode() : 0);
hash = 23 * hash + (this.vals != null ? this.vals.hashCode() : 0);
hash = 23 * hash + (this.rootName != null ? this.rootName.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final GraphPath other = (GraphPath) obj;
if (this.rootName == null && other.rootName != null) {
return false;
}
if (this.rootName != null && other.rootName == null) {
return false;
}
if (this.rootName != null && other.rootName != null) {
if (!this.rootName.equals(other.rootName)) {
return false;
}
}
if (!arrMatch(keys, other.keys)) {
return false;
}
if (!arrMatch(vals, other.vals)) {
return false;
}
return true;
}
private static boolean arrMatch(List<Integer> arr, List<Integer> arr2) {
if (arr.size() != arr2.size()) {
return false;
}
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) != arr2.get(i)) {
return false;
}
}
return true;
}
@Override
public String toString() {
String ret = rootName;
for (int i = 0; i < keys.size(); i++) {
ret += "/" + keys.get(i) + ":" + vals.get(i);
}
return ret;
}
}
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.action.Action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public abstract class GraphSource implements Serializable {
public abstract int size();
public abstract GraphSourceItem get(int pos);
public abstract boolean isEmpty();
public abstract List<GraphTargetItem> translatePart(GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException;
private void visitCode(int ip, int lastIp, HashMap<Integer, List<Integer>> refs, int endIp) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
boolean debugMode = false;
while (((endIp == -1) || (ip < endIp)) && (ip < size())) {
refs.get(ip).add(lastIp);
lastIp = ip;
if (refs.get(ip).size() > 1) {
break;
}
GraphSourceItem ins = get(ip);
if (ins.isIgnored()) {
ip++;
continue;
}
if (debugMode) {
System.err.println("visit ip " + ip + " action:" + ins);
}
if (ins.isExit()) {
break;
}
if (ins instanceof GraphSourceItemContainer) {
GraphSourceItemContainer cnt = (GraphSourceItemContainer) ins;
if (ins instanceof Action) { //TODO: Remove dependency of AVM1
long endAddr = ((Action) ins).getAddress() + cnt.getHeaderSize();
for (long size : cnt.getContainerSizes()) {
if (size != 0) {
visitCode(adr2pos(endAddr), ip, refs, adr2pos(endAddr + size));
}
endAddr += size;
}
ip = adr2pos(endAddr);
continue;
}
}
if (ins.isBranch() || ins.isJump()) {
List<Integer> branches = ins.getBranches(this);
for (int b : branches) {
if (b >= 0) {
visitCode(b, ip, refs, endIp);
}
}
break;
}
ip++;
};
}
public HashMap<Integer, List<Integer>> visitCode(List<Integer> alternateEntries) throws InterruptedException {
HashMap<Integer, List<Integer>> refs = new HashMap<>();
int siz = size();
for (int i = 0; i < siz; i++) {
refs.put(i, new ArrayList<Integer>());
}
visitCode(0, 0, refs, -1);
int pos = 0;
for (int e : alternateEntries) {
pos++;
visitCode(e, -pos, refs, -1);
}
return refs;
}
public abstract int adr2pos(long adr);
public abstract long pos2adr(int pos);
}
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.BaseLocalData;
import java.io.Serializable;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface GraphSourceItem extends Serializable {
public void translate(BaseLocalData localData, TranslateStack stack, List<GraphTargetItem> output, int staticOperation, String path) throws InterruptedException;
public boolean isJump();
public boolean isBranch();
public boolean isExit();
public long getOffset();
public boolean ignoredLoops();
public List<Integer> getBranches(GraphSource code);
public boolean isIgnored();
public void setIgnored(boolean ignored, int pos);
public boolean isDeobfuscatePop();
}
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface GraphSourceItemContainer {
public long getHeaderSize();
public List<Long> getContainerSizes();
public void setContainerSize(int index, long size);
public String getASMSourceBetween(int pos);
public boolean parseDivision(long size, FlasmLexer lexer);
public HashMap<Integer, String> getRegNames();
public void translateContainer(List<List<GraphTargetItem>> contents, TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions);
public String getName();
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2010-2014 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.io.Serializable;
/**
*
* @author JPEXS
*/
public class GraphSourceItemPos implements Serializable {
public GraphSourceItem item;
public int pos;
public GraphSourceItemPos(GraphSourceItem item, int pos) {
this.item = item;
this.pos = pos;
}
}
@@ -0,0 +1,258 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.graph.model.BinaryOp;
import com.jpexs.decompiler.graph.model.LocalData;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author JPEXS
*/
public abstract class GraphTargetItem implements Serializable {
public static final int PRECEDENCE_PRIMARY = 0;
public static final int PRECEDENCE_POSTFIX = 1;
public static final int PRECEDENCE_UNARY = 2;
public static final int PRECEDENCE_MULTIPLICATIVE = 3;
public static final int PRECEDENCE_ADDITIVE = 4;
public static final int PRECEDENCE_BITWISESHIFT = 5;
public static final int PRECEDENCE_RELATIONAL = 6;
public static final int PRECEDENCE_EQUALITY = 7;
public static final int PRECEDENCE_BITWISEAND = 8;
public static final int PRECEDENCE_BITWISEXOR = 9;
public static final int PRECEDENCE_BITWISEOR = 10;
public static final int PRECEDENCE_LOGICALAND = 11;
public static final int PRECEDENCE_LOGICALOR = 12;
public static final int PRECEDENCE_CONDITIONAL = 13;
public static final int PRECEDENCE_ASSIGMENT = 14;
public static final int PRECEDENCE_COMMA = 15;
public static final int NOPRECEDENCE = 16;
public GraphSourceItem src;
public int pos = -1;
protected int precedence;
public List<GraphSourceItemPos> moreSrc = new ArrayList<>();
public GraphPart firstPart;
public GraphTargetItem value;
public GraphPart getFirstPart() {
if (value == null) {
return firstPart;
}
GraphPart ret = value.getFirstPart();
if (ret == null) {
return firstPart;
}
return ret;
}
public GraphTargetItem() {
this(null, NOPRECEDENCE);
}
public GraphTargetItem(GraphSourceItem src, int precedence) {
this.src = src;
this.precedence = precedence;
}
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = new ArrayList<>();
ret.add(new GraphSourceItemPos(src, pos));
ret.addAll(moreSrc);
if (value != null) {
ret.addAll(value.getNeededSources());
}
return ret;
}
public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos);
appendTo(writer, localData);
if (needsSemicolon()) {
writer.append(";");
}
writer.endOffset();
return writer;
}
public boolean needsSemicolon() {
return true;
}
@Override
public String toString() {
return this.getClass().getName();
}
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos);
appendTo(writer, localData);
writer.endOffset();
return writer;
}
public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException;
public String toString(LocalData localData) throws InterruptedException {
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
toString(writer, localData);
return writer.toString();
}
public int getPrecedence() {
return precedence;
}
public boolean isCompileTime() {
Set<GraphTargetItem> dependencies = new HashSet<>();
dependencies.add(this);
return isCompileTime(dependencies);
}
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
public boolean hasSideEffect() {
return false;
}
public boolean isVariableComputed() {
return false;
}
public Object getResult() {
return null;
}
public String toStringNoQuotes(LocalData localData) {
return toString();
}
public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos);
appendToNoQuotes(writer, localData);
writer.endOffset();
return writer;
}
public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData);
}
public GraphTargetItem getNotCoerced() {
return this;
}
public GraphTargetItem getThroughRegister() {
return this;
}
public boolean needsNewLine() {
return false;
}
public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos);
appendTo(writer, localData);
if (needsNewLine()) {
writer.newLine();
}
writer.endOffset();
return writer;
}
public boolean isEmpty() {
return false;
}
public GraphTargetItem getThroughNotCompilable() {
return this;
}
public GraphTargetItem getThroughDuplicate() {
return this;
}
public boolean valueEquals(GraphTargetItem target) {
return equals(target);
}
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
}
public List<GraphSourceItem> toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if (!hasReturnValue()) {
return toSource(localData, generator);
}
return generator.generateDiscardValue(localData, this);
}
protected List<GraphSourceItem> toSourceBinary(BinaryOp op, GraphSourceItem action) {
List<GraphSourceItem> ret = new ArrayList<>();
return ret;
}
public static List<GraphSourceItem> toSourceMerge(SourceGeneratorLocalData localData, SourceGenerator gen, Object... tar) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
for (Object o : tar) {
if (o == null) {
continue;
}
if (o instanceof GraphTargetItem) {
ret.addAll(((GraphTargetItem) o).toSource(localData, gen));
}
if (o instanceof GraphSourceItem) {
ret.add((GraphSourceItem) o);
}
if (o instanceof List) {
List l = (List) o;
for (Object o2 : l) {
if (o2 instanceof GraphSourceItem) {
ret.add((GraphSourceItem) o2);
}
if (o2 instanceof GraphTargetItem) {
ret.addAll(((GraphTargetItem) o2).toSource(localData, gen));
}
}
}
}
return ret;
}
public abstract boolean hasReturnValue();
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
if (value != null) {
ret.add(value);
}
return ret;
}
public abstract GraphTargetItem returnType();
}
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2010-2014 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.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class Loop implements Serializable {
public GraphPart loopContinue;
public GraphPart loopBreak;
public GraphPart loopPreContinue;
public List<GraphPart> breakCandidates = new ArrayList<>();
public List<Integer> breakCandidatesLevels = new ArrayList<>();
public long id;
public int leadsToMark;
public int reachableMark;
public int phase;
public int breakCandidatesLocked = 0;
public Loop(long id, GraphPart loopContinue, GraphPart loopBreak) {
this.loopContinue = loopContinue;
this.loopBreak = loopBreak;
this.id = id;
}
@Override
public String toString() {
return "loop(id:" + id + (loopPreContinue != null ? ",precontinue:" + loopPreContinue : "") + ",continue:" + loopContinue + ", break:" + loopBreak + ", phase:" + phase + ")";
}
}
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.AppStrings;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.LocalData;
/**
*
* @author JPEXS
*/
public class MarkItem extends GraphTargetItem {
private final String mark;
public MarkItem(String mark) {
super(null, NOPRECEDENCE);
this.mark = mark;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("//" + AppStrings.translate("decompilerMark") + ":" + mark);
}
public String getMark() {
return mark;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.LocalData;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class NotCompileTimeItem extends GraphTargetItem {
public GraphTargetItem object;
public NotCompileTimeItem(GraphSourceItem instruction, GraphTargetItem object) {
super(instruction, NOPRECEDENCE);
this.object = object;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
@Override
public GraphTargetItem getThroughNotCompilable() {
if (object == null) {
return object;
}
return object.getThroughNotCompilable();
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return object.toString(writer, localData);
}
@Override
public boolean hasReturnValue() {
return object.hasReturnValue();
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2014 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.Stack;
/**
*
* @author JPEXS
*/
public class ScopeStack extends Stack<GraphTargetItem> {
}
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.CommaExpressionItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DoWhileItem;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface SourceGenerator {
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, AndItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, OrItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, IfItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TernarOpItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, WhileItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, DoWhileItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, ForItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, SwitchItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, NotItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, DuplicateItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, BreakItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, ContinueItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, List<GraphTargetItem> commands) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, CommaExpressionItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TypeItem item) throws CompilationException;
public List<GraphSourceItem> generateDiscardValue(SourceGeneratorLocalData localData, GraphTargetItem item) throws CompilationException;
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010-2014 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;
/**
*
* @author JPEXS
*/
public class TranslateException extends RuntimeException {
public TranslateException(String s) {
super(s);
}
}
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2010-2014 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.Stack;
/**
*
* @author JPEXS
*/
public class TranslateStack extends Stack<GraphTargetItem> {
}
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2014 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 com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.UnboundedTypeItem;
import java.util.Objects;
/**
*
* @author JPEXS
*/
public class TypeFunctionItem extends GraphTargetItem {
public static TypeFunctionItem BOOLEAN = new TypeFunctionItem("Boolean");
public static TypeFunctionItem STRING = new TypeFunctionItem("String");
public static TypeFunctionItem ARRAY = new TypeFunctionItem("Array");
public static UnboundedTypeItem UNBOUNDED = new UnboundedTypeItem();
public String fullTypeName;
public TypeFunctionItem(String fullTypeName) {
super(null, NOPRECEDENCE);
this.fullTypeName = fullTypeName;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.fullTypeName);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final TypeFunctionItem other = (TypeFunctionItem) obj;
if (!Objects.equals(this.fullTypeName, other.fullTypeName)) {
return false;
}
return true;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append(fullTypeName);
return writer;
}
@Override
public GraphTargetItem returnType() {
return this;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public String toString() {
return "Function[" + fullTypeName + "]";
}
}
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2014 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 com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.UnboundedTypeItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
*
* @author JPEXS
*/
public class TypeItem extends GraphTargetItem {
public static TypeItem BOOLEAN = new TypeItem("Boolean");
public static TypeItem STRING = new TypeItem("String");
public static TypeItem ARRAY = new TypeItem("Array");
public static UnboundedTypeItem UNBOUNDED = new UnboundedTypeItem();
public String fullTypeName;
public TypeItem(String fullTypeName) {
this(fullTypeName, new ArrayList<GraphTargetItem>());
}
public TypeItem(String fullTypeName, List<GraphTargetItem> subtypes) {
super(null, NOPRECEDENCE);
this.fullTypeName = fullTypeName;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.fullTypeName);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final TypeItem other = (TypeItem) obj;
if (!Objects.equals(this.fullTypeName, other.fullTypeName)) {
return false;
}
return true;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (localData.fullyQualifiedNames.contains(fullTypeName)) {
writer.append(fullTypeName);
} else {
String simpleName = fullTypeName;
if (simpleName.contains(".")) {
simpleName = simpleName.substring(simpleName.lastIndexOf('.') + 1);
}
writer.append(simpleName);
}
return writer;
}
@Override
public GraphTargetItem returnType() {
return this;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public String toString() {
return fullTypeName;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
public class AndItem extends BinaryOpItem {
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(leftSide.getNeededSources());
ret.addAll(rightSide.getNeededSources());
return ret;
}
public AndItem(GraphSourceItem src, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, PRECEDENCE_LOGICALAND, leftSide, rightSide, "&&");
this.leftSide = leftSide;
this.rightSide = rightSide;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface BinaryOp {
public GraphTargetItem getLeftSide();
public GraphTargetItem getRightSide();
public void setLeftSide(GraphTargetItem value);
public void setRightSide(GraphTargetItem value);
public int getPrecedence();
public List<GraphTargetItem> getAllSubItems();
}
@@ -0,0 +1,198 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
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 java.util.ArrayList;
import java.util.List;
import java.util.Set;
public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
public GraphTargetItem leftSide;
public GraphTargetItem rightSide;
protected String operator = "";
@Override
public GraphPart getFirstPart() {
GraphPart fp = leftSide.getFirstPart();
if (fp == null) {
return super.getFirstPart();
}
return fp;
}
public BinaryOpItem(GraphSourceItem instruction, int precedence, GraphTargetItem leftSide, GraphTargetItem rightSide, String operator) {
super(instruction, precedence);
this.leftSide = leftSide;
this.rightSide = rightSide;
this.operator = operator;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (leftSide.getPrecedence() > precedence) {
writer.append("(");
leftSide.toString(writer, localData);
writer.append(")");
} else {
leftSide.toString(writer, localData);
}
writer.append(" ");
writer.append(operator);
writer.append(" ");
if (rightSide.getPrecedence() > precedence) {
writer.append("(");
rightSide.toString(writer, localData);
writer.append(")");
} else {
rightSide.toString(writer, localData);
}
return writer;
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(leftSide.getNeededSources());
ret.addAll(rightSide.getNeededSources());
return ret;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(leftSide)) {
return false;
}
dependencies.add(leftSide);
if (leftSide != rightSide && dependencies.contains(rightSide)) {
return false;
}
dependencies.add(rightSide);
return leftSide.isCompileTime(dependencies) && rightSide.isCompileTime(dependencies);
}
@Override
public boolean isVariableComputed() {
return leftSide.isVariableComputed() || rightSide.isVariableComputed();
}
@Override
public boolean hasSideEffect() {
return leftSide.hasSideEffect() || rightSide.hasSideEffect();
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + (this.leftSide != null ? this.leftSide.hashCode() : 0);
hash = 71 * hash + (this.rightSide != null ? this.rightSide.hashCode() : 0);
hash = 71 * hash + (this.operator != null ? this.operator.hashCode() : 0);
return hash;
}
public GraphTargetItem getLeftMostItem(GraphTargetItem item) {
GraphTargetItem ret = item;
if (ret instanceof BinaryOpItem) {
ret = ((BinaryOpItem) ret).getLeftMostItem();
}
return ret;
}
public GraphTargetItem getLeftMostItem() {
GraphTargetItem ret = leftSide;
if (ret instanceof BinaryOpItem) {
ret = ((BinaryOpItem) ret).getLeftMostItem();
}
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final BinaryOpItem other = (BinaryOpItem) obj;
if (this.leftSide != other.leftSide && (this.leftSide == null || !this.leftSide.equals(other.leftSide))) {
return false;
}
if (this.rightSide != other.rightSide && (this.rightSide == null || !this.rightSide.equals(other.rightSide))) {
return false;
}
if ((this.operator == null) ? (other.operator != null) : !this.operator.equals(other.operator)) {
return false;
}
return true;
}
/*@Override
public boolean toBoolean() {
double val=toNumber();
if(Double.isNaN(val)){
return false;
}
if(Double.compare(val, 0)==0){
return false;
}
return true;
}*/
@Override
public GraphTargetItem getLeftSide() {
return leftSide;
}
@Override
public GraphTargetItem getRightSide() {
return rightSide;
}
@Override
public void setLeftSide(GraphTargetItem value) {
leftSide = value;
}
@Override
public void setRightSide(GraphTargetItem value) {
rightSide = value;
}
@Override
public int getPrecedence() {
return precedence;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
ret.add(getLeftSide());
ret.add(getRightSide());
return ret;
}
}
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
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.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class BlockItem extends GraphTargetItem {
List<GraphTargetItem> commands;
public BlockItem(GraphSourceItem src, List<GraphTargetItem> commands) {
super(src, PRECEDENCE_PRIMARY);
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startBlock();
Graph.graphToString(commands, writer, localData);
return writer.endBlock();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, commands);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class BreakItem extends GraphTargetItem {
public long loopId;
private boolean labelRequired;
public BreakItem(GraphSourceItem src, long loopId) {
super(src, NOPRECEDENCE);
this.loopId = loopId;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("break");
if (writer instanceof NulWriter) {
NulWriter nulWriter = (NulWriter) writer;
labelRequired = loopId != nulWriter.getLoop();
if (labelRequired) {
nulWriter.setLoopUsed(loopId);
}
}
if (labelRequired) {
writer.append(" loop" + loopId);
}
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class CommaExpressionItem extends GraphTargetItem {
public List<GraphTargetItem> commands;
public CommaExpressionItem(GraphSourceItem src, List<GraphTargetItem> commands) {
super(src, PRECEDENCE_PRIMARY);
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
boolean first = true;
for (GraphTargetItem t : commands) {
if (!first) {
writer.append(", ");
}
t.toString(writer, localData);
first = false;
}
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return commands.isEmpty() ? TypeItem.UNBOUNDED : commands.get(commands.size() - 1).returnType();
}
}
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class CommentItem extends GraphTargetItem {
private final String[] commentLines;
public CommentItem(String comment) {
super(null, NOPRECEDENCE);
this.commentLines = new String[]{comment};
}
public CommentItem(String[] commentLines) {
super(null, NOPRECEDENCE);
this.commentLines = commentLines;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("/* ");
for (int i = 0; i < commentLines.length; i++) {
writer.append(commentLines[i]);
if (i != commentLines.length - 1) {
writer.newLine();
}
}
return writer.append(" */");
}
public String[] getCommentLines() {
return commentLines;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ContinueItem extends GraphTargetItem {
public long loopId;
private boolean labelRequired;
public ContinueItem(GraphSourceItem src, long loopId) {
super(src, NOPRECEDENCE);
this.loopId = loopId;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
writer.append("continue");
if (writer instanceof NulWriter) {
NulWriter nulWriter = (NulWriter) writer;
labelRequired = loopId != nulWriter.getNonSwitchLoop();
if (labelRequired) {
nulWriter.setLoopUsed(loopId);
}
}
if (labelRequired) {
writer.append(" loop" + loopId);
}
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
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.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class DoWhileItem extends LoopItem implements Block {
public List<GraphTargetItem> commands;
public List<GraphTargetItem> expression;
private boolean labelUsed;
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (commands != null) {
ret.add(commands);
}
return ret;
}
public DoWhileItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> commands, List<GraphTargetItem> expression) {
super(src, loop);
this.expression = expression;
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("do");
writer.startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock().newLine();
writer.append("while");
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
writer.append(" ");
}
writer.append("(");
for (int i = 0; i < expression.size(); i++) {
if (expression.get(i).isEmpty()) {
continue;
}
if (i != 0) {
writer.append(", ");
}
expression.get(i).toString(writer, localData);
}
writer.append(");").newLine();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class DuplicateItem extends GraphTargetItem {
public DuplicateItem(GraphSourceItem src, GraphTargetItem value) {
super(src, value.getPrecedence());
this.value = value;
}
@Override
public Object getResult() {
return value.getResult();
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return value.toString(writer, localData);
}
@Override
public GraphTargetItem getNotCoerced() {
return value.getNotCoerced();
}
@Override
public GraphTargetItem getThroughRegister() {
return value.getThroughRegister();
}
@Override
public GraphTargetItem getThroughDuplicate() {
return value.getThroughDuplicate();
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(value)) {
return false;
}
dependencies.add(value);
return value.isCompileTime(dependencies);
}
@Override
public boolean isVariableComputed() {
return value.isVariableComputed();
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2010-2014 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.model;
/**
*
* @author JPEXS
*/
public interface ExitItem {
}
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
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.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class ForItem extends LoopItem implements Block {
public List<GraphTargetItem> firstCommands;
public GraphTargetItem expression;
public List<GraphTargetItem> finalCommands;
public List<GraphTargetItem> commands;
private boolean labelUsed;
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (firstCommands != null) {
ret.add(firstCommands);
}
if (commands != null) {
ret.add(commands);
}
if (finalCommands != null) {
ret.add(finalCommands);
}
return ret;
}
public ForItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> firstCommands, GraphTargetItem expression, List<GraphTargetItem> finalCommands, List<GraphTargetItem> commands) {
super(src, loop);
this.firstCommands = firstCommands;
this.expression = expression;
this.finalCommands = finalCommands;
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("for");
if (writer.getFormatting().spaceBeforeParenthesesForParentheses) {
writer.append(" ");
}
writer.append("(");
int p = 0;
for (int i = 0; i < firstCommands.size(); i++) {
if (firstCommands.get(i).isEmpty()) {
continue;
}
if (p > 0) {
writer.append(",");
}
firstCommands.get(i).toString(writer, localData);
p++;
}
writer.append(";");
expression.toString(writer, localData);
writer.append(";");
p = 0;
for (int i = 0; i < finalCommands.size(); i++) {
if (finalCommands.get(i).isEmpty()) {
continue;
}
if (p > 0) {
writer.append(",");
}
finalCommands.get(i).toString(writer, localData);
p++;
}
writer.append(")").startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,163 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class IfItem extends GraphTargetItem implements Block {
public GraphTargetItem expression;
public List<GraphTargetItem> onTrue;
public List<GraphTargetItem> onFalse;
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(expression)) {
return false;
}
dependencies.add(expression);
return expression.isCompileTime(dependencies);
}
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (onTrue != null) {
ret.add(onTrue);
}
if (onFalse != null) {
ret.add(onFalse);
}
return ret;
}
public IfItem(GraphSourceItem src, GraphTargetItem expression, List<GraphTargetItem> onTrue, List<GraphTargetItem> onFalse) {
super(src, NOPRECEDENCE);
this.expression = expression;
this.onTrue = onTrue;
this.onFalse = onFalse;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
GraphTargetItem expr = expression;
List<GraphTargetItem> ifBranch = onTrue;
List<GraphTargetItem> elseBranch = onFalse;
if (onTrue.isEmpty()) {
if (onFalse.isEmpty()) {
if (expr instanceof NotItem) {
expr = ((NotItem) expr).getOriginal();
}
} else {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
ifBranch = onFalse;
elseBranch = onTrue;
}
}
writer.append("if");
if (writer.getFormatting().spaceBeforeParenthesesIfParentheses) {
writer.append(" ");
}
writer.append("(");
expr.toString(writer, localData);
writer.append(")").startBlock();
for (GraphTargetItem ti : ifBranch) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (elseBranch.size() > 0) {
boolean elseIf = elseBranch.size() == 1 && (elseBranch.get(0) instanceof IfItem);
if (writer.getFormatting().beginBlockOnNewLine) {
writer.newLine();
} else {
writer.append(" ");
}
writer.append("else");
if (!elseIf) {
writer.startBlock();
} else {
writer.append(" ");
}
for (GraphTargetItem ti : elseBranch) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
if (!elseIf) {
writer.endBlock();
}
}
return writer;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : onTrue) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
for (GraphTargetItem ti : onFalse) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class IntegerValueItem extends GraphTargetItem {
private final int intValue;
public IntegerValueItem(GraphSourceItem src, int value) {
super(src, PRECEDENCE_PRIMARY);
this.intValue = value;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("" + intValue);
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return true;
}
@Override
public Object getResult() {
return Double.valueOf(intValue);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public class LocalData {
public static LocalData empty = new LocalData();
public ConstantPool constants;
public com.jpexs.decompiler.flash.abc.avm2.ConstantPool constantsAvm2;
public HashMap<Integer, String> localRegNames;
public List<String> fullyQualifiedNames;
public static LocalData create(ConstantPool constants) {
LocalData localData = new LocalData();
localData.constants = constants;
return localData;
}
public static LocalData create(com.jpexs.decompiler.flash.abc.avm2.ConstantPool constants, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
LocalData localData = new LocalData();
localData.constantsAvm2 = constants;
localData.localRegNames = localRegNames;
localData.fullyQualifiedNames = fullyQualifiedNames;
return localData;
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public interface LogicalOpItem {
public GraphTargetItem invert();
}
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
public abstract class LoopItem extends GraphTargetItem {
public Loop loop;
public LoopItem(GraphSourceItem src, Loop loop) {
super(src, NOPRECEDENCE);
this.loop = loop;
}
}
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.action.model.operations.Inverted;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
import java.util.Set;
/**
*
* @author JPEXS
*/
public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
public NotItem(GraphSourceItem instruction, GraphTargetItem value) {
super(instruction, PRECEDENCE_UNARY, value, "!");
}
@Override
public Object getResult() {
Object ret = EcmaScript.toBoolean(value.getResult());
if (ret == Boolean.TRUE) {
return Boolean.FALSE;
}
if (ret == Boolean.FALSE) {
return Boolean.TRUE;
}
return ret;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(value)) {
return false;
}
dependencies.add(value);
return value.isCompileTime(dependencies);
}
@Override
public GraphTargetItem invert() {
return value;
}
public GraphTargetItem getOriginal() {
return value;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
public class OrItem extends BinaryOpItem {
public OrItem(GraphSourceItem src, GraphTargetItem leftSide, GraphTargetItem rightSide) {
super(src, PRECEDENCE_LOGICALOR, leftSide, rightSide, "||");
this.leftSide = leftSide;
this.rightSide = rightSide;
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(leftSide.getNeededSources());
ret.addAll(rightSide.getNeededSources());
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ParenthesisItem extends GraphTargetItem {
public ParenthesisItem(GraphSourceItem src, GraphTargetItem value) {
super(src, PRECEDENCE_PRIMARY);
this.value = value;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append("(");
value.toString(writer, localData);
return writer.append(")");
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return value.toSource(localData, generator);
}
@Override
public boolean hasReturnValue() {
return value.hasReturnValue();
}
@Override
public GraphTargetItem returnType() {
return value.returnType();
}
}
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class ScriptEndItem extends GraphTargetItem implements ExitItem {
public ScriptEndItem() {
super(null, NOPRECEDENCE);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,158 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
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.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class SwitchItem extends LoopItem implements Block {
public GraphTargetItem switchedObject;
public List<GraphTargetItem> caseValues;
public List<List<GraphTargetItem>> caseCommands;
public List<GraphTargetItem> defaultCommands;
public List<Integer> valuesMapping;
private boolean labelUsed;
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
ret.addAll(caseCommands);
if (defaultCommands != null) {
ret.add(defaultCommands);
}
return ret;
}
public SwitchItem(GraphSourceItem instruction, Loop loop, GraphTargetItem switchedObject, List<GraphTargetItem> caseValues, List<List<GraphTargetItem>> caseCommands, List<GraphTargetItem> defaultCommands, List<Integer> valuesMapping) {
super(instruction, loop);
this.switchedObject = switchedObject;
this.caseValues = caseValues;
this.caseCommands = caseCommands;
this.defaultCommands = defaultCommands;
this.valuesMapping = valuesMapping;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_SWITCH);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("switch");
if (writer.getFormatting().spaceBeforeParenthesesSwitchParentheses) {
writer.append(" ");
}
writer.append("(");
switchedObject.toString(writer, localData);
writer.append(")").startBlock();
for (int i = 0; i < caseCommands.size(); i++) {
for (int k = 0; k < valuesMapping.size(); k++) {
if (valuesMapping.get(k) == i) {
writer.append("case ");
caseValues.get(k).toString(writer, localData);
writer.append(":").newLine();
}
}
writer.indent();
for (int j = 0; j < caseCommands.get(i).size(); j++) {
if (!caseCommands.get(i).get(j).isEmpty()) {
caseCommands.get(i).get(j).toStringSemicoloned(writer, localData).newLine();
}
}
writer.unindent();
}
if (defaultCommands != null) {
if (defaultCommands.size() > 0) {
writer.append("default");
writer.append(":").newLine();
writer.indent();
for (int j = 0; j < defaultCommands.size(); j++) {
if (!defaultCommands.get(j).isEmpty()) {
defaultCommands.get(j).toStringSemicoloned(writer, localData).newLine();
}
}
writer.unindent();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (List<GraphTargetItem> onecase : caseCommands) {
for (GraphTargetItem ti : onecase) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
}
if (defaultCommands != null) {
for (GraphTargetItem ti : defaultCommands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
}
return ret;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SourceGenerator;
import java.util.List;
public class TernarOpItem extends GraphTargetItem {
public GraphTargetItem expression;
public GraphTargetItem onTrue;
public GraphTargetItem onFalse;
public TernarOpItem(GraphSourceItem src, GraphTargetItem expression, GraphTargetItem onTrue, GraphTargetItem onFalse) {
super(src, PRECEDENCE_CONDITIONAL);
this.expression = expression;
this.onTrue = onTrue;
this.onFalse = onFalse;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
expression.toString(writer, localData);
writer.append("?");
onTrue.toString(writer, localData);
writer.append(":");
onFalse.toString(writer, localData);
return writer;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return onTrue.returnType();
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class TrueItem extends GraphTargetItem {
public TrueItem(GraphSourceItem src) {
super(src, PRECEDENCE_PRIMARY);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("true");
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public interface UnaryOp {
public GraphTargetItem getValue();
public int getPrecedence();
}
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.List;
import java.util.Set;
public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
public GraphTargetItem value;
public String operator;
public UnaryOpItem(GraphSourceItem instruction, int precedence, GraphTargetItem value, String operator) {
super(instruction, precedence);
this.value = value;
this.operator = operator;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append(operator);
if (value != null) {
if (value.getPrecedence() > precedence) {
writer.append("(");
value.toString(writer, localData);
writer.append(")");
} else {
value.toString(writer, localData);
}
} else {
writer.append("null");
}
return writer;
}
@Override
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
if (dependencies.contains(value)) {
return false;
}
dependencies.add(value);
return value.isCompileTime(dependencies);
}
@Override
public boolean isVariableComputed() {
return value.isVariableComputed();
}
@Override
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = super.getNeededSources();
ret.addAll(value.getNeededSources());
return ret;
}
@Override
public boolean hasSideEffect() {
return value.hasSideEffect();
}
@Override
public int getPrecedence() {
return precedence;
}
@Override
public GraphTargetItem getValue() {
return value;
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2014 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.model;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public class UnboundedTypeItem extends AVM2Item {
public UnboundedTypeItem() {
super(null, NOPRECEDENCE);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append("*");
return writer;
}
@Override
public GraphTargetItem returnType() {
return this;
}
@Override
public String toString() {
return "*";
}
@Override
public boolean hasReturnValue() {
return true;
}
}
@@ -0,0 +1,105 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class UniversalLoopItem extends LoopItem implements Block {
public List<GraphTargetItem> commands;
private boolean labelUsed;
public UniversalLoopItem(GraphSourceItem src, Loop loop) {
super(src, loop);
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("while");
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
writer.append(" ");
}
writer.append("(true)").startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (commands != null) {
ret.add(commands);
}
return ret;
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}
@@ -0,0 +1,123 @@
/*
* Copyright (C) 2010-2014 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.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.LoopWithType;
import com.jpexs.decompiler.flash.helpers.NulWriter;
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.Loop;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.ArrayList;
import java.util.List;
public class WhileItem extends LoopItem implements Block {
public List<GraphTargetItem> expression;
public List<GraphTargetItem> commands;
private boolean labelUsed;
@Override
public List<List<GraphTargetItem>> getSubs() {
List<List<GraphTargetItem>> ret = new ArrayList<>();
if (commands != null) {
ret.add(commands);
}
return ret;
}
public WhileItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> expression, List<GraphTargetItem> commands) {
super(src, loop);
this.expression = expression;
this.commands = commands;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (writer instanceof NulWriter) {
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
}
if (labelUsed) {
writer.append("loop" + loop.id + ":").newLine();
}
writer.append("while");
if (writer.getFormatting().spaceBeforeParenthesesWhileParentheses) {
writer.append(" ");
}
writer.append("(");
for (int i = 0; i < expression.size(); i++) {
if (expression.get(i).isEmpty()) {
continue;
}
if (i != 0) {
writer.append(", ");
}
expression.get(i).toString(writer, localData);
}
writer.append(")");
writer.startBlock();
for (GraphTargetItem ti : commands) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
}
}
writer.endBlock();
if (writer instanceof NulWriter) {
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
labelUsed = loopOjb.used;
}
return writer;
}
@Override
public List<ContinueItem> getContinues() {
List<ContinueItem> ret = new ArrayList<>();
for (GraphTargetItem ti : commands) {
if (ti instanceof ContinueItem) {
ret.add((ContinueItem) ti);
}
if (ti instanceof Block) {
ret.addAll(((Block) ti).getContinues());
}
}
return ret;
}
@Override
public boolean needsSemicolon() {
return false;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public boolean hasReturnValue() {
return false;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
}