Write the type of Object fields in structs as ref type instead of anyref.

This commit is contained in:
Volker Berlin 2019-04-26 17:28:57 +02:00
parent b08a986945
commit 272fa76af0
4 changed files with 25 additions and 9 deletions

View File

@ -569,11 +569,11 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
break;
case 180: // getfield
ref = (ConstantRef)constantPool.get( byteCode.readUnsignedShort() );
addStructInstruction( StructOperator.GET, ref.getClassName(), new NamedStorageType( ref ), codePos, lineNumber );
addStructInstruction( StructOperator.GET, ref.getClassName(), new NamedStorageType( ref, getTypeManager() ), codePos, lineNumber );
break;
case 181: // putfield
ref = (ConstantRef)constantPool.get( byteCode.readUnsignedShort() );
addStructInstruction( StructOperator.SET, ref.getClassName(), new NamedStorageType( ref ), codePos, lineNumber );
addStructInstruction( StructOperator.SET, ref.getClassName(), new NamedStorageType( ref, getTypeManager() ), codePos, lineNumber );
break;
case 182: // invokevirtual
case 183: // invokespecial, invoke a constructor

View File

@ -267,7 +267,7 @@ public class ModuleGenerator {
if( field.isStatic() ) {
continue;
}
list.add( new NamedStorageType( className, field ) );
list.add( new NamedStorageType( className, field, types ) );
}
}

View File

@ -116,6 +116,15 @@ public abstract class WasmCodeBuilder {
return localVariables.getTempVariable( valueType, startCodePosition, endCodePosition );
}
/**
* Get the type manager.
*
* @return the type manager
*/
protected TypeManager getTypeManager() {
return types;
}
/**
* Reset the code builder.
*

View File

@ -17,6 +17,7 @@ package de.inetsoftware.jwebassembly.wasm;
import de.inetsoftware.classparser.ConstantRef;
import de.inetsoftware.classparser.FieldInfo;
import de.inetsoftware.jwebassembly.module.TypeManager;
/**
* A ValueType with a name for debug information.
@ -38,9 +39,11 @@ public class NamedStorageType {
* the parent className of the field
* @param field
* the FieldInfo
* @param types
* the type manager
*/
public NamedStorageType( String className, FieldInfo field ) {
this( field.getType(), className, field.getName() );
public NamedStorageType( String className, FieldInfo field, TypeManager types ) {
this( field.getType(), className, field.getName(), types );
}
/**
@ -48,9 +51,11 @@ public class NamedStorageType {
*
* @param ref
* the reference
* @param types
* the type manager
*/
public NamedStorageType( ConstantRef ref ) {
this( ref.getType(), ref.getClassName(), ref.getName() );
public NamedStorageType( ConstantRef ref, TypeManager types ) {
this( ref.getType(), ref.getClassName(), ref.getName(), types );
}
/**
@ -62,9 +67,11 @@ public class NamedStorageType {
* the class name
* @param name
* the name
* @param types
* the type manager
*/
private NamedStorageType( String type, String className, String name ) {
this.type = new ValueTypeParser( type ).next();
private NamedStorageType( String type, String className, String name, TypeManager types ) {
this.type = new ValueTypeParser( type, types ).next();
this.className = className;
this.name = name;
}