attribute handling in bytecode

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

@ -21,49 +21,22 @@ package jode.decompiler;
import java.io.*;
import jode.Decompiler;
import jode.type.Type;
import jode.bytecode.AttributeInfo;
import jode.bytecode.ConstantPool;
import jode.bytecode.LocalVariableInfo;
public class LocalVariableTable {
LocalVariableRangeList[] locals;
public LocalVariableTable(int size, ConstantPool constantPool,
AttributeInfo attr) {
locals = new LocalVariableRangeList[size];
for (int i=0; i<size; i++)
public LocalVariableTable(int maxLocals, LocalVariableInfo[] lvt) {
locals = new LocalVariableRangeList[maxLocals];
for (int i=0; i < maxLocals; i++)
locals[i] = new LocalVariableRangeList(i);
DataInputStream stream = new DataInputStream
(new ByteArrayInputStream(attr.getContents()));
try {
int count = stream.readUnsignedShort();
for (int i=0; i < count; i++) {
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);
}
for (int i=0; i<lvt.length; i++) {
int length = (lvt[i].end.addr + lvt[i].end.length
- lvt[i].start.addr);
locals[lvt[i].slot].addLocal(lvt[i].start.addr, length,
lvt[i].name, Type.tType(lvt[i].type));
}
}
public LocalVariableRangeList getLocal(int slot)

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

Loading…
Cancel
Save