From c269bae44364b5a48eeade81eaf945841365aaeb Mon Sep 17 00:00:00 2001
From: Volker <Volker@Volker.fritz.box>
Date: Tue, 14 Aug 2018 12:14:36 +0200
Subject: [PATCH] Move method getValueType() into class ValueType.

---
 .../jwebassembly/module/ModuleGenerator.java  | 43 ++-----------------
 .../jwebassembly/module/ValueType.java        | 42 +++++++++++++++++-
 .../module/WasmCallInstruction.java           |  4 +-
 3 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java
index 3b6708c..6d72e8d 100644
--- a/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java
+++ b/src/de/inetsoftware/jwebassembly/module/ModuleGenerator.java
@@ -221,7 +221,7 @@ public class ModuleGenerator {
                 kind = "result";
                 continue;
             }
-            type = getValueType( signature, i );
+            type = ValueType.getValueType( signature, i );
             if( type != null ) {
                 writer.writeMethodParam( kind, type );
             }
@@ -230,43 +230,6 @@ public class ModuleGenerator {
         writer.writeMethodParamFinish();
     }
 
-    /**
-     * Get the WebAssembly value type from a Java signature.
-     * 
-     * @param signature
-     *            the signature
-     * @param idx
-     *            the index in the signature
-     * @return the value type or null if void
-     */
-    static ValueType getValueType( String signature, int idx ) {
-        String javaType;
-        switch( signature.charAt( idx ) ) {
-            case '[': // array
-                javaType = "array";
-                break;
-            case 'L':
-                javaType = "object";
-                break;
-            case 'B': // byte
-            case 'C': // char
-            case 'S': // short
-            case 'I': // int
-                return ValueType.i32;
-            case 'D': // double
-                return ValueType.f64;
-            case 'F': // float
-                return ValueType.f32;
-            case 'J': // long
-                return ValueType.i64;
-            case 'V': // void
-                return null;
-            default:
-                javaType = signature.substring( idx, idx + 1 );
-        }
-        throw new WasmException( "Not supported Java data type in method signature: " + javaType, null, -1 );
-    }
-
     /**
      * Write the byte code of a method.
      * 
@@ -693,8 +656,8 @@ public class ModuleGenerator {
                     //TODO case 183: // invokespecial
                     case 184: // invokestatic
                         idx = byteCode.readUnsignedShort();
-                        ConstantRef method = (ConstantRef)constantPool.get( idx );
-                        instr = new WasmCallInstruction( method, codePos );
+                        ref = (ConstantRef)constantPool.get( idx );
+                        instr = new WasmCallInstruction( ref, codePos );
                         break;
                     //TODO case 185: // invokeinterface
                     //TODO case 187: // new
diff --git a/src/de/inetsoftware/jwebassembly/module/ValueType.java b/src/de/inetsoftware/jwebassembly/module/ValueType.java
index 0f390d5..b637312 100644
--- a/src/de/inetsoftware/jwebassembly/module/ValueType.java
+++ b/src/de/inetsoftware/jwebassembly/module/ValueType.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Volker Berlin (i-net software)
+ * Copyright 2017 - 2018 Volker Berlin (i-net software)
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
  */
 package de.inetsoftware.jwebassembly.module;
 
+import de.inetsoftware.jwebassembly.WasmException;
+
 /**
  * @author Volker Berlin
  */
@@ -49,4 +51,42 @@ public enum ValueType {
     public int getCode() {
         return code;
     }
+
+    /**
+     * Get the WebAssembly value type from a Java signature.
+     * 
+     * @param javaSignature
+     *            the signature
+     * @param idx
+     *            the index in the signature
+     * @return the value type or null if void
+     */
+    public static ValueType getValueType( String javaSignature, int idx ) {
+        String javaType;
+        switch( javaSignature.charAt( idx ) ) {
+            case '[': // array
+                javaType = "array";
+                break;
+            case 'L':
+                javaType = "object";
+                break;
+            case 'B': // byte
+            case 'C': // char
+            case 'S': // short
+            case 'I': // int
+                return ValueType.i32;
+            case 'D': // double
+                return ValueType.f64;
+            case 'F': // float
+                return ValueType.f32;
+            case 'J': // long
+                return ValueType.i64;
+            case 'V': // void
+                return null;
+            default:
+                javaType = javaSignature.substring( idx, idx + 1 );
+        }
+        throw new WasmException( "Not supported Java data type in method signature: " + javaType, null, -1 );
+    }
+
 }
diff --git a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java
index 11c81e0..4d812ee 100644
--- a/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java
+++ b/src/de/inetsoftware/jwebassembly/module/WasmCallInstruction.java
@@ -46,7 +46,7 @@ class WasmCallInstruction extends WasmInstruction {
         super( javaCodePos );
         this.method = method;
         String signature = method.getType();
-        this.valueType = ModuleGenerator.getValueType(  signature, signature.indexOf( ')' ) + 1 );
+        this.valueType = ValueType.getValueType(  signature, signature.indexOf( ')' ) + 1 );
     }
 
     /**
@@ -77,7 +77,7 @@ class WasmCallInstruction extends WasmInstruction {
                 return paramCount;
             }
             paramCount++;
-            ModuleGenerator.getValueType(  signature, i );
+            ValueType.getValueType(  signature, i );
         }
         throw new Error(); 
     }