use also registered replace methods if does not exists an original in the current search path.

This commit is contained in:
Volker Berlin 2020-01-12 19:13:20 +01:00
parent 8a24d0b8b8
commit 7247623dc6

View File

@ -185,8 +185,6 @@ public class ModuleGenerator {
FunctionName next; FunctionName next;
NEXT: NEXT:
while( (next = functions.nextScannLater()) != null ) { while( (next = functions.nextScannLater()) != null ) {
ClassFile classFile = classFileLoader.get( next.className );
if( classFile == null ) {
if( next instanceof SyntheticFunctionName ) { if( next instanceof SyntheticFunctionName ) {
JWebAssembly.LOGGER.fine( '\t' + next.methodName + next.signature ); JWebAssembly.LOGGER.fine( '\t' + next.methodName + next.signature );
SyntheticFunctionName synth = (SyntheticFunctionName)next; SyntheticFunctionName synth = (SyntheticFunctionName)next;
@ -196,29 +194,29 @@ public class ModuleGenerator {
functions.markAsImport( synth, synth.getAnnotation() ); functions.markAsImport( synth, synth.getAnnotation() );
} }
functions.markAsScanned( next, false ); functions.markAsScanned( next, false );
} continue;
} else { }
JWebAssembly.LOGGER.fine( "scan class: " + next.className );
iterateMethods( classFile, method -> { JWebAssembly.LOGGER.fine( "scan " + next.signatureName );
try { MethodInfo method = null;
FunctionName name = new FunctionName( method ); ClassFile classFile = classFileLoader.get( next.className );
if( functions.needToScan( name ) ) { if( classFile != null ) {
JWebAssembly.LOGGER.fine( '\t' + name.methodName + name.signature ); method = classFile.getMethod( next.methodName, next.signature );
scanMethod( createInstructions( functions.replace( name, method ) ) ); }
boolean needThisParameter = !method.isStatic() || "<init>".equals( method.getName() ); if( method == null ) {
functions.markAsScanned( name, needThisParameter ); method = functions.replace( next, null );
} }
} catch (IOException ioex){ if( method != null ) {
throw WasmException.create( ioex, sourceFile, className, -1 ); scanMethod( createInstructions( functions.replace( next, method ) ) );
} boolean needThisParameter = !method.isStatic() || "<init>".equals( method.getName() );
} ); functions.markAsScanned( next, needThisParameter );
continue;
} }
if( functions.needToScan( next ) ) { // function was not found
// search if there is a super class with the same signature // search if there is a super class with the same signature
ClassFile superClassFile = classFile; ClassFile superClassFile = classFile;
while( superClassFile != null ) { while( superClassFile != null ) {
MethodInfo method = superClassFile.getMethod( next.methodName, next.signature ); method = superClassFile.getMethod( next.methodName, next.signature );
if( method != null ) { if( method != null ) {
FunctionName name = new FunctionName( method ); FunctionName name = new FunctionName( method );
functions.markAsNeeded( name ); functions.markAsNeeded( name );
@ -234,7 +232,7 @@ public class ModuleGenerator {
while( superClassFile != null ) { while( superClassFile != null ) {
for( ConstantClass iface : superClassFile.getInterfaces() ) { for( ConstantClass iface : superClassFile.getInterfaces() ) {
ClassFile iClassFile = classFileLoader.get( iface.getName() ); ClassFile iClassFile = classFileLoader.get( iface.getName() );
MethodInfo method = iClassFile.getMethod( next.methodName, next.signature ); method = iClassFile.getMethod( next.methodName, next.signature );
if( method != null ) { if( method != null ) {
FunctionName name = new FunctionName( method ); FunctionName name = new FunctionName( method );
functions.markAsNeeded( name ); functions.markAsNeeded( name );
@ -249,7 +247,6 @@ public class ModuleGenerator {
throw new WasmException( "Missing function: " + next.signatureName, -1 ); throw new WasmException( "Missing function: " + next.signatureName, -1 );
} }
} }
}
/** /**
* Finish the prepare after all classes/methods are prepare. This must be call before we can start with write the * Finish the prepare after all classes/methods are prepare. This must be call before we can start with write the