Class TypeManager.StructType
- java.lang.Object
-
- de.inetsoftware.jwebassembly.module.TypeManager.StructType
-
- All Implemented Interfaces:
AnyType
- Direct Known Subclasses:
ArrayType
,TypeManager.LambdaType
- Enclosing class:
- TypeManager
public static class TypeManager.StructType extends java.lang.Object implements AnyType
A reference to a type.
-
-
Field Summary
Fields Modifier and Type Field Description private int
classIndex
private int
code
private java.util.List<NamedStorageType>
fields
private java.util.Set<TypeManager.StructType>
instanceOFs
private java.util.Map<TypeManager.StructType,java.util.List<FunctionName>>
interfaceMethods
private TypeManager.StructTypeKind
kind
private TypeManager
manager
private java.lang.String
name
private java.util.HashSet<java.lang.String>
neededFields
private java.util.List<FunctionName>
vtable
private int
vtableOffset
The offset to the vtable in the data section.
-
Constructor Summary
Constructors Modifier Constructor Description protected
StructType(java.lang.String name, TypeManager.StructTypeKind kind, TypeManager manager)
Create a reference to type
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addOrUpdateVTable(FunctionManager functions, FunctionName funcName, boolean isDefault)
Add the function to the vtable or replace if already existsint
getClassIndex()
The running index of the class/type for class meta data, instanceof and interface calls.int
getCode()
The type code(typeidx) in WebAssembly.protected int
getComponentClassIndex()
The running index of the component/array class/type for class meta data, instanceof and interface calls.java.util.List<NamedStorageType>
getFields()
Get the fields of this structTypeManager.StructTypeKind
getKind()
Get kind of the StructTypejava.lang.String
getName()
Get the name of the Java typeint
getVTable()
Get the vtable offset.boolean
isRefType()
If the type is a reference type.boolean
isSubTypeOf(AnyType type)
Check if this is a sub type of given type.private void
listInterfaces(FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader)
List all interfaces of this StructType and and mark all instance methods of used interface methods.private void
listInterfaceTypes(ClassFile classFile, TypeManager types, ClassFileLoader classFileLoader, java.util.Set<TypeManager.StructType> interfaceTypes, java.util.Set<java.lang.String> interfaceNames)
List all interface StrucTypes recursively.private void
listStructFields(java.lang.String className, FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader, java.util.HashSet<java.lang.String> allNeededFields)
List the non static fields of the class and its super classes.private void
scanTypeHierarchy(FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader)
Write this struct type and initialize internal structuresjava.lang.String
toString()
(package private) void
useFieldName(NamedStorageType fieldName)
Mark that the field was used in any getter or setter.private void
writeStructType(ModuleWriter writer)
Write this struct type and initialize internal structuresvoid
writeToStream(java.io.ByteArrayOutputStream dataStream, java.util.function.ToIntFunction<FunctionName> getFunctionsID, WasmOptions options)
Write the struct/class meta data to the datastream and set the offset position.
-
-
-
Field Detail
-
name
private final java.lang.String name
-
kind
private final TypeManager.StructTypeKind kind
-
manager
private final TypeManager manager
-
classIndex
private final int classIndex
-
code
private int code
-
neededFields
private java.util.HashSet<java.lang.String> neededFields
-
fields
private java.util.List<NamedStorageType> fields
-
vtable
private java.util.List<FunctionName> vtable
-
instanceOFs
private java.util.Set<TypeManager.StructType> instanceOFs
-
interfaceMethods
private java.util.Map<TypeManager.StructType,java.util.List<FunctionName>> interfaceMethods
-
vtableOffset
private int vtableOffset
The offset to the vtable in the data section.
-
-
Constructor Detail
-
StructType
protected StructType(@Nonnull java.lang.String name, @Nonnull TypeManager.StructTypeKind kind, @Nonnull TypeManager manager)
Create a reference to type- Parameters:
name
- the Java class name like "java/lang/String"kind
- the type kindmanager
- the manager which hold all StructTypes
-
-
Method Detail
-
useFieldName
void useFieldName(NamedStorageType fieldName)
Mark that the field was used in any getter or setter.- Parameters:
fieldName
- the name of the field
-
scanTypeHierarchy
private void scanTypeHierarchy(FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader) throws java.io.IOException
Write this struct type and initialize internal structures- Parameters:
functions
- the used functions for the vtables of the typestypes
- for types of fieldsclassFileLoader
- for loading the class files- Throws:
java.io.IOException
- if any I/O error occur on loading or writing
-
writeStructType
private void writeStructType(ModuleWriter writer) throws java.io.IOException
Write this struct type and initialize internal structures- Parameters:
writer
- the targets for the types- Throws:
java.io.IOException
- if any I/O error occur on loading or writing
-
listStructFields
private void listStructFields(java.lang.String className, FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader, java.util.HashSet<java.lang.String> allNeededFields) throws java.io.IOException
List the non static fields of the class and its super classes.- Parameters:
className
- the className to list. because the recursion this must not the name of this classfunctions
- the used functions for the vtables of the typestypes
- for types of fieldsclassFileLoader
- for loading the class filesallNeededFields
- for recursive call list this all used fields- Throws:
java.io.IOException
- if any I/O error occur on loading or writing
-
addOrUpdateVTable
private void addOrUpdateVTable(FunctionManager functions, FunctionName funcName, boolean isDefault)
Add the function to the vtable or replace if already exists- Parameters:
functions
- the function managerfuncName
- the function to addedisDefault
- true, if the function is a default implementation of a interface
-
listInterfaces
private void listInterfaces(FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader) throws java.io.IOException
List all interfaces of this StructType and and mark all instance methods of used interface methods.- Add all used interfaces to the instanceOf set.
- Create the itable for every interface. A list of real functions that should be called if the interface method is called for this type.
- mark all implementations of used interface method in this type as used. For example if "java/util/List.size()I" is used anywhere and this StructType implements "java/util/List" then the "size()I" method of this StrucType must also compiled.
- Parameters:
functions
- the used functions for the vtables of the typestypes
- for types of fieldsclassFileLoader
- for loading the class files- Throws:
java.io.IOException
- if any I/O error occur on loading or writing
-
listInterfaceTypes
private void listInterfaceTypes(ClassFile classFile, TypeManager types, ClassFileLoader classFileLoader, java.util.Set<TypeManager.StructType> interfaceTypes, java.util.Set<java.lang.String> interfaceNames) throws java.io.IOException
List all interface StrucTypes recursively.- Parameters:
classFile
- The class from which the interfaces should listedtypes
- the type manager with references to the typesclassFileLoader
- for loading the class filesinterfaceTypes
- the targetinterfaceNames
- already listed interfaces to prevent a endless loop- Throws:
java.io.IOException
- if any I/O error occur on loading or writing
-
getCode
public int getCode()
The type code(typeidx) in WebAssembly. Predefined types have an negative typeidx. Custom types have the positive index in the type section.
-
isRefType
public boolean isRefType()
If the type is a reference type. A GC reference to the heap.
-
isSubTypeOf
public boolean isSubTypeOf(AnyType type)
Check if this is a sub type of given type.- Specified by:
isSubTypeOf
in interfaceAnyType
- Parameters:
type
- type to check- Returns:
- true, if both are identical or this is a sub type of
other
. Or ifother
is a parent type of this.
-
getKind
public TypeManager.StructTypeKind getKind()
Get kind of the StructType- Returns:
- the type kind
-
getName
public java.lang.String getName()
Get the name of the Java type- Returns:
- the name
-
getClassIndex
public int getClassIndex()
The running index of the class/type for class meta data, instanceof and interface calls.- Returns:
- the unique index
-
getComponentClassIndex
protected int getComponentClassIndex()
The running index of the component/array class/type for class meta data, instanceof and interface calls.- Returns:
- the unique index or -1 id not an array
-
getFields
public java.util.List<NamedStorageType> getFields()
Get the fields of this struct- Returns:
- the fields
-
writeToStream
public void writeToStream(java.io.ByteArrayOutputStream dataStream, java.util.function.ToIntFunction<FunctionName> getFunctionsID, WasmOptions options) throws java.io.IOException
Write the struct/class meta data to the datastream and set the offset position.- Parameters:
dataStream
- the target streamgetFunctionsID
- source for function IDsoptions
- the compiler options- Throws:
java.io.IOException
- should never occur- See Also:
TypeManager.TYPE_DESCRIPTION_INTERFACE_OFFSET
,TypeManager.TYPE_DESCRIPTION_INSTANCEOF_OFFSET
,TypeManager.TYPE_DESCRIPTION_TYPE_NAME
-
getVTable
public int getVTable()
Get the vtable offset.- Returns:
- the offset
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-