#1594 Option to disable AS3 P-code indentation, label on separate line

This commit is contained in:
Jindra Petřík
2021-02-11 12:34:46 +01:00
parent 66b0d0bb13
commit ac15728b9d
7 changed files with 121 additions and 17 deletions

View File

@@ -1194,7 +1194,11 @@ public class AVM2Code implements Cloneable {
public GraphTextWriter toASMSource(ABC abc, AVM2ConstantPool constants, MethodInfo info, MethodBody body, List<Integer> outputMap, ScriptExportMode exportMode, GraphTextWriter writer) {
if (info != null) {
writer.appendNoHilight("method").indent().newLine();
writer.appendNoHilight("method");
if (Configuration.indentAs3PCode.get()) {
writer.indent();
}
writer.newLine();
writer.appendNoHilight("name ");
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME);
writer.newLine();
@@ -1272,7 +1276,11 @@ public class AVM2Code implements Cloneable {
Set<Long> importantOffsets = getImportantOffsets(body, true);
if (body != null) {
writer.appendNoHilight("body").indent().newLine();
writer.appendNoHilight("body");
if (Configuration.indentAs3PCode.get()) {
writer.indent();
}
writer.newLine();
writer.appendNoHilight("maxstack ");
writer.appendNoHilight(body.max_stack);
@@ -1292,12 +1300,19 @@ public class AVM2Code implements Cloneable {
for (Trait t : body.traits.traits) {
t.convertTraitHeader(abc, writer);
writer.unindent().appendNoHilight("end ; trait").newLine();
if (Configuration.indentAs3PCode.get()) {
writer.unindent();
}
writer.appendNoHilight("end ; trait").newLine();
}
}
writer.newLine();
writer.appendNoHilight("code").indent().newLine();
writer.appendNoHilight("code");
if (Configuration.indentAs3PCode.get()) {
writer.indent();
}
writer.newLine();
int ip = 0;
int largeLimit = 20000;
boolean markOffsets = code.size() <= largeLimit;
@@ -1314,10 +1329,18 @@ public class AVM2Code implements Cloneable {
}
if (Configuration.showAllAddresses.get() || importantOffsets.contains(addr)) {
String label = "ofs" + Helper.formatAddress(addr) + ":";
writer.unindent().unindent().unindent();
if (Configuration.labelOnSeparateLineAs3PCode.get() && Configuration.indentAs3PCode.get()) {
writer.unindent().unindent().unindent();
}
writer.appendNoHilight(label);
writer.newLine();
writer.indent().indent().indent();
if (Configuration.labelOnSeparateLineAs3PCode.get()) {
writer.newLine();
if (Configuration.indentAs3PCode.get()) {
writer.indent().indent().indent();
}
}
}
/*for (int e = 0; e < body.exceptions.length; e++) {
if (body.exceptions[e].start == ofs) {
@@ -1346,7 +1369,10 @@ public class AVM2Code implements Cloneable {
} else if (exportMode == ScriptExportMode.CONSTANTS) {
writer.appendNoHilight("Constant export mode is not supported.").newLine();
}
writer.unindent().appendNoHilight("end ; code").newLine();
if (Configuration.indentAs3PCode.get()) {
writer.unindent();
}
writer.appendNoHilight("end ; code").newLine();
if (body != null) {
for (int e = 0; e < body.exceptions.length; e++) {
ABCException exception = body.exceptions[e];
@@ -1374,10 +1400,16 @@ public class AVM2Code implements Cloneable {
writer.appendNoHilight(" end");
writer.newLine();
}
writer.unindent().appendNoHilight("end ; body").newLine();
if (Configuration.indentAs3PCode.get()) {
writer.unindent();
}
writer.appendNoHilight("end ; body").newLine();
}
if (info != null) {
writer.unindent().appendNoHilight("end ; method").newLine();
if (Configuration.indentAs3PCode.get()) {
writer.unindent();
}
writer.appendNoHilight("end ; method").newLine();
}
return writer;

View File

@@ -366,7 +366,9 @@ public abstract class Trait implements Cloneable, Serializable {
writer.hilightSpecial(traitType, HighlightSpecialType.TRAIT_TYPE);
writer.appendNoHilight(" ");
writer.hilightSpecial(abc.constants.multinameToString(name_index), HighlightSpecialType.TRAIT_NAME);
writer.indent();
if (Configuration.indentAs3PCode.get()) {
writer.indent();
}
if ((kindFlags & ATTR_Final) > 0) {
writer.newLine();
writer.append("flag ");
@@ -394,7 +396,9 @@ public abstract class Trait implements Cloneable, Serializable {
writer.append("\"");
writer.append(Helper.escapeActionScriptString(abc.constants.getString(abc.metadata_info.get(m).name_index)));
writer.append("\"");
writer.indent();
if (Configuration.indentAs3PCode.get()) {
writer.indent();
}
writer.newLine();
if (m >= 0 && m < abc.metadata_info.size()) {
for (int i = 0; i < abc.metadata_info.get(m).keys.length; i++) {
@@ -414,7 +418,9 @@ public abstract class Trait implements Cloneable, Serializable {
writer.newLine();
}
}
writer.unindent();
if (Configuration.indentAs3PCode.get()) {
writer.unindent();
}
writer.append("end ; metadata");
}
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.configuration;
import com.jpexs.decompiler.flash.ApplicationInfo;
@@ -655,6 +656,14 @@ public final class Configuration {
@ConfigurationInternal
public static ConfigurationItem<Boolean> showLineNumbersInPCodeGraphvizGraph = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("format")
public static ConfigurationItem<Boolean> indentAs3PCode = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("format")
public static ConfigurationItem<Boolean> labelOnSeparateLineAs3PCode = null;
private enum OSId {
WINDOWS, OSX, UNIX
}