[IR] KotlinLikeDumper: better support for callable references
This commit is contained in:
committed by
teamcityserver
parent
87eb06a21f
commit
0d3d61862b
@@ -865,22 +865,24 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
|
|
||||||
override fun visitCall(expression: IrCall, data: IrDeclaration?) {
|
override fun visitCall(expression: IrCall, data: IrDeclaration?) {
|
||||||
// TODO process specially builtin symbols
|
// TODO process specially builtin symbols
|
||||||
expression.printFunctionAccessExpressionWithNoIndent(
|
expression.printMemberAccessExpressionWithNoIndent(
|
||||||
expression.symbol.owner.name.asString(),
|
expression.symbol.owner.name.asString(),
|
||||||
superQualifierSymbol = expression.superQualifierSymbol,
|
expression.symbol.owner.valueParameters,
|
||||||
omitBracesIfNoArguments = false,
|
expression.superQualifierSymbol,
|
||||||
data
|
omitAllBracketsIfNoArguments = false,
|
||||||
|
data = data,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructorCall(expression: IrConstructorCall, data: IrDeclaration?) {
|
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.printFunctionAccessExpressionWithNoIndent(
|
expression.printMemberAccessExpressionWithNoIndent(
|
||||||
clazz.name.asString(),
|
clazz.name.asString(),
|
||||||
|
expression.symbol.owner.valueParameters,
|
||||||
superQualifierSymbol = null,
|
superQualifierSymbol = null,
|
||||||
omitBracesIfNoArguments = clazz.isAnnotationClass,
|
omitAllBracketsIfNoArguments = clazz.isAnnotationClass,
|
||||||
data
|
data = data,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -912,19 +914,24 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
delegatingClassName // required only for IrEnumConstructorCall
|
delegatingClassName // required only for IrEnumConstructorCall
|
||||||
}
|
}
|
||||||
|
|
||||||
printFunctionAccessExpressionWithNoIndent(
|
printMemberAccessExpressionWithNoIndent(
|
||||||
name,
|
name,
|
||||||
|
symbol.owner.valueParameters,
|
||||||
superQualifierSymbol = null,
|
superQualifierSymbol = null,
|
||||||
omitBracesIfNoArguments = false,
|
omitAllBracketsIfNoArguments = false,
|
||||||
data
|
data = data,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrFunctionAccessExpression.printFunctionAccessExpressionWithNoIndent(
|
private fun IrMemberAccessExpression<*>.printMemberAccessExpressionWithNoIndent(
|
||||||
name: String,
|
name: String,
|
||||||
|
valueParameters: List<IrValueParameter>,
|
||||||
superQualifierSymbol: IrClassSymbol?,
|
superQualifierSymbol: IrClassSymbol?,
|
||||||
omitBracesIfNoArguments: Boolean,
|
omitAllBracketsIfNoArguments: Boolean,
|
||||||
data: IrDeclaration?
|
data: IrDeclaration?,
|
||||||
|
accessOperator: String = ".",
|
||||||
|
omitAccessOperatorIfNoReceivers: Boolean = true,
|
||||||
|
wrapArguments: Boolean = false
|
||||||
) {
|
) {
|
||||||
// TODO origin
|
// TODO origin
|
||||||
|
|
||||||
@@ -954,15 +961,25 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dispatchReceiver != null || extensionReceiver != null || superQualifierSymbol != null) {
|
if (!omitAccessOperatorIfNoReceivers ||
|
||||||
p.printWithNoIndent(".")
|
(dispatchReceiver != null || extensionReceiver != null || superQualifierSymbol != null)
|
||||||
|
) {
|
||||||
|
p.printWithNoIndent(accessOperator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// what if it's unbound
|
|
||||||
val declaration = symbol.owner
|
|
||||||
|
|
||||||
p.printWithNoIndent(name)
|
p.printWithNoIndent(name)
|
||||||
|
|
||||||
|
fun allValueArgumentsAreNull(): Boolean {
|
||||||
|
for (i in 0 until valueArgumentsCount) {
|
||||||
|
if (getValueArgument(i) != null) return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (omitAllBracketsIfNoArguments && typeArgumentsCount == 0 && (valueArgumentsCount == 0 || allValueArgumentsAreNull())) return
|
||||||
|
|
||||||
|
if (wrapArguments) p.printWithNoIndent("/*")
|
||||||
|
|
||||||
if (typeArgumentsCount > 0) {
|
if (typeArgumentsCount > 0) {
|
||||||
p.printWithNoIndent("<")
|
p.printWithNoIndent("<")
|
||||||
repeat(typeArgumentsCount) {
|
repeat(typeArgumentsCount) {
|
||||||
@@ -975,15 +992,6 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printWithNoIndent(">")
|
p.printWithNoIndent(">")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allValueArgumentsAreNull(): Boolean {
|
|
||||||
for (i in 0 until valueArgumentsCount) {
|
|
||||||
if (getValueArgument(i) != null) return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (omitBracesIfNoArguments && typeArgumentsCount == 0 && (valueArgumentsCount == 0 || allValueArgumentsAreNull())) return
|
|
||||||
|
|
||||||
p.printWithNoIndent("(")
|
p.printWithNoIndent("(")
|
||||||
|
|
||||||
// TODO introduce a flag to print receiver this way?
|
// TODO introduce a flag to print receiver this way?
|
||||||
@@ -999,12 +1007,13 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
getValueArgument(i)?.let {
|
getValueArgument(i)?.let {
|
||||||
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(valueParameters[i].name.asString() + " = ")
|
||||||
it.accept(this@KotlinLikeDumper, data)
|
it.accept(this@KotlinLikeDumper, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.printWithNoIndent(")")
|
p.printWithNoIndent(")")
|
||||||
|
if (wrapArguments) p.printWithNoIndent("*/")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall, data: IrDeclaration?) {
|
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall, data: IrDeclaration?) {
|
||||||
@@ -1147,19 +1156,6 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
p.printWithNoIndent("::class")
|
p.printWithNoIndent("::class")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCallableReference(expression: IrCallableReference<*>, data: IrDeclaration?) {
|
|
||||||
// TODO check
|
|
||||||
/*
|
|
||||||
TODO
|
|
||||||
dispatchReceiver
|
|
||||||
extensionReceiver
|
|
||||||
getTypeArgument
|
|
||||||
getValueArgument
|
|
||||||
*/
|
|
||||||
p.printWithNoIndent("::")
|
|
||||||
p.printWithNoIndent(expression.referencedName.asString())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitClassReference(expression: IrClassReference, data: IrDeclaration?) {
|
override fun visitClassReference(expression: IrClassReference, data: IrDeclaration?) {
|
||||||
// TODO use classType
|
// TODO use classType
|
||||||
p.printWithNoIndent((expression.symbol.owner as IrDeclarationWithName).name.asString())
|
p.printWithNoIndent((expression.symbol.owner as IrDeclarationWithName).name.asString())
|
||||||
@@ -1358,15 +1354,31 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunctionReference(expression: IrFunctionReference, data: IrDeclaration?) {
|
override fun visitFunctionReference(expression: IrFunctionReference, data: IrDeclaration?) {
|
||||||
super.visitFunctionReference(expression, data)
|
// TODO reflectionTarget
|
||||||
|
expression.printCallableReferenceWithNoIndent(expression.symbol.owner.valueParameters, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPropertyReference(expression: IrPropertyReference, data: IrDeclaration?) {
|
override fun visitPropertyReference(expression: IrPropertyReference, data: IrDeclaration?) {
|
||||||
super.visitPropertyReference(expression, data)
|
// TODO do we need additional fields (field, getter, setter)?
|
||||||
|
expression.printCallableReferenceWithNoIndent(emptyList(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: IrDeclaration?) {
|
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: IrDeclaration?) {
|
||||||
super.visitLocalDelegatedPropertyReference(expression, data)
|
// TODO do we need additional fields (delegate, getter, setter)?
|
||||||
|
expression.printCallableReferenceWithNoIndent(emptyList(), data)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun IrCallableReference<*>.printCallableReferenceWithNoIndent(valueParameters: List<IrValueParameter>, data: IrDeclaration?) {
|
||||||
|
printMemberAccessExpressionWithNoIndent(
|
||||||
|
referencedName.asString(), // effectively it's same as `symbol.owner.name.asString()`
|
||||||
|
valueParameters,
|
||||||
|
superQualifierSymbol = null,
|
||||||
|
omitAllBracketsIfNoArguments = true,
|
||||||
|
data = data,
|
||||||
|
accessOperator = "::",
|
||||||
|
omitAccessOperatorIfNoReceivers = false,
|
||||||
|
wrapArguments = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBranch(branch: IrBranch, data: IrDeclaration?) {
|
override fun visitBranch(branch: IrBranch, data: IrDeclaration?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user