[IR] KotlinLikeDumper: support for IrEnumConstructorCall and better rendering for IrEnumEntry
This commit is contained in:
committed by
teamcityserver
parent
b518c19b38
commit
6e318893f6
@@ -11,9 +11,7 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
@@ -41,7 +39,7 @@ import org.jetbrains.kotlin.utils.Printer
|
|||||||
|
|
||||||
fun IrElement.dumpKotlinLike(options: KotlinLikeDumpOptions = KotlinLikeDumpOptions()): String {
|
fun IrElement.dumpKotlinLike(options: KotlinLikeDumpOptions = KotlinLikeDumpOptions()): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
acceptVoid(KotlinLikeDumper(Printer(sb, " "), options))
|
accept(KotlinLikeDumper(Printer(sb, 1, " "), options), null)
|
||||||
return sb.toString()
|
return sb.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +76,8 @@ enum class FakeOverridesStrategy {
|
|||||||
NONE
|
NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOptions) : IrElementVisitorVoid {
|
private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOptions) : IrElementVisitor<Unit, IrDeclaration?> {
|
||||||
override fun visitElement(element: IrElement) {
|
override fun visitElement(element: IrElement, data: IrDeclaration?) {
|
||||||
val e = "/* ERROR: unsupported element type: " + element.javaClass.simpleName + " */"
|
val e = "/* ERROR: unsupported element type: " + element.javaClass.simpleName + " */"
|
||||||
if (element is IrExpression) {
|
if (element is IrExpression) {
|
||||||
// TODO message?
|
// TODO message?
|
||||||
@@ -90,11 +88,11 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitModuleFragment(declaration: IrModuleFragment) {
|
override fun visitModuleFragment(declaration: IrModuleFragment, data: IrDeclaration?) {
|
||||||
declaration.acceptChildrenVoid(this)
|
declaration.acceptChildren(this, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFile(declaration: IrFile) {
|
override fun visitFile(declaration: IrFile, data: IrDeclaration?) {
|
||||||
if (options.printRegionsPerFile) p.println("//region block: ${declaration.name}")
|
if (options.printRegionsPerFile) p.println("//region block: ${declaration.name}")
|
||||||
|
|
||||||
if (options.printFileName) p.println("// FILE: ${declaration.name}")
|
if (options.printFileName) p.println("// FILE: ${declaration.name}")
|
||||||
@@ -106,12 +104,12 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
}
|
}
|
||||||
if (!p.isEmpty) p.printlnWithNoIndent()
|
if (!p.isEmpty) p.printlnWithNoIndent()
|
||||||
|
|
||||||
declaration.declarations.forEach { it.acceptVoid(this) }
|
declaration.declarations.forEach { it.accept(this, null) }
|
||||||
|
|
||||||
if (options.printRegionsPerFile) p.println("//endregion")
|
if (options.printRegionsPerFile) p.println("//endregion")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass) {
|
override fun visitClass(declaration: IrClass, data: IrDeclaration?) {
|
||||||
// TODO omit super class for enums, annotations?
|
// TODO omit super class for enums, annotations?
|
||||||
// TODO omit Companion name for companion objects?
|
// TODO omit Companion name for companion objects?
|
||||||
// TODO thisReceiver
|
// TODO thisReceiver
|
||||||
@@ -169,7 +167,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printlnWithNoIndent(" {")
|
p.printlnWithNoIndent(" {")
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|
||||||
declaration.declarations.forEach { it.acceptVoid(this) }
|
declaration.declarations.forEach { it.accept(this, declaration) }
|
||||||
|
|
||||||
p.popIndent()
|
p.popIndent()
|
||||||
p.println("}")
|
p.println("}")
|
||||||
@@ -199,7 +197,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
|
|
||||||
it.defaultValue?.let { v ->
|
it.defaultValue?.let { v ->
|
||||||
p.printWithNoIndent(" = ")
|
p.printWithNoIndent(" = ")
|
||||||
v.acceptVoid(this@KotlinLikeDumper)
|
v.accept(this@KotlinLikeDumper, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.printWithNoIndent(")")
|
p.printWithNoIndent(")")
|
||||||
@@ -265,7 +263,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
|
|
||||||
private fun IrConstructorCall.printAnAnnotationWithNoIndent(prefix: String = "") {
|
private fun IrConstructorCall.printAnAnnotationWithNoIndent(prefix: String = "") {
|
||||||
p.printWithNoIndent("@" + (if (prefix.isEmpty()) "" else "$prefix:"))
|
p.printWithNoIndent("@" + (if (prefix.isEmpty()) "" else "$prefix:"))
|
||||||
visitConstructorCall(this)
|
visitConstructorCall(this, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrAnnotationContainer.printlnAnnotations(prefix: String = "") {
|
private fun IrAnnotationContainer.printlnAnnotations(prefix: String = "") {
|
||||||
@@ -402,7 +400,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p(isData, "data")
|
p(isData, "data")
|
||||||
p(isCompanion, "companion")
|
p(isCompanion, "companion")
|
||||||
p(isFunInterface, "fun")
|
p(isFunInterface, "fun")
|
||||||
p(classKind) { name.toLowerCase().replace('_', ' ') }
|
p(classKind) { name.toLowerCase().replace('_', ' ') + if (this == ClassKind.ENUM_ENTRY) " class" else "" }
|
||||||
p(isInfix, "infix")
|
p(isInfix, "infix")
|
||||||
p(isOperator, "operator")
|
p(isOperator, "operator")
|
||||||
}
|
}
|
||||||
@@ -492,13 +490,13 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
printWhereClauseIfNeededWithNoIndent()
|
printWhereClauseIfNeededWithNoIndent()
|
||||||
p.printWithNoIndent(" ")
|
p.printWithNoIndent(" ")
|
||||||
|
|
||||||
body?.acceptVoid(this@KotlinLikeDumper)
|
body?.accept(this@KotlinLikeDumper, null)
|
||||||
} else {
|
} else {
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSimpleFunction(declaration: IrSimpleFunction) {
|
override fun visitSimpleFunction(declaration: IrSimpleFunction, data: IrDeclaration?) {
|
||||||
declaration.printSimpleFunction(
|
declaration.printSimpleFunction(
|
||||||
"fun ",
|
"fun ",
|
||||||
declaration.name.asString(),
|
declaration.name.asString(),
|
||||||
@@ -508,7 +506,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructor(declaration: IrConstructor) {
|
override fun visitConstructor(declaration: IrConstructor, data: IrDeclaration?) {
|
||||||
// TODO primary!!!
|
// TODO primary!!!
|
||||||
// TODO name?
|
// TODO name?
|
||||||
// TODO is it worth to merge code for IrConstructor and IrSimpleFunction?
|
// TODO is it worth to merge code for IrConstructor and IrSimpleFunction?
|
||||||
@@ -548,11 +546,11 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
declaration.printWhereClauseIfNeededWithNoIndent()
|
declaration.printWhereClauseIfNeededWithNoIndent()
|
||||||
p.printWithNoIndent(" ")
|
p.printWithNoIndent(" ")
|
||||||
p(declaration.isPrimary, commentBlockH("primary"))
|
p(declaration.isPrimary, commentBlockH("primary"))
|
||||||
declaration.body?.acceptVoid(this)
|
declaration.body?.accept(this, declaration)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitProperty(declaration: IrProperty) {
|
override fun visitProperty(declaration: IrProperty, data: IrDeclaration?) {
|
||||||
if (options.printFakeOverridesStrategy == FakeOverridesStrategy.NONE && declaration.isFakeOverride) return
|
if (options.printFakeOverridesStrategy == FakeOverridesStrategy.NONE && declaration.isFakeOverride) return
|
||||||
|
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
@@ -623,7 +621,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
// TODO it's not valid kotlin
|
// TODO it's not valid kotlin
|
||||||
declaration.backingField?.initializer?.let {
|
declaration.backingField?.initializer?.let {
|
||||||
p.print("field = ")
|
p.print("field = ")
|
||||||
it.acceptVoid(this)
|
it.accept(this, declaration)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,7 +638,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
printSimpleFunction("", s, printTypeParametersAndExtensionReceiver = false, printSignatureAndBody = isDefaultAccessor)
|
printSimpleFunction("", s, printTypeParametersAndExtensionReceiver = false, printSignatureAndBody = isDefaultAccessor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitField(declaration: IrField) {
|
override fun visitField(declaration: IrField, data: IrDeclaration?) {
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
p.print("")
|
p.print("")
|
||||||
|
|
||||||
@@ -681,7 +679,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
|
|
||||||
declaration.initializer?.let {
|
declaration.initializer?.let {
|
||||||
p.printWithNoIndent(" = ")
|
p.printWithNoIndent(" = ")
|
||||||
it.acceptVoid(this)
|
it.accept(this, declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO correspondingPropertySymbol
|
// TODO correspondingPropertySymbol
|
||||||
@@ -689,7 +687,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitTypeAlias(declaration: IrTypeAlias) {
|
override fun visitTypeAlias(declaration: IrTypeAlias, data: IrDeclaration?) {
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
p.print("")
|
p.print("")
|
||||||
|
|
||||||
@@ -706,7 +704,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitVariable(declaration: IrVariable) {
|
override fun visitVariable(declaration: IrVariable, data: IrDeclaration?) {
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
p.print("")
|
p.print("")
|
||||||
|
|
||||||
@@ -716,7 +714,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
|
|
||||||
declaration.initializer?.let {
|
declaration.initializer?.let {
|
||||||
p.printWithNoIndent(" = ")
|
p.printWithNoIndent(" = ")
|
||||||
it.acceptVoid(this)
|
it.accept(this, declaration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,20 +726,26 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
type.printTypeWithNoIndent()
|
type.printTypeWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitEnumEntry(declaration: IrEnumEntry) {
|
override fun visitEnumEntry(declaration: IrEnumEntry, data: IrDeclaration?) {
|
||||||
|
// TODO better rendering for enum entries
|
||||||
|
|
||||||
|
declaration.correspondingClass?.let { p.println() }
|
||||||
|
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
p.print("")
|
p.print("")
|
||||||
|
|
||||||
// TODO correspondingClass
|
|
||||||
p.printWithNoIndent(declaration.name)
|
p.printWithNoIndent(declaration.name)
|
||||||
declaration.initializerExpression?.let {
|
declaration.initializerExpression?.let {
|
||||||
// TODO better rendering for init
|
p.printWithNoIndent(" = ")
|
||||||
p.printWithNoIndent(" init = ")
|
it.accept(this, declaration)
|
||||||
it.acceptVoid(this)
|
}
|
||||||
} ?: p.printlnWithNoIndent()
|
p.println()
|
||||||
|
|
||||||
|
declaration.correspondingClass?.accept(this, declaration)
|
||||||
|
|
||||||
|
p.println()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) {
|
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: IrDeclaration?) {
|
||||||
// Looks like IrAnonymousInitializer has annotations accidentally. No tests.
|
// Looks like IrAnonymousInitializer has annotations accidentally. No tests.
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
p.print("")
|
p.print("")
|
||||||
@@ -749,12 +753,12 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
// TODO looks like there are no irText tests for isStatic flag
|
// TODO looks like there are no irText tests for isStatic flag
|
||||||
p(declaration.isStatic, commentBlockH("static"))
|
p(declaration.isStatic, commentBlockH("static"))
|
||||||
p.printWithNoIndent("init ")
|
p.printWithNoIndent("init ")
|
||||||
declaration.body.acceptVoid(this)
|
declaration.body.accept(this, declaration)
|
||||||
|
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty) {
|
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: IrDeclaration?) {
|
||||||
declaration.printlnAnnotations()
|
declaration.printlnAnnotations()
|
||||||
p.print("")
|
p.print("")
|
||||||
|
|
||||||
@@ -764,7 +768,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|
||||||
declaration.delegate.acceptVoid(this)
|
declaration.delegate.accept(this, declaration)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
|
|
||||||
declaration.getter.printAccessor("get")
|
declaration.getter.printAccessor("get")
|
||||||
@@ -774,36 +778,41 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitExpressionBody(body: IrExpressionBody) {
|
override fun visitExpressionBody(body: IrExpressionBody, data: IrDeclaration?) {
|
||||||
// TODO should we print something here?
|
// TODO should we print something here?
|
||||||
body.expression.acceptVoid(this)
|
body.expression.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBlockBody(body: IrBlockBody) {
|
override fun visitBlockBody(body: IrBlockBody, data: IrDeclaration?) {
|
||||||
body.printStatementContainer("{", "}")
|
body.printStatementContainer("{", "}", data)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitComposite(expression: IrComposite) {
|
override fun visitComposite(expression: IrComposite, data: IrDeclaration?) {
|
||||||
expression.printStatementContainer("// COMPOSITE {", "// }", withIndentation = false)
|
expression.printStatementContainer("// COMPOSITE {", "// }", data, withIndentation = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBlock(expression: IrBlock) {
|
override fun visitBlock(expression: IrBlock, data: IrDeclaration?) {
|
||||||
// TODO special blocks using `origin`
|
// TODO special blocks using `origin`
|
||||||
// TODO inlineFunctionSymbol for IrReturnableBlock
|
// TODO inlineFunctionSymbol for IrReturnableBlock
|
||||||
// TODO no tests for IrReturnableBlock?
|
// TODO no tests for IrReturnableBlock?
|
||||||
val kind = if (expression is IrReturnableBlock) "RETURNABLE BLOCK" else "BLOCK"
|
val kind = if (expression is IrReturnableBlock) "RETURNABLE BLOCK" else "BLOCK"
|
||||||
expression.printStatementContainer("{ // $kind", "}")
|
expression.printStatementContainer("{ // $kind", "}", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrStatementContainer.printStatementContainer(before: String, after: String, withIndentation: Boolean = true) {
|
private fun IrStatementContainer.printStatementContainer(
|
||||||
|
before: String,
|
||||||
|
after: String,
|
||||||
|
data: IrDeclaration?,
|
||||||
|
withIndentation: Boolean = true
|
||||||
|
) {
|
||||||
// TODO type for IrContainerExpression
|
// TODO type for IrContainerExpression
|
||||||
p.printlnWithNoIndent(before)
|
p.printlnWithNoIndent(before)
|
||||||
if (withIndentation) p.pushIndent()
|
if (withIndentation) p.pushIndent()
|
||||||
|
|
||||||
statements.forEach {
|
statements.forEach {
|
||||||
if (it is IrExpression) p.printIndent()
|
if (it is IrExpression) p.printIndent()
|
||||||
it.acceptVoid(this@KotlinLikeDumper)
|
it.accept(this@KotlinLikeDumper, data)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,33 +820,73 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.print(after)
|
p.print(after)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSyntheticBody(body: IrSyntheticBody) {
|
override fun visitSyntheticBody(body: IrSyntheticBody, data: IrDeclaration?) {
|
||||||
p.printlnWithNoIndent("/* Synthetic body for ${body.kind} */")
|
p.printlnWithNoIndent("/* Synthetic body for ${body.kind} */")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall) {
|
override fun visitCall(expression: IrCall, data: IrDeclaration?) {
|
||||||
// TODO process specially builtin symbols
|
// TODO process specially builtin symbols
|
||||||
expression.printIrFunctionAccessExpressionWithNoIndent(
|
expression.printIrFunctionAccessExpressionWithNoIndent(
|
||||||
expression.symbol.owner.name,
|
expression.symbol.owner.name.asString(),
|
||||||
superQualifierSymbol = expression.superQualifierSymbol,
|
superQualifierSymbol = expression.superQualifierSymbol,
|
||||||
omitBracesIfNoArguments = false
|
omitBracesIfNoArguments = false,
|
||||||
|
data
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructorCall(expression: IrConstructorCall) {
|
override fun visitConstructorCall(expression: IrConstructorCall, data: IrDeclaration?) {
|
||||||
// TODO could constructors have receiver?
|
// TODO could constructors have receiver?
|
||||||
val clazz = expression.symbol.owner.parentAsClass
|
val clazz = expression.symbol.owner.parentAsClass
|
||||||
expression.printIrFunctionAccessExpressionWithNoIndent(
|
expression.printIrFunctionAccessExpressionWithNoIndent(
|
||||||
clazz.name,
|
clazz.name.asString(),
|
||||||
superQualifierSymbol = null,
|
superQualifierSymbol = null,
|
||||||
omitBracesIfNoArguments = clazz.isAnnotationClass
|
omitBracesIfNoArguments = clazz.isAnnotationClass,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: IrDeclaration?) {
|
||||||
|
// TODO skip Any?
|
||||||
|
// TODO flag to omit comment block?
|
||||||
|
val delegatingClass = expression.symbol.owner.parentAsClass
|
||||||
|
val currentClass = data?.parentAsClass
|
||||||
|
val delegatingClassName = delegatingClass.name.asString()
|
||||||
|
val name = when (currentClass) {
|
||||||
|
null -> "delegating/*$delegatingClassName*/"
|
||||||
|
delegatingClass -> "this/*$delegatingClassName*/"
|
||||||
|
else -> "super/*$delegatingClassName*/"
|
||||||
|
}
|
||||||
|
expression.printIrFunctionAccessExpressionWithNoIndent(
|
||||||
|
name,
|
||||||
|
superQualifierSymbol = null,
|
||||||
|
omitBracesIfNoArguments = false,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: IrDeclaration?) {
|
||||||
|
val delegatingClass = expression.symbol.owner.parentAsClass
|
||||||
|
val currentClass = data?.parentAsClass
|
||||||
|
val delegatingClassName = delegatingClass.name.asString()
|
||||||
|
val name = when {
|
||||||
|
data !is IrConstructor -> delegatingClassName
|
||||||
|
currentClass == null -> "delegating/*$delegatingClassName*/"
|
||||||
|
currentClass == delegatingClass -> "this/*$delegatingClassName*/"
|
||||||
|
else -> "super/*$delegatingClassName*/"
|
||||||
|
}
|
||||||
|
expression.printIrFunctionAccessExpressionWithNoIndent(
|
||||||
|
name,
|
||||||
|
superQualifierSymbol = null,
|
||||||
|
omitBracesIfNoArguments = false,
|
||||||
|
data
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrFunctionAccessExpression.printIrFunctionAccessExpressionWithNoIndent(
|
private fun IrFunctionAccessExpression.printIrFunctionAccessExpressionWithNoIndent(
|
||||||
name: Name,
|
name: String,
|
||||||
superQualifierSymbol: IrClassSymbol?,
|
superQualifierSymbol: IrClassSymbol?,
|
||||||
omitBracesIfNoArguments: Boolean
|
omitBracesIfNoArguments: Boolean,
|
||||||
|
data: IrDeclaration?
|
||||||
) {
|
) {
|
||||||
// TODO origin
|
// TODO origin
|
||||||
|
|
||||||
@@ -850,17 +899,18 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
|
|
||||||
superQualifierSymbol?.let {
|
superQualifierSymbol?.let {
|
||||||
// TODO should we print super classifier somehow?
|
// TODO should we print super classifier somehow?
|
||||||
|
// TODO which supper? smart mode?
|
||||||
p.printWithNoIndent("super")
|
p.printWithNoIndent("super")
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatchReceiver?.let {
|
dispatchReceiver?.let {
|
||||||
if (superQualifierSymbol == null) it.acceptVoid(this@KotlinLikeDumper)
|
if (superQualifierSymbol == null) it.accept(this@KotlinLikeDumper, data)
|
||||||
// else assert dispatchReceiver === this
|
// else assert dispatchReceiver === this
|
||||||
}
|
}
|
||||||
if (twoReceivers) {
|
if (twoReceivers) {
|
||||||
p.printWithNoIndent(", ")
|
p.printWithNoIndent(", ")
|
||||||
}
|
}
|
||||||
extensionReceiver?.acceptVoid(this@KotlinLikeDumper)
|
extensionReceiver?.accept(this@KotlinLikeDumper, data)
|
||||||
if (twoReceivers) {
|
if (twoReceivers) {
|
||||||
p.printWithNoIndent(")")
|
p.printWithNoIndent(")")
|
||||||
}
|
}
|
||||||
@@ -873,7 +923,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
// what if it's unbound
|
// what if it's unbound
|
||||||
val declaration = symbol.owner
|
val declaration = symbol.owner
|
||||||
|
|
||||||
p.printWithNoIndent(name.asString())
|
p.printWithNoIndent(name)
|
||||||
|
|
||||||
if (typeArgumentsCount > 0) {
|
if (typeArgumentsCount > 0) {
|
||||||
p.printWithNoIndent("<")
|
p.printWithNoIndent("<")
|
||||||
@@ -904,24 +954,14 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
if (i > 0) p.printWithNoIndent(", ")
|
if (i > 0) p.printWithNoIndent(", ")
|
||||||
// TODO flag to print param name
|
// TODO flag to print param name
|
||||||
p.printWithNoIndent(declaration.valueParameters[i].name.asString() + " = ")
|
p.printWithNoIndent(declaration.valueParameters[i].name.asString() + " = ")
|
||||||
it.acceptVoid(this@KotlinLikeDumper)
|
it.accept(this@KotlinLikeDumper, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printWithNoIndent(")")
|
p.printWithNoIndent(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall) {
|
override fun visitFunctionExpression(expression: IrFunctionExpression, data: IrDeclaration?) {
|
||||||
// TODO
|
|
||||||
p.printWithNoIndent("TODO(\"IrDelegatingConstructorCall\")")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitEnumConstructorCall(expression: IrEnumConstructorCall) {
|
|
||||||
// TODO
|
|
||||||
p.printWithNoIndent("TODO(\"IrEnumConstructorCall\")")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitFunctionExpression(expression: IrFunctionExpression) {
|
|
||||||
// TODO support
|
// TODO support
|
||||||
// TODO omit the name when it's possible
|
// TODO omit the name when it's possible
|
||||||
// TODO Is there a difference between `<anonymous>` and `<no name provided>`?
|
// TODO Is there a difference between `<anonymous>` and `<no name provided>`?
|
||||||
@@ -932,14 +972,14 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
expression.function.printSimpleFunction("fun ", expression.function.name.asString(), printTypeParametersAndExtensionReceiver = true, printSignatureAndBody = true)
|
expression.function.printSimpleFunction("fun ", expression.function.name.asString(), printTypeParametersAndExtensionReceiver = true, printSignatureAndBody = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitGetField(expression: IrGetField) {
|
override fun visitGetField(expression: IrGetField, data: IrDeclaration?) {
|
||||||
expression.printFieldAccess()
|
expression.printFieldAccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSetField(expression: IrSetField) {
|
override fun visitSetField(expression: IrSetField, data: IrDeclaration?) {
|
||||||
expression.printFieldAccess()
|
expression.printFieldAccess()
|
||||||
p.printWithNoIndent(" = ")
|
p.printWithNoIndent(" = ")
|
||||||
expression.value.acceptVoid(this)
|
expression.value.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrFieldAccessExpression.printFieldAccess() {
|
private fun IrFieldAccessExpression.printFieldAccess() {
|
||||||
@@ -948,27 +988,27 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printWithNoIndent("#" + symbol.owner.name.asString())
|
p.printWithNoIndent("#" + symbol.owner.name.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitReturn(expression: IrReturn) {
|
override fun visitReturn(expression: IrReturn, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent("return ")
|
p.printWithNoIndent("return ")
|
||||||
expression.value.acceptVoid(this)
|
expression.value.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitThrow(expression: IrThrow) {
|
override fun visitThrow(expression: IrThrow, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent("throw ")
|
p.printWithNoIndent("throw ")
|
||||||
expression.value.acceptVoid(this)
|
expression.value.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitStringConcatenation(expression: IrStringConcatenation) {
|
override fun visitStringConcatenation(expression: IrStringConcatenation, data: IrDeclaration?) {
|
||||||
// TODO escape? see IrTextTestCaseGenerated.Expressions#testStringTemplates
|
// TODO escape? see IrTextTestCaseGenerated.Expressions#testStringTemplates
|
||||||
expression.arguments.forEachIndexed { i, e ->
|
expression.arguments.forEachIndexed { i, e ->
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
p.printlnWithNoIndent(" + ")
|
p.printlnWithNoIndent(" + ")
|
||||||
}
|
}
|
||||||
e.acceptVoid(this)
|
e.accept(this, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T> visitConst(expression: IrConst<T>) {
|
override fun <T> visitConst(expression: IrConst<T>, data: IrDeclaration?) {
|
||||||
val kind = expression.kind
|
val kind = expression.kind
|
||||||
|
|
||||||
val (prefix, postfix) = when (kind) {
|
val (prefix, postfix) = when (kind) {
|
||||||
@@ -987,62 +1027,62 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printWithNoIndent(prefix, expression.value ?: "null", postfix)
|
p.printWithNoIndent(prefix, expression.value ?: "null", postfix)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitVararg(expression: IrVararg) {
|
override fun visitVararg(expression: IrVararg, data: IrDeclaration?) {
|
||||||
// TODO ???
|
// TODO ???
|
||||||
p.printWithNoIndent("[")
|
p.printWithNoIndent("[")
|
||||||
expression.elements.forEachIndexed { i, e ->
|
expression.elements.forEachIndexed { i, e ->
|
||||||
if (i > 0) p.printWithNoIndent(", ")
|
if (i > 0) p.printWithNoIndent(", ")
|
||||||
e.acceptVoid(this)
|
e.accept(this, data)
|
||||||
}
|
}
|
||||||
p.printWithNoIndent("]")
|
p.printWithNoIndent("]")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSpreadElement(spread: IrSpreadElement) {
|
override fun visitSpreadElement(spread: IrSpreadElement, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent("*")
|
p.printWithNoIndent("*")
|
||||||
spread.expression.acceptVoid(this)
|
spread.expression.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDeclarationReference(expression: IrDeclarationReference) {
|
override fun visitDeclarationReference(expression: IrDeclarationReference, data: IrDeclaration?) {
|
||||||
super.visitDeclarationReference(expression)
|
super.visitDeclarationReference(expression, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSingletonReference(expression: IrGetSingletonValue) {
|
override fun visitSingletonReference(expression: IrGetSingletonValue, data: IrDeclaration?) {
|
||||||
// TODO check
|
// TODO check
|
||||||
expression.type.printTypeWithNoIndent()
|
expression.type.printTypeWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitGetValue(expression: IrGetValue) {
|
override fun visitGetValue(expression: IrGetValue, data: IrDeclaration?) {
|
||||||
// TODO support `this` and receiver
|
// TODO support `this` and receiver
|
||||||
p.printWithNoIndent(expression.symbol.owner.name.asString())
|
p.printWithNoIndent(expression.symbol.owner.name.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSetValue(expression: IrSetValue) {
|
override fun visitSetValue(expression: IrSetValue, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent(expression.symbol.owner.name.asString() + " = ")
|
p.printWithNoIndent(expression.symbol.owner.name.asString() + " = ")
|
||||||
expression.value.acceptVoid(this)
|
expression.value.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitGetClass(expression: IrGetClass) {
|
override fun visitGetClass(expression: IrGetClass, data: IrDeclaration?) {
|
||||||
expression.argument.acceptVoid(this)
|
expression.argument.accept(this, data)
|
||||||
p.printWithNoIndent("::class")
|
p.printWithNoIndent("::class")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCallableReference(expression: IrCallableReference<*>) {
|
override fun visitCallableReference(expression: IrCallableReference<*>, data: IrDeclaration?) {
|
||||||
// TODO check
|
// TODO check
|
||||||
p.printWithNoIndent("::")
|
p.printWithNoIndent("::")
|
||||||
p.printWithNoIndent(expression.referencedName.asString())
|
p.printWithNoIndent(expression.referencedName.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassReference(expression: IrClassReference) {
|
override fun visitClassReference(expression: IrClassReference, data: IrDeclaration?) {
|
||||||
// TODO use type
|
// TODO use type
|
||||||
p.printWithNoIndent((expression.symbol.owner as IrDeclarationWithName).name.asString())
|
p.printWithNoIndent((expression.symbol.owner as IrDeclarationWithName).name.asString())
|
||||||
p.printWithNoIndent("::class")
|
p.printWithNoIndent("::class")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall) {
|
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall, data: IrDeclaration?) {
|
||||||
p.println("/* InstanceInitializerCall */")
|
p.println("/* InstanceInitializerCall */")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitTypeOperator(expression: IrTypeOperatorCall) {
|
override fun visitTypeOperator(expression: IrTypeOperatorCall, data: IrDeclaration?) {
|
||||||
val (operator, after) = when (expression.operator) {
|
val (operator, after) = when (expression.operator) {
|
||||||
IrTypeOperator.CAST -> "as" to ""
|
IrTypeOperator.CAST -> "as" to ""
|
||||||
IrTypeOperator.IMPLICIT_CAST -> "/*as" to " */"
|
IrTypeOperator.IMPLICIT_CAST -> "/*as" to " */"
|
||||||
@@ -1057,24 +1097,24 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
IrTypeOperator.REINTERPRET_CAST -> "/*=>" to " */"
|
IrTypeOperator.REINTERPRET_CAST -> "/*=>" to " */"
|
||||||
}
|
}
|
||||||
|
|
||||||
expression.argument.acceptVoid(this)
|
expression.argument.accept(this, data)
|
||||||
p.printWithNoIndent(" $operator ")
|
p.printWithNoIndent(" $operator ")
|
||||||
expression.typeOperand.printTypeWithNoIndent()
|
expression.typeOperand.printTypeWithNoIndent()
|
||||||
p.printWithNoIndent(after)
|
p.printWithNoIndent(after)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitWhen(expression: IrWhen) {
|
override fun visitWhen(expression: IrWhen, data: IrDeclaration?) {
|
||||||
p.printlnWithNoIndent("when {")
|
p.printlnWithNoIndent("when {")
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|
||||||
for (b in expression.branches) {
|
for (b in expression.branches) {
|
||||||
p.printIndent()
|
p.printIndent()
|
||||||
b.condition.acceptVoid(this)
|
b.condition.accept(this, data)
|
||||||
|
|
||||||
p.printWithNoIndent(" -> ")
|
p.printWithNoIndent(" -> ")
|
||||||
|
|
||||||
b.result.acceptVoid(this)
|
b.result.accept(this, data)
|
||||||
|
|
||||||
p.println()
|
p.println()
|
||||||
}
|
}
|
||||||
@@ -1083,65 +1123,65 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.print("}")
|
p.print("}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitWhileLoop(loop: IrWhileLoop) {
|
override fun visitWhileLoop(loop: IrWhileLoop, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent("while (")
|
p.printWithNoIndent("while (")
|
||||||
loop.condition.acceptVoid(this)
|
loop.condition.accept(this, data)
|
||||||
|
|
||||||
p.printWithNoIndent(") ")
|
p.printWithNoIndent(") ")
|
||||||
|
|
||||||
loop.body?.acceptVoid(this)
|
loop.body?.accept(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDoWhileLoop(loop: IrDoWhileLoop) {
|
override fun visitDoWhileLoop(loop: IrDoWhileLoop, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent("do")
|
p.printWithNoIndent("do")
|
||||||
|
|
||||||
loop.body?.acceptVoid(this)
|
loop.body?.accept(this, data)
|
||||||
|
|
||||||
p.print("while (")
|
p.print("while (")
|
||||||
loop.condition.acceptVoid(this)
|
loop.condition.accept(this, data)
|
||||||
p.printWithNoIndent(")")
|
p.printWithNoIndent(")")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitTry(aTry: IrTry) {
|
override fun visitTry(aTry: IrTry, data: IrDeclaration?) {
|
||||||
p.printWithNoIndent("try ")
|
p.printWithNoIndent("try ")
|
||||||
aTry.tryResult.acceptVoid(this)
|
aTry.tryResult.accept(this, data)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
|
|
||||||
aTry.catches.forEach { it.acceptVoid(this) }
|
aTry.catches.forEach { it.accept(this, data) }
|
||||||
|
|
||||||
aTry.finallyExpression?.let {
|
aTry.finallyExpression?.let {
|
||||||
p.print("finally ")
|
p.print("finally ")
|
||||||
it.acceptVoid(this)
|
it.accept(this, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCatch(aCatch: IrCatch) {
|
override fun visitCatch(aCatch: IrCatch, data: IrDeclaration?) {
|
||||||
p.print("catch (...) ")
|
p.print("catch (...) ")
|
||||||
aCatch.result.acceptVoid(this)
|
aCatch.result.accept(this, data)
|
||||||
p.printlnWithNoIndent()
|
p.printlnWithNoIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBreak(jump: IrBreak) {
|
override fun visitBreak(jump: IrBreak, data: IrDeclaration?) {
|
||||||
// TODO label
|
// TODO label
|
||||||
p.printWithNoIndent("break")
|
p.printWithNoIndent("break")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitContinue(jump: IrContinue) {
|
override fun visitContinue(jump: IrContinue, data: IrDeclaration?) {
|
||||||
// TODO label
|
// TODO label
|
||||||
p.printWithNoIndent("continue")
|
p.printWithNoIndent("continue")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitErrorDeclaration(declaration: IrErrorDeclaration) {
|
override fun visitErrorDeclaration(declaration: IrErrorDeclaration, data: IrDeclaration?) {
|
||||||
p.println("/* ERROR DECLARATION */")
|
p.println("/* ERROR DECLARATION */")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitErrorExpression(expression: IrErrorExpression) {
|
override fun visitErrorExpression(expression: IrErrorExpression, data: IrDeclaration?) {
|
||||||
// TODO description
|
// TODO description
|
||||||
p.printWithNoIndent("error(\"\") /* ERROR EXPRESSION */")
|
p.printWithNoIndent("error(\"\") /* ERROR EXPRESSION */")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitErrorCallExpression(expression: IrErrorCallExpression) {
|
override fun visitErrorCallExpression(expression: IrErrorCallExpression, data: IrDeclaration?) {
|
||||||
// TODO receiver, arguments
|
// TODO receiver, arguments
|
||||||
p.printWithNoIndent("error(\"\") /* ERROR CALL */")
|
p.printWithNoIndent("error(\"\") /* ERROR CALL */")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user