Types moved to jode.type

dumpExpression


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@598 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 67f9091be8
commit 40616f0ac6
  1. 37
      jode/jode/expr/CheckCastOperator.java
  2. 19
      jode/jode/expr/CheckNullOperator.java
  3. 11
      jode/jode/expr/ClassFieldOperator.java
  4. 15
      jode/jode/expr/CompareBinaryOperator.java
  5. 21
      jode/jode/expr/CompareToIntOperator.java
  6. 15
      jode/jode/expr/CompareUnaryOperator.java
  7. 13
      jode/jode/expr/ConstOperator.java
  8. 30
      jode/jode/expr/ConstantArrayOperator.java
  9. 22
      jode/jode/expr/ConstructorOperator.java
  10. 16
      jode/jode/expr/ConvertOperator.java
  11. 48
      jode/jode/expr/Expression.java
  12. 47
      jode/jode/expr/GetFieldOperator.java
  13. 10
      jode/jode/expr/IIncOperator.java
  14. 26
      jode/jode/expr/IfThenElseOperator.java
  15. 32
      jode/jode/expr/InstanceOfOperator.java
  16. 96
      jode/jode/expr/InvokeOperator.java
  17. 11
      jode/jode/expr/LocalLoadOperator.java
  18. 17
      jode/jode/expr/LocalPrePostFixOperator.java
  19. 7
      jode/jode/expr/LocalStoreOperator.java
  20. 16
      jode/jode/expr/MonitorEnterOperator.java
  21. 20
      jode/jode/expr/MonitorExitOperator.java
  22. 28
      jode/jode/expr/NewArrayOperator.java
  23. 9
      jode/jode/expr/NewOperator.java
  24. 15
      jode/jode/expr/NopOperator.java
  25. 9
      jode/jode/expr/PopOperator.java
  26. 30
      jode/jode/expr/PrePostFixOperator.java
  27. 53
      jode/jode/expr/PutFieldOperator.java
  28. 25
      jode/jode/expr/StoreInstruction.java
  29. 15
      jode/jode/expr/StringAddOperator.java
  30. 14
      jode/jode/expr/UnaryOperator.java

