From 1fdcae519187914ae75abb1a418e9fd17ecd4556 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sun, 27 Oct 2019 19:41:43 +0100 Subject: [PATCH] expand the hierarchy of SyntheticFunctionName for future improvements --- .../JavaScriptSyntheticFunctionName.java | 4 +- .../module/ArraySyntheticFunctionName.java | 55 +++++++++++++++++++ .../module/SyntheticFunctionName.java | 18 +----- .../module/WatCodeSyntheticFunctionName.java | 2 +- 4 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 src/de/inetsoftware/jwebassembly/module/ArraySyntheticFunctionName.java diff --git a/src/de/inetsoftware/jwebassembly/javascript/JavaScriptSyntheticFunctionName.java b/src/de/inetsoftware/jwebassembly/javascript/JavaScriptSyntheticFunctionName.java index 1d68a1d..81929f7 100644 --- a/src/de/inetsoftware/jwebassembly/javascript/JavaScriptSyntheticFunctionName.java +++ b/src/de/inetsoftware/jwebassembly/javascript/JavaScriptSyntheticFunctionName.java @@ -19,7 +19,7 @@ package de.inetsoftware.jwebassembly.javascript; import java.util.function.Function; import java.util.function.Supplier; -import de.inetsoftware.jwebassembly.module.SyntheticFunctionName; +import de.inetsoftware.jwebassembly.module.ArraySyntheticFunctionName; import de.inetsoftware.jwebassembly.wasm.AnyType; /** @@ -28,7 +28,7 @@ import de.inetsoftware.jwebassembly.wasm.AnyType; * @author Volker Berlin * */ -public class JavaScriptSyntheticFunctionName extends SyntheticFunctionName { +public class JavaScriptSyntheticFunctionName extends ArraySyntheticFunctionName { private final Supplier js; diff --git a/src/de/inetsoftware/jwebassembly/module/ArraySyntheticFunctionName.java b/src/de/inetsoftware/jwebassembly/module/ArraySyntheticFunctionName.java new file mode 100644 index 0000000..440af2d --- /dev/null +++ b/src/de/inetsoftware/jwebassembly/module/ArraySyntheticFunctionName.java @@ -0,0 +1,55 @@ +/* + Copyright 2019 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. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ +package de.inetsoftware.jwebassembly.module; + +import java.util.Arrays; +import java.util.Iterator; + +import de.inetsoftware.jwebassembly.wasm.AnyType; + +/** + * Synthetic/dynamic method with a signature as array of types. + * + * @author Volker Berlin + */ +public abstract class ArraySyntheticFunctionName extends SyntheticFunctionName { + + private final AnyType[] signature; + + /** + * Create a new instance. + * + * @param className + * the Java class name + * @param name + * the function name + * @param signature + * the method signature, first the parameters, then null and the the return types + */ + public ArraySyntheticFunctionName( String className, String name, AnyType... signature ) { + super( className, name, "()V" ); //TODO better signature name + this.signature = signature; + } + + /** + * {@inheritDoc} + */ + @Override + public Iterator getSignature( TypeManager types ) { + return Arrays.asList( signature ).iterator(); + } +} diff --git a/src/de/inetsoftware/jwebassembly/module/SyntheticFunctionName.java b/src/de/inetsoftware/jwebassembly/module/SyntheticFunctionName.java index 57609ab..bc08945 100644 --- a/src/de/inetsoftware/jwebassembly/module/SyntheticFunctionName.java +++ b/src/de/inetsoftware/jwebassembly/module/SyntheticFunctionName.java @@ -16,11 +16,8 @@ */ package de.inetsoftware.jwebassembly.module; -import java.util.Arrays; -import java.util.Iterator; import java.util.function.Function; -import de.inetsoftware.jwebassembly.wasm.AnyType; import de.inetsoftware.jwebassembly.watparser.WatParser; /** @@ -30,8 +27,6 @@ import de.inetsoftware.jwebassembly.watparser.WatParser; */ public abstract class SyntheticFunctionName extends FunctionName { - private final AnyType[] signature; - /** * Create a new instance. * @@ -42,17 +37,8 @@ public abstract class SyntheticFunctionName extends FunctionName { * @param signature * the method signature, first the parameters, then null and the the return types */ - public SyntheticFunctionName( String className, String name, AnyType... signature ) { - super( className, name, "()V" ); //TODO better signature name - this.signature = signature; - } - - /** - * {@inheritDoc} - */ - @Override - public Iterator getSignature( TypeManager types ) { - return Arrays.asList( signature ).iterator(); + public SyntheticFunctionName( String className, String name, String signature ) { + super( className, name, signature ); } /** diff --git a/src/de/inetsoftware/jwebassembly/module/WatCodeSyntheticFunctionName.java b/src/de/inetsoftware/jwebassembly/module/WatCodeSyntheticFunctionName.java index f6e4a9a..5dd3746 100644 --- a/src/de/inetsoftware/jwebassembly/module/WatCodeSyntheticFunctionName.java +++ b/src/de/inetsoftware/jwebassembly/module/WatCodeSyntheticFunctionName.java @@ -24,7 +24,7 @@ import de.inetsoftware.jwebassembly.watparser.WatParser; * * @author Volker Berlin */ -class WatCodeSyntheticFunctionName extends SyntheticFunctionName { +class WatCodeSyntheticFunctionName extends ArraySyntheticFunctionName { private final String code;