Class FunctionManager
java.lang.Object
de.inetsoftware.jwebassembly.module.FunctionManager
Manage the required function/methods
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
State of a function/methodprivate static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final Map
<FunctionName, FunctionManager.FunctionState> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
addReplacement
(FunctionName name, MethodInfo method) Add a replacement for a method(package private) Iterator
<FunctionName> Get all FunctionNames that are abstract and used.Get the annotation of an import function(package private) int
getITableIndex
(FunctionName name) Get the index of a function in an interface.(package private) Iterator
<FunctionName> Get all FunctionNames that need importedprivate FunctionManager.FunctionState
getOrCreate
(FunctionName name) Get an existing state or create one.Get all used classes.(package private) int
getVTableIndex
(FunctionName name) Get the index of a virtual function in a type.(package private) Iterator
<FunctionName> Get all FunctionName that is required but was not written.(package private) Iterator
<FunctionName> 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 Iterator
<FunctionName> 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, Function<String, Object> importAnannotation) Mark the a function as a import function.(package private) void
markAsImport
(FunctionName name, Map<String, 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
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
(String className) Mark a class as used.(package private) boolean
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
Get the first FunctionName that is required but was not scanned.(package private) void
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 Details
-
states
-
usedClasses
-
isFinish
private boolean isFinish
-
-
Constructor Details
-
FunctionManager
FunctionManager()
-
-
Method Details
-
prepareFinish
void prepareFinish()Finish the prepare. Now no new function should be added. -
getOrCreate
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
Check if this function is already known/registered.- Parameters:
name
- the function name- Returns:
- true, if known
-
markClassAsUsed
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
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
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
Same like markAsNeeded but it will replace the function name if already registered.- Parameters:
name
- the function name
-
markAsNeeded
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
Mark the a function as scanned in the prepare phase. This should only occur with needed functions.- Parameters:
name
- the function name
-
markAsWritten
Mark the a function as written to the wasm file.- Parameters:
name
- the function name
-
markAsAbstract
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
Iterator<FunctionName> getNeededImports()Get all FunctionNames that need imported- Returns:
- an iterator
-
getImportAnannotation
Get the annotation of an import function- Parameters:
name
- the function name- Returns:
- the annotation or null
-
nextScannLater
Get the first FunctionName that is required but was not scanned.- Returns:
- the FunctionName or null
-
getUsedClasses
Get all used classes.- Returns:
- an iterator
-
getWriteLaterClinit
Get all static constructor FunctionName of used classes.- Returns:
- an iterator
-
getWriteLater
Get all FunctionName that is required but was not written.- Returns:
- an iterator
-
getAbstractedFunctions
Iterator<FunctionName> getAbstractedFunctions()Get all FunctionNames that are abstract and used.- Returns:
- an iterator
-
iterator
@Nonnull private Iterator<FunctionName> iterator(Predicate<Map.Entry<FunctionName, FunctionManager.FunctionState>> filter) get a iterator for function names- Parameters:
filter
- the filter- Returns:
- the iterator
-
needToScan
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
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
Test if the function is called anywhere.- Parameters:
name
- the function name- Returns:
- true, if used
-
needThisParameter
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
Add a replacement for a method- Parameters:
name
- the name of the method which should be replacedmethod
- the new implementation
-
setAlias
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
Check if there is a replacement method- Parameters:
name
- the namemethod
- the current method- Returns:
- the method that should be write
-
setVTableIndex
Set the index of a virtual function in a type.- Parameters:
name
- the namevtableIdx
- the index in the vtable
-
getVTableIndex
Get the index of a virtual function in a type.- Parameters:
name
- the name- Returns:
- the index
-
setITableIndex
Set the index of a function in an interface.- Parameters:
name
- the nameitableIdx
- the index in the itable
-
getITableIndex
Get the index of a function in an interface.- Parameters:
name
- the name- Returns:
- the index in the itable
-