allow name/type hints

isConstant added (to check if something can get final)
methodAnalyzer field added


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@883 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 2ce2054875
commit 364d7f8739
  1. 75
      jode/jode/decompiler/LocalInfo.java

@ -41,6 +41,7 @@ public class LocalInfo implements Declarable {
private static int serialnr = 0; private static int serialnr = 0;
private static int nextAnonymousSlot = -1; private static int nextAnonymousSlot = -1;
private int slot; private int slot;
private MethodAnalyzer methodAnalyzer;
private boolean nameIsGenerated = false; private boolean nameIsGenerated = false;
private boolean isUnique; private boolean isUnique;
private String name; private String name;
@ -52,6 +53,36 @@ public class LocalInfo implements Declarable {
private boolean isFinal = false; private boolean isFinal = false;
private Expression constExpr = null; private Expression constExpr = null;
public static class Hint {
String name;
Type type;
public Hint(String name, Type type) {
this.name = name;
this.type = type;
}
public final Type getType() {
return type;
}
public final String getName() {
return name;
}
public boolean equals(Object o) {
if (o instanceof Hint) {
Hint h = (Hint) o;
return name.equals(h.name) && type.equals(h.type);
}
return false;
}
public int hashCode() {
return name.hashCode() ^ type.hashCode();
}
}
/** /**
* Create a new local info with an anonymous slot. * Create a new local info with an anonymous slot.
*/ */
@ -65,9 +96,10 @@ public class LocalInfo implements Declarable {
* Create a new local info. * Create a new local info.
* @param slot The slot of this variable. * @param slot The slot of this variable.
*/ */
public LocalInfo(int slot) { public LocalInfo(MethodAnalyzer method, int slot) {
name = null; name = null;
type = Type.tUnknown; type = Type.tUnknown;
this.methodAnalyzer = method;
this.slot = slot; this.slot = slot;
} }
@ -79,8 +111,8 @@ public class LocalInfo implements Declarable {
getLocalInfo().operators.addElement(operator); getLocalInfo().operators.addElement(operator);
} }
public void addHint(LocalVarEntry entry) { public void addHint(String name, Type type) {
getLocalInfo().hints.addElement(entry); getLocalInfo().hints.addElement(new Hint(name, type));
} }
public int getUseCount() { public int getUseCount() {
@ -133,9 +165,9 @@ public class LocalInfo implements Declarable {
enum = hints.elements(); enum = hints.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
Object entry = enum.nextElement(); Object hint = enum.nextElement();
if (!shadow.hints.contains(entry)) if (!shadow.hints.contains(hint))
shadow.hints.addElement(entry); shadow.hints.addElement(hint);
} }
/* Clear unused fields, to allow garbage collection. /* Clear unused fields, to allow garbage collection.
@ -178,14 +210,16 @@ public class LocalInfo implements Declarable {
if (name == null) { if (name == null) {
Enumeration enum = hints.elements(); Enumeration enum = hints.elements();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
LocalVarEntry entry = (LocalVarEntry) enum.nextElement(); Hint hint = (Hint) enum.nextElement();
if (type.isOfType(entry.getType())) { if (type.isOfType(hint.getType())) {
name = entry.getName(); name = hint.getName();
setType(entry.getType()); setType(hint.getType());
return name; return name;
} }
} }
nameIsGenerated = true; nameIsGenerated = true;
if ((GlobalOptions.debuggingFlags & GlobalOptions.DEBUG_TYPES) != 0)
GlobalOptions.err.println(getName()+" set type to getHint()");
setType(type.getHint()); setType(type.getHint());
if ((Decompiler.options & Decompiler.OPTION_PRETTY) != 0) { if ((Decompiler.options & Decompiler.OPTION_PRETTY) != 0) {
name = type.getDefaultName(); name = type.getDefaultName();
@ -325,6 +359,23 @@ public class LocalInfo implements Declarable {
return removed; return removed;
} }
public boolean isConstant() {
LocalInfo li = getLocalInfo();
Enumeration enum = li.operators.elements();
int writes = 0;
while (enum.hasMoreElements()) {
if (((LocalVarOperator) enum.nextElement()).isWrite())
writes++;
}
if (writes > 1)
return false;
return true;
}
public MethodAnalyzer getMethodAnalyzer() {
return methodAnalyzer;
}
public boolean markFinal() { public boolean markFinal() {
LocalInfo li = getLocalInfo(); LocalInfo li = getLocalInfo();
Enumeration enum = li.operators.elements(); Enumeration enum = li.operators.elements();
@ -339,6 +390,10 @@ public class LocalInfo implements Declarable {
return true; return true;
} }
public boolean isFinal() {
return getLocalInfo().isFinal;
}
public String toString() { public String toString() {
return getName().toString(); return getName().toString();
} }

Loading…
Cancel
Save