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; break;
case 180: // getfield case 180: // getfield
ref = (ConstantRef)constantPool.get( byteCode.readUnsignedShort() ); 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; break;
case 181: // putfield case 181: // putfield
ref = (ConstantRef)constantPool.get( byteCode.readUnsignedShort() ); 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; break;
case 182: // invokevirtual case 182: // invokevirtual
case 183: // invokespecial, invoke a constructor case 183: // invokespecial, invoke a constructor

View File

@ -267,7 +267,7 @@ public class ModuleGenerator {
if( field.isStatic() ) { if( field.isStatic() ) {
continue; 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 ); return localVariables.getTempVariable( valueType, startCodePosition, endCodePosition );
} }
/**
* Get the type manager.
*
* @return the type manager
*/
protected TypeManager getTypeManager() {
return types;
}
/** /**
* Reset the code builder. * Reset the code builder.
* *

View File

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