Class FunctionManager
- java.lang.Object
-
- de.inetsoftware.jwebassembly.module.FunctionManager
-
class FunctionManager extends java.lang.Object
Manage the required function/methods
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FunctionManager.FunctionState
State of a function/methodprivate static class
FunctionManager.State
-
Field Summary
Fields Modifier and Type Field Description private boolean
isFinish
private java.util.Map<FunctionName,FunctionManager.FunctionState>
states
private java.util.Set<java.lang.String>
usedClasses
-
Constructor Summary
Constructors Constructor Description FunctionManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addReplacement(FunctionName name, MethodInfo method)
Add a replacement for a method(package private) java.util.Iterator<FunctionName>
getAbstractedFunctions()
Get all FunctionNames that are abstract and used.(package private) java.util.function.Function<java.lang.String,java.lang.Object>
getImportAnannotation(FunctionName name)
Get the annotation of an import function(package private) int
getITableIndex(FunctionName name)
Get the index of a function in an interface.(package private) java.util.Iterator<FunctionName>
getNeededImports()
Get all FunctionNames that need importedprivate FunctionManager.FunctionState
getOrCreate(FunctionName name)
Get an existing state or create one.(package private) java.util.Iterator<java.lang.String>
getUsedClasses()
Get all used classes.(package private) int
getVTableIndex(FunctionName name)
Get the index of a virtual function in a type.(package private) java.util.Iterator<FunctionName>
getWriteLater()
Get all FunctionName that is required but was not written.(package private) java.util.Iterator<FunctionName>
getWriteLaterClinit()
Get all static constructor FunctionName of used classes.(package private) boolean
isKnown(FunctionName name)
Check if this function is already known/registered.(package private) boolean
isUsed(FunctionName name)
Test if the function is called anywhere.private java.util.Iterator<FunctionName>
iterator(java.util.function.Predicate<java.util.Map.Entry<FunctionName,FunctionManager.FunctionState>> filter)
get a iterator for function names(package private) void
markAsAbstract(FunctionName name)
Mark the a function as abstract or interface.(package private) void
markAsImport(FunctionName name, java.util.function.Function<java.lang.String,java.lang.Object> importAnannotation)
Mark the a function as a import function.(package private) void
markAsImport(FunctionName name, java.util.Map<java.lang.String,java.lang.Object> importAnannotation)
Mark the a function as a import function.(package private) FunctionName
markAsNeeded(FunctionName name, boolean needThisParameter)
Mark a function as used/called and return the real name if there is an alias.(package private) void
markAsNeededAndReplaceIfExists(SyntheticFunctionName name)
Same like markAsNeeded but it will replace the function name if already registered.(package private) void
markAsScanned(FunctionName name)
Mark the a function as scanned in the prepare phase.(package private) void
markAsWritten(FunctionName name)
Mark the a function as written to the wasm file.(package private) void
markClassAsUsed(java.lang.String className)
Mark a class as used.(package private) boolean
needThisParameter(FunctionName name)
If this function need additional to the parameter of the signature an extra "this" parameter.(package private) boolean
needToScan(FunctionName name)
if the given function is required but was not scanned.(package private) boolean
needToWrite(FunctionName name)
if the given function is required but was not written.(package private) FunctionName
nextScannLater()
Get the first FunctionName that is required but was not scanned.(package private) void
prepareFinish()
Finish the prepare.(package private) MethodInfo
replace(FunctionName name, MethodInfo method)
Check if there is a replacement method(package private) void
setAlias(FunctionName name, FunctionName alias)
Set an alias for the method.(package private) void
setITableIndex(FunctionName name, int itableIdx)
Set the index of a function in an interface.(package private) void
setVTableIndex(FunctionName name, int vtableIdx)
Set the index of a virtual function in a type.(package private) int
size()
Get the count of known functions
-
-
-
Field Detail
-
states
private final java.util.Map<FunctionName,FunctionManager.FunctionState> states
-
usedClasses
private final java.util.Set<java.lang.String> usedClasses
-
isFinish
private boolean isFinish
-
-
Method Detail
-
prepareFinish
void prepareFinish()
Finish the prepare. Now no new function should be added.
-
getOrCreate
@Nonnull private FunctionManager.FunctionState getOrCreate(@Nonnull FunctionName name)
Get an existing state or create one.- Parameters:
name
- the FunctionName- Returns:
- the state
-
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 nameimportAnannotation
- 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 nameimportAnannotation
- 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 nameneedThisParameter
- 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 replacedmethod
- 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 namealias
- the new name.
-
replace
@Nonnull MethodInfo replace(@Nonnull FunctionName name, MethodInfo method)
Check if there is a replacement method- Parameters:
name
- the namemethod
- 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 namevtableIdx
- 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 nameitableIdx
- 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
-
-