mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-11 12:03:33 +00:00
Issue #302 AS3: more goto declaration - Types, extends, implements, variables, catch variables
This commit is contained in:
@@ -34,6 +34,9 @@ public class GetLexAVM2Item extends AVM2Item {
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
|
||||
|
||||
String localName = propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
|
||||
srcData.put("localName",localName);
|
||||
return writer.append(propertyName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class GetSlotAVM2Item extends AVM2Item {
|
||||
if (slotName == null) {
|
||||
return writer.append("/*UnknownSlot*/");
|
||||
}
|
||||
srcData.put("slotName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
|
||||
srcData.put("localName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
|
||||
|
||||
return writer.append(slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ public class LocalRegAVM2Item extends AVM2Item {
|
||||
computedResult = null;
|
||||
}
|
||||
}
|
||||
this.computedValue = computedValue;
|
||||
srcData.put("regIndex", ""+regIndex);
|
||||
this.computedValue = computedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,7 +63,9 @@ public class LocalRegAVM2Item extends AVM2Item {
|
||||
if (computedValue instanceof FilterAVM2Item) {
|
||||
return computedValue.toString(writer, localData);
|
||||
}
|
||||
return writer.append(localRegName(localData.localRegNames, regIndex));
|
||||
String localName = localRegName(localData.localRegNames, regIndex);
|
||||
srcData.put("localName", localName);
|
||||
return writer.append(localName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,13 +42,14 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig
|
||||
public SetLocalAVM2Item(AVM2Instruction instruction, int regIndex, GraphTargetItem value) {
|
||||
super(instruction, PRECEDENCE_ASSIGMENT);
|
||||
this.regIndex = regIndex;
|
||||
this.value = value;
|
||||
srcData.put("regIndex", ""+regIndex);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
writer.append(localRegName(localData.localRegNames, regIndex) + " = ");
|
||||
String localName = localRegName(localData.localRegNames, regIndex);
|
||||
srcData.put("localName", localName);
|
||||
writer.append(localName + " = ");
|
||||
return value.toString(writer, localData);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
srcData.put("slotName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
|
||||
srcData.put("localName", slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false));
|
||||
getName(writer, localData);
|
||||
writer.append(" = ");
|
||||
return value.toString(writer, localData);
|
||||
|
||||
@@ -16,15 +16,19 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.model.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.CoerceAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.ConvertAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.SetSlotAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.Multiname;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -43,13 +47,15 @@ public class DeclarationAVM2Item extends AVM2Item {
|
||||
|
||||
public DeclarationAVM2Item(GraphTargetItem assignment) {
|
||||
this(assignment, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
|
||||
if (assignment instanceof SetLocalAVM2Item) {
|
||||
SetLocalAVM2Item lti = (SetLocalAVM2Item) assignment;
|
||||
srcData.put("regIndex",""+lti.regIndex);
|
||||
String localName = localRegName(localData.localRegNames, lti.regIndex);
|
||||
srcData.put("localName",localName);
|
||||
srcData.put("declaration", "true");
|
||||
GraphTargetItem coerType = TypeItem.UNBOUNDED;
|
||||
if (lti.value instanceof CoerceAVM2Item) {
|
||||
@@ -59,19 +65,20 @@ public class DeclarationAVM2Item extends AVM2Item {
|
||||
coerType = ((ConvertAVM2Item) lti.value).type;
|
||||
}
|
||||
writer.append("var ");
|
||||
writer.append(localRegName(localData.localRegNames, lti.regIndex));
|
||||
writer.append(":");
|
||||
writer.append(localName);
|
||||
writer.append(":");
|
||||
coerType.appendTo(writer, localData);
|
||||
writer.append(" = ");
|
||||
return lti.value.toString(writer, localData);
|
||||
}
|
||||
if (assignment instanceof SetSlotAVM2Item) {
|
||||
SetSlotAVM2Item ssti = (SetSlotAVM2Item) assignment;
|
||||
srcData.put("slotName",""+ssti.getNameAsStr(localData));
|
||||
srcData.put("localName",ssti.getNameAsStr(localData));
|
||||
srcData.put("declaration", "true");
|
||||
writer.append("var ");
|
||||
ssti.getName(writer, localData);
|
||||
writer.append(":");
|
||||
|
||||
type.appendTo(writer, localData);
|
||||
writer.append(" = ");
|
||||
return ssti.value.toString(writer, localData);
|
||||
|
||||
@@ -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.abc.avm2.model.clauses;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -31,7 +32,9 @@ import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.ContinueItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TryAVM2Item extends AVM2Item implements Block {
|
||||
|
||||
@@ -74,7 +77,15 @@ public class TryAVM2Item extends AVM2Item implements Block {
|
||||
writer.endBlock();
|
||||
for (int e = 0; e < catchExceptions.size(); e++) {
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
writer.append("catch(");
|
||||
String localName = catchExceptions.get(e).getVarName(localData.constantsAvm2, localData.fullyQualifiedNames);
|
||||
Map<String,String> data=new HashMap<>();
|
||||
data.put("localName", localName);
|
||||
data.put("declaration", "true");
|
||||
writer.hilightSpecial(localName, "try.name",e,data);
|
||||
writer.append(":");
|
||||
writer.hilightSpecial(catchExceptions.get(e).getTypeName(localData.constantsAvm2, localData.fullyQualifiedNames),"try.type",e);
|
||||
writer.append(")");
|
||||
writer.startBlock();
|
||||
List<GraphTargetItem> commands = catchCommands.get(e);
|
||||
for (GraphTargetItem ti : commands) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.abc.types;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -52,28 +53,13 @@ public class InstanceInfo {
|
||||
return "name_index=" + abc.constants.getMultiname(name_index).toString(abc.constants, fullyQualifiedNames) + " super_index=" + supIndexStr + " flags=" + flags + " protectedNS=" + protectedNS + " interfaces=" + Helper.intArrToString(interfaces) + " method_index=" + iinit_index + "\r\n" + instance_traits.toString(abc, fullyQualifiedNames);
|
||||
}
|
||||
|
||||
public String getClassHeaderStr(ABC abc, List<String> fullyQualifiedNames) {
|
||||
String supIndexStr = "";
|
||||
if (super_index > 0) {
|
||||
supIndexStr = " extends " + abc.constants.getMultiname(super_index).getName(abc.constants, fullyQualifiedNames, false);////+" flags="+flags+" protectedNS="+protectedNS+" interfaces="+Helper.intArrToString(interfaces)+" method_index="+iinit_index
|
||||
}
|
||||
String implStr = "";
|
||||
if (interfaces.length > 0) {
|
||||
if (isInterface()) {
|
||||
implStr = " extends ";
|
||||
} else {
|
||||
implStr = " implements ";
|
||||
}
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
if (i > 0) {
|
||||
implStr += ", ";
|
||||
}
|
||||
implStr += abc.constants.getMultiname(interfaces[i]).getName(abc.constants, fullyQualifiedNames, false);
|
||||
}
|
||||
}
|
||||
public GraphTextWriter getClassHeaderStr(GraphTextWriter writer,ABC abc, List<String> fullyQualifiedNames, boolean allowPrivate) {
|
||||
String modifiers;
|
||||
Namespace ns = abc.constants.getMultiname(name_index).getNamespace(abc.constants);
|
||||
modifiers = ns.getPrefix(abc);
|
||||
if(!allowPrivate && modifiers.equals("private")){
|
||||
modifiers = "";
|
||||
}
|
||||
if (!modifiers.isEmpty()) {
|
||||
modifiers += " ";
|
||||
}
|
||||
@@ -88,7 +74,31 @@ public class InstanceInfo {
|
||||
if (isInterface()) {
|
||||
objType = "interface ";
|
||||
}
|
||||
return modifiers + objType + abc.constants.getMultiname(name_index).getName(abc.constants, new ArrayList<String>()/* No full names here*/, false) + supIndexStr + implStr;
|
||||
writer.appendNoHilight(modifiers + objType + abc.constants.getMultiname(name_index).getName(abc.constants, new ArrayList<String>()/* No full names here*/, false));
|
||||
|
||||
|
||||
|
||||
if (super_index > 0) {
|
||||
String typeName = abc.constants.getMultiname(super_index).getNameWithNamespace(abc.constants, true);
|
||||
writer.appendNoHilight(" extends ");
|
||||
writer.hilightSpecial(abc.constants.getMultiname(super_index).getName(abc.constants, fullyQualifiedNames, false),"typename",typeName);
|
||||
}
|
||||
if (interfaces.length > 0) {
|
||||
if (isInterface()) {
|
||||
writer.appendNoHilight(" extends ");
|
||||
} else {
|
||||
writer.appendNoHilight(" implements ");
|
||||
}
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
if (i > 0) {
|
||||
writer.append(", ");
|
||||
}
|
||||
String typeName = abc.constants.getMultiname(interfaces[i]).getNameWithNamespace(abc.constants, true);
|
||||
writer.hilightSpecial(abc.constants.getMultiname(interfaces[i]).getName(abc.constants, fullyQualifiedNames, false),"typename",typeName);
|
||||
}
|
||||
}
|
||||
|
||||
return writer;
|
||||
}
|
||||
|
||||
public Multiname getName(AVM2ConstantPool constants) {
|
||||
|
||||
@@ -279,10 +279,9 @@ public class MethodInfo {
|
||||
writer.appendNoHilight(", ");
|
||||
}
|
||||
pdata=new HashMap<>();
|
||||
pdata.put("declaration", "true");
|
||||
pdata.put("regIndex", ""+(i+1));
|
||||
pdata.put("declaration", "true");
|
||||
if (!localRegNames.isEmpty()) {
|
||||
pdata.put("slotName", localRegNames.get(i + 1)); //assuming it is a slot
|
||||
pdata.put("localName", localRegNames.get(i + 1)); //assuming it is a slot
|
||||
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(true,localRegNames.get(i + 1)),"paramname",i,pdata);
|
||||
} else if ((paramNames.length > i) && (paramNames[i] != 0) && Configuration.paramNamesEnable.get()) {
|
||||
writer.hilightSpecial(IdentifiersDeobfuscation.printIdentifier(true,constants.getString(paramNames[i])),"paramname",i,pdata);
|
||||
@@ -309,14 +308,16 @@ public class MethodInfo {
|
||||
restAdd += ", ";
|
||||
}
|
||||
restAdd += "... ";
|
||||
String restName;
|
||||
if (!localRegNames.isEmpty()) {
|
||||
restAdd += localRegNames.get(param_types.length + 1);
|
||||
restName = localRegNames.get(param_types.length + 1);
|
||||
} else {
|
||||
restAdd += "rest";
|
||||
restName = "rest";
|
||||
}
|
||||
restAdd += restName;
|
||||
pdata=new HashMap<>();
|
||||
pdata.put("declaration", "true");
|
||||
pdata.put("regIndex", ""+(param_types.length + 1));
|
||||
pdata.put("localName",restName);
|
||||
writer.hilightSpecial(restAdd, "flag.NEED_REST",0,pdata);
|
||||
}
|
||||
return writer;
|
||||
|
||||
@@ -348,8 +348,8 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
|
||||
@Override
|
||||
public GraphTextWriter toStringHeader(Trait parent, String path, List<ABCContainerTag> abcTags, ABC abc, boolean isStatic, ScriptExportMode exportMode, int scriptIndex, int classIndex, GraphTextWriter writer, List<String> fullyQualifiedNames, boolean parallel) {
|
||||
String classHeader = abc.instance_info.get(class_info).getClassHeaderStr(abc, fullyQualifiedNames);
|
||||
return writer.appendNoHilight(classHeader);
|
||||
abc.instance_info.get(class_info).getClassHeaderStr(writer,abc, fullyQualifiedNames,false);
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -447,11 +447,8 @@ public class TraitClass extends Trait implements TraitWithSlot {
|
||||
}
|
||||
|
||||
//class header
|
||||
String classHeader = abc.instance_info.get(class_info).getClassHeaderStr(abc, fullyQualifiedNames);
|
||||
if (classHeader.startsWith("private ")) {
|
||||
classHeader = classHeader.substring("private ".length());
|
||||
}
|
||||
writer.appendNoHilight(classHeader).startBlock();
|
||||
abc.instance_info.get(class_info).getClassHeaderStr(writer,abc, fullyQualifiedNames,false);
|
||||
writer.startBlock();
|
||||
|
||||
int bodyIndex = abc.findBodyIndex(abc.class_info.get(class_info).cinit_index);
|
||||
if (bodyIndex != -1) {
|
||||
|
||||
@@ -49,13 +49,13 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTextWriter hilightSpecial(String text, String type, int index) {
|
||||
public FileTextWriter hilightSpecial(String text, String type, String index) {
|
||||
writeToFile(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter hilightSpecial(String text, String type, int index, Map<String, String> data) {
|
||||
public GraphTextWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
|
||||
writeToFile(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -103,14 +103,23 @@ public abstract class GraphTextWriter {
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type) {
|
||||
return hilightSpecial(text, type, 0);
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type, int index) {
|
||||
return hilightSpecial(text, type, 0, new HashMap<String, String>());
|
||||
return hilightSpecial(text, type, "0");
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type, int index) {
|
||||
return hilightSpecial(text, type, ""+index);
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type, String index) {
|
||||
return hilightSpecial(text, type, "0", new HashMap<String, String>());
|
||||
}
|
||||
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type, int index, Map<String,String> data) {
|
||||
return hilightSpecial(text, type, ""+index, data);
|
||||
}
|
||||
|
||||
public GraphTextWriter hilightSpecial(String text, String type, String index, Map<String,String> data) {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,20 +144,20 @@ public class HilightedTextWriter extends GraphTextWriter {
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter hilightSpecial(String text, String type) {
|
||||
return hilightSpecial(text, type, 0);
|
||||
return hilightSpecial(text, type, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter hilightSpecial(String text, String type, int index) {
|
||||
public HilightedTextWriter hilightSpecial(String text, String type, String index) {
|
||||
return hilightSpecial(text, type, index, new HashMap<String, String>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HilightedTextWriter hilightSpecial(String text, String type, int index, Map<String, String> data) {
|
||||
public HilightedTextWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
|
||||
Map<String, String> ndata = new HashMap<>();
|
||||
ndata.putAll(data);
|
||||
ndata.put("subtype", type);
|
||||
ndata.put("index", Long.toString(index));
|
||||
ndata.put("index", index);
|
||||
start(ndata, HilightType.SPECIAL);
|
||||
appendNoHilight(text);
|
||||
return end(HilightType.SPECIAL);
|
||||
|
||||
@@ -99,13 +99,13 @@ public class NulWriter extends GraphTextWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter hilightSpecial(String text, String type, int index) {
|
||||
public NulWriter hilightSpecial(String text, String type, String index) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NulWriter hilightSpecial(String text, String type, int index, Map<String, String> data) {
|
||||
public NulWriter hilightSpecial(String text, String type, String index, Map<String, String> data) {
|
||||
stringAdded = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,16 @@ public class Highlighting implements Serializable {
|
||||
public static Highlighting search(List<Highlighting> list, long pos, Map<String,String> properties, long from, long to) {
|
||||
Highlighting ret = null;
|
||||
looph:for (Highlighting h : list) {
|
||||
if (from > -1) {
|
||||
if (h.startPos < from) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (to > -1) {
|
||||
if (h.startPos > to) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for(String property:properties.keySet()){
|
||||
if (property != null) {
|
||||
String v = h.getPropertyString(property);
|
||||
@@ -108,16 +118,7 @@ public class Highlighting implements Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (from > -1) {
|
||||
if (h.startPos < from) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (to > -1) {
|
||||
if (h.startPos > to) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (pos == -1 || (pos >= h.startPos && (pos < h.startPos + h.len))) {
|
||||
if (ret == null || h.startPos > ret.startPos) { //get the closest one
|
||||
ret = h;
|
||||
|
||||
@@ -12,15 +12,21 @@
|
||||
* 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.graph;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.Multiname;
|
||||
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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -67,16 +73,17 @@ public class TypeItem extends GraphTargetItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
if (localData.fullyQualifiedNames.contains(fullTypeName)) {
|
||||
if (localData.fullyQualifiedNames.contains(fullTypeName)) {
|
||||
writer.hilightSpecial(fullTypeName,"typename",fullTypeName);
|
||||
} else {
|
||||
String simpleName = fullTypeName;
|
||||
if (simpleName.contains(".")) {
|
||||
simpleName = simpleName.substring(simpleName.lastIndexOf('.') + 1);
|
||||
}
|
||||
}
|
||||
writer.hilightSpecial(simpleName,"typename",fullTypeName);
|
||||
}
|
||||
|
||||
return writer;
|
||||
|
||||
Reference in New Issue
Block a user