From a2a185be8a92448a14ece6be67f738886c38dbd4 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Mon, 22 Apr 2019 21:24:22 +0200 Subject: [PATCH] Search className and fieldName separately --- .../module/WasmStructInstruction.java | 18 +++++++++++++++++- .../jwebassembly/wasm/NamedStorageType.java | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java index 9425527..bc86fe6 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmStructInstruction.java @@ -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 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 ); } diff --git a/src/de/inetsoftware/jwebassembly/wasm/NamedStorageType.java b/src/de/inetsoftware/jwebassembly/wasm/NamedStorageType.java index 9fe9938..b7f2c6c 100644 --- a/src/de/inetsoftware/jwebassembly/wasm/NamedStorageType.java +++ b/src/de/inetsoftware/jwebassembly/wasm/NamedStorageType.java @@ -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