mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 18:44:47 +01:00
Search className and fieldName separately
This commit is contained in:
parent
3e9e1e1601
commit
a2a185be8a
@ -17,6 +17,7 @@
|
||||
package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -93,7 +94,22 @@ class WasmStructInstruction extends WasmInstruction {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
int idx = type != null && fieldName != null ? type.getFields().indexOf( fieldName ) : -1;
|
||||
int idx = -1;
|
||||
if( type != null && fieldName != null ) {
|
||||
// The fieldName of the struct operation does not contain the class name in which the field was declared. It contains the class name of the variable. This can be the class or a subclass.
|
||||
List<NamedStorageType> fields = type.getFields();
|
||||
boolean classNameMatched = false;
|
||||
for( int i = fields.size()-1; i >= 0; i-- ) {
|
||||
NamedStorageType field = fields.get( i );
|
||||
if( !classNameMatched && field.geClassName().equals( fieldName.geClassName() ) ) {
|
||||
classNameMatched = true;
|
||||
}
|
||||
if( classNameMatched && field.getName().equals( fieldName.getName() ) ) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.writeStructOperator( op, type, fieldName, idx );
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,15 @@ public class NamedStorageType {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name in which the filed is define.
|
||||
*
|
||||
* @return the field
|
||||
*/
|
||||
public String geClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the global unique name of the field. See
|
||||
* https://github.com/lars-t-hansen/moz-gc-experiments/blob/master/version2.md#struct-and-ref-types
|
||||
|
Loading…
x
Reference in New Issue
Block a user