mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
fix interface calls for redefinied defaults with new defaults
This commit is contained in:
parent
d3acc3698f
commit
43140453c9
@ -575,7 +575,7 @@ public class TypeManager {
|
|||||||
for( ; idx < vtable.size(); idx++ ) {
|
for( ; idx < vtable.size(); idx++ ) {
|
||||||
FunctionName func = vtable.get( idx );
|
FunctionName func = vtable.get( idx );
|
||||||
if( func.methodName.equals( funcName.methodName ) && func.signature.equals( funcName.signature ) ) {
|
if( func.methodName.equals( funcName.methodName ) && func.signature.equals( funcName.signature ) ) {
|
||||||
if( !isDefault ) {
|
if( !isDefault || functions.getITableIndex( func ) >= 0 ) {
|
||||||
vtable.set( idx, funcName ); // use the override method
|
vtable.set( idx, funcName ); // use the override method
|
||||||
functions.markAsNeeded( funcName ); // mark all overridden methods also as needed if the super method is used
|
functions.markAsNeeded( funcName ); // mark all overridden methods also as needed if the super method is used
|
||||||
}
|
}
|
||||||
@ -616,18 +616,11 @@ public class TypeManager {
|
|||||||
// all classes in the hierarchy
|
// all classes in the hierarchy
|
||||||
ArrayList<ClassFile> classFiles = new ArrayList<>();
|
ArrayList<ClassFile> classFiles = new ArrayList<>();
|
||||||
|
|
||||||
|
// list classes of the hierarchy and its interfaces
|
||||||
|
Set<String> interfaceNames = new LinkedHashSet<>();
|
||||||
for( ClassFile classFile = classFileLoader.get( name );; ) {
|
for( ClassFile classFile = classFileLoader.get( name );; ) {
|
||||||
classFiles.add( classFile );
|
classFiles.add( classFile );
|
||||||
for( ConstantClass interClass : classFile.getInterfaces() ) {
|
listInterfaceTypes( classFile, types, classFileLoader, interfaceTypes, interfaceNames );
|
||||||
String interName = interClass.getName();
|
|
||||||
StructType type = types.structTypes.get( interName );
|
|
||||||
if( type == null ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
interfaceTypes.add( type );
|
|
||||||
// add all used interfaces to the instanceof set
|
|
||||||
instanceOFs.add( type );
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstantClass superClass = classFile.getSuperClass();
|
ConstantClass superClass = classFile.getSuperClass();
|
||||||
if( superClass == null ) {
|
if( superClass == null ) {
|
||||||
@ -660,8 +653,8 @@ public class TypeManager {
|
|||||||
|
|
||||||
if( method == null ) {
|
if( method == null ) {
|
||||||
// search if there is a default implementation in an interface
|
// search if there is a default implementation in an interface
|
||||||
for( StructType iType : interfaceTypes ) {
|
for( String iClassName : interfaceNames ) {
|
||||||
ClassFile iClassFile = classFileLoader.get( iType.name );
|
ClassFile iClassFile = classFileLoader.get( iClassName );
|
||||||
method = iClassFile.getMethod( iName.methodName, iName.signature );
|
method = iClassFile.getMethod( iName.methodName, iName.signature );
|
||||||
if( method != null ) {
|
if( method != null ) {
|
||||||
break;
|
break;
|
||||||
@ -685,6 +678,40 @@ public class TypeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all interface StrucTypes recursively.
|
||||||
|
*
|
||||||
|
* @param classFile
|
||||||
|
* The class from which the interfaces should listed
|
||||||
|
* @param types
|
||||||
|
* the type manager with references to the types
|
||||||
|
* @param classFileLoader
|
||||||
|
* for loading the class files
|
||||||
|
* @param interfaceTypes
|
||||||
|
* the target
|
||||||
|
* @param interfaceNames
|
||||||
|
* already listed interfaces to prevent a endless loop
|
||||||
|
* @throws IOException
|
||||||
|
* if any I/O error occur on loading or writing
|
||||||
|
*/
|
||||||
|
private void listInterfaceTypes( ClassFile classFile, TypeManager types, ClassFileLoader classFileLoader, Set<StructType> interfaceTypes, Set<String> interfaceNames ) throws IOException {
|
||||||
|
for( ConstantClass interClass : classFile.getInterfaces() ) {
|
||||||
|
String interName = interClass.getName();
|
||||||
|
if( interfaceNames.add( interName ) ) {
|
||||||
|
StructType type = types.structTypes.get( interName );
|
||||||
|
if( type != null ) {
|
||||||
|
interfaceTypes.add( type );
|
||||||
|
// add all used interfaces to the instanceof set
|
||||||
|
instanceOFs.add( type );
|
||||||
|
}
|
||||||
|
ClassFile interClassFile = classFileLoader.get( interName );
|
||||||
|
if( interClassFile != null ) {
|
||||||
|
listInterfaceTypes( interClassFile, types, classFileLoader, interfaceTypes, interfaceNames );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@ -786,7 +813,7 @@ public class TypeManager {
|
|||||||
for( Entry<StructType, List<FunctionName>> entry : interfaceMethods.entrySet() ) {
|
for( Entry<StructType, List<FunctionName>> entry : interfaceMethods.entrySet() ) {
|
||||||
data.writeInt32( entry.getKey().getClassIndex() );
|
data.writeInt32( entry.getKey().getClassIndex() );
|
||||||
List<FunctionName> iMethods = entry.getValue();
|
List<FunctionName> iMethods = entry.getValue();
|
||||||
int nextClassPosition = data.size() + 4 * (1 + iMethods.size());
|
int nextClassPosition = 4 * (2 + iMethods.size());
|
||||||
data.writeInt32( nextClassPosition );
|
data.writeInt32( nextClassPosition );
|
||||||
for( FunctionName funcName : iMethods ) {
|
for( FunctionName funcName : iMethods ) {
|
||||||
int functIdx = getFunctionsID.applyAsInt( funcName );
|
int functIdx = getFunctionsID.applyAsInt( funcName );
|
||||||
|
@ -45,6 +45,7 @@ public class InterfaceOperations extends AbstractBaseTest {
|
|||||||
addParam( list, script, "getDefaultOverride2" );
|
addParam( list, script, "getDefaultOverride2" );
|
||||||
addParam( list, script, "getDefaultExtends" );
|
addParam( list, script, "getDefaultExtends" );
|
||||||
addParam( list, script, "getDefaultReimplement" );
|
addParam( list, script, "getDefaultReimplement" );
|
||||||
|
addParam( list, script, "getDefaultRedefinied" );
|
||||||
addParam( list, script, "abstractParent" );
|
addParam( list, script, "abstractParent" );
|
||||||
}
|
}
|
||||||
rule.setTestParameters( list );
|
rule.setTestParameters( list );
|
||||||
@ -89,6 +90,12 @@ public class InterfaceOperations extends AbstractBaseTest {
|
|||||||
return bar.getDefaultValue();
|
return bar.getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
static int getDefaultRedefinied() {
|
||||||
|
Bar bar = new Bar2() {};
|
||||||
|
return bar.getDefaultValue();
|
||||||
|
}
|
||||||
|
|
||||||
interface Bar {
|
interface Bar {
|
||||||
default int getDefaultValue() {
|
default int getDefaultValue() {
|
||||||
return 7;
|
return 7;
|
||||||
@ -114,6 +121,12 @@ public class InterfaceOperations extends AbstractBaseTest {
|
|||||||
static class BarReimplement extends BarExtends implements Bar {
|
static class BarReimplement extends BarExtends implements Bar {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Bar2 extends Bar {
|
||||||
|
default int getDefaultValue() {
|
||||||
|
return 99;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Export
|
@Export
|
||||||
static int abstractParent() {
|
static int abstractParent() {
|
||||||
Foo foo = new FooAdder() {
|
Foo foo = new FooAdder() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user