From f5c2cf0fa320d446ef2c289df83ef528feba30e1 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 16 May 2019 18:50:03 +0300 Subject: [PATCH] C: fix generation of virtual tables inheriting interface default methods --- .../backend/c/generate/CallSiteGenerator.java | 6 ++++++ .../backend/c/generate/ClassGenerator.java | 1 - .../model/classes/VirtualTableProvider.java | 19 +++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java index 81852480b..240d10389 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/CallSiteGenerator.java @@ -114,6 +114,9 @@ public class CallSiteGenerator { } private void generateLocations() { + if (locations.isEmpty()) { + return; + } includes.includeClass(CALL_SITE_LOCATION); writer.print("static ").print(callSiteLocationName).print(" callSiteLocations_" + callSitesName + "[" + locations.size() + "] = {").indent(); @@ -147,6 +150,9 @@ public class CallSiteGenerator { } private void generateHandlers() { + if (exceptionHandlers.isEmpty()) { + return; + } includes.includeClass(EXCEPTION_HANDLER); writer.print("static ").print(exceptionHandlerName).print(" exceptionHandlers_" + callSitesName + "[" + exceptionHandlers.size() + "] = {").indent(); diff --git a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java index b364133e4..0ca44822b 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java @@ -613,7 +613,6 @@ public class ClassGenerator { codeWriter.println(".superclass = " + parent + ","); codeWriter.println(".superinterfaceCount = " + superinterfaceCount + ","); codeWriter.println(".superinterfaces = " + superinterfaces + ","); - codeWriter.println(".enumValues = NULL,"); codeWriter.println(".layout = " + layout + ","); codeWriter.println(".enumValues = " + enumConstants + ","); codeWriter.println(".init = " + initFunction); diff --git a/core/src/main/java/org/teavm/model/classes/VirtualTableProvider.java b/core/src/main/java/org/teavm/model/classes/VirtualTableProvider.java index e4f853133..915bb6a52 100644 --- a/core/src/main/java/org/teavm/model/classes/VirtualTableProvider.java +++ b/core/src/main/java/org/teavm/model/classes/VirtualTableProvider.java @@ -69,12 +69,11 @@ public class VirtualTableProvider { } if (cls.getParent() != null) { fillClass(cls.getParent(), methodCalledVirtually); - VirtualTable parentTable = virtualTables.get(cls.getParent()); - for (VirtualTableEntry parentEntry : parentTable.entries.values()) { - VirtualTableEntry entry = new VirtualTableEntry(table, parentEntry.getMethod(), - parentEntry.getImplementor(), parentEntry.getIndex()); - table.entries.put(entry.getMethod(), entry); - } + copyEntriesFromSupertype(table, virtualTables.get(cls.getParent())); + } + for (String itf : cls.getInterfaces()) { + fillClass(itf, methodCalledVirtually); + copyEntriesFromSupertype(table, virtualTables.get(itf)); } Set newDescriptors = virtualMethodMap.get(className); @@ -106,6 +105,14 @@ public class VirtualTableProvider { } } + private void copyEntriesFromSupertype(VirtualTable table, VirtualTable supertypeTable) { + for (VirtualTableEntry parentEntry : supertypeTable.entries.values()) { + VirtualTableEntry entry = new VirtualTableEntry(table, parentEntry.getMethod(), + parentEntry.getImplementor(), parentEntry.getIndex()); + table.entries.put(entry.getMethod(), entry); + } + } + public VirtualTableEntry lookup(MethodReference method) { VirtualTable vtable = virtualTables.get(interfaceMapping.mapClass(method.getClassName())); if (vtable == null) {