From 1d229b6dca7fa65c6736c323a5e25ddb7d5ac1dc Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 17 Oct 2019 12:43:38 +0300 Subject: [PATCH] FIR2IR: isExpect --- .../fir/backend/Fir2IrDeclarationStorage.kt | 44 +++++++++++++------ .../expectClassInherited.fir.txt | 8 ++-- .../multiplatform/expectedEnumClass.fir.txt | 4 +- .../multiplatform/expectedSealedClass.fir.txt | 8 ++-- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 1bbedcecb3b..37c2c5f9bdb 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -133,11 +133,20 @@ class Fir2IrDeclarationStorage( return regularClass.convertWithOffsets { startOffset, endOffset -> irSymbolTable.declareClass(startOffset, endOffset, origin, descriptor, modality) { symbol -> IrClassImpl( - startOffset, endOffset, origin, symbol, - regularClass.name, regularClass.classKind, - regularClass.visibility, modality, - regularClass.isCompanion, regularClass.isInner, - regularClass.isData, false, regularClass.isInline + startOffset, + endOffset, + origin, + symbol, + regularClass.name, + regularClass.classKind, + regularClass.visibility, + modality, + isCompanion = regularClass.isCompanion, + isInner = regularClass.isInner, + isData = regularClass.isData, + isExternal = regularClass.isExternal, + isInline = regularClass.isInline, + isExpect = regularClass.isExpect ).apply { descriptor.bind(this) if (setParent) { @@ -183,7 +192,7 @@ class Fir2IrDeclarationStorage( startOffset, endOffset, origin, symbol, Name.special(""), anonymousObject.classKind, Visibilities.LOCAL, modality, - isCompanion = false, isInner = false, isData = false, isExternal = false, isInline = false + isCompanion = false, isInner = false, isData = false, isExternal = false, isInline = false, isExpect = false ).apply { descriptor.bind(this) declareThisReceiver() @@ -350,8 +359,11 @@ class Fir2IrDeclarationStorage( startOffset, endOffset, origin, symbol, function.name, function.visibility, function.modality!!, function.returnTypeRef.toIrType(session, this), - function.isInline, function.isExternal, - function.isTailRec, function.isSuspend + isInline = function.isInline, + isExternal = function.isExternal, + isTailrec = function.isTailRec, + isSuspend = function.isSuspend, + isExpect = function.isExpect ) } }.bindAndDeclareParameters(function, descriptor, irParent, isStatic = function.isStatic, shouldLeaveScope = shouldLeaveScope) @@ -388,7 +400,8 @@ class Fir2IrDeclarationStorage( function.returnTypeRef.toIrType(session, this), isInline = false, isExternal = false, isTailrec = false, // TODO: suspend lambda - isSuspend = false + isSuspend = false, + isExpect = false ) }.bindAndDeclareParameters( function, descriptor, irParent = null, isStatic = false, shouldLeaveScope = false @@ -411,7 +424,7 @@ class Fir2IrDeclarationStorage( startOffset, endOffset, origin, symbol, constructor.name, constructor.visibility, constructor.returnTypeRef.toIrType(session, this), - isInline = false, isExternal = false, isPrimary = isPrimary + isInline = false, isExternal = false, isPrimary = isPrimary, isExpect = false ).bindAndDeclareParameters(constructor, descriptor, irParent, isStatic = true, shouldLeaveScope = shouldLeaveScope) } } @@ -442,7 +455,7 @@ class Fir2IrDeclarationStorage( Name.special("<$prefix-${correspondingProperty.name}>"), propertyAccessor?.visibility ?: correspondingProperty.visibility, correspondingProperty.modality, accessorReturnType, - isInline = false, isExternal = false, isTailrec = false, isSuspend = false + isInline = false, isExternal = false, isTailrec = false, isSuspend = false, isExpect = false ).apply { if (propertyAccessor == null && isSetter) { declareDefaultSetterParameter(propertyType) @@ -474,10 +487,13 @@ class Fir2IrDeclarationStorage( IrPropertyImpl( startOffset, endOffset, origin, symbol, property.name, property.visibility, property.modality!!, - property.isVar, property.isConst, property.isLateInit, - property.delegate != null, + isVar = property.isVar, + isConst = property.isConst, + isLateinit = property.isLateInit, + isDelegated = property.delegate != null, // TODO - isExternal = false + isExternal = false, + isExpect = property.isExpect ).apply { descriptor.bind(this) val type = property.returnTypeRef.toIrType(session, this@Fir2IrDeclarationStorage) diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.txt index c4db6bb995b..6b38090bb1e 100644 --- a/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.txt +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectClassInherited.fir.txt @@ -1,10 +1,10 @@ FILE fqName: fileName:/expectClassInherited.kt - CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + CLASS CLASS name:A modality:ABSTRACT visibility:public [expect] superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A CONSTRUCTOR visibility:protected <> () returnType:.A [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:ABSTRACT visibility:public [expect] superTypes:[kotlin.Any]' FUN name:foo visibility:public modality:ABSTRACT <> ($this:.A) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.A FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean @@ -20,13 +20,13 @@ FILE fqName: fileName:/expectClassInherited.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS CLASS name:B modality:OPEN visibility:public superTypes:[.A] + CLASS CLASS name:B modality:OPEN visibility:public [expect] superTypes:[.A] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B CONSTRUCTOR visibility:public <> (i:kotlin.Int) returnType:.B [primary] VALUE_PARAMETER name:i index:0 type:kotlin.Int BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:OPEN visibility:public superTypes:[.A]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:OPEN visibility:public [expect] superTypes:[.A]' FUN name:foo visibility:public modality:OPEN <> ($this:.B) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.B FUN name:bar visibility:public modality:OPEN <> ($this:.B, s:kotlin.String) returnType:kotlin.Unit diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.txt index fd8aefd5b4a..536b0e53e8d 100644 --- a/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.txt +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedEnumClass.fir.txt @@ -1,11 +1,11 @@ FILE fqName: fileName:/expectedEnumClass.kt - CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public superTypes:[kotlin.Enum] + CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public [expect] superTypes:[kotlin.Enum] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.MyEnum CONSTRUCTOR visibility:private <> () returnType:.MyEnum [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor (name: kotlin.String, ordinal: kotlin.Int) [primary] declared in kotlin.Enum' : - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public superTypes:[kotlin.Enum]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:MyEnum modality:FINAL visibility:public [expect] superTypes:[kotlin.Enum]' CLASS ENUM_ENTRY name:FOO modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.MyEnum.FOO CONSTRUCTOR visibility:public <> () returnType:.MyEnum.FOO [primary] diff --git a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt index 186a3640261..6efe080f13b 100644 --- a/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt +++ b/compiler/testData/ir/irText/declarations/multiplatform/expectedSealedClass.fir.txt @@ -1,10 +1,10 @@ FILE fqName: fileName:/expectedSealedClass.kt - CLASS CLASS name:Ops modality:SEALED visibility:public superTypes:[kotlin.Any] + CLASS CLASS name:Ops modality:SEALED visibility:public [expect] superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Ops CONSTRUCTOR visibility:private <> () returnType:.Ops [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Ops modality:SEALED visibility:public superTypes:[kotlin.Any]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Ops modality:SEALED visibility:public [expect] superTypes:[kotlin.Any]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any @@ -18,12 +18,12 @@ FILE fqName: fileName:/expectedSealedClass.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS CLASS name:Add modality:FINAL visibility:public superTypes:[.Ops] + CLASS CLASS name:Add modality:FINAL visibility:public [expect] superTypes:[.Ops] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Add CONSTRUCTOR visibility:public <> () returnType:.Add [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Add modality:FINAL visibility:public superTypes:[.Ops]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Add modality:FINAL visibility:public [expect] superTypes:[.Ops]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any