mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
add support for abstract methods, WIP
This commit is contained in:
parent
16f49f3078
commit
ff5b8f8442
@ -119,7 +119,12 @@ class FunctionManager {
|
||||
*/
|
||||
void markAsScanned( FunctionName name, boolean needThisParameter ) {
|
||||
FunctionState state = getOrCreate( name );
|
||||
state.state = State.Scanned;
|
||||
switch( state.state ) {
|
||||
case None:
|
||||
case Needed:
|
||||
state.state = State.Scanned;
|
||||
break;
|
||||
}
|
||||
state.needThisParameter = needThisParameter;
|
||||
}
|
||||
|
||||
@ -133,6 +138,16 @@ class FunctionManager {
|
||||
getOrCreate( name ).state = State.Written;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the a function as abstract or interface. This function can be called but will not be write to the wasm file.
|
||||
*
|
||||
* @param name
|
||||
* the function name
|
||||
*/
|
||||
void markAsAbstract( FunctionName name ) {
|
||||
getOrCreate( name ).state = State.Abstract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same like markAsNeeded but it will replace the function name if already registered.
|
||||
*
|
||||
@ -230,14 +245,13 @@ class FunctionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all FunctionNames that need imported
|
||||
* Get all FunctionNames that are abstract and used.
|
||||
*
|
||||
* @return an iterator
|
||||
*/
|
||||
Iterator<FunctionName> getNeededFunctions() {
|
||||
Iterator<FunctionName> getAbstractedFunctions() {
|
||||
return iterator( entry -> {
|
||||
FunctionState state = entry.getValue();
|
||||
switch( state.state ) {
|
||||
switch( entry.getValue().state ) {
|
||||
case Needed:
|
||||
case Scanned:
|
||||
return true;
|
||||
@ -386,6 +400,6 @@ class FunctionManager {
|
||||
}
|
||||
|
||||
private static enum State {
|
||||
None, Needed, Scanned, Written;
|
||||
None, Needed, Scanned, Written, Abstract;
|
||||
}
|
||||
}
|
||||
|
@ -299,11 +299,17 @@ public class ModuleGenerator {
|
||||
}
|
||||
|
||||
// init/write the function types
|
||||
for( Iterator<FunctionName> iterator = functions.getNeededFunctions(); iterator.hasNext(); ) {
|
||||
for( Iterator<FunctionName> iterator = functions.getWriteLater(); iterator.hasNext(); ) {
|
||||
FunctionName name = iterator.next();
|
||||
writeMethodSignature( name, null );
|
||||
}
|
||||
|
||||
// register types of abstract and interface methods
|
||||
for( Iterator<FunctionName> iterator = functions.getAbstractedFunctions(); iterator.hasNext(); ) {
|
||||
FunctionName name = iterator.next();
|
||||
//writeMethodSignature( name, null );
|
||||
}
|
||||
|
||||
JWebAssembly.LOGGER.fine( "scan finsih" );
|
||||
types.prepareFinish( writer, classFileLoader );
|
||||
functions.prepareFinish();
|
||||
@ -478,6 +484,9 @@ public class ModuleGenerator {
|
||||
} else if( code != null ) { // abstract methods and interface methods does not have code
|
||||
javaCodeBuilder.buildCode( code, method );
|
||||
return javaCodeBuilder;
|
||||
} else if( method.isAbstract() ) {
|
||||
functions.markAsAbstract( new FunctionName( method ) ); // there is nothing to write for an abstract method
|
||||
return null;
|
||||
} else {
|
||||
FunctionName name = new FunctionName( method );
|
||||
if( "java/lang/Class.typeTableMemoryOffset()I".equals( name.signatureName ) ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user