attribute handling in bytecode

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@631 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 863e1410b2
commit 78eb752b08
  1. 45
      jode/jode/decompiler/LocalVariableTable.java
  2. 32
      jode/jode/decompiler/MethodAnalyzer.java

@ -21,48 +21,21 @@ package jode.decompiler;
import java.io.*; import java.io.*;
import jode.Decompiler; import jode.Decompiler;
import jode.type.Type; import jode.type.Type;
import jode.bytecode.AttributeInfo; import jode.bytecode.LocalVariableInfo;
import jode.bytecode.ConstantPool;
public class LocalVariableTable { public class LocalVariableTable {
LocalVariableRangeList[] locals; LocalVariableRangeList[] locals;
public LocalVariableTable(int size, ConstantPool constantPool, public LocalVariableTable(int maxLocals, LocalVariableInfo[] lvt) {
AttributeInfo attr) { locals = new LocalVariableRangeList[maxLocals];
for (int i=0; i < maxLocals; i++)
locals = new LocalVariableRangeList[size];
for (int i=0; i<size; i++)
locals[i] = new LocalVariableRangeList(i); locals[i] = new LocalVariableRangeList(i);
DataInputStream stream = new DataInputStream for (int i=0; i<lvt.length; i++) {
(new ByteArrayInputStream(attr.getContents())); int length = (lvt[i].end.addr + lvt[i].end.length
try { - lvt[i].start.addr);
int count = stream.readUnsignedShort(); locals[lvt[i].slot].addLocal(lvt[i].start.addr, length,
for (int i=0; i < count; i++) { lvt[i].name, Type.tType(lvt[i].type));
int start = stream.readUnsignedShort();
int end = start + stream.readUnsignedShort();
int nameIndex = stream.readUnsignedShort();
int typeIndex = stream.readUnsignedShort();
if (nameIndex == 0 || typeIndex == 0
|| constantPool.getTag(nameIndex) != constantPool.UTF8
|| constantPool.getTag(typeIndex) != constantPool.UTF8) {
// This is probably an evil lvt as created by HashJava
// simply ignore it.
if (Decompiler.showLVT)
Decompiler.err.println("Illegal entry, ignoring LVT");
return;
}
String name = constantPool.getUTF8(nameIndex);
Type type = Type.tType(constantPool.getUTF8(typeIndex));
int slot = stream.readUnsignedShort();
locals[slot].addLocal(start, end-start, name, type);
if (Decompiler.showLVT)
Decompiler.err.println("\t"+name + ": " + type
+" range "+start+" - "+end
+" slot "+slot);
}
} catch (IOException ex) {
ex.printStackTrace(Decompiler.err);
} }
} }

@ -19,7 +19,6 @@
package jode.decompiler; package jode.decompiler;
import jode.bytecode.MethodInfo; import jode.bytecode.MethodInfo;
import jode.bytecode.AttributeInfo;
import jode.type.Type; import jode.type.Type;
import jode.type.*; import jode.type.*;
import jode.AssertError; import jode.AssertError;
@ -47,36 +46,23 @@ public class MethodAnalyzer implements Analyzer {
this.classAnalyzer = cla; this.classAnalyzer = cla;
this.imports = imports; this.imports = imports;
this.modifiers = minfo.getModifiers(); this.modifiers = minfo.getModifiers();
this.methodType = minfo.getType(); this.methodType = Type.tMethod(minfo.getType());
this.methodName = minfo.getName(); this.methodName = minfo.getName();
this.isStatic = minfo.isStatic(); this.isStatic = minfo.isStatic();
this.isConstructor = this.isConstructor =
methodName.equals("<init>") || methodName.equals("<clinit>"); methodName.equals("<init>") || methodName.equals("<clinit>");
this.isSynthetic = (minfo.findAttribute("Synthetic") != null); this.isSynthetic = minfo.isSynthetic();
this.isDeprecated = (minfo.findAttribute("Deprecated") != null); this.isDeprecated = minfo.isDeprecated();
AttributeInfo codeattr = minfo.findAttribute("Code"); code = new CodeAnalyzer(this, minfo, imports);
if (codeattr != null) { String[] excattr = minfo.getExceptions();
code = new CodeAnalyzer(this, minfo, codeattr, imports);
}
AttributeInfo excattr = minfo.findAttribute("Exceptions");
if (excattr == null) { if (excattr == null) {
exceptions = new Type[0]; exceptions = new Type[0];
} else { } else {
DataInputStream stream = new DataInputStream int excCount = excattr.length;
(new ByteArrayInputStream(excattr.getContents())); this.exceptions = new Type[excCount];
try { for (int i=0; i< excCount; i++)
int throwCount = stream.readUnsignedShort(); exceptions[i] = Type.tClass(excattr[i]);
this.exceptions = new Type[throwCount];
for (int t=0; t< throwCount; t++) {
int idx = stream.readUnsignedShort();
exceptions[t] = Type.tClass(classAnalyzer.getConstantPool()
.getClassName(idx));
}
} catch (IOException ex) {
throw new AssertError("exception attribute too long?");
}
} }
} }

Loading…
Cancel
Save