Raw FIR: make component call a function call, its argument -> receiver
This commit is contained in:
@@ -354,9 +354,7 @@ internal fun generateDestructuringBlock(
|
|||||||
statements += FirVariableImpl(
|
statements += FirVariableImpl(
|
||||||
session, entry, entry.nameAsSafeName,
|
session, entry, entry.nameAsSafeName,
|
||||||
entry.typeReference.toFirOrImplicitTypeRef(), isVar,
|
entry.typeReference.toFirOrImplicitTypeRef(), isVar,
|
||||||
FirComponentCallImpl(session, entry, index + 1).apply {
|
FirComponentCallImpl(session, entry, index + 1, generateAccessExpression(session, entry, container.name)),
|
||||||
arguments += generateAccessExpression(session, entry, container.name)
|
|
||||||
},
|
|
||||||
FirVariableSymbol(entry.nameAsSafeName) // TODO?
|
FirVariableSymbol(entry.nameAsSafeName) // TODO?
|
||||||
).apply {
|
).apply {
|
||||||
entry.extractAnnotationsTo(this)
|
entry.extractAnnotationsTo(this)
|
||||||
|
|||||||
@@ -28,6 +28,6 @@ FILE: annotated.kt
|
|||||||
}
|
}
|
||||||
public? final? fun bar(two: Two): kotlin/Unit {
|
public? final? fun bar(two: Two): kotlin/Unit {
|
||||||
lval <destruct>: <implicit> = two#
|
lval <destruct>: <implicit> = two#
|
||||||
@Ann() lval x: <implicit> = component1(<destruct>#)
|
@Ann() lval x: <implicit> = <destruct>#.component1()
|
||||||
@Ann() lval y: <implicit> = component2(<destruct>#)
|
@Ann() lval y: <implicit> = <destruct>#.component2()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ FILE: destructuring.kt
|
|||||||
}
|
}
|
||||||
public? final? fun foo(some: Some): kotlin/Unit {
|
public? final? fun foo(some: Some): kotlin/Unit {
|
||||||
lval <destruct>: <implicit> = some#
|
lval <destruct>: <implicit> = some#
|
||||||
lvar x: <implicit> = component1(<destruct>#)
|
lvar x: <implicit> = <destruct>#.component1()
|
||||||
lvar y: <implicit> = component2(<destruct>#)
|
lvar y: <implicit> = <destruct>#.component2()
|
||||||
lvar z: String = component3(<destruct>#)
|
lvar z: String = <destruct>#.component3()
|
||||||
lval <unary>: <implicit> = x#
|
lval <unary>: <implicit> = x#
|
||||||
x# = inc#(<unary>#)
|
x# = inc#(<unary>#)
|
||||||
<unary>#
|
<unary>#
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ FILE: for.kt
|
|||||||
lval <iterator>: <implicit> = <range>#.iterator#()
|
lval <iterator>: <implicit> = <range>#.iterator#()
|
||||||
while(<iterator>#.hasNext#()) {
|
while(<iterator>#.hasNext#()) {
|
||||||
lval <destruct>: <implicit> = <iterator>#.next#()
|
lval <destruct>: <implicit> = <iterator>#.next#()
|
||||||
lval x: <implicit> = component1(<destruct>#)
|
lval x: <implicit> = <destruct>#.component1()
|
||||||
lval y: <implicit> = component2(<destruct>#)
|
lval y: <implicit> = <destruct>#.component2()
|
||||||
println#(plus#(String(x = ), x#, String( y = ), y#))
|
println#(plus#(String(x = ), x#, String( y = ), y#))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ FILE: lambda.kt
|
|||||||
|
|
||||||
use#(use@fun <implicit>.<anonymous>(<destruct>: <implicit>): <implicit> {
|
use#(use@fun <implicit>.<anonymous>(<destruct>: <implicit>): <implicit> {
|
||||||
^ {
|
^ {
|
||||||
lval x: <implicit> = component1(<destruct>#)
|
lval x: <implicit> = <destruct>#.component1()
|
||||||
lval y: <implicit> = component2(<destruct>#)
|
lval y: <implicit> = <destruct>#.component2()
|
||||||
plus#(x#, y#)
|
plus#(x#, y#)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -868,8 +868,8 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
|||||||
|
|
||||||
override fun visitComponentCall(componentCall: FirComponentCall) {
|
override fun visitComponentCall(componentCall: FirComponentCall) {
|
||||||
componentCall.annotations.renderAnnotations()
|
componentCall.annotations.renderAnnotations()
|
||||||
print("component${componentCall.componentIndex}")
|
componentCall.explicitReceiver.accept(this)
|
||||||
visitCall(componentCall)
|
print(".component${componentCall.componentIndex}()")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitGetClassCall(getClassCall: FirGetClassCall) {
|
override fun visitGetClassCall(getClassCall: FirGetClassCall) {
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ package org.jetbrains.kotlin.fir.expressions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||||
|
|
||||||
interface FirComponentCall : FirCall {
|
interface FirComponentCall : FirFunctionCall {
|
||||||
// Starting from 1, not from 0
|
// Starting from 1, not from 0
|
||||||
val componentIndex: Int
|
val componentIndex: Int
|
||||||
|
|
||||||
|
override val explicitReceiver: FirExpression
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||||
visitor.visitComponentCall(this, data)
|
visitor.visitComponentCall(this, data)
|
||||||
}
|
}
|
||||||
+29
-2
@@ -6,11 +6,38 @@
|
|||||||
package org.jetbrains.kotlin.fir.expressions.impl
|
package org.jetbrains.kotlin.fir.expressions.impl
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
|
import org.jetbrains.kotlin.fir.FirNamedReference
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
|
import org.jetbrains.kotlin.fir.expressions.FirComponentCall
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
|
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||||
|
import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference
|
||||||
|
import org.jetbrains.kotlin.fir.transformSingle
|
||||||
|
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||||
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
class FirComponentCallImpl(
|
class FirComponentCallImpl(
|
||||||
session: FirSession,
|
session: FirSession,
|
||||||
psi: PsiElement?,
|
psi: PsiElement?,
|
||||||
override val componentIndex: Int
|
override val componentIndex: Int,
|
||||||
) : FirAbstractCall(session, psi), FirComponentCall
|
override var explicitReceiver: FirExpression
|
||||||
|
) : FirAbstractCall(session, psi), FirComponentCall {
|
||||||
|
override var calleeReference: FirNamedReference =
|
||||||
|
FirSimpleNamedReference(session, psi, Name.identifier("component$componentIndex"))
|
||||||
|
|
||||||
|
override val typeArguments: List<FirTypeProjection>
|
||||||
|
get() = emptyList()
|
||||||
|
|
||||||
|
override fun <D> transformCalleeReference(transformer: FirTransformer<D>, data: D): FirQualifiedAccess {
|
||||||
|
calleeReference = calleeReference.transformSingle(transformer, data)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
||||||
|
calleeReference = calleeReference.transformSingle(transformer, data)
|
||||||
|
explicitReceiver = explicitReceiver.transformSingle(transformer, data)
|
||||||
|
return super<FirAbstractCall>.transformChildren(transformer, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-4
@@ -212,10 +212,6 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
|
|||||||
return transformCall(arraySetCall, data)
|
return transformCall(arraySetCall, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun transformComponentCall(componentCall: FirComponentCall, data: D): CompositeTransformResult<FirStatement> {
|
|
||||||
return transformCall(componentCall, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun transformDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): CompositeTransformResult<FirStatement> {
|
open fun transformDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): CompositeTransformResult<FirStatement> {
|
||||||
return transformCall(delegatedConstructorCall, data)
|
return transformCall(delegatedConstructorCall, data)
|
||||||
}
|
}
|
||||||
@@ -224,6 +220,10 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
|
|||||||
return transformCall(functionCall, data)
|
return transformCall(functionCall, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun transformComponentCall(componentCall: FirComponentCall, data: D): CompositeTransformResult<FirStatement> {
|
||||||
|
return transformFunctionCall(componentCall, data)
|
||||||
|
}
|
||||||
|
|
||||||
open fun transformGetClassCall(getClassCall: FirGetClassCall, data: D): CompositeTransformResult<FirStatement> {
|
open fun transformGetClassCall(getClassCall: FirGetClassCall, data: D): CompositeTransformResult<FirStatement> {
|
||||||
return transformCall(getClassCall, data)
|
return transformCall(getClassCall, data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,10 +212,6 @@ abstract class FirVisitor<out R, in D> {
|
|||||||
return visitCall(arraySetCall, data)
|
return visitCall(arraySetCall, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun visitComponentCall(componentCall: FirComponentCall, data: D): R {
|
|
||||||
return visitCall(componentCall, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): R {
|
open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: D): R {
|
||||||
return visitCall(delegatedConstructorCall, data)
|
return visitCall(delegatedConstructorCall, data)
|
||||||
}
|
}
|
||||||
@@ -224,6 +220,10 @@ abstract class FirVisitor<out R, in D> {
|
|||||||
return visitCall(functionCall, data)
|
return visitCall(functionCall, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun visitComponentCall(componentCall: FirComponentCall, data: D): R {
|
||||||
|
return visitFunctionCall(componentCall, data)
|
||||||
|
}
|
||||||
|
|
||||||
open fun visitGetClassCall(getClassCall: FirGetClassCall, data: D): R {
|
open fun visitGetClassCall(getClassCall: FirGetClassCall, data: D): R {
|
||||||
return visitCall(getClassCall, data)
|
return visitCall(getClassCall, data)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -212,10 +212,6 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
|
|||||||
visitCall(arraySetCall, null)
|
visitCall(arraySetCall, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun visitComponentCall(componentCall: FirComponentCall) {
|
|
||||||
visitCall(componentCall, null)
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall) {
|
open fun visitDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall) {
|
||||||
visitCall(delegatedConstructorCall, null)
|
visitCall(delegatedConstructorCall, null)
|
||||||
}
|
}
|
||||||
@@ -224,6 +220,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
|
|||||||
visitCall(functionCall, null)
|
visitCall(functionCall, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun visitComponentCall(componentCall: FirComponentCall) {
|
||||||
|
visitFunctionCall(componentCall, null)
|
||||||
|
}
|
||||||
|
|
||||||
open fun visitGetClassCall(getClassCall: FirGetClassCall) {
|
open fun visitGetClassCall(getClassCall: FirGetClassCall) {
|
||||||
visitCall(getClassCall, null)
|
visitCall(getClassCall, null)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user