mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 22:20:46 +00:00
using stringbuilder for generating the AS source
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOp;
|
||||
import java.io.Serializable;
|
||||
@@ -82,23 +83,30 @@ public abstract class GraphTargetItem implements Serializable {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String hilight(String str, boolean highlight) {
|
||||
if (src == null || !highlight) {
|
||||
return str;
|
||||
}
|
||||
return Highlighting.hilighOffset(str, src.getOffset() + pos + 1);
|
||||
public HilightedTextWriter hilight(String str, HilightedTextWriter writer) {
|
||||
return writer.append(str, src, pos);
|
||||
}
|
||||
|
||||
public String toStringSemicoloned(boolean highlight, List<Object> localData) {
|
||||
return toString(highlight, localData) + (needsSemicolon() ? hilight(";", highlight) : "");
|
||||
HilightedTextWriter writer = new HilightedTextWriter(highlight);
|
||||
toStringSemicoloned(writer, localData);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public String toStringSemicoloned(boolean highlight, Object... localData) {
|
||||
public HilightedTextWriter toStringSemicoloned(HilightedTextWriter writer, List<Object> localData) {
|
||||
toString(writer, localData);
|
||||
if (needsSemicolon()) {
|
||||
hilight(";", writer);
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
public HilightedTextWriter toStringSemicoloned(HilightedTextWriter writer, Object... localData) {
|
||||
List<Object> localData2 = new ArrayList<>();
|
||||
for (Object o : localData) {
|
||||
localData2.add(o);
|
||||
}
|
||||
return toStringSemicoloned(highlight, localData2);
|
||||
return toStringSemicoloned(writer, localData2);
|
||||
}
|
||||
|
||||
public boolean needsSemicolon() {
|
||||
@@ -110,14 +118,20 @@ public abstract class GraphTargetItem implements Serializable {
|
||||
return this.getClass().getName();
|
||||
}
|
||||
|
||||
public abstract String toString(boolean highlight, List<Object> localData);
|
||||
public abstract HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData);
|
||||
|
||||
public String toString(boolean highlight, Object... localData) {
|
||||
HilightedTextWriter writer = new HilightedTextWriter(highlight);
|
||||
toString(writer, localData);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, Object... localData) {
|
||||
List<Object> localData2 = new ArrayList<>();
|
||||
for (Object o : localData) {
|
||||
localData2.add(o);
|
||||
}
|
||||
return toString(highlight, localData2);
|
||||
return toString(writer, localData2);
|
||||
}
|
||||
|
||||
public int getPrecedence() {
|
||||
@@ -148,15 +162,27 @@ public abstract class GraphTargetItem implements Serializable {
|
||||
}
|
||||
|
||||
public String toStringNoQuotes(boolean highlight, List<Object> localData) {
|
||||
return toString(highlight, localData);
|
||||
HilightedTextWriter writer = new HilightedTextWriter(highlight);
|
||||
toStringNoQuotes(writer, localData);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public HilightedTextWriter toStringNoQuotes(HilightedTextWriter writer, List<Object> localData) {
|
||||
return toString(writer, localData);
|
||||
}
|
||||
|
||||
public String toStringNoQuotes(boolean highlight, Object... localData) {
|
||||
HilightedTextWriter writer = new HilightedTextWriter(highlight);
|
||||
toStringNoQuotes(writer, localData);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
public HilightedTextWriter toStringNoQuotes(HilightedTextWriter writer, Object... localData) {
|
||||
List<Object> localData2 = new ArrayList<>();
|
||||
for (Object o : localData) {
|
||||
localData2.add(o);
|
||||
}
|
||||
return toStringNoQuotes(highlight, localData2);
|
||||
return toStringNoQuotes(writer, localData2);
|
||||
}
|
||||
|
||||
public GraphTargetItem getNotCoerced() {
|
||||
@@ -171,12 +197,12 @@ public abstract class GraphTargetItem implements Serializable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String toStringNL(boolean highlight, Object... localData) {
|
||||
public String toStringNL(HilightedTextWriter writer, Object... localData) {
|
||||
List<Object> localData2 = new ArrayList<>();
|
||||
for (Object o : localData) {
|
||||
localData2.add(o);
|
||||
}
|
||||
return toString(highlight, localData2) + (needsNewLine() ? "\r\n" : "");
|
||||
return toString(writer, localData2) + (needsNewLine() ? "\r\n" : "");
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -32,8 +33,8 @@ public class MarkItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("//decompiler mark:" + mark, highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return hilight("//decompiler mark:" + mark, writer);
|
||||
}
|
||||
|
||||
public String getMark() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,8 +46,8 @@ public class NotCompileTimeItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return object.toString(highlight, localData);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return object.toString(writer, localData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphPart;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItemPos;
|
||||
@@ -46,24 +47,27 @@ public abstract class BinaryOpItem extends GraphTargetItem implements BinaryOp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
if (leftSide.getPrecedence() > precedence) {
|
||||
ret += hilight("(", highlight) + leftSide.toString(highlight, localData) + hilight(")", highlight);
|
||||
hilight("(", writer);
|
||||
leftSide.toString(writer, localData);
|
||||
hilight(")", writer);
|
||||
} else {
|
||||
ret += leftSide.toString(highlight, localData);
|
||||
leftSide.toString(writer, localData);
|
||||
}
|
||||
|
||||
ret += " ";
|
||||
ret += hilight(operator, highlight);
|
||||
ret += " ";
|
||||
hilight(" ", writer);
|
||||
hilight(operator, writer);
|
||||
hilight(" ", writer);
|
||||
|
||||
if (rightSide.getPrecedence() > precedence) {
|
||||
ret += hilight("(", highlight) + rightSide.toString(highlight, localData) + hilight(")", highlight);
|
||||
hilight("(", writer);
|
||||
rightSide.toString(writer, localData);
|
||||
hilight(")", writer);
|
||||
} else {
|
||||
ret += rightSide.toString(highlight, localData);
|
||||
rightSide.toString(writer, localData);
|
||||
}
|
||||
return ret;
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -36,10 +37,13 @@ public class BlockItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("{", highlight) + "\r\n" + Graph.INDENTOPEN + "\r\n"
|
||||
+ Graph.graphToString(commands, highlight, false, localData) + "\r\n"
|
||||
+ Graph.INDENTCLOSE + "\r\n" + hilight("}", highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
writer.appendNoHilight(Graph.graphToString(commands, writer.getIsHighlighted(), false, localData));
|
||||
writer.appendNewLine();
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
return hilight("}", writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
@@ -19,8 +20,9 @@ public class BreakItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("break", highlight) + " " + hilight("loop" + loopId, highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("break ", writer);
|
||||
return hilight("loop" + loopId, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
@@ -35,17 +36,16 @@ public class CommaExpressionItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
boolean first = true;
|
||||
for (GraphTargetItem t : commands) {
|
||||
if (!first) {
|
||||
ret += hilight(", ", highlight);
|
||||
hilight(", ", writer);
|
||||
}
|
||||
ret += t.toString(highlight, localData);
|
||||
t.toString(writer, localData);
|
||||
first = false;
|
||||
}
|
||||
return ret;
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import java.util.List;
|
||||
|
||||
@@ -33,8 +34,8 @@ public class CommentItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("/* " + comment + " */", highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return hilight("/* " + comment + " */", writer);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
@@ -19,8 +20,9 @@ public class ContinueItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("continue", highlight) + " " + hilight("loop" + loopId, highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("continue ", writer);
|
||||
return hilight("loop" + loopId, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -49,31 +50,32 @@ public class DoWhileItem extends LoopItem implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
ret += hilight("loop" + loop.id + ":", highlight) + "\r\n";
|
||||
ret += hilight("do", highlight) + "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("loop" + loop.id + ":", writer).appendNewLine();
|
||||
hilight("do", writer).appendNewLine();
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ret += ti.toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
ti.toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
String expStr = "";
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
hilight("}", writer).appendNewLine();
|
||||
hilight("while(", writer);
|
||||
|
||||
for (int i = 0; i < expression.size(); i++) {
|
||||
if (expression.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (!expStr.equals("")) {
|
||||
expStr += hilight(", ", highlight);
|
||||
if (i != 0) {
|
||||
hilight(", ", writer);
|
||||
}
|
||||
expStr += expression.get(i).toString(highlight, localData);
|
||||
expression.get(i).toString(writer, localData);
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight) + "\r\n" + hilight("while(", highlight) + expStr + hilight(");", highlight) + "\r\n";
|
||||
ret += hilight(":loop" + loop.id, highlight);
|
||||
|
||||
return ret;
|
||||
|
||||
hilight(");", writer).appendNewLine();
|
||||
return hilight(":loop" + loop.id, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
@@ -38,8 +39,8 @@ public class DuplicateItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return value.toString(highlight, localData);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return value.toString(writer, localData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -49,18 +50,10 @@ public class ForItem extends LoopItem implements Block {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
private String stripSemicolon(String s) {
|
||||
if (s.endsWith(";")) {
|
||||
s = s.substring(0, s.length() - 1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
ret += hilight("loop" + loop.id + ":", highlight) + "\r\n";
|
||||
ret += hilight("for(", highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("loop" + loop.id + ":", writer).appendNewLine();
|
||||
hilight("for(", writer);
|
||||
int p = 0;
|
||||
for (int i = 0; i < firstCommands.size(); i++) {
|
||||
if (firstCommands.get(i).isEmpty()) {
|
||||
@@ -68,36 +61,39 @@ public class ForItem extends LoopItem implements Block {
|
||||
}
|
||||
|
||||
if (p > 0) {
|
||||
ret += hilight(",", highlight);
|
||||
hilight(",", writer);
|
||||
}
|
||||
ret += stripSemicolon(firstCommands.get(i).toString(highlight, localData));
|
||||
firstCommands.get(i).toString(writer, localData);
|
||||
writer.stripSemicolon();
|
||||
p++;
|
||||
}
|
||||
ret += ";";
|
||||
ret += expression.toString(highlight, localData);
|
||||
ret += ";";
|
||||
hilight(";", writer);
|
||||
expression.toString(writer, localData);
|
||||
hilight(";", writer);
|
||||
p = 0;
|
||||
for (int i = 0; i < finalCommands.size(); i++) {
|
||||
if (finalCommands.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (p > 0) {
|
||||
ret += ",";
|
||||
hilight(",", writer);
|
||||
}
|
||||
ret += stripSemicolon(finalCommands.get(i).toString(highlight, localData));
|
||||
finalCommands.get(i).toString(writer, localData);
|
||||
writer.stripSemicolon();
|
||||
p++;
|
||||
}
|
||||
ret += hilight(")", highlight) + "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
hilight(")", writer).appendNewLine();
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ret += ti.toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
ti.toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight) + "\r\n";
|
||||
ret += ":loop" + loop.id;
|
||||
return ret;
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
hilight("}", writer).appendNewLine();
|
||||
hilight(":loop" + loop.id, writer).appendNewLine();
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -51,8 +52,7 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret;
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
GraphTargetItem expr = expression;
|
||||
List<GraphTargetItem> ifBranch = onTrue;
|
||||
List<GraphTargetItem> elseBranch = onFalse;
|
||||
@@ -71,27 +71,30 @@ public class IfItem extends GraphTargetItem implements Block {
|
||||
elseBranch = onTrue;
|
||||
}
|
||||
}
|
||||
ret = hilight("if(", highlight) + expr.toString(highlight, localData) + hilight(")", highlight) + "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
hilight("if(", writer);
|
||||
expr.toString(writer, localData);
|
||||
hilight(")", writer).appendNewLine();
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (GraphTargetItem ti : ifBranch) {
|
||||
if (!ti.isEmpty()) {
|
||||
ret += ti.toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
ti.toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight);
|
||||
hilight(Graph.INDENTCLOSE + "\r\n", writer);
|
||||
hilight("}", writer);
|
||||
if (elseBranch.size() > 0) {
|
||||
ret += "\r\n" + hilight("else", highlight) + "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
hilight("\r\nelse\r\n", writer);
|
||||
hilight("{\r\n" + Graph.INDENTOPEN + "\r\n", writer);
|
||||
for (GraphTargetItem ti : elseBranch) {
|
||||
if (!ti.isEmpty()) {
|
||||
ret += ti.toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
ti.toStringSemicoloned(writer, localData);
|
||||
hilight("\r\n", writer);
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight);
|
||||
hilight(Graph.INDENTCLOSE + "\r\n}", writer);
|
||||
}
|
||||
return ret;
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import java.util.List;
|
||||
@@ -34,8 +35,8 @@ public class IntegerValueItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("" + intValue, highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return hilight("" + intValue, writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
@@ -33,8 +34,10 @@ public class ParenthesisItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("(", highlight) + value.toString(highlight, localData) + hilight(")", highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("(", writer);
|
||||
value.toString(writer, localData);
|
||||
return hilight(")", writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,8 +31,8 @@ public class ScriptEndItem extends GraphTargetItem implements ExitItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return "";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -51,41 +52,46 @@ public class SwitchItem extends LoopItem implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
ret += hilight("loopswitch" + loop.id + ":", highlight) + "\r\n";
|
||||
ret += hilight("switch(", highlight) + switchedObject.toString(highlight, localData) + hilight(")", highlight) + "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("loopswitch" + loop.id + ":", writer).appendNewLine();
|
||||
hilight("switch(", writer);
|
||||
switchedObject.toString(writer, localData);
|
||||
hilight(")", writer).appendNewLine();
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (int i = 0; i < caseCommands.size(); i++) {
|
||||
for (int k = 0; k < valuesMapping.size(); k++) {
|
||||
if (valuesMapping.get(k) == i) {
|
||||
ret += hilight("case ", highlight) + caseValues.get(k).toString(highlight, localData) + hilight(":", highlight) + "\r\n";
|
||||
hilight("case ", writer);
|
||||
caseValues.get(k).toString(writer, localData);
|
||||
hilight(":", writer).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (int j = 0; j < caseCommands.get(i).size(); j++) {
|
||||
if (!caseCommands.get(i).get(j).isEmpty()) {
|
||||
ret += caseCommands.get(i).get(j).toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
caseCommands.get(i).get(j).toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
}
|
||||
if (defaultCommands != null) {
|
||||
if (defaultCommands.size() > 0) {
|
||||
ret += hilight("default", highlight) + hilight(":", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
hilight("default", writer);
|
||||
hilight(":", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (int j = 0; j < defaultCommands.size(); j++) {
|
||||
if (!defaultCommands.get(j).isEmpty()) {
|
||||
ret += defaultCommands.get(j).toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
defaultCommands.get(j).toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight) + "\r\n";
|
||||
ret += ":loop" + loop.id;
|
||||
return ret;
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
hilight("}", writer).appendNewLine();
|
||||
hilight(":loop" + loop.id, writer);
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
@@ -35,8 +36,13 @@ public class TernarOpItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return expression.toString(highlight, localData) + hilight("?", highlight) + onTrue.toString(highlight, localData) + hilight(":", highlight) + onFalse.toString(highlight, localData);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
expression.toString(writer, localData);
|
||||
hilight("?", writer);
|
||||
onTrue.toString(writer, localData);
|
||||
hilight(":", writer);
|
||||
onFalse.toString(writer, localData);
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import java.util.List;
|
||||
@@ -15,8 +16,8 @@ public class TrueItem extends GraphTargetItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
return hilight("true", highlight);
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
return hilight("true", writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItemPos;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
@@ -33,14 +34,20 @@ public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String s = (value == null ? hilight("null", highlight) : value.toString(highlight, localData));
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight(operator, writer);
|
||||
if (value != null) {
|
||||
if (value.precedence > precedence) {
|
||||
s = hilight("(", highlight) + s + hilight(")", highlight);
|
||||
hilight("(", writer);
|
||||
value.toString(writer, localData);
|
||||
hilight(")", writer);
|
||||
} else {
|
||||
value.toString(writer, localData);
|
||||
}
|
||||
} else {
|
||||
hilight("null", writer);
|
||||
}
|
||||
return hilight(operator, highlight) + s;
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -37,21 +38,20 @@ public class UniversalLoopItem extends LoopItem implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
ret += hilight("loop" + loop.id + ":", highlight) + "\r\n";
|
||||
ret += hilight("while(true)", highlight);
|
||||
ret += "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("loop" + loop.id + ":", writer).appendNewLine();
|
||||
hilight("while(true)", writer).appendNewLine();
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ret += ti.toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
ti.toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight) + "\r\n";
|
||||
ret += hilight(":loop" + loop.id, highlight);
|
||||
return ret;
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
hilight("}", writer).appendNewLine();
|
||||
hilight(":loop" + loop.id, writer);
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.graph.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.Graph;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
@@ -44,30 +45,30 @@ public class WhileItem extends LoopItem implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(boolean highlight, List<Object> localData) {
|
||||
String ret = "";
|
||||
ret += hilight("loop" + loop.id + ":", highlight) + "\r\n";
|
||||
String expStr = "";
|
||||
public HilightedTextWriter toString(HilightedTextWriter writer, List<Object> localData) {
|
||||
hilight("loop" + loop.id + ":", writer).appendNewLine();
|
||||
hilight("while(", writer);
|
||||
for (int i = 0; i < expression.size(); i++) {
|
||||
if (expression.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (!expStr.equals("")) {
|
||||
expStr += hilight(", ", highlight);
|
||||
if (i != 0) {
|
||||
hilight(", ", writer);
|
||||
}
|
||||
expStr += expression.get(i).toString(highlight, localData);
|
||||
expression.get(i).toString(writer, localData);
|
||||
}
|
||||
ret += hilight("while(", highlight) + expStr + hilight(")", highlight) + "\r\n" + hilight("{", highlight) + "\r\n";
|
||||
ret += Graph.INDENTOPEN + "\r\n";
|
||||
hilight(")", writer).appendNewLine();
|
||||
hilight("{", writer).appendNewLine();
|
||||
hilight(Graph.INDENTOPEN, writer).appendNewLine();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ret += ti.toStringSemicoloned(highlight, localData) + "\r\n";
|
||||
ti.toStringSemicoloned(writer, localData).appendNewLine();
|
||||
}
|
||||
}
|
||||
ret += Graph.INDENTCLOSE + "\r\n";
|
||||
ret += hilight("}", highlight) + "\r\n";
|
||||
ret += hilight(":loop" + loop.id, highlight);
|
||||
return ret;
|
||||
hilight(Graph.INDENTCLOSE, writer).appendNewLine();
|
||||
hilight("}", writer).appendNewLine();
|
||||
hilight(":loop" + loop.id, writer);
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user