mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
parse InvokeDynamic constants
This commit is contained in:
parent
81c865706c
commit
431d5f5a4a
63
src/de/inetsoftware/classparser/ConstantInvokeDynamic.java
Normal file
63
src/de/inetsoftware/classparser/ConstantInvokeDynamic.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2019 Volker Berlin (i-net software)
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Volker Berlin
|
||||||
|
*/
|
||||||
|
public class ConstantInvokeDynamic implements Member {
|
||||||
|
|
||||||
|
private final ConstantNameAndType nameAndType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke dynamic info in the constant pool.
|
||||||
|
* https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.4.10
|
||||||
|
*
|
||||||
|
* @param bootstrapMethodAttrIndex
|
||||||
|
* a valid index into the bootstrap_methods array of the bootstrap method table
|
||||||
|
* @param nameAndType
|
||||||
|
* the name and type
|
||||||
|
*/
|
||||||
|
ConstantInvokeDynamic( int bootstrapMethodAttrIndex, ConstantNameAndType nameAndType ) {
|
||||||
|
this.nameAndType = nameAndType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return nameAndType.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getClassName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type of the method. For example "(Ljava.lang.String;)I"
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return nameAndType.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,8 +27,7 @@ public class ConstantPool {
|
|||||||
private final Object[] constantPool;
|
private final Object[] constantPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4
|
* https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.4
|
||||||
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#20080
|
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
* the stream of the class
|
* the stream of the class
|
||||||
@ -60,6 +59,7 @@ public class ConstantPool {
|
|||||||
break;
|
break;
|
||||||
case 7: //CONSTANT_Class
|
case 7: //CONSTANT_Class
|
||||||
case 8: //CONSTANT_String
|
case 8: //CONSTANT_String
|
||||||
|
case 16: // CONSTANT_MethodType
|
||||||
case 19: // CONSTANT_Module
|
case 19: // CONSTANT_Module
|
||||||
case 20: // CONSTANT_Package
|
case 20: // CONSTANT_Package
|
||||||
pool[i] = new int[] { type, input.readUnsignedShort() };
|
pool[i] = new int[] { type, input.readUnsignedShort() };
|
||||||
@ -68,8 +68,12 @@ public class ConstantPool {
|
|||||||
case 10: //CONSTANT_Methodref
|
case 10: //CONSTANT_Methodref
|
||||||
case 11: //CONSTANT_InterfaceMethodref
|
case 11: //CONSTANT_InterfaceMethodref
|
||||||
case 12: //CONSTANT_NameAndType
|
case 12: //CONSTANT_NameAndType
|
||||||
|
case 18: // CONSTANT_InvokeDynamic
|
||||||
pool[i] = new int[] { type, input.readUnsignedShort(), input.readUnsignedShort() };
|
pool[i] = new int[] { type, input.readUnsignedShort(), input.readUnsignedShort() };
|
||||||
break;
|
break;
|
||||||
|
case 15: // CONSTANT_MethodHandle
|
||||||
|
pool[i] = new int[] { type, input.readUnsignedByte(), input.readUnsignedShort() };
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IOException( "Unknown constant pool type: " + type );
|
throw new IOException( "Unknown constant pool type: " + type );
|
||||||
}
|
}
|
||||||
@ -85,7 +89,8 @@ public class ConstantPool {
|
|||||||
case 7: //CONSTANT_Class
|
case 7: //CONSTANT_Class
|
||||||
pool[i] = new ConstantClass( (String)pool[data[1]] );
|
pool[i] = new ConstantClass( (String)pool[data[1]] );
|
||||||
break;
|
break;
|
||||||
case 8: //CONSTANT_String
|
case 8: // CONSTANT_String
|
||||||
|
case 16: // CONSTANT_MethodType
|
||||||
case 19: // CONSTANT_Module
|
case 19: // CONSTANT_Module
|
||||||
case 20: // CONSTANT_Package
|
case 20: // CONSTANT_Package
|
||||||
pool[i] = pool[data[1]];
|
pool[i] = pool[data[1]];
|
||||||
@ -114,6 +119,12 @@ public class ConstantPool {
|
|||||||
case 12: //CONSTANT_NameAndType
|
case 12: //CONSTANT_NameAndType
|
||||||
pool[i] = new ConstantNameAndType( (String)pool[data[1]], (String)pool[data[2]] );
|
pool[i] = new ConstantNameAndType( (String)pool[data[1]], (String)pool[data[2]] );
|
||||||
break;
|
break;
|
||||||
|
case 15: // CONSTANT_MethodHandle
|
||||||
|
pool[i] = pool[data[2]];
|
||||||
|
break;
|
||||||
|
case 18: // CONSTANT_InvokeDynamic
|
||||||
|
pool[i] = new ConstantInvokeDynamic( data[1], (ConstantNameAndType)pool[data[2]] );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IOException( "Unknown constant pool type: " + data[0] );
|
throw new IOException( "Unknown constant pool type: " + data[0] );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user