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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate intprivate List<NamedStorageType> private Set<TypeManager.StructType> private Map<TypeManager.StructType, List<FunctionName>> private final TypeManager.StructTypeKindprivate final TypeManagerprivate final Stringprivate List<FunctionName> private intThe offset to the vtable in the data section. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedStructType(String name, TypeManager.StructTypeKind kind, TypeManager manager) Create a reference to type -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddOrUpdateVTable(FunctionManager functions, FunctionName funcName, boolean isDefault) Add the function to the vtable or replace if already existsintThe running index of the class/type for class meta data, instanceof and interface calls.intgetCode()The type code(typeidx) in WebAssembly.protected intThe running index of the component/array class/type for class meta data, instanceof and interface calls.Get the fields of this structgetKind()Get kind of the StructTypegetName()Get the name of the Java typeintGet the vtable offset.booleanIf the type is a reference type.booleanisSubTypeOf(AnyType type) Check if this is a sub type of given type.private voidlistInterfaces(FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader) List all interfaces of this StructType and and mark all instance methods of used interface methods.private voidlistInterfaceTypes(ClassFile classFile, TypeManager types, ClassFileLoader classFileLoader, Set<TypeManager.StructType> interfaceTypes, Set<String> interfaceNames) List all interface StrucTypes recursively.private voidlistStructFields(String className, FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader, HashSet<String> allNeededFields) List the non static fields of the class and its super classes.private voidscanTypeHierarchy(FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader) Write this struct type and initialize internal structurestoString()(package private) voiduseFieldName(NamedStorageType fieldName) Mark that the field was used in any getter or setter.private voidwriteStructType(ModuleWriter writer) Write this struct type and initialize internal structuresvoidwriteToStream(ByteArrayOutputStream dataStream, ToIntFunction<FunctionName> getFunctionsID, WasmOptions options) Write the struct/class meta data to the datastream and set the offset position.
-
Field Details
-
name
-
kind
-
manager
-
classIndex
private final int classIndex -
code
private int code -
neededFields
-
fields
-
vtable
-
instanceOFs
-
interfaceMethods
-
vtableOffset
private int vtableOffsetThe offset to the vtable in the data section.
-
-
Constructor Details
-
StructType
protected StructType(@Nonnull 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 Details
-
useFieldName
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 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:
IOException- if any I/O error occur on loading or writing
-
writeStructType
Write this struct type and initialize internal structures- Parameters:
writer- the targets for the types- Throws:
IOException- if any I/O error occur on loading or writing
-
listStructFields
private void listStructFields(String className, FunctionManager functions, TypeManager types, ClassFileLoader classFileLoader, HashSet<String> allNeededFields) throws 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:
IOException- if any I/O error occur on loading or writing
-
addOrUpdateVTable
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 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:
IOException- if any I/O error occur on loading or writing
-
listInterfaceTypes
private void listInterfaceTypes(ClassFile classFile, TypeManager types, ClassFileLoader classFileLoader, Set<TypeManager.StructType> interfaceTypes, Set<String> interfaceNames) throws 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:
IOException- if any I/O error occur on loading or writing
-
getCode
-
isRefType
-
isSubTypeOf
Check if this is a sub type of given type.- Specified by:
isSubTypeOfin interfaceAnyType- Parameters:
type- type to check- Returns:
- true, if both are identical or this is a sub type of
other. Or ifotheris a parent type of this.
-
getKind
-
getName
-
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
-
writeToStream
public void writeToStream(ByteArrayOutputStream dataStream, ToIntFunction<FunctionName> getFunctionsID, WasmOptions options) throws 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:
IOException- should never occur- See Also:
-
getVTable
public int getVTable()Get the vtable offset.- Returns:
- the offset
-
toString
-