add isSubTypeOf(9 to the type hierarchy

This commit is contained in:
Volker Berlin 2020-04-10 21:05:46 +02:00
parent bab77094c2
commit 5ec2e34c57
3 changed files with 27 additions and 0 deletions

View File

@ -15,6 +15,8 @@
*/
package de.inetsoftware.jwebassembly.wasm;
import javax.annotation.Nonnull;
/**
* Interface of all possible types in WebAssembly. This are predefined (native) types and custom types in the type section.
* <pre><code>
@ -36,4 +38,13 @@ public interface AnyType {
* @return the code
*/
public int getCode();
/**
* Check if this is a sub type of given type.
*
* @param type
* type to check
* @return true, if both are identical or the type is a sub type
*/
public boolean isSubTypeOf( @Nonnull AnyType type );
}

View File

@ -50,6 +50,14 @@ public class ArrayType implements AnyType {
return ValueType.anyref.getCode();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSubTypeOf( AnyType type ) {
return type == this || type == ValueType.anyref;
}
/**
* {@inheritDoc}
*/

View File

@ -57,4 +57,12 @@ public enum ValueType implements AnyType {
public int getCode() {
return code;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isSubTypeOf( AnyType type ) {
return type == this;
}
}