Raw FIR: introduce string concatenation call
This removes some 'plus' calls to be resolved
This commit is contained in:
@@ -80,6 +80,8 @@ internal class Fir2IrVisitor(
|
||||
|
||||
private val booleanType = FirImplicitBooleanTypeRef(session, null).toIrType(session, declarationStorage)
|
||||
|
||||
private val stringType = FirImplicitStringTypeRef(session, null).toIrType(session, declarationStorage)
|
||||
|
||||
private fun ModuleDescriptor.findPackageFragmentForFile(file: FirFile): PackageFragmentDescriptor =
|
||||
getPackage(file.packageFqName).fragments.first()
|
||||
|
||||
@@ -1070,6 +1072,15 @@ internal class Fir2IrVisitor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: Any?): IrElement {
|
||||
return stringConcatenationCall.convertWithOffsets { startOffset, endOffset ->
|
||||
IrStringConcatenationImpl(
|
||||
startOffset, endOffset, stringType,
|
||||
stringConcatenationCall.arguments.map { it.toIrExpression() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: Any?): IrElement {
|
||||
return typeOperatorCall.convertWithOffsets { startOffset, endOffset ->
|
||||
val irTypeOperand = typeOperatorCall.conversionTypeRef.toIrType(session, declarationStorage)
|
||||
|
||||
@@ -304,14 +304,13 @@ internal fun Array<KtStringTemplateEntry>.toInterpolatingCall(
|
||||
}
|
||||
result = when {
|
||||
result == null -> nextArgument
|
||||
callCreated && result is FirFunctionCallImpl -> result.apply {
|
||||
callCreated && result is FirStringConcatenationCallImpl -> result.apply {
|
||||
arguments += nextArgument
|
||||
}
|
||||
else -> {
|
||||
callCreated = true
|
||||
FirFunctionCallImpl(session, base).apply {
|
||||
calleeReference = FirSimpleNamedReference(session, base, OperatorNameConventions.PLUS)
|
||||
explicitReceiver = result
|
||||
FirStringConcatenationCallImpl(session, base).apply {
|
||||
arguments += result!!
|
||||
arguments += nextArgument
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ FILE: for.kt
|
||||
lval <destruct>: <implicit> = <iterator>#.next#()
|
||||
lval x: <implicit> = <destruct>#.component1()
|
||||
lval y: <implicit> = <destruct>#.component2()
|
||||
println#(String(x = ).plus#(x#, String( y = ), y#))
|
||||
println#(<strcat>(String(x = ), x#, String( y = ), y#))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -641,6 +641,11 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
|
||||
print(")")
|
||||
}
|
||||
|
||||
override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall) {
|
||||
print("<strcat>")
|
||||
visitCall(stringConcatenationCall)
|
||||
}
|
||||
|
||||
override fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall) {
|
||||
print("(")
|
||||
typeOperatorCall.argument.accept(this)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
interface FirStringConcatenationCall : FirCall {
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||
visitor.visitStringConcatenationCall(this, data)
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.expressions.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStringConcatenationCall
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitStringTypeRef
|
||||
|
||||
class FirStringConcatenationCallImpl(
|
||||
session: FirSession,
|
||||
psi: PsiElement?
|
||||
) : FirAbstractCall(session, psi), FirStringConcatenationCall {
|
||||
override var typeRef: FirTypeRef = FirImplicitStringTypeRef(session, psi)
|
||||
}
|
||||
@@ -63,3 +63,8 @@ class FirImplicitNothingTypeRef(
|
||||
psi: PsiElement?
|
||||
) : FirImplicitBuiltinTypeRef(session, psi, StandardClassIds.Nothing)
|
||||
|
||||
class FirImplicitStringTypeRef(
|
||||
session: FirSession,
|
||||
psi: PsiElement?
|
||||
) : FirImplicitBuiltinTypeRef(session, psi, StandardClassIds.String)
|
||||
|
||||
|
||||
+8
@@ -232,6 +232,10 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
|
||||
return transformOperatorCall(typeOperatorCall, data)
|
||||
}
|
||||
|
||||
open fun transformStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: D): CompositeTransformResult<FirStatement> {
|
||||
return transformCall(stringConcatenationCall, data)
|
||||
}
|
||||
|
||||
open fun transformClassReferenceExpression(classReferenceExpression: FirClassReferenceExpression, data: D): CompositeTransformResult<FirStatement> {
|
||||
return transformExpression(classReferenceExpression, data)
|
||||
}
|
||||
@@ -668,6 +672,10 @@ abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirEle
|
||||
return transformStatement(statement, data)
|
||||
}
|
||||
|
||||
final override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: D): CompositeTransformResult<FirElement> {
|
||||
return transformStringConcatenationCall(stringConcatenationCall, data)
|
||||
}
|
||||
|
||||
final override fun visitSuperReference(superReference: FirSuperReference, data: D): CompositeTransformResult<FirElement> {
|
||||
return transformSuperReference(superReference, data)
|
||||
}
|
||||
|
||||
@@ -232,6 +232,10 @@ abstract class FirVisitor<out R, in D> {
|
||||
return visitOperatorCall(typeOperatorCall, data)
|
||||
}
|
||||
|
||||
open fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: D): R {
|
||||
return visitCall(stringConcatenationCall, data)
|
||||
}
|
||||
|
||||
open fun visitClassReferenceExpression(classReferenceExpression: FirClassReferenceExpression, data: D): R {
|
||||
return visitExpression(classReferenceExpression, data)
|
||||
}
|
||||
|
||||
+8
@@ -232,6 +232,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
|
||||
visitOperatorCall(typeOperatorCall, null)
|
||||
}
|
||||
|
||||
open fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall) {
|
||||
visitCall(stringConcatenationCall, null)
|
||||
}
|
||||
|
||||
open fun visitClassReferenceExpression(classReferenceExpression: FirClassReferenceExpression) {
|
||||
visitExpression(classReferenceExpression, null)
|
||||
}
|
||||
@@ -668,6 +672,10 @@ abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>() {
|
||||
visitStatement(statement)
|
||||
}
|
||||
|
||||
final override fun visitStringConcatenationCall(stringConcatenationCall: FirStringConcatenationCall, data: Nothing?) {
|
||||
visitStringConcatenationCall(stringConcatenationCall)
|
||||
}
|
||||
|
||||
final override fun visitSuperReference(superReference: FirSuperReference, data: Nothing?) {
|
||||
visitSuperReference(superReference)
|
||||
}
|
||||
|
||||
@@ -59,8 +59,9 @@ FILE fqName:<root> fileName:/constValInitializers.kt
|
||||
PROPERTY name:STR4 visibility:public modality:FINAL [const,val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:STR4 type:kotlin.String visibility:public [final,static]
|
||||
EXPRESSION_BODY
|
||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
||||
other: CALL 'public final fun <get-STR2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CALL 'public final fun <get-STR1> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
CALL 'public final fun <get-STR2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-STR4> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:STR4 visibility:public modality:FINAL [const,val]
|
||||
BLOCK_BODY
|
||||
|
||||
+19
-14
@@ -38,7 +38,8 @@ FILE fqName:<root> fileName:/kt28006.kt
|
||||
PROPERTY name:testConst3 visibility:public modality:FINAL [const,val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:testConst3 type:kotlin.String visibility:public [final,static]
|
||||
EXPRESSION_BODY
|
||||
ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CONST String type=kotlin.String value="\uD83E"
|
||||
CONST String type=kotlin.String value="\uDD17"
|
||||
CALL 'public final fun <get-testConst2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-testConst3> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
@@ -49,8 +50,9 @@ FILE fqName:<root> fileName:/kt28006.kt
|
||||
PROPERTY name:testConst4 visibility:public modality:FINAL [const,val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:testConst4 type:kotlin.String visibility:public [final,static]
|
||||
EXPRESSION_BODY
|
||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
||||
other: CALL 'public final fun <get-testConst2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CALL 'public final fun <get-testConst2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
CALL 'public final fun <get-testConst2> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-testConst4> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:testConst4 visibility:public modality:FINAL [const,val]
|
||||
BLOCK_BODY
|
||||
@@ -60,21 +62,24 @@ FILE fqName:<root> fileName:/kt28006.kt
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.Int): kotlin.String declared in <root>'
|
||||
ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String
|
||||
CONST String type=kotlin.String value="\uDD17"
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
||||
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:IrErrorType
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): IrErrorType declared in <root>'
|
||||
ERROR_CALL 'Unresolved reference: <Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]>#' type=IrErrorType
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CONST String type=kotlin.String value="\uD83E"
|
||||
CONST String type=kotlin.String value="\uDD17"
|
||||
FUN name:test3 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:IrErrorType
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.test1' type=kotlin.Int origin=null
|
||||
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.String
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): IrErrorType declared in <root>'
|
||||
ERROR_CALL 'Unresolved reference: <Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]>#' type=IrErrorType
|
||||
RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.Int): kotlin.String declared in <root>'
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.test2' type=kotlin.Int origin=null
|
||||
CONST String type=kotlin.String value="\uD83E"
|
||||
CONST String type=kotlin.String value="\uDD17"
|
||||
FUN name:test3 visibility:public modality:FINAL <> (x:kotlin.Int) returnType:kotlin.String
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.Int
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.Int): kotlin.String declared in <root>'
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.test3' type=kotlin.Int origin=null
|
||||
CONST String type=kotlin.String value="\uD83E"
|
||||
CONST String type=kotlin.String value="\uDD17"
|
||||
GET_VAR 'x: kotlin.Int declared in <root>.test3' type=kotlin.Int origin=null
|
||||
|
||||
+3
-2
@@ -19,8 +19,9 @@ FILE fqName:<root> fileName:/objectReferenceInFieldInitializer.kt
|
||||
PROPERTY name:b visibility:private modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
||||
other: CALL 'private final fun <get-a> (): kotlin.String declared in <root>.A' type=kotlin.String origin=null
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CONST String type=kotlin.String value="1234"
|
||||
CALL 'private final fun <get-a> (): kotlin.String declared in <root>.A' type=kotlin.String origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-b> visibility:private modality:FINAL <> ($this:<root>.A) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:b visibility:private modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.A
|
||||
|
||||
@@ -60,7 +60,8 @@ FILE fqName:<root> fileName:/stringTemplates.kt
|
||||
PROPERTY name:test6 visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test6 type:kotlin.String visibility:public [final,static]
|
||||
EXPRESSION_BODY
|
||||
ERROR_CALL 'Cannot bind 2 arguments to plus call with 1 parameters' type=kotlin.String
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CALL 'public final fun <get-test1> (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
CONST String type=kotlin.String value=" "
|
||||
CALL 'public final fun foo (): kotlin.String declared in <root>' type=kotlin.String origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test6> visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
|
||||
@@ -19,8 +19,9 @@ FILE fqName:<root> fileName:/coercionInLoop.kt
|
||||
GET_VAR 'var i: kotlin.Int [var] declared in <root>.box' type=kotlin.Int origin=null
|
||||
arg1: ERROR_CALL 'Unresolved reference: <Unresolved name: next>#' type=IrErrorType
|
||||
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String declared in kotlin.String' type=kotlin.String origin=null
|
||||
other: GET_VAR 'var i: kotlin.Int [var] declared in <root>.box' type=kotlin.Int origin=null
|
||||
STRING_CONCATENATION type=kotlin.String
|
||||
CONST String type=kotlin.String value="Fail "
|
||||
GET_VAR 'var i: kotlin.Int [var] declared in <root>.box' type=kotlin.Int origin=null
|
||||
VAR name:<unary> type:kotlin.Int [val]
|
||||
GET_VAR 'var i: kotlin.Int [var] declared in <root>.box' type=kotlin.Int origin=null
|
||||
ERROR_CALL 'Unresolved reference: R|<local>/i|' type=IrErrorType
|
||||
|
||||
Reference in New Issue
Block a user