[FIR] Generate IR for generated FIR declarations

This commit is contained in:
Dmitriy Novozhilov
2021-10-01 15:11:06 +03:00
committed by TeamCityServer
parent e3579389ee
commit 233b9f1242
15 changed files with 265 additions and 71 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
import org.jetbrains.kotlin.fir.declarations.FirConstructor
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import org.jetbrains.kotlin.fir.declarations.builder.buildPrimaryConstructor
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
@OptIn(SymbolInternals::class)
fun FirDeclarationGenerationExtension.buildMaterializeFunction(
matchedClassSymbol: FirClassLikeSymbol<*>,
callableId: CallableId
@@ -50,6 +52,10 @@ fun FirDeclarationGenerationExtension.buildMaterializeFunction(
}
name = callableId.callableName
symbol = FirNamedFunctionSymbol(callableId)
dispatchReceiverType = callableId.classId?.let {
val firClass = session.symbolProvider.getClassLikeSymbolByClassId(it)?.fir as? FirClass
firClass?.defaultType()
}
}
}
@@ -26,7 +26,24 @@ FILE fqName:<root> fileName:/classWithGeneratedMembersAndNestedClass.kt
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:materialize visibility:public modality:FINAL <> () returnType:<root>.Foo [fake_override]
FUN name:materialize visibility:public modality:FINAL <> ($this:<root>.Foo) returnType:<root>.Foo
$this: VALUE_PARAMETER name:<this> type:<root>.Foo
CLASS CLASS name:Nested modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo.Nested
CONSTRUCTOR visibility:public <> () returnType:<root>.Foo.Nested [primary]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
@@ -63,6 +80,7 @@ FILE fqName:<root> fileName:/classWithGeneratedMembersAndNestedClass.kt
VALUE_PARAMETER name:foo index:0 type:<root>.Foo
BLOCK_BODY
VAR name:foo2 type:<root>.Foo [val]
CALL 'public final fun materialize (): <root>.Foo declared in <root>' type=<root>.Foo origin=null
CALL 'public final fun materialize (): <root>.Foo declared in <root>.Foo' type=<root>.Foo origin=null
$this: GET_VAR 'foo: <root>.Foo declared in <root>.test_1' type=<root>.Foo origin=null
VAR name:nested type:<root>.Foo.Nested [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Foo.Nested' type=<root>.Foo.Nested origin=null
@@ -14,6 +14,8 @@ FILE: classWithGeneratedMembersAndNestedClass.kt
public final fun materialize(): R|Foo|
public final class Nested : R|kotlin/Any| {
public constructor(): R|Foo.Nested|
}
}
@@ -56,8 +56,60 @@ FILE fqName:bar fileName:/generatedClassWithMembersAndNestedClasses.kt
VAR name:nestedFoo type:foo.AllOpenGenerated.NestedFoo [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in foo.AllOpenGenerated.NestedFoo' type=foo.AllOpenGenerated.NestedFoo origin=null
CALL 'public final fun foo (): kotlin.Unit declared in bar.Foo' type=kotlin.Unit origin=null
$this: CALL 'public final fun materialize (): bar.Foo declared in foo' type=bar.Foo origin=null
$this: CALL 'public final fun materialize (): bar.Foo declared in foo.AllOpenGenerated.NestedFoo' type=bar.Foo origin=null
$this: GET_VAR 'val nestedFoo: foo.AllOpenGenerated.NestedFoo [val] declared in bar.testNestedClasses' type=foo.AllOpenGenerated.NestedFoo origin=null
VAR name:nestedBar type:foo.AllOpenGenerated.NestedBar [val]
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in foo.AllOpenGenerated.NestedBar' type=foo.AllOpenGenerated.NestedBar origin=null
CALL 'public final fun bar (): kotlin.Unit declared in bar.Bar' type=kotlin.Unit origin=null
$this: CALL 'public final fun materialize (): bar.Foo declared in foo' type=bar.Bar origin=null
$this: CALL 'public final fun materialize (): bar.Bar declared in foo.AllOpenGenerated.NestedBar' type=bar.Bar origin=null
$this: GET_VAR 'val nestedBar: foo.AllOpenGenerated.NestedBar [val] declared in bar.testNestedClasses' type=foo.AllOpenGenerated.NestedBar origin=null
FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt
CLASS CLASS name:AllOpenGenerated modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.AllOpenGenerated
CLASS CLASS name:NestedFoo modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.AllOpenGenerated.NestedFoo
FUN name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedFoo) returnType:bar.Foo
$this: VALUE_PARAMETER name:<this> type:foo.AllOpenGenerated.NestedFoo
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:NestedBar modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.AllOpenGenerated.NestedBar
FUN name:materialize visibility:public modality:FINAL <> ($this:foo.AllOpenGenerated.NestedBar) returnType:bar.Bar
$this: VALUE_PARAMETER name:<this> type:foo.AllOpenGenerated.NestedBar
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -28,18 +28,24 @@ FILE: generatedClassWithMembersAndNestedClasses.kt
lval nestedBar: R|foo/AllOpenGenerated.NestedBar| = Q|foo/AllOpenGenerated|.R|foo/AllOpenGenerated.NestedBar|()
R|<local>/nestedBar|.R|foo/AllOpenGenerated.NestedBar.materialize|().R|bar/Bar.bar|()
}
FILE: ### GENERATED DECLARATIONS ###
FILE: __GENERATED DECLARATIONS__.kt
package foo
public final class AllOpenGenerated : R|kotlin/Any| {
public constructor(): R|foo/AllOpenGenerated|
public final class NestedFoo : R|kotlin/Any| {
public final fun materialize(): R|bar/Foo|
public constructor(): R|foo/AllOpenGenerated.NestedFoo|
}
public final class NestedBar : R|kotlin/Any| {
public final fun materialize(): R|bar/Bar|
public constructor(): R|foo/AllOpenGenerated.NestedBar|
}
}
@@ -31,3 +31,6 @@ FILE fqName:foo fileName:/topLevelCallables.kt
FUN name:takeString visibility:public modality:FINAL <> (s:kotlin.String) returnType:kotlin.Unit
VALUE_PARAMETER name:s index:0 type:kotlin.String
BLOCK_BODY
FILE fqName:foo fileName:__GENERATED DECLARATIONS__.kt
FUN name:dummyMySuperClass visibility:public modality:FINAL <> (value:foo.MySuperClass) returnType:kotlin.String
VALUE_PARAMETER name:value index:0 type:foo.MySuperClass
@@ -14,7 +14,7 @@ FILE: topLevelCallables.kt
}
public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| {
}
FILE: ### GENERATED DECLARATIONS ###
FILE: __GENERATED DECLARATIONS__.kt
package foo
public final fun dummyMySuperClass(value: R|foo/MySuperClass|): R|kotlin/String|