From 03594baa07e459d8c1417142029219eda9b35af8 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 8 Dec 2020 01:10:51 +0300 Subject: [PATCH] [IR] Improve dumpKotlinLike * Generate a comment for modules. * Fix printing supertypes for classes. * Don't fail while printing constructor call if data's parent isn't IrClass --- .../jetbrains/kotlin/ir/util/dumpKotlinLike.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/dumpKotlinLike.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/dumpKotlinLike.kt index 496aa6f74bb..fbf847d5202 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/dumpKotlinLike.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/dumpKotlinLike.kt @@ -110,6 +110,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption } override fun visitModuleFragment(declaration: IrModuleFragment, data: IrDeclaration?) { + p.println("// MODULE: ${declaration.name.asString()}") declaration.acceptChildren(this, null) } @@ -176,11 +177,18 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption p.printWithNoIndent(declaration.name.asString()) declaration.printTypeParametersWithNoIndent() + // TODO no test if (declaration.superTypes.isNotEmpty()) { - for ((i, type) in declaration.superTypes.withIndex()) { + var first = true + for (type in declaration.superTypes) { if (type.isAny()) continue - p.printWithNoIndent(if (i > 0) ", " else " : ") + if (!first) { + p.printWithNoIndent(", ") + } else { + p.printWithNoIndent(" : ") + first = false + } type.printTypeWithNoIndent() } @@ -991,8 +999,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption ) { // TODO flag to omit comment block? val delegatingClass = symbol.owner.parentAsClass - // TODO don't crash when parent isn't class - val currentClass = data?.parentAsClass + val currentClass = data?.parent as? IrClass val delegatingClassName = delegatingClass.name.asString() val name = if (data is IrConstructor) {