Use TypeSignature instead of Type

getDefaultConstant added


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1138 379699f6-c40d-0410-875b-85095c16579e
branch_1_1
jochen 26 years ago
parent f4d9bae9f6
commit 4e007feb53
  1. 30
      jode/jode/obfuscator/ConstantRuntimeEnvironment.java.in

@ -23,9 +23,10 @@ import jode.jvm.SimpleRuntimeEnvironment;
import jode.jvm.InterpreterException; import jode.jvm.InterpreterException;
import jode.bytecode.Reference; import jode.bytecode.Reference;
import jode.bytecode.BytecodeInfo; import jode.bytecode.BytecodeInfo;
import jode.type.*; import jode.bytecode.TypeSignature;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import @COLLECTIONS@.Set; import @COLLECTIONS@.Set;
import @COLLECTIONS@.HashSet; import @COLLECTIONS@.HashSet;
@ -219,17 +220,35 @@ public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment {
interpreter = new Interpreter(this); interpreter = new Interpreter(this);
} }
public static Object getDefaultValue(String typeSig) {
switch(typeSig.charAt(0)) {
case 'Z':
case 'B':
case 'S':
case 'C':
case 'I':
return new Integer(0);
case 'J':
return new Long(0L);
case 'D':
return new Double(0.0);
case 'F':
return new Float(0.0F);
default:
return null;
}
}
public Object getField(Reference ref, Object obj) public Object getField(Reference ref, Object obj)
throws InterpreterException { throws InterpreterException {
if (isWhite(ref)) if (isWhite(ref))
return super.getField(ref, obj); return super.getField(ref, obj);
Type type = Type.tType(ref.getType());
FieldIdentifier fi FieldIdentifier fi
= (FieldIdentifier) Main.getClassBundle().getIdentifier(ref); = (FieldIdentifier) Main.getClassBundle().getIdentifier(ref);
if (fi != null && !fi.isNotConstant()) { if (fi != null && !fi.isNotConstant()) {
Object result = fi.getConstant(); Object result = fi.getConstant();
if (result == null) if (result == null)
result = type.getDefaultValue(); result = getDefaultValue(ref.getType());
return result; return result;
} }
throw new InterpreterException("Field " + ref + " not constant"); throw new InterpreterException("Field " + ref + " not constant");
@ -252,7 +271,6 @@ public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment {
throws InterpreterException, InvocationTargetException { throws InterpreterException, InvocationTargetException {
if (isWhite(ref)) if (isWhite(ref))
return super.invokeMethod(ref, isVirtual, cls, params); return super.invokeMethod(ref, isVirtual, cls, params);
Type type = Type.tType(ref.getType());
MethodIdentifier mi MethodIdentifier mi
= (MethodIdentifier) Main.getClassBundle().getIdentifier(ref); = (MethodIdentifier) Main.getClassBundle().getIdentifier(ref);
if (mi != null) { if (mi != null) {
@ -280,8 +298,8 @@ public class ConstantRuntimeEnvironment extends SimpleRuntimeEnvironment {
if (type.length() == dimensions.length + 1) { if (type.length() == dimensions.length + 1) {
Class clazz; Class clazz;
try { try {
clazz = Type.tType(type.substring(dimensions.length)) clazz = TypeSignature
.getTypeClass(); .getClass(type.substring(dimensions.length));
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
throw new InterpreterException throw new InterpreterException
("Class "+ex.getMessage()+" not found"); ("Class "+ex.getMessage()+" not found");

Loading…
Cancel
Save