[FIR2IR] Minor: reuse calculated expression

This commit is contained in:
Ivan Kochurkin
2021-12-02 23:42:28 +03:00
committed by Space
parent 522d2064bb
commit fa41e0f5a9
3 changed files with 14 additions and 17 deletions
@@ -517,21 +517,21 @@ class ExpressionsConverter(
var firSelector: FirExpression? = null
var firReceiver: FirExpression? = null //before dot
dotQualifiedExpression.forEachChildren {
when (it.tokenType) {
when (val tokenType = it.tokenType) {
DOT -> isSelector = true
SAFE_ACCESS -> {
isSafe = true
isSelector = true
}
else -> {
val isEffectiveSelector = isSelector && it.tokenType != TokenType.ERROR_ELEMENT
val isEffectiveSelector = isSelector && tokenType != TokenType.ERROR_ELEMENT
val firExpression =
getAsFirExpression<FirExpression>(it, "Incorrect ${if (isEffectiveSelector) "selector" else "receiver"} expression")
if (isEffectiveSelector) {
val callExpressionCallee = if (it.tokenType == CALL_EXPRESSION) it.getFirstChildExpressionUnwrapped() else null
val callExpressionCallee = if (tokenType == CALL_EXPRESSION) it.getFirstChildExpressionUnwrapped() else null
firSelector =
if (it.tokenType is KtNameReferenceExpressionElementType ||
(it.tokenType == CALL_EXPRESSION && callExpressionCallee?.tokenType != LAMBDA_EXPRESSION)
if (tokenType is KtNameReferenceExpressionElementType ||
(tokenType == CALL_EXPRESSION && callExpressionCallee?.tokenType != LAMBDA_EXPRESSION)
) {
firExpression
} else {
@@ -69,14 +69,10 @@ private fun FirMemberDeclaration.getBackingFieldIfApplicable(): FirBackingField?
// This check prevents resolving protected and
// public fields.
val visibility = field.visibility
if (
visibility == Visibilities.PrivateToThis ||
visibility == Visibilities.Private ||
visibility == Visibilities.Internal
) {
return field
return when (field.visibility) {
Visibilities.PrivateToThis,
Visibilities.Private,
Visibilities.Internal -> field
else -> null
}
return null
}
@@ -166,10 +166,11 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : IrEle
private fun propertyReferenceKind(expression: IrCallableReference<*>, mutable: Boolean, i: Int): PropertyReferenceKind {
check(i in 0..2) { "Incorrect number of receivers ($i) for property reference: ${expression.render()}" }
val symbols = context.ir.symbols
return PropertyReferenceKind(
context.ir.symbols.getPropertyReferenceClass(mutable, i, false),
context.ir.symbols.getPropertyReferenceClass(mutable, i, true),
context.ir.symbols.reflection.owner.functions.single {
symbols.getPropertyReferenceClass(mutable, i, false),
symbols.getPropertyReferenceClass(mutable, i, true),
symbols.reflection.owner.functions.single {
it.name.asString() == (if (mutable) "mutableProperty$i" else "property$i")
}
)