*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@106 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 88fee293cb
commit a421adad08
  1. 16
      jode/jode/decompiler/ClassAnalyzer.java
  2. 3
      jode/jode/decompiler/CodeAnalyzer.java
  3. 47
      jode/jode/decompiler/FieldAnalyzer.java
  4. 54
      jode/jode/decompiler/MethodAnalyzer.java
  5. 1
      jode/jode/flow/VariableSet.java

@ -122,15 +122,23 @@ public class ClassAnalyzer implements Analyzer {
public Type getConstantType(int i) public Type getConstantType(int i)
throws ClassFormatError throws ClassFormatError
{ {
int t = classType.getConstant(i).getTag(); CpoolEntry constant = getConstant(i);
switch(t) { switch(constant.getTag()) {
case ConstantPool.INTEGER: return Type.tInt ; case ConstantPool.INTEGER: {
int value = ((CpoolValue1)constant).getValue();
return ((value < Short.MIN_VALUE || value > Character.MAX_VALUE)
? Type.tInt
: (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE)
? Type.tRange(Type.tInt, Type.tChar)
: Type.tUInt);
}
case ConstantPool.FLOAT : return Type.tFloat ; case ConstantPool.FLOAT : return Type.tFloat ;
case ConstantPool.LONG : return Type.tLong ; case ConstantPool.LONG : return Type.tLong ;
case ConstantPool.DOUBLE : return Type.tDouble; case ConstantPool.DOUBLE : return Type.tDouble;
case ConstantPool.STRING : return Type.tString; case ConstantPool.STRING : return Type.tString;
default: default:
throw new ClassFormatError("invalid constant type: "+t); throw new ClassFormatError("invalid constant type: "
+ constant.getTag());
} }
} }

@ -32,6 +32,7 @@ import gnu.bytecode.CodeAttr;
import gnu.bytecode.Attribute; import gnu.bytecode.Attribute;
import gnu.bytecode.LocalVarsAttr; import gnu.bytecode.LocalVarsAttr;
import gnu.bytecode.CpoolClass; import gnu.bytecode.CpoolClass;
import gnu.bytecode.Spy;
public class CodeAnalyzer implements Analyzer { public class CodeAnalyzer implements Analyzer {
@ -94,7 +95,7 @@ public class CodeAnalyzer implements Analyzer {
} }
handler = new TransformExceptionHandlers(instr); handler = new TransformExceptionHandlers(instr);
short[] handlers = gnu.bytecode.Spy.getExceptionHandlers(bincode); short[] handlers = Spy.getExceptionHandlers(bincode);
for (int i=0; i<handlers.length; i += 4) { for (int i=0; i<handlers.length; i += 4) {
Type type = null; Type type = null;

@ -21,50 +21,57 @@ package jode;
import java.lang.reflect.*; import java.lang.reflect.*;
import gnu.bytecode.Attribute; import gnu.bytecode.Attribute;
import gnu.bytecode.MiscAttr; import gnu.bytecode.MiscAttr;
import gnu.bytecode.Spy;
public class FieldAnalyzer implements Analyzer { public class FieldAnalyzer implements Analyzer {
ClassAnalyzer clazz; ClassAnalyzer clazz;
int constantValue;
Field field;
JodeEnvironment env; JodeEnvironment env;
int modifiers;
Type type;
String fieldName;
ConstOperator constant;
public FieldAnalyzer(ClassAnalyzer cla, Field fd, JodeEnvironment e) public FieldAnalyzer(ClassAnalyzer cla, Field fd, JodeEnvironment e)
{ {
clazz = cla; clazz = cla;
field = fd;
env = e; env = e;
}
public void analyze() { modifiers = fd.getModifiers();
Type.tType(field.getType()).useType(); type = Type.tType(fd.getType());
constantValue = 0; fieldName = fd.getName();
constant = null;
Attribute attribute = Attribute attribute =
Attribute.get(clazz.classType.getField(field.getName()), Attribute.get(clazz.classType.getField(fieldName),
"ConstantValue"); "ConstantValue");
if (attribute != null) { if (attribute != null) {
byte[] data = gnu.bytecode.Spy.getAttribute((MiscAttr)attribute); try {
constantValue = (unsigned(data[0]) << 8) | unsigned(data[1]); int index = Spy.getAttributeStream((MiscAttr)attribute)
.readUnsignedShort();
constant = new ConstOperator
(type.intersection(cla.getConstantType(index)),
cla.getConstantString(index));
} catch (java.io.IOException ex) {
throw new AssertError("attribute too small");
}
} }
} }
private final int unsigned(byte value) { public void analyze() {
if (value < 0) type.useType();
return value + 256;
else
return value;
} }
public void dumpSource(TabbedPrintWriter writer) public void dumpSource(TabbedPrintWriter writer)
throws java.io.IOException throws java.io.IOException
{ {
String modif = Modifier.toString(field.getModifiers()); String modif = Modifier.toString(modifiers);
if (modif.length() > 0) if (modif.length() > 0)
writer.print(modif+" "); writer.print(modif+" ");
writer.print(Type.tType(field.getType()).toString() writer.print(type.toString() + " " + fieldName);
+ " " + field.getName()); if (constant != null) {
if (constantValue != 0) { writer.print(" = " + constant.toString());
writer.print(" = "+clazz.getConstantString(constantValue));
} }
writer.println(";"); writer.println(";");
} }

@ -21,6 +21,9 @@ package jode;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import gnu.bytecode.Attribute; import gnu.bytecode.Attribute;
import gnu.bytecode.CodeAttr; import gnu.bytecode.CodeAttr;
import gnu.bytecode.CpoolClass;
import gnu.bytecode.Method;
import gnu.bytecode.MiscAttr;
import gnu.bytecode.Spy; import gnu.bytecode.Spy;
public class MethodAnalyzer implements Analyzer { public class MethodAnalyzer implements Analyzer {
@ -33,52 +36,7 @@ public class MethodAnalyzer implements Analyzer {
MethodType methodType; MethodType methodType;
Type[] exceptions; Type[] exceptions;
// private MethodAnalyzer(ClassAnalyzer cla, Method m, Constructor c, public MethodAnalyzer(ClassAnalyzer cla, Method mdef,
// JodeEnvironment e)
// {
// classAnalyzer = cla;
// isConstructor = (c != null);
// env = e;
// this.modifiers = isConstructor
// ? c.getModifiers() : m.getModifiers();
// {
// Class[] exceptClasses = isConstructor
// ? c.getExceptionTypes() : m.getExceptionTypes();
// this.exceptions = new Type[exceptClasses.length];
// for (int i=0; i< exceptClasses.length; i++)
// exceptions[i] = Type.tType(exceptClasses[i]);
// }
// {
// Class[] paramTypes = (isConstructor
// ? c.getParameterTypes()
// : m.getParameterTypes());
// Class returnType = (isConstructor
// ? Void.TYPE : m.getReturnType());
// methodType = new MethodType
// (!isConstructor && Modifier.isStatic(modifiers),
// paramTypes, returnType);
// methodName = isConstructor ? "<init>" : m.getName();
// }
// gnu.bytecode.Method mdef;
// for (mdef = cla.classType.getMethods(); ; mdef = mdef.getNext()) {
// if (mdef.getName().equals(methodName)) {
// MethodType type = new MethodType(mdef.getStaticFlag(),
// mdef.getSignature());
// if (type.equals(methodType))
// break;
// }
// }
// Attribute attr = Attribute.get(mdef, "Code");
// if (attr != null && attr instanceof CodeAttr)
// code = new CodeAnalyzer(this, (CodeAttr) attr, env);
// }
public MethodAnalyzer(ClassAnalyzer cla, gnu.bytecode.Method mdef,
JodeEnvironment env) { JodeEnvironment env) {
this.classAnalyzer = cla; this.classAnalyzer = cla;
this.env = env; this.env = env;
@ -98,13 +56,13 @@ public class MethodAnalyzer implements Analyzer {
exceptions = new Type[0]; exceptions = new Type[0];
} else { } else {
java.io.DataInputStream stream = Spy.getAttributeStream java.io.DataInputStream stream = Spy.getAttributeStream
((gnu.bytecode.MiscAttr) excattr); ((MiscAttr) excattr);
try { try {
int throwCount = stream.readUnsignedShort(); int throwCount = stream.readUnsignedShort();
this.exceptions = new Type[throwCount]; this.exceptions = new Type[throwCount];
for (int t=0; t< throwCount; t++) { for (int t=0; t< throwCount; t++) {
int idx = stream.readUnsignedShort(); int idx = stream.readUnsignedShort();
gnu.bytecode.CpoolClass cpcls = (gnu.bytecode.CpoolClass) CpoolClass cpcls = (CpoolClass)
classAnalyzer.getConstant(idx); classAnalyzer.getConstant(idx);
exceptions[t] = Type.tClass(cpcls.getName().getString()); exceptions[t] = Type.tClass(cpcls.getName().getString());
} }

@ -34,6 +34,7 @@ public class VariableSet extends java.util.Vector {
* Creates a new empty variable set * Creates a new empty variable set
*/ */
public VariableSet() { public VariableSet() {
super(0, 0);
} }
/** /**

Loading…
Cancel
Save