From 238a281757142fa17e62d58330a3dac5582bffc7 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Fri, 18 Jan 2019 18:17:19 +0100 Subject: [PATCH] Move the call to ValueTypeParser into the FunctionName --- .../jwebassembly/module/FunctionName.java | 16 +++++++++++++++- .../jwebassembly/module/ModuleGenerator.java | 3 +-- .../jwebassembly/module/WasmCallInstruction.java | 6 +----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/module/FunctionName.java b/src/de/inetsoftware/jwebassembly/module/FunctionName.java index a552ac8..ddb2e83 100644 --- a/src/de/inetsoftware/jwebassembly/module/FunctionName.java +++ b/src/de/inetsoftware/jwebassembly/module/FunctionName.java @@ -16,9 +16,13 @@ */ package de.inetsoftware.jwebassembly.module; +import java.util.Iterator; + import javax.annotation.Nonnull; import de.inetsoftware.classparser.Member; +import de.inetsoftware.jwebassembly.wasm.AnyType; +import de.inetsoftware.jwebassembly.wasm.ValueTypeParser; /** * Described the name of WebAssembly function. @@ -50,7 +54,7 @@ public class FunctionName { * The signature */ @Nonnull - public final String signature; + private final String signature; /** * Create a new instance from the given reference in the ConstantPool or parsed method. @@ -116,4 +120,14 @@ public class FunctionName { FunctionName other = (FunctionName)obj; return signatureName.equals( other.signatureName ); } + + /** + * Get the method signature iterator for parameter and return values. + * + * @return the iterator + */ + @Nonnull + public Iterator getSignature() { + return new ValueTypeParser( signature ); + } } diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java index 16b17fa..a8d0d58 100644 --- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java +++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java @@ -350,12 +350,11 @@ public class ModuleGenerator { * if some Java code can't converted */ private void writeMethodSignature( FunctionName name, boolean isStatic, @Nullable LocalVariableTable variables, WasmCodeBuilder codeBuilder ) throws IOException, WasmException { - String signature = name.signature; int paramCount = 0; if( !isStatic ) { writer.writeMethodParam( "param", ValueType.anyref, "this" ); } - Iterator parser = new ValueTypeParser( signature ); + Iterator parser = name.getSignature(); AnyType type; for( String kind : new String[] {"param","result"}) { while( parser.hasNext() && (type = parser.next()) != null ) { diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java index 68d0db4..16beda0 100644 --- a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java +++ b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java @@ -24,7 +24,6 @@ import javax.annotation.Nonnull; import de.inetsoftware.classparser.Member; import de.inetsoftware.jwebassembly.wasm.AnyType; import de.inetsoftware.jwebassembly.wasm.ValueType; -import de.inetsoftware.jwebassembly.wasm.ValueTypeParser; /** * WasmInstruction for a function call. @@ -34,8 +33,6 @@ import de.inetsoftware.jwebassembly.wasm.ValueTypeParser; */ class WasmCallInstruction extends WasmInstruction { - private final Member method; - private ValueType valueType; private final FunctionName name; @@ -52,7 +49,6 @@ class WasmCallInstruction extends WasmInstruction { */ WasmCallInstruction( Member method, int javaCodePos ) { super( javaCodePos ); - this.method = method; this.name = new FunctionName( method ); } @@ -105,7 +101,7 @@ class WasmCallInstruction extends WasmInstruction { if( paramCount >= 0 ) { return; } - Iterator parser = new ValueTypeParser( method.getType() ); + Iterator parser = name.getSignature(); paramCount = 0; while( parser.next() != null ) { paramCount++;