mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 13:00:47 +00:00
AS3: initializing constants
This commit is contained in:
@@ -52,7 +52,6 @@ public class ABC {
|
||||
public long stringOffsets[];
|
||||
public static String IDENT_STRING = " ";
|
||||
public static final int MINORwithDECIMAL = 17;
|
||||
public static final boolean AUTOINIT_STATIC_VARIABLES = false;
|
||||
protected HashSet<EventListener> listeners = new HashSet<EventListener>();
|
||||
private static Logger logger = Logger.getLogger(ABC.class.getName());
|
||||
|
||||
|
||||
@@ -44,7 +44,9 @@ import com.jpexs.asdec.abc.types.ABCException;
|
||||
import com.jpexs.asdec.abc.types.MethodBody;
|
||||
import com.jpexs.asdec.abc.types.MethodInfo;
|
||||
import com.jpexs.asdec.abc.types.Multiname;
|
||||
import com.jpexs.asdec.abc.types.traits.Trait;
|
||||
import com.jpexs.asdec.abc.types.traits.TraitSlotConst;
|
||||
import com.jpexs.asdec.abc.types.traits.Traits;
|
||||
import com.jpexs.asdec.helpers.Helper;
|
||||
import com.jpexs.asdec.helpers.Highlighting;
|
||||
import java.io.*;
|
||||
@@ -1662,8 +1664,8 @@ public class AVM2Code {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap<Integer, String> localRegNames, Stack<TreeItem> scopeStack, boolean isStaticInitializer, List<String> fullyQualifiedNames) {
|
||||
return toSource(isStatic, classIndex, abc, constants, method_info, body, false, localRegNames, scopeStack, isStaticInitializer, fullyQualifiedNames);
|
||||
public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap<Integer, String> localRegNames, Stack<TreeItem> scopeStack, boolean isStaticInitializer, List<String> fullyQualifiedNames, Traits initTraits) {
|
||||
return toSource(isStatic, classIndex, abc, constants, method_info, body, false, localRegNames, scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits);
|
||||
}
|
||||
|
||||
public List<TreeItem> toTree(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
|
||||
@@ -1672,6 +1674,7 @@ public class AVM2Code {
|
||||
unknownJumps = new ArrayList<Integer>();
|
||||
parsedExceptions = new ArrayList<ABCException>();
|
||||
finallyJumps = new ArrayList<Integer>();
|
||||
ignoredIns = new ArrayList<Integer>();
|
||||
HashMap<Integer, TreeItem> localRegs = new HashMap<Integer, TreeItem>();
|
||||
try {
|
||||
return toSource(isStatic, classIndex, localRegs, new Stack<TreeItem>(), new Stack<TreeItem>(), abc, constants, method_info, body, 0, code.size() - 1, localRegNames, fullyQualifiedNames).output;
|
||||
@@ -1741,7 +1744,7 @@ public class AVM2Code {
|
||||
}
|
||||
}
|
||||
|
||||
public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted, HashMap<Integer, String> localRegNames, Stack<TreeItem> scopeStack, boolean isStaticInitializer, List<String> fullyQualifiedNames) {
|
||||
public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted, HashMap<Integer, String> localRegNames, Stack<TreeItem> scopeStack, boolean isStaticInitializer, List<String> fullyQualifiedNames, Traits initTraits) {
|
||||
toSourceCount = 0;
|
||||
loopList = new ArrayList<Loop>();
|
||||
unknownJumps = new ArrayList<Integer>();
|
||||
@@ -1764,8 +1767,31 @@ public class AVM2Code {
|
||||
|
||||
try {
|
||||
list = toSource(isStatic, classIndex, localRegs, new Stack<TreeItem>(), scopeStack, abc, constants, method_info, body, 0, code.size() - 1, localRegNames, fullyQualifiedNames).output;
|
||||
if (initTraits != null) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
TreeItem ti = list.get(i);
|
||||
if (ti instanceof InitPropertyTreeItem) {
|
||||
int multinameIndex = ((InitPropertyTreeItem) ti).propertyName.multinameIndex;
|
||||
TreeItem value = ((InitPropertyTreeItem) ti).value;
|
||||
for (Trait t : initTraits.traits) {
|
||||
if (t.name_index == multinameIndex) {
|
||||
if ((t instanceof TraitSlotConst)) {
|
||||
if (((TraitSlotConst) t).isConst() || isStaticInitializer) {
|
||||
((TraitSlotConst) t).assignedValue = value;
|
||||
list.remove(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isStaticInitializer) {
|
||||
|
||||
List<TreeItem> newList = new ArrayList<TreeItem>();
|
||||
for (TreeItem ti : list) {
|
||||
if (!(ti instanceof ReturnVoidTreeItem)) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class NewFunctionIns extends InstructionDefinition {
|
||||
String bodyStr = "";
|
||||
String paramStr = "";
|
||||
if (mybody != null) {
|
||||
bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info, new Stack<TreeItem>()/*scopeStack*/, false, true, fullyQualifiedNames) + Highlighting.hilighMethodBegin(body.method_info);
|
||||
bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info, new Stack<TreeItem>()/*scopeStack*/, false, true, fullyQualifiedNames, null) + Highlighting.hilighMethodBegin(body.method_info);
|
||||
paramStr = method_info[methodIndex].getParamStr(constants, mybody, abc, fullyQualifiedNames);
|
||||
}
|
||||
stack.push(new NewFunctionTreeItem(ins, paramStr, method_info[methodIndex].getReturnTypeStr(constants, fullyQualifiedNames), bodyStr));
|
||||
|
||||
@@ -43,6 +43,7 @@ public abstract class TreeItem {
|
||||
public static final int NOPRECEDENCE = 16;
|
||||
public int precedence = NOPRECEDENCE;
|
||||
public AVM2Instruction instruction;
|
||||
public boolean hidden = false;
|
||||
|
||||
public TreeItem(AVM2Instruction instruction, int precedence) {
|
||||
this.instruction = instruction;
|
||||
|
||||
@@ -27,21 +27,21 @@ import javax.swing.tree.TreePath;
|
||||
class ClassIndexVisitor implements TreeVisitor {
|
||||
|
||||
private TreeElement found = null;
|
||||
private int classIndex=0;
|
||||
private int classIndex = 0;
|
||||
|
||||
public ClassIndexVisitor(int classIndex) {
|
||||
this.classIndex = classIndex;
|
||||
}
|
||||
|
||||
public void onBranch(TreeElement branch) {
|
||||
Object o=branch.getItem();
|
||||
if(o==null){
|
||||
Object o = branch.getItem();
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
TreeLeafScript sc=(TreeLeafScript)o;
|
||||
for(Trait t:sc.abc.script_info[sc.scriptIndex].traits.traits){
|
||||
if(t instanceof TraitClass){
|
||||
if(((TraitClass)t).class_info==classIndex){
|
||||
TreeLeafScript sc = (TreeLeafScript) o;
|
||||
for (Trait t : sc.abc.script_info[sc.scriptIndex].traits.traits) {
|
||||
if (t instanceof TraitClass) {
|
||||
if (((TraitClass) t).class_info == classIndex) {
|
||||
found = branch;
|
||||
return;
|
||||
}
|
||||
@@ -50,14 +50,14 @@ class ClassIndexVisitor implements TreeVisitor {
|
||||
}
|
||||
|
||||
public void onLeaf(TreeElement leaf) {
|
||||
Object o=leaf.getItem();
|
||||
if(o==null){
|
||||
Object o = leaf.getItem();
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
TreeLeafScript sc=(TreeLeafScript)o;
|
||||
for(Trait t:sc.abc.script_info[sc.scriptIndex].traits.traits){
|
||||
if(t instanceof TraitClass){
|
||||
if(((TraitClass)t).class_info==classIndex){
|
||||
TreeLeafScript sc = (TreeLeafScript) o;
|
||||
for (Trait t : sc.abc.script_info[sc.scriptIndex].traits.traits) {
|
||||
if (t instanceof TraitClass) {
|
||||
if (((TraitClass) t).class_info == classIndex) {
|
||||
found = leaf;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MethodBody implements Cloneable {
|
||||
/*public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack<TreeItem> scopeStack, boolean isStaticInitializer) {
|
||||
return toString(pcode, isStatic, classIndex, abc, constants, method_info, scopeStack, isStaticInitializer,false);
|
||||
}*/
|
||||
public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack<TreeItem> scopeStack, boolean isStaticInitializer, boolean hilight, List<String> fullyQualifiedNames) {
|
||||
public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack<TreeItem> scopeStack, boolean isStaticInitializer, boolean hilight, List<String> fullyQualifiedNames, Traits initTraits) {
|
||||
String s = "";
|
||||
|
||||
//s+="method_info="+method_info+" max_stack="+max_stack+" max_regs="+max_regs+" scope_depth="+scope_depth+" max_scope="+max_scope;
|
||||
@@ -86,7 +86,7 @@ public class MethodBody implements Cloneable {
|
||||
s += code.toASMSource(constants, this);
|
||||
} else {
|
||||
try {
|
||||
s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames);
|
||||
s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits);
|
||||
s = s.trim();
|
||||
if (hilight) {
|
||||
s = Highlighting.hilighMethod(s, this.method_info);
|
||||
|
||||
@@ -366,39 +366,12 @@ public class TraitClass extends Trait {
|
||||
String toPrint;
|
||||
List<String> outTraits = new LinkedList<String>();
|
||||
|
||||
//if (class_info[i].cinit_index != 0) {
|
||||
if (ABC.AUTOINIT_STATIC_VARIABLES) {
|
||||
int bodyIndex = abc.findBodyIndex(abc.class_info[class_info].cinit_index);
|
||||
List<TreeItem> initializer = abc.bodies[bodyIndex].code.toTree(true, class_info, abc, abc.constants, abc.method_info, abc.bodies[bodyIndex], abc.bodies[bodyIndex].code.getLocalRegNamesFromDebug(abc), fullyQualifiedNames);
|
||||
for (TreeItem ti : initializer) {
|
||||
if (ti instanceof SetPropertyTreeItem) {
|
||||
int multinameIndex = ((SetPropertyTreeItem) ti).propertyName.multinameIndex;
|
||||
TreeItem value = ((SetPropertyTreeItem) ti).value;
|
||||
for (Trait t : abc.class_info[class_info].static_traits.traits) {
|
||||
if (t.name_index == multinameIndex) {
|
||||
if (t instanceof TraitSlotConst) {
|
||||
((TraitSlotConst) t).assignedValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ti instanceof InitPropertyTreeItem) {
|
||||
int multinameIndex = ((InitPropertyTreeItem) ti).propertyName.multinameIndex;
|
||||
TreeItem value = ((InitPropertyTreeItem) ti).value;
|
||||
for (Trait t : abc.class_info[class_info].static_traits.traits) {
|
||||
if (t.name_index == multinameIndex) {
|
||||
if (t instanceof TraitSlotConst) {
|
||||
((TraitSlotConst) t).assignedValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int bodyIndex;
|
||||
String bodyStr = "";
|
||||
int bodyIndex = abc.findBodyIndex(abc.class_info[class_info].cinit_index);
|
||||
bodyIndex = abc.findBodyIndex(abc.class_info[class_info].cinit_index);
|
||||
if (bodyIndex != -1) {
|
||||
bodyStr = abc.bodies[bodyIndex].toString(pcode, true, class_info, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), true, highlight, fullyQualifiedNames);
|
||||
bodyStr = abc.bodies[bodyIndex].toString(pcode, true, class_info, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), true, highlight, fullyQualifiedNames, abc.class_info[class_info].static_traits);
|
||||
}
|
||||
if (Highlighting.stripHilights(bodyStr).equals("")) {
|
||||
toPrint = ABC.addTabs(bodyStr, 3);
|
||||
@@ -412,7 +385,6 @@ public class TraitClass extends Trait {
|
||||
//}
|
||||
|
||||
//constructor
|
||||
//if (instance_info[i].iinit_index != 0) {
|
||||
if (!abc.instance_info[class_info].isInterface()) {
|
||||
String modifier = "";
|
||||
Multiname m = abc.constants.constant_multiname[abc.instance_info[class_info].name_index];
|
||||
@@ -433,7 +405,7 @@ public class TraitClass extends Trait {
|
||||
bodyStr = "";
|
||||
bodyIndex = abc.findBodyIndex(abc.instance_info[class_info].iinit_index);
|
||||
if (bodyIndex != -1) {
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(pcode, false, class_info, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), false, highlight, fullyQualifiedNames), 3);
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(pcode, false, class_info, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), false, highlight, fullyQualifiedNames, abc.instance_info[class_info].instance_traits), 3);
|
||||
constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(abc.constants, abc.bodies[bodyIndex], abc, fullyQualifiedNames);
|
||||
} else {
|
||||
constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(abc.constants, null, abc, fullyQualifiedNames);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TraitFunction extends Trait {
|
||||
String bodyStr = "";
|
||||
int bodyIndex = abc.findBodyIndex(method_info);
|
||||
if (bodyIndex != -1) {
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(pcode, isStatic, classIndex, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), false, highlight, fullyQualifiedNames), 3);
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(pcode, isStatic, classIndex, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), false, highlight, fullyQualifiedNames, null), 3);
|
||||
}
|
||||
return ABC.IDENT_STRING + ABC.IDENT_STRING + header + (abc.instance_info[classIndex].isInterface() ? ";" : " {\r\n" + bodyStr + "\r\n" + ABC.IDENT_STRING + ABC.IDENT_STRING + "}");
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class TraitMethodGetterSetter extends Trait {
|
||||
String bodyStr = "";
|
||||
int bodyIndex = abc.findBodyIndex(method_info);
|
||||
if (bodyIndex != -1) {
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(pcode, isStatic, classIndex, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), false, highlight, fullyQualifiedNames), 3);
|
||||
bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(pcode, isStatic, classIndex, abc, abc.constants, abc.method_info, new Stack<TreeItem>(), false, highlight, fullyQualifiedNames, null), 3);
|
||||
}
|
||||
return ABC.IDENT_STRING + ABC.IDENT_STRING + header + (abc.instance_info[classIndex].isInterface() ? ";" : " {\r\n" + bodyStr + "\r\n" + ABC.IDENT_STRING + ABC.IDENT_STRING + "}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user