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 Object implements AnyType
A reference to a type.
  • Field Details

  • Constructor Details

  • Method Details

    • 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 IOException
      Write this struct type and initialize internal structures
      Parameters:
      functions - the used functions for the vtables of the types
      types - for types of fields
      classFileLoader - for loading the class files
      Throws:
      IOException - if any I/O error occur on loading or writing
    • writeStructType

      private void writeStructType(ModuleWriter writer) throws IOException
      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 class
      functions - the used functions for the vtables of the types
      types - for types of fields
      classFileLoader - for loading the class files
      allNeededFields - for recursive call list this all used fields
      Throws:
      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 manager
      funcName - the function to added
      isDefault - 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 types
      types - for types of fields
      classFileLoader - 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 listed
      types - the type manager with references to the types
      classFileLoader - for loading the class files
      interfaceTypes - the target
      interfaceNames - already listed interfaces to prevent a endless loop
      Throws:
      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.
      Specified by:
      getCode in interface AnyType
      Returns:
      the code
    • isRefType

      public boolean isRefType()
      If the type is a reference type. A GC reference to the heap.
      Specified by:
      isRefType in interface AnyType
      Returns:
      true, is GC type
    • isSubTypeOf

      public boolean isSubTypeOf(AnyType type)
      Check if this is a sub type of given type.
      Specified by:
      isSubTypeOf in interface AnyType
      Parameters:
      type - type to check
      Returns:
      true, if both are identical or this is a sub type of other. Or if other is a parent type of this.
    • getKind

      public TypeManager.StructTypeKind getKind()
      Get kind of the StructType
      Returns:
      the type kind
    • getName

      public 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 List<NamedStorageType> getFields()
      Get the fields of this struct
      Returns:
      the fields
    • 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 stream
      getFunctionsID - source for function IDs
      options - the compiler options
      Throws:
      IOException - should never occur
      See Also:
    • getVTable

      public int getVTable()
      Get the vtable offset.
      Returns:
      the offset
    • toString

      public String toString()
      Overrides:
      toString in class Object