IR: get rid of descriptors in local delegated properties rendering

This commit is contained in:
Dmitry Petrov
2019-03-21 15:28:03 +03:00
parent 12e9943f8f
commit d4525e19dd
21 changed files with 104 additions and 79 deletions
@@ -183,16 +183,12 @@ class DumpIrTreeVisitor(
private fun IrMemberAccessExpression.getTypeParameterNames(expectedCount: Int): List<String> =
if (this is IrDeclarationReference && symbol.isBound)
symbol.owner.getTypeParameterNames(expectedCount)
else if (this is IrCallableReference)
getPlaceholderParameterNames(expectedCount) // TODO IrCallableReference should be an IrDeclarationReference
else
getPlaceholderParameterNames(expectedCount)
private fun IrMemberAccessExpression.getValueParameterNames(expectedCount: Int): List<String> =
if (this is IrDeclarationReference && symbol.isBound)
symbol.owner.getValueParameterNames(expectedCount)
else if (this is IrCallableReference)
getPlaceholderParameterNames(expectedCount) // TODO IrCallableReference should be an IrDeclarationReference
else
getPlaceholderParameterNames(expectedCount)
@@ -144,12 +144,7 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
append(declaration.name.asString())
append(' ')
if (declaration.typeParameters.isNotEmpty()) {
appendListWith(declaration.typeParameters, "<", ">", ", ") { typeParameter ->
append(typeParameter.name.asString())
}
append(' ')
}
renderTypeParameters(declaration)
appendListWith(declaration.valueParameters, "(", ")", ", ") { valueParameter ->
val varargElementType = valueParameter.varargElementType
@@ -179,6 +174,43 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
renderDeclaredIn(declaration)
}
private fun StringBuilder.renderTypeParameters(declaration: IrTypeParametersContainer) {
if (declaration.typeParameters.isNotEmpty()) {
appendListWith(declaration.typeParameters, "<", ">", ", ") { typeParameter ->
append(typeParameter.name.asString())
}
append(' ')
}
}
override fun visitProperty(declaration: IrProperty, data: Nothing?) =
buildString {
append(declaration.visibility)
append(' ')
append(declaration.modality.toString().toLowerCase())
append(' ')
append(declaration.name.asString())
val type = declaration.getter?.returnType ?: declaration.backingField?.type
if (type != null) {
append(": ")
append(type.render())
}
append(' ')
append(declaration.renderPropertyFlags())
}
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: Nothing?): String =
buildString {
if (declaration.isVar) append("var ") else append("val ")
append(declaration.name.asString())
append(": ")
append(declaration.type.render())
append(" by (...)")
}
private fun StringBuilder.renderDeclaredIn(irDeclaration: IrDeclaration) {
append("declared in ")
renderParentOfReferencedDeclaration(irDeclaration)
@@ -508,7 +540,7 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: Nothing?): String =
buildString {
append("LOCAL_DELEGATED_PROPERTY_REFERENCE ")
append("'${expression.descriptor.ref()}' ")
append("'${expression.symbol.renderReference()}' ")
append("delegate='${expression.delegate.renderReference()}' ")
append("getter='${expression.getter.renderReference()}' ")
appendNullableAttribute("setter=", expression.setter) { "'${it.renderReference()}'" }
@@ -535,17 +567,17 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
"DYN_MEMBER memberName='${expression.memberName}' type=${expression.type.render()}"
override fun visitErrorDeclaration(declaration: IrErrorDeclaration, data: Nothing?): String =
"ERROR_DECL ${declaration.descriptor::class.java.simpleName} ${declaration.descriptor.ref()}"
"ERROR_DECL ${declaration.descriptor::class.java.simpleName} " +
descriptorRendererForErrorDeclarations.renderDescriptor(declaration.descriptor.original)
override fun visitErrorExpression(expression: IrErrorExpression, data: Nothing?): String =
"ERROR_EXPR '${expression.description}' type=${expression.type.render()}"
override fun visitErrorCallExpression(expression: IrErrorCallExpression, data: Nothing?): String =
"ERROR_CALL '${expression.description}' type=${expression.type.render()}"
}
@Deprecated("Rewrite descriptor-based code")
private val REFERENCE_RENDERER = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES
private val descriptorRendererForErrorDeclarations = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES
}
internal fun IrDeclaration.name(): String =
descriptor.name.toString()
@@ -556,9 +588,6 @@ internal fun DescriptorRenderer.renderDescriptor(descriptor: DeclarationDescript
else
render(descriptor)
internal fun DeclarationDescriptor.ref(): String =
REFERENCE_RENDERER.renderDescriptor(this.original)
internal fun IrDeclaration.renderOriginIfNonTrivial(): String =
if (origin != IrDeclarationOrigin.DEFINED) "$origin " else ""