add getPosition() to LocalVariable

This commit is contained in:
Volker Berlin 2017-04-09 22:21:47 +02:00
parent 14dc89aacb
commit 68aaa5c589
2 changed files with 231 additions and 219 deletions

View File

@ -34,11 +34,9 @@ public class LocalVariable {
private int index; private int index;
private boolean declared; private int position;
protected LocalVariable() { private boolean declared;
// nothing
}
/** /**
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13 * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13
@ -47,23 +45,35 @@ public class LocalVariable {
* @param input * @param input
* the stream of the class * the stream of the class
* @throws IOException * @throws IOException
* if any I/O error occurs.
*/ */
LocalVariable( DataInputStream input ) throws IOException { LocalVariable( DataInputStream input, int position ) throws IOException {
start_pc = input.readUnsignedShort(); start_pc = input.readUnsignedShort();
length = input.readUnsignedShort(); length = input.readUnsignedShort();
name_index = input.readUnsignedShort(); name_index = input.readUnsignedShort();
descriptor_index = input.readUnsignedShort(); descriptor_index = input.readUnsignedShort();
index = input.readUnsignedShort(); index = input.readUnsignedShort();
this.position = position;
} }
/** /**
* Get the index in the local variable table. * Get the index in the local variable table (memory location/slot).
*
* @return the index. * @return the index.
*/ */
public int getIndex() { public int getIndex() {
return index; return index;
} }
/**
* Get the position in the local variable table.
*
* @return the position
*/
public int getPosition() {
return position;
}
/** /**
* Get the name of the variable * Get the name of the variable
* @param constantPool ConstantPool of the current class * @param constantPool ConstantPool of the current class

View File

@ -47,8 +47,10 @@ public class LocalVariableTable {
* *
* @param input * @param input
* the stream of the class * the stream of the class
* @param withPositions a hack if we find a better solution to map the positions LocalVariableTypeTable * @param withPositions
* a hack if we find a better solution to map the positions LocalVariableTypeTable
* @throws IOException * @throws IOException
* if any I/O error occurs.
*/ */
void read( DataInputStream input, boolean withPositions ) throws IOException { void read( DataInputStream input, boolean withPositions ) throws IOException {
count = input.readUnsignedShort(); count = input.readUnsignedShort();
@ -57,7 +59,7 @@ public class LocalVariableTable {
tablePosition = new LocalVariable[count]; tablePosition = new LocalVariable[count];
} }
for( int i = 0; i < count; i++ ) { for( int i = 0; i < count; i++ ) {
LocalVariable var = new LocalVariable( input ); LocalVariable var = new LocalVariable( input, i );
int idx = var.getIndex(); int idx = var.getIndex();
if( withPositions ) { if( withPositions ) {
tablePosition[i] = var; tablePosition[i] = var;
@ -95,7 +97,7 @@ public class LocalVariableTable {
} }
/** /**
* Get the LocalVariable with its memory location. The index has empty places with double and long variables. * Get the LocalVariable with its memory location (slot). The index has empty places with double and long variables.
* *
* @param idx * @param idx
* the index in the memory * the index in the memory