summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/modules
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2014-10-24 21:16:23 +1100
committermd_5 <git@md-5.net>2014-10-25 09:30:59 +1100
commitb98e02e557eb7c30d6425ffd9cfa8b7b71b164dc (patch)
tree4c1ac9026ebda849390d4000fe744cea917c4a17 /src/org/jetbrains/java/decompiler/modules
parente0f22e66296eeaf1e2a9af73af0c7f9ba28521b1 (diff)
downloadfernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar.gz
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar.lz
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar.xz
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.zip
Spigot Changes
Diffstat (limited to 'src/org/jetbrains/java/decompiler/modules')
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java9
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java4
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java2
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java19
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java15
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java11
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionPaar.java22
-rw-r--r--src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java8
8 files changed, 70 insertions, 20 deletions
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
index e283fdf..7b2f3a2 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java
@@ -41,6 +41,7 @@ import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import java.util.*;
+import org.jetbrains.java.decompiler.util.SortUtil;
public class ExprProcessor implements CodeConstants {
@@ -814,8 +815,10 @@ public class ExprProcessor implements CodeConstants {
String new_line_separator = DecompilerContext.getNewLineSeparator();
StringBuilder buf = new StringBuilder();
-
- for (Exprent expr : lst) {
+ // Spigot Start
+ for (Iterator<Exprent> iter = SortUtil.sortIndexed(lst.iterator()); iter.hasNext();) {
+ Exprent expr = iter.next();
+ // Spigot End
String content = expr.toJava(indent, tracer);
if (content.length() > 0) {
if (expr.type != Exprent.EXPRENT_VAR || !((VarExprent)expr).isClassdef()) {
@@ -877,7 +880,7 @@ public class ExprProcessor implements CodeConstants {
boolean cast =
!leftType.isSuperset(rightType) && (rightType.equals(VarType.VARTYPE_OBJECT) || leftType.type != CodeConstants.TYPE_OBJECT);
- cast |= castAlways;
+ cast |= castAlways && !leftType.equals(rightType); // Spigot
if (!cast && castNull && rightType.type == CodeConstants.TYPE_NULL) {
// check for a nameless anonymous class
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java
index 6198da1..6f83baf 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/FinallyProcessor.java
@@ -529,7 +529,7 @@ public class FinallyProcessor {
}
while (index < lst.size());
- HashSet<BasicBlock> res = new HashSet<BasicBlock>();
+ HashSet<BasicBlock> res = new LinkedHashSet<BasicBlock>(); // Spigot: Fix determinism
for (Statement st : lst) {
res.add(((BasicBlockStatement)st).getBlock());
@@ -571,7 +571,7 @@ public class FinallyProcessor {
}
// identify start blocks
- HashSet<BasicBlock> startBlocks = new HashSet<BasicBlock>();
+ HashSet<BasicBlock> startBlocks = new LinkedHashSet<BasicBlock>(); // Spigot: Fix determinism
for (BasicBlock block : tryBlocks) {
startBlocks.addAll(block.getSuccs());
}
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java
index e51615d..5363477 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/FieldExprent.java
@@ -102,7 +102,7 @@ public class FieldExprent extends Exprent {
if (isStatic) {
ClassNode node = (ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_NODE);
- if (node == null || !classname.equals(node.classStruct.qualifiedName)) {
+ if (true || node == null || !classname.equals(node.classStruct.qualifiedName)) { // Spigot
buf.append(DecompilerContext.getImportCollector().getShortName(ExprProcessor.buildJavaClassName(classname)));
buf.append(".");
}
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
index 92d549e..e9d9064 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
@@ -373,13 +373,26 @@ public class InvocationExprent extends Exprent {
return buf.toString();
}
+ private Set<StructClass> addAllSuper(Set<StructClass> set, String clazz) {
+ StructClass cstr = DecompilerContext.getStructContext().getClass(clazz);
+ if (cstr == null) {
+ return set;
+ }
+ set.add(cstr);
+ for (String inter : cstr.getInterfaceNames()) {
+ addAllSuper(set, inter);
+ }
+ addAllSuper(set, cstr.superClass.getString());
+
+ return set;
+ }
+
private Set<Integer> getAmbiguousParameters() {
Set<Integer> ret = new HashSet<Integer>();
- StructClass cstr = DecompilerContext.getStructContext().getClass(classname);
- if (cstr != null) {
- List<MethodDescriptor> lstMethods = new ArrayList<MethodDescriptor>();
+ List<MethodDescriptor> lstMethods = new ArrayList<MethodDescriptor>();
+ for (StructClass cstr : addAllSuper(new HashSet<StructClass>(), classname)) {
for (StructMethod meth : cstr.getMethods()) {
if (name.equals(meth.getName())) {
MethodDescriptor md = MethodDescriptor.parseDescriptor(meth.getDescriptor());
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java
index 16e6c64..b8e60e7 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/VarExprent.java
@@ -27,11 +27,12 @@ import org.jetbrains.java.decompiler.modules.decompiler.vars.VarTypeProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.vars.VarVersionPaar;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
+import org.jetbrains.java.decompiler.util.SortUtil;
import java.util.ArrayList;
import java.util.List;
-public class VarExprent extends Exprent {
+public class VarExprent extends Exprent implements SortUtil.Indexed { // Spigot
public static final int STACK_BASE = 10000;
@@ -94,15 +95,16 @@ public class VarExprent extends Exprent {
}
else {
String name = null;
+ String typeName = ExprProcessor.getCastTypeName(getVartype()); // Spigot
if (processor != null) {
- name = processor.getVarName(new VarVersionPaar(index, version));
+ name = processor.getVarName(new VarVersionPaar(index, version, typeName, false)); // Spigot
}
if (definition) {
if (processor != null && processor.getVarFinal(new VarVersionPaar(index, version)) == VarTypeProcessor.VAR_FINALEXPLICIT) {
buffer.append("final ");
}
- buffer.append(ExprProcessor.getCastTypeName(getVartype())).append(" ");
+ buffer.append(typeName).append(" "); // Spigot
}
buffer.append(name == null ? ("var" + index + (version == 0 ? "" : "_" + version)) : name);
}
@@ -128,6 +130,13 @@ public class VarExprent extends Exprent {
this.index = index;
}
+ // Spigot Start
+ @Override
+ public int getSortIndex() {
+ return (definition) ? index : -1;
+ }
+ // Spigot End
+
public VarType getVartype() {
VarType vt = null;
if (processor != null) {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java
index 266ba94..4d4dabb 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarProcessor.java
@@ -21,6 +21,7 @@ import org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement;
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
import org.jetbrains.java.decompiler.struct.StructMethod;
import org.jetbrains.java.decompiler.struct.gen.VarType;
+import org.jetbrains.java.decompiler.util.VarHelper; // Spigot
import java.util.*;
import java.util.Map.Entry;
@@ -36,6 +37,8 @@ public class VarProcessor {
private HashSet<VarVersionPaar> externvars = new HashSet<VarVersionPaar>();
+ private VarHelper helper = new VarHelper(); // Spigot
+
public void setVarVersions(RootStatement root) {
varvers = new VarVersionsProcessor();
@@ -104,7 +107,13 @@ public class VarProcessor {
}
public String getVarName(VarVersionPaar varpaar) {
- return mapVarNames == null ? null : mapVarNames.get(varpaar);
+ // Spigot Start
+ String name = mapVarNames.get(varpaar);
+ if (name != null) {
+ mapVarNames.put(varpaar, name = helper.help(name, varpaar.type, varpaar.varargs));
+ }
+ return name;
+ // Spigot End
}
public void setVarName(VarVersionPaar varpaar, String name) {
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionPaar.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionPaar.java
index 5f3e520..3bf29fe 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionPaar.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionPaar.java
@@ -17,10 +17,12 @@ package org.jetbrains.java.decompiler.modules.decompiler.vars;
import org.jetbrains.java.decompiler.modules.decompiler.exps.VarExprent;
-public class VarVersionPaar {
+public class VarVersionPaar implements Comparable<VarVersionPaar> { // Spigot
public int var;
public int version;
+ public String type;
+ public boolean varargs;
private int hashCode = -1;
@@ -29,9 +31,11 @@ public class VarVersionPaar {
this.version = version;
}
- public VarVersionPaar(Integer var, Integer version) {
- this.var = var.intValue();
- this.version = version.intValue();
+ public VarVersionPaar(int var, int version, String type, boolean varargs) {
+ this.var = var;
+ this.version = version;
+ this.type = type;
+ this.varargs = varargs;
}
public VarVersionPaar(VarExprent var) {
@@ -60,4 +64,14 @@ public class VarVersionPaar {
public String toString() {
return "(" + var + "," + version + ")";
}
+
+ // Spigot Start
+ @Override
+ public int compareTo(VarVersionPaar o) {
+ if (this.var != o.var) {
+ return this.var - o.var;
+ }
+ return this.version - o.version;
+ }
+ // Spigot End
}
diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java
index 06b7216..6a30f1b 100644
--- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java
+++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java
@@ -31,6 +31,7 @@ import org.jetbrains.java.decompiler.util.FastSparseSetFactory.FastSparseSet;
import java.util.*;
import java.util.Map.Entry;
+import org.jetbrains.java.decompiler.util.SortUtil;
public class VarVersionsProcessor {
@@ -254,9 +255,10 @@ public class VarVersionsProcessor {
HashMap<Integer, Integer> mapOriginalVarIndices = new HashMap<Integer, Integer>();
// map var-version paars on new var indexes
- HashSet<VarVersionPaar> set = new HashSet<VarVersionPaar>(mapExprentMinTypes.keySet());
- for (VarVersionPaar vpaar : set) {
-
+ // Spigot Start
+ for (Iterator<VarVersionPaar> iter = SortUtil.sortComparable(mapExprentMinTypes.keySet().iterator()); iter.hasNext();) {
+ VarVersionPaar vpaar = iter.next();
+ // Spigot End
if (vpaar.version >= 0) {
int newindex = vpaar.version == 1 ? vpaar.var :
ccon.getCounterAndIncrement(CounterContainer.VAR_COUNTER);