Added debug output to vTable builder
This commit is contained in:
+40
@@ -87,10 +87,21 @@ internal class OverriddenFunctionDescriptor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class ClassVtablesBuilder(val classDescriptor: ClassDescriptor, val context: Context) {
|
internal class ClassVtablesBuilder(val classDescriptor: ClassDescriptor, val context: Context) {
|
||||||
|
private val DEBUG = 0
|
||||||
|
|
||||||
|
private inline fun DEBUG_OUTPUT(severity: Int, block: () -> Unit) {
|
||||||
|
if (DEBUG > severity) block()
|
||||||
|
}
|
||||||
|
|
||||||
val vtableEntries: List<OverriddenFunctionDescriptor> by lazy {
|
val vtableEntries: List<OverriddenFunctionDescriptor> by lazy {
|
||||||
|
|
||||||
assert(!classDescriptor.isInterface)
|
assert(!classDescriptor.isInterface)
|
||||||
|
|
||||||
|
DEBUG_OUTPUT(0) {
|
||||||
|
println()
|
||||||
|
println("BUILDING vTable for ${classDescriptor.descriptor}")
|
||||||
|
}
|
||||||
|
|
||||||
val superVtableEntries = if (classDescriptor.isSpecialClassWithNoSupertypes()) {
|
val superVtableEntries = if (classDescriptor.isSpecialClassWithNoSupertypes()) {
|
||||||
emptyList()
|
emptyList()
|
||||||
} else {
|
} else {
|
||||||
@@ -101,12 +112,31 @@ internal class ClassVtablesBuilder(val classDescriptor: ClassDescriptor, val con
|
|||||||
val methods = classDescriptor.sortedOverridableOrOverridingMethods
|
val methods = classDescriptor.sortedOverridableOrOverridingMethods
|
||||||
val newVtableSlots = mutableListOf<OverriddenFunctionDescriptor>()
|
val newVtableSlots = mutableListOf<OverriddenFunctionDescriptor>()
|
||||||
|
|
||||||
|
DEBUG_OUTPUT(0) {
|
||||||
|
println()
|
||||||
|
println("SUPER vTable:")
|
||||||
|
superVtableEntries.forEach { println(" ${it.overriddenDescriptor.descriptor} -> ${it.descriptor.descriptor}") }
|
||||||
|
|
||||||
|
println()
|
||||||
|
println("METHODS:")
|
||||||
|
methods.forEach { println(" ${it.descriptor}") }
|
||||||
|
|
||||||
|
println()
|
||||||
|
println("BUILDING INHERITED vTable")
|
||||||
|
}
|
||||||
|
|
||||||
val inheritedVtableSlots = superVtableEntries.map { superMethod ->
|
val inheritedVtableSlots = superVtableEntries.map { superMethod ->
|
||||||
val overridingMethod = methods.singleOrNull { it.overrides(superMethod.descriptor) }
|
val overridingMethod = methods.singleOrNull { it.overrides(superMethod.descriptor) }
|
||||||
if (overridingMethod == null) {
|
if (overridingMethod == null) {
|
||||||
|
|
||||||
|
DEBUG_OUTPUT(0) { println("Taking super ${superMethod.overriddenDescriptor.descriptor} -> ${superMethod.descriptor.descriptor}") }
|
||||||
|
|
||||||
superMethod
|
superMethod
|
||||||
} else {
|
} else {
|
||||||
newVtableSlots.add(OverriddenFunctionDescriptor(overridingMethod, superMethod.descriptor))
|
newVtableSlots.add(OverriddenFunctionDescriptor(overridingMethod, superMethod.descriptor))
|
||||||
|
|
||||||
|
DEBUG_OUTPUT(0) { println("Taking overridden ${superMethod.overriddenDescriptor.descriptor} -> ${overridingMethod.descriptor}") }
|
||||||
|
|
||||||
OverriddenFunctionDescriptor(overridingMethod, superMethod.overriddenDescriptor)
|
OverriddenFunctionDescriptor(overridingMethod, superMethod.overriddenDescriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,6 +151,16 @@ internal class ClassVtablesBuilder(val classDescriptor: ClassDescriptor, val con
|
|||||||
.distinctBy { it.descriptor to it.bridgeDirections }
|
.distinctBy { it.descriptor to it.bridgeDirections }
|
||||||
.filter { it.descriptor.isOverridable }
|
.filter { it.descriptor.isOverridable }
|
||||||
|
|
||||||
|
DEBUG_OUTPUT(0) {
|
||||||
|
println()
|
||||||
|
println("INHERITED vTable slots:")
|
||||||
|
inheritedVtableSlots.forEach { println(" ${it.overriddenDescriptor.descriptor} -> ${it.descriptor.descriptor}") }
|
||||||
|
|
||||||
|
println()
|
||||||
|
println("MY OWN vTable slots:")
|
||||||
|
filteredNewVtableSlots.forEach { println(" ${it.overriddenDescriptor.descriptor} -> ${it.descriptor.descriptor}") }
|
||||||
|
}
|
||||||
|
|
||||||
inheritedVtableSlots + filteredNewVtableSlots.sortedBy { it.overriddenDescriptor.functionName.localHash.value }
|
inheritedVtableSlots + filteredNewVtableSlots.sortedBy { it.overriddenDescriptor.functionName.localHash.value }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user