@ -18,16 +18,11 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class CheckCastOperator extends SimpleOperator { public class CheckCastOperator extends SimpleOperator {
Type castType; Type castType;
/**
* There are special cases where a cast isn't allowed. We must cast
* to the common super type before. This cases always give a runtime
* error, but we want to decompile even bad programs.
*/
Type superType = null;
public CheckCastOperator(Type type) { public CheckCastOperator(Type type) {
super(type, 0, 1); super(type, 0, 1);
@ -39,19 +34,27 @@ public class CheckCastOperator extends SimpleOperator {
return 700; return 700;
} }
public int getOperandPriority(int i) {
return getPriority();
}
public void setOperandType(Type[] type) { public void setOperandType(Type[] type) {
super.setOperandType(type); super.setOperandType(type);
superType = castType.getCastHelper(type[0]);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
StringBuffer sb = new StringBuffer("(").append(castType).append(")"); Expression[] operands)
if (superType != null) throws java.io.IOException {
sb.append("(").append(superType).append(")"); writer.print("(");
return sb.append(operands[0]).toString(); writer.printType(castType);
writer.print(") ");
/* There are special cases where a cast isn't allowed. We must cast
* to the common super type before. This cases always give a runtime
* error, but we want to decompile even bad programs.
*/
Type superType = castType.getCastHelper(operands[0].getType());
if (superType != null) {
writer.print("(");
writer.printType(superType);
writer.print(") ");
}
operands[0].dumpExpression(writer, 700);
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.LocalInfo; import jode.decompiler.LocalInfo;
import jode.decompiler.TabbedPrintWriter;
/** /**
* This is a pseudo operator, which represents the check against null * This is a pseudo operator, which represents the check against null
@ -80,15 +81,11 @@ public class CheckNullOperator extends Operator {
local.setType(type); local.setType(type);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
/* There is no way to produce exactly the same code. Expression[] operands)
* This is a good approximation. throws java.io.IOException {
* op.getClass will throw a null pointer exception if operands[0] writer.print("("+local.getName()+" = ");
* is null, otherwise return something not equal to null. operands[0].dumpExpression(writer, 0);
* The bad thing is that this isn't atomar. writer.print(").getClass() != null ? "+local.getName()+" : null");
*/
return ("(" + local.getName() + " = "
+ operands[0] + ").getClass() != null ? "
+ local.getName() + " : null");
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
import jode.decompiler.TabbedPrintWriter;
public class ClassFieldOperator extends NoArgOperator { public class ClassFieldOperator extends NoArgOperator {
Type classType; Type classType;
@ -27,14 +28,16 @@ public class ClassFieldOperator extends NoArgOperator {
public ClassFieldOperator(Type classType) { public ClassFieldOperator(Type classType) {
super(Type.tJavaLangClass); super(Type.tJavaLangClass);
this.classType = classType; this.classType = classType;
classType.useType();
} }
public int getPriority() { public int getPriority() {
return 950; return 950;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return classType.toString() + ".class"; Expression[] operands)
throws java.io.IOException {
writer.printType(classType);
writer.print(".class");
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class CompareBinaryOperator extends SimpleOperator { public class CompareBinaryOperator extends SimpleOperator {
public CompareBinaryOperator(Type type, int op) { public CompareBinaryOperator(Type type, int op) {
@ -40,10 +41,6 @@ public class CompareBinaryOperator extends SimpleOperator {
throw new RuntimeException("Illegal operator"); throw new RuntimeException("Illegal operator");
} }
public int getOperandPriority(int i) {
return getPriority()+i;
}
public void setOperandType(Type[] inputTypes) { public void setOperandType(Type[] inputTypes) {
super.setOperandType(inputTypes); super.setOperandType(inputTypes);
operandTypes[0] = operandTypes[1] = operandTypes[0] = operandTypes[1] =
@ -55,7 +52,11 @@ public class CompareBinaryOperator extends SimpleOperator {
((CompareBinaryOperator)o).operator == operator; ((CompareBinaryOperator)o).operator == operator;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return operands[0] + getOperatorString() + operands[1]; Expression[] operands)
throws java.io.IOException {
operands[0].dumpExpression(writer, getPriority());
writer.print(getOperatorString());
operands[1].dumpExpression(writer, getPriority()+1);
} }
} }

@ -18,22 +18,22 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class CompareToIntOperator extends SimpleOperator { public class CompareToIntOperator extends SimpleOperator {
public CompareToIntOperator(Type type, int lessGreater) { boolean greaterOnNAN;
public CompareToIntOperator(Type type, boolean greaterOnNAN) {
super(Type.tInt, 0, 2); super(Type.tInt, 0, 2);
operandTypes[0] = operandTypes[1] = type; operandTypes[0] = operandTypes[1] = type;
this.greaterOnNAN = greaterOnNAN;
} }
public int getPriority() { public int getPriority() {
return 499; return 499;
} }
public int getOperandPriority(int i) {
return 550;
}
public void setOperandType(Type[] inputTypes) { public void setOperandType(Type[] inputTypes) {
super.setOperandType(inputTypes); super.setOperandType(inputTypes);
Type operandType = operandTypes[0].intersection(operandTypes[1]); Type operandType = operandTypes[0].intersection(operandTypes[1]);
@ -44,7 +44,12 @@ public class CompareToIntOperator extends SimpleOperator {
return (o instanceof CompareToIntOperator); return (o instanceof CompareToIntOperator);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return operands[0] + " <=> " + operands[1]; Expression[] operands)
throws java.io.IOException
{
operands[0].dumpExpression(writer, 550);
writer.print(" <=>" + (greaterOnNAN ? 'g' : 'l') + ' ');
operands[1].dumpExpression(writer, 551);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class CompareUnaryOperator extends SimpleOperator { public class CompareUnaryOperator extends SimpleOperator {
boolean objectType; boolean objectType;
@ -43,16 +44,16 @@ public class CompareUnaryOperator extends SimpleOperator {
throw new RuntimeException("Illegal operator"); throw new RuntimeException("Illegal operator");
} }
public int getOperandPriority(int i) {
return getPriority();
}
public boolean equals(Object o) { public boolean equals(Object o) {
return (o instanceof CompareUnaryOperator) && return (o instanceof CompareUnaryOperator) &&
((CompareUnaryOperator)o).operator == operator; ((CompareUnaryOperator)o).operator == operator;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return operands[0] + getOperatorString() + (objectType?"null":"0"); Expression[] operands)
throws java.io.IOException {
operands[0].dumpExpression(writer, getPriority());
writer.print(getOperatorString());
writer.print(objectType?"null":"0");
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.IntegerType; import jode.type.IntegerType;
import jode.decompiler.TabbedPrintWriter;
public class ConstOperator extends NoArgOperator { public class ConstOperator extends NoArgOperator {
Object value; Object value;
@ -129,7 +130,7 @@ public class ConstOperator extends NoArgOperator {
return result.append("\"").toString(); return result.append("\"").toString();
} }
public String toString(String[] operands) { public String toString() {
String strVal = String.valueOf(value); String strVal = String.valueOf(value);
if (type.isOfType(Type.tBoolean)) { if (type.isOfType(Type.tBoolean)) {
int intVal = ((Integer)value).intValue(); int intVal = ((Integer)value).intValue();
@ -215,4 +216,10 @@ public class ConstOperator extends NoArgOperator {
return strVal; return strVal;
} }
public void dumpExpression(TabbedPrintWriter writer,
Expression[] operands)
throws java.io.IOException {
writer.print(toString());
}
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.ArrayType; import jode.type.ArrayType;
import jode.decompiler.TabbedPrintWriter;
public class ConstantArrayOperator extends NoArgOperator { public class ConstantArrayOperator extends NoArgOperator {
@ -93,14 +94,25 @@ public class ConstantArrayOperator extends NoArgOperator {
return this; return this;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
StringBuffer result = isInitializer ? new StringBuffer("{ ") Expression[] operands)
: new StringBuffer("new ").append(type).append(" { "); throws java.io.IOException {
writer.print("new ");
writer.printType(type);
writer.println(" {");
writer.tab();
for (int i=0; i< values.length; i++) { for (int i=0; i< values.length; i++) {
if (i>0) if (i>0) {
result.append(", "); if (i % 10 == 0)
result.append((values[i] != null) ? values[i] : empty); writer.println(",");
else
writer.print(", ");
}
values[i].dumpExpression(writer, 0);
} }
return result.append(" }").toString(); writer.println();
writer.untab();
writer.print("}");
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.MethodType; import jode.type.MethodType;
import jode.decompiler.TabbedPrintWriter;
public class ConstructorOperator extends Operator public class ConstructorOperator extends Operator
implements MatchableOperator { implements MatchableOperator {
@ -80,14 +81,19 @@ public class ConstructorOperator extends Operator
? EMPTYSTRING : null; ? EMPTYSTRING : null;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
StringBuffer result = Expression[] operands)
new StringBuffer("new ").append(classType.toString()).append("("); throws java.io.IOException {
writer.print("new ");
writer.printType(classType);
writer.print("(");
for (int i=0; i < methodType.getParameterTypes().length; i++) { for (int i=0; i < methodType.getParameterTypes().length; i++) {
if (i>0) if (i>0)
result.append(", "); writer.print(", ");
result.append(operands[i]); operands[i].dumpExpression(writer, 0);
} }
return result.append(")").toString(); writer.print(")");
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class ConvertOperator extends Operator { public class ConvertOperator extends Operator {
Type from; Type from;
@ -32,10 +33,6 @@ public class ConvertOperator extends Operator {
return 700; return 700;
} }
public int getOperandPriority(int i) {
return 700;
}
public int getOperandCount() { public int getOperandCount() {
return 1; return 1;
} }
@ -48,8 +45,11 @@ public class ConvertOperator extends Operator {
from = from.intersection(inputTypes[0]); from = from.intersection(inputTypes[0]);
} }
public String toString(String[] operands) public void dumpExpression(TabbedPrintWriter writer,
{ Expression[] ops) throws java.io.IOException {
return "("+type.toString()+") "+operands[0]; writer.print("(");
writer.printType(type);
writer.print(")");
ops[0].dumpExpression(writer, 700);
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.Decompiler; import jode.Decompiler;
import jode.decompiler.TabbedPrintWriter;
public abstract class Expression { public abstract class Expression {
protected Type type; protected Type type;
@ -166,14 +167,47 @@ public abstract class Expression {
return true; return true;
} }
public abstract String toString(); public abstract void dumpExpression(TabbedPrintWriter writer)
throws java.io.IOException;
String toString(int minPriority) { public void dumpExpression(TabbedPrintWriter writer, int minPriority)
String result = toString(); throws java.io.IOException {
if (getOperator().getPriority() < minPriority) boolean needParen1 = false, needParen2 = false;
return "("+result+")"; if (Decompiler.isTypeDebugging) {
return result; if (minPriority > 700) {
needParen1 = true;
writer.print("(");
} }
writer.print("("+getType()+") ");
minPriority = 700;
} else if (getType() == Type.tError) {
writer.print("(/*type error */");
needParen1 = true;
}
if (getOperator().getPriority() < minPriority) {
needParen2 = true;
writer.print("(");
}
dumpExpression(writer);
if (needParen2)
writer.print(")");
if (needParen1)
writer.print(")");
}
public String toString() {
try {
java.io.StringWriter strw = new java.io.StringWriter();
TabbedPrintWriter writer = new TabbedPrintWriter(strw);
dumpExpression(writer);
return strw.toString();
} catch (java.io.IOException ex) {
return super.toString();
}
}
public boolean isVoid() { public boolean isVoid() {
return getType() == Type.tVoid; return getType() == Type.tVoid;

@ -18,9 +18,11 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.type.NullType;
import jode.bytecode.Reference; import jode.bytecode.Reference;
import jode.decompiler.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
import jode.decompiler.TabbedPrintWriter;
public class GetFieldOperator extends Operator { public class GetFieldOperator extends Operator {
boolean staticFlag; boolean staticFlag;
@ -37,7 +39,7 @@ public class GetFieldOperator extends Operator {
this.classType = Type.tType(ref.getClazz()); this.classType = Type.tType(ref.getClazz());
this.ref = ref; this.ref = ref;
if (staticFlag) if (staticFlag)
classType.useType(); codeAnalyzer.useType(classType);
} }
public int getPriority() { public int getPriority() {
@ -61,19 +63,36 @@ public class GetFieldOperator extends Operator {
needCast = types[0].getHint().equals(Type.tNull); needCast = types[0].getHint().equals(Type.tNull);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer, Expression[] operands)
throws java.io.IOException {
boolean opIsThis =
(!staticFlag
&& operands[0] instanceof LocalLoadOperator
&& (((LocalLoadOperator) operands[0]).getLocalInfo()
.equals(codeAnalyzer.getParamInfo(0)))
&& !codeAnalyzer.getMethod().isStatic());
String fieldName = ref.getName(); String fieldName = ref.getName();
return staticFlag if (staticFlag) {
? (classType.equals(Type.tClass(codeAnalyzer.getClazz())) if (!classType.equals(Type.tClass(codeAnalyzer.getClazz()))
&& codeAnalyzer.findLocal(fieldName) == null || codeAnalyzer.findLocal(fieldName) != null) {
? fieldName writer.printType(classType);
: classType.toString() + "." + fieldName) writer.print(".");
: (operands[0].equals("null") }
? "((" + classType + ") null)." + fieldName writer.print(fieldName);
: (operands[0].equals("this") } else if (operands[0].getType() instanceof NullType) {
&& codeAnalyzer.findLocal(fieldName) == null writer.print("((");
? fieldName writer.printType(classType);
: operands[0] + "." + fieldName)); writer.print(")");
operands[0].dumpExpression(writer, 700);
writer.print(").");
writer.print(fieldName);
} else {
if (!opIsThis || codeAnalyzer.findLocal(fieldName) != null) {
operands[0].dumpExpression(writer, 950);
writer.print(".");
}
writer.print(fieldName);
}
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.LocalInfo; import jode.decompiler.LocalInfo;
import jode.decompiler.TabbedPrintWriter;
public class IIncOperator extends NoArgOperator public class IIncOperator extends NoArgOperator
implements LocalVarOperator, CombineableOperator { implements LocalVarOperator, CombineableOperator {
@ -96,8 +97,9 @@ implements LocalVarOperator, CombineableOperator {
return super.simplify(); return super.simplify();
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return local.getName().toString() + Expression[] operands)
getOperatorString() + value; throws java.io.IOException {
writer.print(local.getName() + getOperatorString() + value);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class IfThenElseOperator extends SimpleOperator { public class IfThenElseOperator extends SimpleOperator {
public IfThenElseOperator(Type type) { public IfThenElseOperator(Type type) {
@ -34,19 +35,6 @@ public class IfThenElseOperator extends SimpleOperator {
return 200; return 200;
} }
public int getOperandPriority(int i) {
switch (i) {
case 0:
return 201;
case 1:
return 0;
case 2:
return 200;
default:
throw new jode.AssertError("ifthenelse with operand "+i);
}
}
public void setOperandType(Type[] inputTypes) { public void setOperandType(Type[] inputTypes) {
super.setOperandType(inputTypes); super.setOperandType(inputTypes);
Type operandType = Type operandType =
@ -70,7 +58,13 @@ public class IfThenElseOperator extends SimpleOperator {
return (o instanceof IfThenElseOperator); return (o instanceof IfThenElseOperator);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return operands[0] + " ? "+operands[1]+" : "+ operands[2]; Expression[] operands)
throws java.io.IOException {
operands[0].dumpExpression(writer, 201);
writer.print(" ? ");
operands[1].dumpExpression(writer, 0);
writer.print(" : ");
operands[2].dumpExpression(writer, 200);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class InstanceOfOperator extends SimpleOperator { public class InstanceOfOperator extends SimpleOperator {
@ -44,22 +45,27 @@ public class InstanceOfOperator extends SimpleOperator {
return 550; return 550;
} }
public int getOperandPriority(int i) {
return getPriority();
}
public void setOperandType(Type[] type) { public void setOperandType(Type[] type) {
super.setOperandType(type); super.setOperandType(type);
superType = instanceType.getCastHelper(type[0]); superType = instanceType.getCastHelper(type[0]);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
StringBuffer sb = new StringBuffer(); Expression[] operands)
if (superType != null) throws java.io.IOException {
sb.append("((").append(superType).append(")"); /* There are special cases where a cast isn't allowed. We must cast
sb.append(operands[0]); * to the common super type before. This cases always give a runtime
if (superType != null) * error, but we want to decompile even bad programs.
sb.append(")"); */
return sb.append(" instanceof ").append(instanceType).toString(); Type superType = instanceType.getCastHelper(operands[0].getType());
if (superType != null) {
writer.print("(");
writer.printType(superType);
writer.print(") ");
operands[0].dumpExpression(writer, 700);
} else
operands[0].dumpExpression(writer, 550);
writer.print(" instanceof ");
writer.printType(instanceType);
} }
} }

@ -20,13 +20,11 @@
package jode.expr; package jode.expr;
import jode.decompiler.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
import jode.decompiler.ClassAnalyzer; import jode.decompiler.ClassAnalyzer;
import jode.MethodType; import jode.decompiler.TabbedPrintWriter;
import jode.Decompiler; import jode.Decompiler;
import jode.Type;
import jode.ArrayType;
import jode.ClassInterfacesType;
import jode.bytecode.*; import jode.bytecode.*;
import jode.jvm.*; import jode.jvm.*;
import jode.type.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
public final class InvokeOperator extends Operator public final class InvokeOperator extends Operator
@ -50,7 +48,7 @@ public final class InvokeOperator extends Operator
this.staticFlag = staticFlag; this.staticFlag = staticFlag;
this.specialFlag = specialFlag; this.specialFlag = specialFlag;
if (staticFlag) if (staticFlag)
clazz.useType(); codeAnalyzer.useType(clazz);
} }
/** /**
@ -97,12 +95,6 @@ public final class InvokeOperator extends Operator
+ methodType.getParameterTypes().length; + methodType.getParameterTypes().length;
} }
public int getOperandPriority(int i) {
if (!isStatic() && i == 0)
return 950;
return 0;
}
public Type getOperandType(int i) { public Type getOperandType(int i) {
if (!isStatic()) { if (!isStatic()) {
if (i == 0) if (i == 0)
@ -144,32 +136,68 @@ public final class InvokeOperator extends Operator
return false; return false;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
String object = specialFlag Expression[] operands)
? (operands[0].equals("this") throws java.io.IOException {
? (/* XXX check if this is a private or final method. */ boolean opIsThis =
isThis() ? "" : "super") (!staticFlag
: (/* XXX check if this is a private or final method. */ && operands[0] instanceof LocalLoadOperator
isThis() ? operands[0] : "NON VIRTUAL " + operands[0])) && (((LocalLoadOperator) operands[0]).getLocalInfo()
: (isStatic() .equals(codeAnalyzer.getParamInfo(0)))
? (isThis() ? "" : clazz.toString()) && !codeAnalyzer.getMethod().isStatic());
: (operands[0].equals("this") ? "" int arg = 1;
: operands[0].equals("null")
? "((" + clazz.toString() + ") null)" if (specialFlag) {
: operands[0])); if (opIsThis) {
if (isThis()) {
int arg = isStatic() ? 0 : 1; /* XXX check if this is a private or final method. */
String method = isConstructor() } else {
? (object.length() == 0 ? "this" : object) /* XXX check that this is the first defined
: (object.length() == 0 ? methodName : object + "." + methodName); * super method. */
writer.print("super");
StringBuffer params = new StringBuffer(); opIsThis = false;
}
} else {
/* XXX check if this is a private or final method. */
if (!isThis()) {
writer.print("(NON VIRTUAL ");
writer.printType(clazz);
writer.print(")");
}
operands[0].dumpExpression(writer, 950);
}
} else if (staticFlag) {
arg = 0;
if (!isThis())
writer.printType(clazz);
} else {
if (!opIsThis) {
int minPriority = 950; /* field access */
if (operands[0].getType() instanceof NullType) {
writer.print("(");
writer.printType(clazz);
writer.print(") ");
minPriority = 700;
}
operands[0].dumpExpression(writer, minPriority);
}
}
if (isConstructor()) {
if (opIsThis)
writer.print("this");
} else {
if (!opIsThis)
writer.print(".");
writer.print(methodName);
}
writer.print("(");
for (int i=0; i < methodType.getParameterTypes().length; i++) { for (int i=0; i < methodType.getParameterTypes().length; i++) {
if (i>0) if (i>0)
params.append(", "); writer.print(", ");
params.append(operands[arg++]); operands[arg++].dumpExpression(writer, 0);
} }
return method+"("+params+")"; writer.print(")");
} }
/** /**

@ -19,8 +19,9 @@
package jode.expr; package jode.expr;
import jode.Decompiler; import jode.Decompiler;
import jode.Type; import jode.type.Type;
import jode.decompiler.LocalInfo; import jode.decompiler.LocalInfo;
import jode.decompiler.TabbedPrintWriter;
public class LocalLoadOperator extends NoArgOperator public class LocalLoadOperator extends NoArgOperator
implements LocalVarOperator { implements LocalVarOperator {
@ -77,7 +78,7 @@ implements LocalVarOperator {
// return slot; // return slot;
// } // }
public String toString(String[] operands) { public String toString() {
return local.getName().toString(); return local.getName().toString();
} }
@ -85,5 +86,11 @@ implements LocalVarOperator {
return (o instanceof LocalLoadOperator && return (o instanceof LocalLoadOperator &&
((LocalLoadOperator) o).local.getSlot() == local.getSlot()); ((LocalLoadOperator) o).local.getSlot() == local.getSlot());
} }
public void dumpExpression(TabbedPrintWriter writer,
Expression[] operands)
throws java.io.IOException {
writer.print(toString());
}
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class LocalPrePostFixOperator extends NoArgOperator { public class LocalPrePostFixOperator extends NoArgOperator {
IIncOperator iinc; IIncOperator iinc;
@ -35,10 +36,14 @@ public class LocalPrePostFixOperator extends NoArgOperator {
return postfix ? 800 : 700; return postfix ? 800 : 700;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
if (postfix) Expression[] operands)
return iinc.getLocalInfo().getName() + getOperatorString(); throws java.io.IOException {
else String local = iinc.getLocalInfo().getName();
return getOperatorString() + iinc.getLocalInfo().getName(); if (postfix) {
writer.print(local+getOperatorString());
} else {
writer.print(getOperatorString()+local);
}
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.LocalInfo; import jode.decompiler.LocalInfo;
import jode.decompiler.TabbedPrintWriter;
public class LocalStoreOperator extends StoreInstruction public class LocalStoreOperator extends StoreInstruction
implements LocalVarOperator { implements LocalVarOperator {
@ -82,8 +83,8 @@ implements LocalVarOperator {
throw new RuntimeException("LocalStoreOperator has no operands"); throw new RuntimeException("LocalStoreOperator has no operands");
} }
public String getLValueString(String[] operands) { public void dumpLValue(TabbedPrintWriter writer, Expression[] operands) {
return local.getName().toString(); writer.print(local.getName());
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class MonitorEnterOperator extends SimpleOperator { public class MonitorEnterOperator extends SimpleOperator {
public MonitorEnterOperator() { public MonitorEnterOperator() {
@ -27,14 +28,13 @@ public class MonitorEnterOperator extends SimpleOperator {
} }
public int getPriority() { public int getPriority() {
return 0; return 700;
} }
public int getOperandPriority(int i) { public void dumpExpression(TabbedPrintWriter writer,
return 0; Expression[] operands)
} throws java.io.IOException {
writer.print("MONITORENTER ");
public String toString(String[] operands) { operands[0].dumpExpression(writer, 700);
return "MONITORENTER "+operands[0];
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class MonitorExitOperator extends SimpleOperator { public class MonitorExitOperator extends SimpleOperator {
public MonitorExitOperator() { public MonitorExitOperator() {
@ -27,18 +28,13 @@ public class MonitorExitOperator extends SimpleOperator {
} }
public int getPriority() { public int getPriority() {
return 0; return 700;
} }
public int getOperandPriority(int i) { public void dumpExpression(TabbedPrintWriter writer,
return 0; Expression[] operands)
} throws java.io.IOException {
writer.print("MONITOREXIT ");
public Type getOperandType(int i) { operands[0].dumpExpression(writer, 700);
return Type.tObject;
}
public String toString(String[] operands) {
return "MONITOREXIT "+operands[0];
} }
} }

@ -18,8 +18,9 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.ArrayType; import jode.type.ArrayType;
import jode.decompiler.TabbedPrintWriter;
public class NewArrayOperator extends SimpleOperator { public class NewArrayOperator extends SimpleOperator {
String baseTypeString; String baseTypeString;
@ -35,21 +36,22 @@ public class NewArrayOperator extends SimpleOperator {
return 900; return 900;
} }
public int getOperandPriority(int i) { public void dumpExpression(TabbedPrintWriter writer,
return 0; Expression[] operands)
} throws java.io.IOException {
public String toString(String[] operands) {
StringBuffer arrays = new StringBuffer();
Type flat = type; Type flat = type;
int i = 0; int depth = 0;
while (flat instanceof ArrayType) { while (flat instanceof ArrayType) {
flat = ((ArrayType)flat).getElementType(); flat = ((ArrayType)flat).getElementType();
depth++;
}
writer.print("new ");
writer.printType(flat);
for (int i=0; i< depth; i++) {
writer.print("[");
if (i < getOperandCount()) if (i < getOperandCount())
arrays.append("[").append(operands[i++]).append("]"); operands[i].dumpExpression(writer, 0);
else writer.print("]");
arrays.append("[]");
} }
return "new "+flat.toString()+arrays;
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class NewOperator extends NoArgOperator { public class NewOperator extends NoArgOperator {
public NewOperator(Type type) { public NewOperator(Type type) {
@ -29,7 +30,9 @@ public class NewOperator extends NoArgOperator {
return 950; return 950;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return "new "+type.toString(); Expression[] expr) throws java.io.IOException{
writer.print("new ");
writer.printType(type);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
/** /**
* A NopOperator takes one or zero arguments and returns it again. It * A NopOperator takes one or zero arguments and returns it again. It
@ -58,9 +59,15 @@ public class NopOperator extends SimpleOperator {
return (o instanceof NopOperator); return (o instanceof NopOperator);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
Expression[] operands)
throws java.io.IOException {
if (type == Type.tVoid) if (type == Type.tVoid)
return "/* nop */"; writer.print("/* NOP */");
return operands[0]; operands[0].dumpExpression(writer);
}
public void dumpExpression(TabbedPrintWriter writer) {
writer.print("POP");
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class PopOperator extends SimpleOperator { public class PopOperator extends SimpleOperator {
@ -35,7 +36,9 @@ public class PopOperator extends SimpleOperator {
return 0; return 0;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return operands[0]; Expression[] operands)
throws java.io.IOException {
operands[0].dumpExpression(writer, 0);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class PrePostFixOperator extends Operator { public class PrePostFixOperator extends Operator {
StoreInstruction store; StoreInstruction store;
@ -35,10 +36,6 @@ public class PrePostFixOperator extends Operator {
return postfix ? 800 : 700; return postfix ? 800 : 700;
} }
public int getOperandPriority(int i) {
return getPriority();
}
public Type getOperandType(int i) { public Type getOperandType(int i) {
return store.getLValueOperandType(i); return store.getLValueOperandType(i);
} }
@ -69,10 +66,23 @@ public class PrePostFixOperator extends Operator {
store.setLValueOperandType(inputTypes); store.setLValueOperandType(inputTypes);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
if (postfix) Expression[] operands)
return store.getLValueString(operands) + getOperatorString(); throws java.io.IOException {
else boolean needBrace = false;
return getOperatorString() + store.getLValueString(operands); int priority = 700;
if (postfix) {
writer.print(getOperatorString());
priority = 800;
}
if (store.getPriority() < priority) {
needBrace = true;
writer.print("(");
}
store.dumpLValue(writer, operands);
if (needBrace)
writer.print(")");
if (!postfix)
writer.print(getOperatorString());
} }
} }

@ -18,10 +18,12 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.type.NullType;
import jode.bytecode.Reference; import jode.bytecode.Reference;
import jode.decompiler.CodeAnalyzer; import jode.decompiler.CodeAnalyzer;
import jode.decompiler.FieldAnalyzer; import jode.decompiler.FieldAnalyzer;
import jode.decompiler.TabbedPrintWriter;
public class PutFieldOperator extends StoreInstruction { public class PutFieldOperator extends StoreInstruction {
CodeAnalyzer codeAnalyzer; CodeAnalyzer codeAnalyzer;
@ -37,7 +39,7 @@ public class PutFieldOperator extends StoreInstruction {
this.ref = ref; this.ref = ref;
this.classType = Type.tType(ref.getClazz()); this.classType = Type.tType(ref.getClazz());
if (staticFlag) if (staticFlag)
classType.useType(); codeAnalyzer.useType(classType);
} }
public boolean isStatic() { public boolean isStatic() {
@ -77,10 +79,6 @@ public class PutFieldOperator extends StoreInstruction {
return staticFlag?0:1; return staticFlag?0:1;
} }
public int getLValueOperandPriority(int i) {
return 900;
}
public Type getLValueOperandType(int i) { public Type getLValueOperandType(int i) {
return classType; return classType;
} }
@ -88,19 +86,36 @@ public class PutFieldOperator extends StoreInstruction {
public void setLValueOperandType(Type[] t) { public void setLValueOperandType(Type[] t) {
} }
public String getLValueString(String[] operands) { public void dumpLValue(TabbedPrintWriter writer, Expression[] operands)
String fieldName = getFieldName(); throws java.io.IOException {
return staticFlag boolean opIsThis =
? (classType.equals(Type.tClass(codeAnalyzer.getClazz())) (!staticFlag
&& codeAnalyzer.findLocal(fieldName) == null && operands[0] instanceof LocalLoadOperator
? fieldName && (((LocalLoadOperator) operands[0]).getLocalInfo()
: classType.toString() + "." + fieldName) .equals(codeAnalyzer.getParamInfo(0)))
: ((operands[0].equals("this") && !codeAnalyzer.getMethod().isStatic());
&& codeAnalyzer.findLocal(fieldName) == null String fieldName = ref.getName();
? fieldName if (staticFlag) {
: operands[0].equals("null") if (!classType.equals(Type.tClass(codeAnalyzer.getClazz()))
? "((" + classType + ") null)." + fieldName || codeAnalyzer.findLocal(fieldName) != null) {
: operands[0] + "." + fieldName)); writer.printType(classType);
writer.print(".");
}
writer.print(fieldName);
} else if (operands[0].getType() instanceof NullType) {
writer.print("((");
writer.printType(classType);
writer.print(")");
operands[0].dumpExpression(writer, 700);
writer.print(").");
writer.print(fieldName);
} else {
if (!opIsThis || codeAnalyzer.findLocal(fieldName) != null) {
operands[0].dumpExpression(writer, 950);
writer.print(".");
}
writer.print(fieldName);
}
} }
public boolean equals(Object o) { public boolean equals(Object o) {

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public abstract class StoreInstruction extends Operator public abstract class StoreInstruction extends Operator
implements CombineableOperator { implements CombineableOperator {
@ -69,7 +70,6 @@ public abstract class StoreInstruction extends Operator
public abstract boolean matches(Operator loadop); public abstract boolean matches(Operator loadop);
public abstract int getLValueOperandCount(); public abstract int getLValueOperandCount();
public abstract int getLValueOperandPriority(int i);
public abstract Type getLValueOperandType(int i); public abstract Type getLValueOperandType(int i);
public abstract void setLValueOperandType(Type [] t); public abstract void setLValueOperandType(Type [] t);
@ -80,19 +80,10 @@ public abstract class StoreInstruction extends Operator
lvalueType = lvalueType.intersection(type); lvalueType = lvalueType.intersection(type);
} }
public abstract String getLValueString(String[] operands);
public int getPriority() { public int getPriority() {
return 100; return 100;
} }
public int getOperandPriority(int i) {
if (i == getLValueOperandCount())
return 100;
else
return getLValueOperandPriority(i);
}
public Type getOperandType(int i) { public Type getOperandType(int i) {
if (i == getLValueOperandCount()) { if (i == getLValueOperandCount()) {
if (getOperatorIndex() == ASSIGN_OP) if (getOperatorIndex() == ASSIGN_OP)
@ -119,9 +110,15 @@ public abstract class StoreInstruction extends Operator
return 1 + getLValueOperandCount(); return 1 + getLValueOperandCount();
} }
public String toString(String[] operands) public abstract void dumpLValue(TabbedPrintWriter writer,
Expression[] operands)
throws java.io.IOException;
public void dumpExpression(TabbedPrintWriter writer, Expression[] operands)
throws java.io.IOException
{ {
return getLValueString(operands) + getOperatorString() + dumpLValue(writer, operands);
operands[getLValueOperandCount()]; writer.print(getOperatorString());
operands[getLValueOperandCount()].dumpExpression(writer, 100);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class StringAddOperator extends SimpleOperator { public class StringAddOperator extends SimpleOperator {
protected Type operandType; protected Type operandType;
@ -36,15 +37,15 @@ public class StringAddOperator extends SimpleOperator {
return 610; return 610;
} }
public int getOperandPriority(int i) {
return 610 + i;
}
public boolean equals(Object o) { public boolean equals(Object o) {
return (o instanceof StringAddOperator); return (o instanceof StringAddOperator);
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return operands[0] + getOperatorString() + operands[1]; Expression[] operands)
throws java.io.IOException {
operands[0].dumpExpression(writer, 610);
writer.print(getOperatorString());
operands[1].dumpExpression(writer, 611);
} }
} }

@ -18,7 +18,8 @@
*/ */
package jode.expr; package jode.expr;
import jode.Type; import jode.type.Type;
import jode.decompiler.TabbedPrintWriter;
public class UnaryOperator extends SimpleOperator { public class UnaryOperator extends SimpleOperator {
public UnaryOperator(Type type, int op) { public UnaryOperator(Type type, int op) {
@ -29,10 +30,6 @@ public class UnaryOperator extends SimpleOperator {
return 700; return 700;
} }
public int getOperandPriority(int i) {
return getPriority();
}
/** /**
* Sets the return type of this operator. * Sets the return type of this operator.
*/ */
@ -47,7 +44,10 @@ public class UnaryOperator extends SimpleOperator {
((UnaryOperator)o).operator == operator; ((UnaryOperator)o).operator == operator;
} }
public String toString(String[] operands) { public void dumpExpression(TabbedPrintWriter writer,
return getOperatorString() + operands[0]; Expression[] operands)
throws java.io.IOException {
writer.print(getOperatorString());
operands[0].dumpExpression(writer, 700);
} }
} }

Loading…
Cancel
Save