mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +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 ) {
|
void markAsScanned( FunctionName name, boolean needThisParameter ) {
|
||||||
FunctionState state = getOrCreate( name );
|
FunctionState state = getOrCreate( name );
|
||||||
state.state = State.Scanned;
|
switch( state.state ) {
|
||||||
|
case None:
|
||||||
|
case Needed:
|
||||||
|
state.state = State.Scanned;
|
||||||
|
break;
|
||||||
|
}
|
||||||
state.needThisParameter = needThisParameter;
|
state.needThisParameter = needThisParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +138,16 @@ class FunctionManager {
|
|||||||
getOrCreate( name ).state = State.Written;
|
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.
|
* 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
|
* @return an iterator
|
||||||
*/
|
*/
|
||||||
Iterator<FunctionName> getNeededFunctions() {
|
Iterator<FunctionName> getAbstractedFunctions() {
|
||||||
return iterator( entry -> {
|
return iterator( entry -> {
|
||||||
FunctionState state = entry.getValue();
|
switch( entry.getValue().state ) {
|
||||||
switch( state.state ) {
|
|
||||||
case Needed:
|
case Needed:
|
||||||
case Scanned:
|
case Scanned:
|
||||||
return true;
|
return true;
|
||||||
@ -386,6 +400,6 @@ class FunctionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static enum State {
|
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
|
// 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();
|
FunctionName name = iterator.next();
|
||||||
writeMethodSignature( name, null );
|
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" );
|
JWebAssembly.LOGGER.fine( "scan finsih" );
|
||||||
types.prepareFinish( writer, classFileLoader );
|
types.prepareFinish( writer, classFileLoader );
|
||||||
functions.prepareFinish();
|
functions.prepareFinish();
|
||||||
@ -478,6 +484,9 @@ public class ModuleGenerator {
|
|||||||
} else if( code != null ) { // abstract methods and interface methods does not have code
|
} else if( code != null ) { // abstract methods and interface methods does not have code
|
||||||
javaCodeBuilder.buildCode( code, method );
|
javaCodeBuilder.buildCode( code, method );
|
||||||
return javaCodeBuilder;
|
return javaCodeBuilder;
|
||||||
|
} else if( method.isAbstract() ) {
|
||||||
|
functions.markAsAbstract( new FunctionName( method ) ); // there is nothing to write for an abstract method
|
||||||
|
return null;
|
||||||
} else {
|
} else {
|
||||||
FunctionName name = new FunctionName( method );
|
FunctionName name = new FunctionName( method );
|
||||||
if( "java/lang/Class.typeTableMemoryOffset()I".equals( name.signatureName ) ) {
|
if( "java/lang/Class.typeTableMemoryOffset()I".equals( name.signatureName ) ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user