Class FunctionManager


  • class FunctionManager
    extends java.lang.Object
    Manage the required function/methods
    • Constructor Detail

      • FunctionManager

        FunctionManager()
    • Method Detail

      • prepareFinish

        void prepareFinish()
        Finish the prepare. Now no new function should be added.
      • size

        int size()
        Get the count of known functions
        Returns:
        the count
      • isKnown

        boolean isKnown​(@Nonnull
                        FunctionName name)
        Check if this function is already known/registered.
        Parameters:
        name - the function name
        Returns:
        true, if known
      • markClassAsUsed

        void markClassAsUsed​(java.lang.String className)
        Mark a class as used. This means the static initializer must be used.
        Parameters:
        className - the name of the class like "java/lang/Object"
      • markAsImport

        void markAsImport​(@Nonnull
                          FunctionName name,
                          java.util.Map<java.lang.String,​java.lang.Object> importAnannotation)
        Mark the a function as a import function. Only if the function is also needed then it will imported from compiler.
        Parameters:
        name - the function name
        importAnannotation - the annotation of the import
      • markAsImport

        void markAsImport​(@Nonnull
                          FunctionName name,
                          java.util.function.Function<java.lang.String,​java.lang.Object> importAnannotation)
        Mark the a function as a import function. Only if the function is also needed then it will imported from compiler.
        Parameters:
        name - the function name
        importAnannotation - the annotation of the import
      • markAsNeededAndReplaceIfExists

        void markAsNeededAndReplaceIfExists​(@Nonnull
                                            SyntheticFunctionName name)
        Same like markAsNeeded but it will replace the function name if already registered.
        Parameters:
        name - the function name
      • markAsNeeded

        FunctionName markAsNeeded​(@Nonnull
                                  FunctionName name,
                                  boolean needThisParameter)
        Mark a function as used/called and return the real name if there is an alias.
        Parameters:
        name - the function name
        needThisParameter - if this function need additional to the parameter of the signature an extra "this" parameter
        Returns:
        the real function name
      • markAsScanned

        void markAsScanned​(@Nonnull
                           FunctionName name)
        Mark the a function as scanned in the prepare phase. This should only occur with needed functions.
        Parameters:
        name - the function name
      • markAsWritten

        void markAsWritten​(@Nonnull
                           FunctionName name)
        Mark the a function as written to the wasm file.
        Parameters:
        name - the function name
      • markAsAbstract

        void markAsAbstract​(@Nonnull
                            FunctionName name)
        Mark the a function as abstract or interface. This function can be called but will not be write to the wasm file.
        Parameters:
        name - the function name
      • getNeededImports

        java.util.Iterator<FunctionName> getNeededImports()
        Get all FunctionNames that need imported
        Returns:
        an iterator
      • getImportAnannotation

        java.util.function.Function<java.lang.String,​java.lang.Object> getImportAnannotation​(FunctionName name)
        Get the annotation of an import function
        Parameters:
        name - the function name
        Returns:
        the annotation or null
      • nextScannLater

        @Nullable
        FunctionName nextScannLater()
        Get the first FunctionName that is required but was not scanned.
        Returns:
        the FunctionName or null
      • getUsedClasses

        @Nonnull
        java.util.Iterator<java.lang.String> getUsedClasses()
        Get all used classes.
        Returns:
        an iterator
      • getWriteLaterClinit

        @Nonnull
        java.util.Iterator<FunctionName> getWriteLaterClinit()
        Get all static constructor FunctionName of used classes.
        Returns:
        an iterator
      • getWriteLater

        @Nonnull
        java.util.Iterator<FunctionName> getWriteLater()
        Get all FunctionName that is required but was not written.
        Returns:
        an iterator
      • getAbstractedFunctions

        java.util.Iterator<FunctionName> getAbstractedFunctions()
        Get all FunctionNames that are abstract and used.
        Returns:
        an iterator
      • iterator

        @Nonnull
        private java.util.Iterator<FunctionName> iterator​(java.util.function.Predicate<java.util.Map.Entry<FunctionName,​FunctionManager.FunctionState>> filter)
        get a iterator for function names
        Parameters:
        filter - the filter
        Returns:
        the iterator
      • needToScan

        boolean needToScan​(@Nonnull
                           FunctionName name)
        if the given function is required but was not scanned.
        Parameters:
        name - the function name
        Returns:
        true, if the function on the to do list
      • needToWrite

        boolean needToWrite​(@Nonnull
                            FunctionName name)
        if the given function is required but was not written.
        Parameters:
        name - the function name
        Returns:
        true, if the function on the to do list
      • isUsed

        boolean isUsed​(@Nonnull
                       FunctionName name)
        Test if the function is called anywhere.
        Parameters:
        name - the function name
        Returns:
        true, if used
      • needThisParameter

        boolean needThisParameter​(@Nonnull
                                  FunctionName name)
        If this function need additional to the parameter of the signature an extra "this" parameter.
        Parameters:
        name - the function name
        Returns:
        true, if the function is static
      • addReplacement

        void addReplacement​(@Nonnull
                            FunctionName name,
                            MethodInfo method)
        Add a replacement for a method
        Parameters:
        name - the name of the method which should be replaced
        method - the new implementation
      • setAlias

        void setAlias​(@Nonnull
                      FunctionName name,
                      FunctionName alias)
        Set an alias for the method. If this method should be called then the alias method should be really called. This is typical a virtual super method.
        Parameters:
        name - the original name
        alias - the new name.
      • replace

        @Nonnull
        MethodInfo replace​(@Nonnull
                           FunctionName name,
                           MethodInfo method)
        Check if there is a replacement method
        Parameters:
        name - the name
        method - the current method
        Returns:
        the method that should be write
      • setVTableIndex

        void setVTableIndex​(@Nonnull
                            FunctionName name,
                            int vtableIdx)
        Set the index of a virtual function in a type.
        Parameters:
        name - the name
        vtableIdx - the index in the vtable
      • getVTableIndex

        int getVTableIndex​(@Nonnull
                           FunctionName name)
        Get the index of a virtual function in a type.
        Parameters:
        name - the name
        Returns:
        the index
      • setITableIndex

        void setITableIndex​(@Nonnull
                            FunctionName name,
                            int itableIdx)
        Set the index of a function in an interface.
        Parameters:
        name - the name
        itableIdx - the index in the itable
      • getITableIndex

        int getITableIndex​(@Nonnull
                           FunctionName name)
        Get the index of a function in an interface.
        Parameters:
        name - the name
        Returns:
        the index in the itable