FIR. Refactor smart-cast representation in FIR tree
Make smart-casts non-transparent expression without delegation to underlying FirQualifiedAccessExpression, as children delegation in fir tree has unclear semantics Remove two different kinds of tree nodes for smart-casts
This commit is contained in:
committed by
teamcity
parent
bc9db58b3c
commit
513af2dfbc
+3
@@ -310,6 +310,9 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
||||
withCopy()
|
||||
}
|
||||
|
||||
builder(smartCastExpression) {
|
||||
}
|
||||
|
||||
builder(tryExpression) {
|
||||
default("calleeReference", "FirStubReference")
|
||||
useTypes(stubReferenceType)
|
||||
|
||||
+2
-6
@@ -120,10 +120,8 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
|
||||
val componentCall by element(Expression, functionCall)
|
||||
val callableReferenceAccess by element(Expression, qualifiedAccessExpression)
|
||||
val thisReceiverExpression by element(Expression, qualifiedAccessExpression)
|
||||
val wrappedExpressionWithSmartcast by element(Expression)
|
||||
val wrappedExpressionWithSmartcastToNothing by element(Expression, wrappedExpressionWithSmartcast)
|
||||
val expressionWithSmartcast by element(Expression, qualifiedAccessExpression, wrappedExpressionWithSmartcast)
|
||||
val expressionWithSmartcastToNothing by element(Expression, expressionWithSmartcast, wrappedExpressionWithSmartcastToNothing)
|
||||
|
||||
val smartCastExpression by element(Expression, expression)
|
||||
val safeCallExpression by element(Expression, expression)
|
||||
val checkedSafeCallSubject by element(Expression, expression)
|
||||
val getClassCall by element(Expression, expression, call)
|
||||
@@ -142,8 +140,6 @@ object FirTreeBuilder : AbstractFirTreeBuilder() {
|
||||
val throwExpression by element(Expression, expression)
|
||||
val variableAssignment by element(Expression, qualifiedAccess)
|
||||
val whenSubjectExpression by element(Expression, expression)
|
||||
val whenSubjectExpressionWithSmartcast by element(Expression, whenSubjectExpression, wrappedExpressionWithSmartcast)
|
||||
val whenSubjectExpressionWithSmartcastToNothing by element(Expression, whenSubjectExpression, wrappedExpressionWithSmartcastToNothing)
|
||||
|
||||
val wrappedDelegateExpression by element(Expression, wrappedExpression)
|
||||
|
||||
|
||||
+9
-7
@@ -189,12 +189,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
publicImplementation()
|
||||
}
|
||||
|
||||
noImpl(expressionWithSmartcast)
|
||||
noImpl(expressionWithSmartcastToNothing)
|
||||
|
||||
noImpl(whenSubjectExpressionWithSmartcast)
|
||||
noImpl(whenSubjectExpressionWithSmartcastToNothing)
|
||||
|
||||
impl(getClassCall) {
|
||||
default("argument") {
|
||||
value = "argumentList.arguments.first()"
|
||||
@@ -360,6 +354,13 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
}
|
||||
}
|
||||
|
||||
impl(smartCastExpression) {
|
||||
default("isStable") {
|
||||
value = "smartcastStability == SmartcastStability.STABLE_VALUE"
|
||||
withGetter = true
|
||||
}
|
||||
}
|
||||
|
||||
impl(resolvedNamedReference) {
|
||||
defaultNull("candidateSymbol", withGetter = true)
|
||||
}
|
||||
@@ -562,7 +563,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
"FirIntegerLiteralOperatorCallImpl",
|
||||
"FirContextReceiverImpl",
|
||||
"FirClassReferenceExpressionImpl",
|
||||
"FirGetClassCallImpl"
|
||||
"FirGetClassCallImpl",
|
||||
"FirSmartCastExpressionImpl"
|
||||
)
|
||||
configureFieldInAllImplementations(
|
||||
field = "typeRef",
|
||||
|
||||
+3
-26
@@ -490,31 +490,16 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
+intField("componentIndex")
|
||||
}
|
||||
|
||||
wrappedExpressionWithSmartcast.configure {
|
||||
withArg("E", expression)
|
||||
smartCastExpression.configure {
|
||||
+typeRefField
|
||||
+field("originalExpression", "E", packageName = null)
|
||||
+field("originalExpression", expression).withTransform()
|
||||
+field("typesFromSmartCast", "Collection<ConeKotlinType>", null, customType = coneKotlinTypeType)
|
||||
+field("originalType", typeRef)
|
||||
+field("smartcastType", typeRef)
|
||||
+field("smartcastTypeWithoutNullableNothing", typeRef, nullable = true)
|
||||
+booleanField("isStable")
|
||||
+smartcastStability
|
||||
}
|
||||
|
||||
wrappedExpressionWithSmartcastToNothing.configure {
|
||||
withArg("E", expression)
|
||||
parentArg(wrappedExpressionWithSmartcast, "E", "E")
|
||||
+field("smartcastTypeWithoutNullableNothing", typeRef)
|
||||
}
|
||||
|
||||
expressionWithSmartcast.configure {
|
||||
parentArg(wrappedExpressionWithSmartcast, "E", qualifiedAccessExpression)
|
||||
}
|
||||
|
||||
expressionWithSmartcastToNothing.configure {
|
||||
parentArg(wrappedExpressionWithSmartcastToNothing, "E", qualifiedAccessExpression)
|
||||
}
|
||||
|
||||
safeCallExpression.configure {
|
||||
+field("receiver", expression).withTransform()
|
||||
// Special node that might be used as a reference to receiver of a safe call after null check
|
||||
@@ -581,14 +566,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
+field("whenRef", whenRefType)
|
||||
}
|
||||
|
||||
whenSubjectExpressionWithSmartcast.configure {
|
||||
parentArg(wrappedExpressionWithSmartcast, "E", whenSubjectExpression)
|
||||
}
|
||||
|
||||
whenSubjectExpressionWithSmartcastToNothing.configure {
|
||||
parentArg(wrappedExpressionWithSmartcastToNothing, "E", whenSubjectExpression)
|
||||
}
|
||||
|
||||
wrappedExpression.configure {
|
||||
+field(expression).withReplace()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user