IR: add module ir.tree.persistent, copy PIR implementation there

Use PersistentIrFactory in JS IR compiler entry points.
This commit is contained in:
Alexander Udalov
2020-07-14 20:57:53 +02:00
parent 9aed92d2dd
commit 77247deb23
48 changed files with 1751 additions and 56 deletions
@@ -0,0 +1,13 @@
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
compileOnly(project(":compiler:ir.tree"))
}
sourceSets {
"main" { projectDefault() }
"test" {}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrAnonymousInitializer
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.AnonymousInitializerCarrier
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
import org.jetbrains.kotlin.ir.symbols.IrAnonymousInitializerSymbol
class PersistentIrAnonymousInitializer(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrAnonymousInitializerSymbol,
override val isStatic: Boolean = false
) : PersistentIrDeclarationBase<AnonymousInitializerCarrier>(startOffset, endOffset, origin),
IrAnonymousInitializer,
AnonymousInitializerCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassDescriptor
get() = symbol.descriptor
override var bodyField: IrBlockBody? = null
override var body: IrBlockBody
get() = getCarrier().bodyField!!
set(v) {
if (getCarrier().bodyField !== v) {
if (v is PersistentIrBodyBase<*>) {
v.container = this
}
setCarrier().bodyField = v
}
}
}
@@ -0,0 +1,143 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ClassCarrier
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import java.util.*
class PersistentIrClass(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrClassSymbol,
override val name: Name,
override val kind: ClassKind,
visibility: Visibility,
modality: Modality,
override val isCompanion: Boolean = false,
override val isInner: Boolean = false,
override val isData: Boolean = false,
override val isExternal: Boolean = false,
override val isInline: Boolean = false,
override val isExpect: Boolean = false,
override val isFun: Boolean = false,
override val source: SourceElement = SourceElement.NO_SOURCE
) :
PersistentIrDeclarationBase<ClassCarrier>(startOffset, endOffset, origin),
IrClass,
ClassCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassDescriptor
get() = symbol.descriptor
override var visibilityField: Visibility = visibility
override var visibility: Visibility
get() = getCarrier().visibilityField
set(v) {
if (visibility !== v) {
setCarrier().visibilityField = v
}
}
override var thisReceiverField: IrValueParameter? = null
override var thisReceiver: IrValueParameter?
get() = getCarrier().thisReceiverField
set(v) {
if (thisReceiver !== v) {
setCarrier().thisReceiverField = v
}
}
private var initialDeclarations: MutableList<IrDeclaration>? = null
override val declarations: MutableList<IrDeclaration> = ArrayList()
get() {
if (createdOn < stageController.currentStage && initialDeclarations == null) {
initialDeclarations = Collections.unmodifiableList(ArrayList(field))
}
return if (stageController.canAccessDeclarationsOf(this)) {
ensureLowered()
field
} else {
initialDeclarations ?: field
}
}
override var typeParametersField: List<IrTypeParameter> = emptyList()
override var typeParameters: List<IrTypeParameter>
get() = getCarrier().typeParametersField
set(v) {
if (typeParameters !== v) {
setCarrier().typeParametersField = v
}
}
override var superTypesField: List<IrType> = emptyList()
override var superTypes: List<IrType>
get() = getCarrier().superTypesField
set(v) {
if (superTypes !== v) {
setCarrier().superTypesField = v
}
}
override var metadataField: MetadataSource? = null
override var metadata: MetadataSource?
get() = getCarrier().metadataField
set(v) {
if (metadata !== v) {
setCarrier().metadataField = v
}
}
override var modalityField: Modality = modality
override var modality: Modality
get() = getCarrier().modalityField
set(v) {
if (modality !== v) {
setCarrier().modalityField = v
}
}
override var attributeOwnerIdField: IrAttributeContainer = this
override var attributeOwnerId: IrAttributeContainer
get() = getCarrier().attributeOwnerIdField
set(v) {
if (attributeOwnerId !== v) {
setCarrier().attributeOwnerIdField = v
}
}
}
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ConstructorCarrier
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
class PersistentIrConstructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrConstructorSymbol,
name: Name,
visibility: Visibility,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
override val isPrimary: Boolean,
isExpect: Boolean
) :
PersistentIrFunctionBase<ConstructorCarrier>(
startOffset, endOffset, origin, name,
visibility,
isInline, isExternal, isExpect,
returnType
),
IrConstructor,
ConstructorCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassConstructorDescriptor
get() = symbol.descriptor
}
@@ -0,0 +1,188 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.BodyCarrier
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.DeclarationCarrier
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
abstract class PersistentIrDeclarationBase<T : DeclarationCarrier>(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin
) : PersistentIrElementBase<T>(startOffset, endOffset),
IrDeclaration,
DeclarationCarrier {
override val factory: IrFactory
get() = PersistentIrFactory
override var parentField: IrDeclarationParent? = null
// TODO reduce boilerplate
override var parent: IrDeclarationParent
get() = getCarrier().parentField ?: throw UninitializedPropertyAccessException("Parent not initialized: $this")
set(p) {
if (getCarrier().parentField !== p) {
setCarrier().parentField = p
}
}
override var originField: IrDeclarationOrigin = origin
override var origin: IrDeclarationOrigin
get() = getCarrier().originField
set(p) {
if (getCarrier().originField !== p) {
setCarrier().originField = p
}
}
var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
override var annotations: List<IrConstructorCall>
get() = getCarrier().annotationsField
set(v) {
if (getCarrier().annotationsField !== v) {
setCarrier().annotationsField = v
}
}
override fun ensureLowered() {
if (stageController.currentStage > loweredUpTo) {
stageController.lazyLower(this)
}
}
}
@Suppress("UNCHECKED_CAST")
abstract class PersistentIrElementBase<T : Carrier>(
startOffset: Int,
endOffset: Int
) : IrElementBase(startOffset, endOffset),
Carrier {
override var lastModified: Int = stageController.currentStage
var loweredUpTo = stageController.currentStage
// TODO Array<T>?
private var values: Array<Carrier>? = null
val createdOn: Int = stageController.currentStage
// get() = values?.let { (it[0] as T).lastModified } ?: lastModified
abstract fun ensureLowered()
protected fun getCarrier(): T {
stageController.currentStage.let { stage ->
ensureLowered()
if (stage >= lastModified) return this as T
if (stage < createdOn) error("Access before creation")
val v = values
?: error("How come?")
var l = -1
var r = v.size
while (r - l > 1) {
val m = (l + r) / 2
if ((v[m] as T).lastModified <= stage) {
l = m
} else {
r = m
}
}
if (l < 0) {
error("access before creation")
}
return v[l] as T
}
}
// TODO naming? e.g. `mutableCarrier`
protected fun setCarrier(): T {
val stage = stageController.currentStage
ensureLowered()
if (!stageController.canModify(this)) {
error("Cannot modify this element!")
}
if (loweredUpTo > stage) {
error("retrospective modification")
}
// TODO move up? i.e. fast path
if (stage == lastModified) {
return this as T
} else {
values = (values ?: emptyArray()) + this.clone() as T
}
this.lastModified = stage
return this as T
}
}
abstract class PersistentIrBodyBase<B : PersistentIrBodyBase<B>>(
startOffset: Int,
endOffset: Int,
private var initializer: (B.() -> Unit)?
) : PersistentIrElementBase<BodyCarrier>(startOffset, endOffset), IrBody, BodyCarrier {
override var containerField: IrDeclaration? = null
var container: IrDeclaration
get() = getCarrier().containerField!!
set(p) {
if (getCarrier().containerField !== p) {
setCarrier().containerField = p
}
}
protected fun <T> checkEnabled(fn: () -> T): T {
if (!stageController.bodiesEnabled) error("Bodies disabled!")
ensureLowered()
return fn()
}
@Suppress("UNCHECKED_CAST")
override fun ensureLowered() {
initializer?.let { initFn ->
initializer = null
stageController.withStage(createdOn) {
stageController.bodyLowering {
initFn.invoke(this as B)
}
}
}
if (loweredUpTo + 1 < stageController.currentStage) {
stageController.lazyLower(this)
}
}
}
@@ -0,0 +1,69 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.EnumEntryCarrier
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
import org.jetbrains.kotlin.name.Name
class PersistentIrEnumEntry(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrEnumEntrySymbol,
override val name: Name
) : PersistentIrDeclarationBase<EnumEntryCarrier>(startOffset, endOffset, origin),
IrEnumEntry,
EnumEntryCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassDescriptor
get() = symbol.descriptor
override var correspondingClassField: IrClass? = null
override var correspondingClass: IrClass?
get() = getCarrier().correspondingClassField
set(v) {
if (correspondingClass !== v) {
setCarrier().correspondingClassField = v
}
}
override var initializerExpressionField: IrExpressionBody? = null
override var initializerExpression: IrExpressionBody?
get() = getCarrier().initializerExpressionField
set(v) {
if (initializerExpression !== v) {
if (v is PersistentIrBodyBase<*>) {
v.container = this
}
setCarrier().initializerExpressionField = v
}
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrErrorDeclaration
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ErrorCarrier
@OptIn(ObsoleteDescriptorBasedAPI::class)
class PersistentIrErrorDeclaration(
startOffset: Int,
endOffset: Int,
override val descriptor: DeclarationDescriptor
) : PersistentIrDeclarationBase<ErrorCarrier>(startOffset, endOffset, IrDeclarationOrigin.DEFINED), IrErrorDeclaration, ErrorCarrier
@@ -0,0 +1,274 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.expressions.persistent.PersistentIrBlockBody
import org.jetbrains.kotlin.ir.expressions.persistent.PersistentIrExpressionBody
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.Variance
object PersistentIrFactory : IrFactory {
override fun createAnonymousInitializer(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrAnonymousInitializerSymbol,
isStatic: Boolean,
): IrAnonymousInitializer =
PersistentIrAnonymousInitializer(startOffset, endOffset, origin, symbol, isStatic)
override fun createClass(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrClassSymbol,
name: Name,
kind: ClassKind,
visibility: Visibility,
modality: Modality,
isCompanion: Boolean,
isInner: Boolean,
isData: Boolean,
isExternal: Boolean,
isInline: Boolean,
isExpect: Boolean,
isFun: Boolean,
source: SourceElement,
): IrClass =
PersistentIrClass(
startOffset, endOffset, origin, symbol, name, kind, visibility, modality,
isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun, source,
)
override fun createConstructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrConstructorSymbol,
name: Name,
visibility: Visibility,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
isPrimary: Boolean,
isExpect: Boolean,
): IrConstructor =
PersistentIrConstructor(
startOffset, endOffset, origin, symbol, name, visibility, returnType, isInline, isExternal, isPrimary, isExpect
)
override fun createEnumEntry(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrEnumEntrySymbol,
name: Name,
): IrEnumEntry =
PersistentIrEnumEntry(startOffset, endOffset, origin, symbol, name)
override fun createErrorDeclaration(
startOffset: Int,
endOffset: Int,
descriptor: DeclarationDescriptor,
): IrErrorDeclaration =
PersistentIrErrorDeclaration(startOffset, endOffset, descriptor)
override fun createField(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrFieldSymbol,
name: Name,
type: IrType,
visibility: Visibility,
isFinal: Boolean,
isExternal: Boolean,
isStatic: Boolean,
): IrField =
PersistentIrField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic)
override fun createFunction(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrSimpleFunctionSymbol,
name: Name,
visibility: Visibility,
modality: Modality,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
isTailrec: Boolean,
isSuspend: Boolean,
isOperator: Boolean,
isInfix: Boolean,
isExpect: Boolean,
isFakeOverride: Boolean,
): IrSimpleFunction =
PersistentIrFunction(
startOffset, endOffset, origin, symbol, name, visibility, modality, returnType,
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride,
)
override fun createFakeOverrideFunction(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
name: Name,
visibility: Visibility,
modality: Modality,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
isTailrec: Boolean,
isSuspend: Boolean,
isOperator: Boolean,
isInfix: Boolean,
isExpect: Boolean,
): IrSimpleFunction =
PersistentIrFakeOverrideFunction(
startOffset, endOffset, origin, name, visibility, modality, returnType,
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect,
)
override fun createLocalDelegatedProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrLocalDelegatedPropertySymbol,
name: Name,
type: IrType,
isVar: Boolean,
): IrLocalDelegatedProperty =
PersistentIrLocalDelegatedProperty(
startOffset, endOffset, origin, symbol, name, type, isVar
)
override fun createProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrPropertySymbol,
name: Name,
visibility: Visibility,
modality: Modality,
isVar: Boolean,
isConst: Boolean,
isLateinit: Boolean,
isDelegated: Boolean,
isExternal: Boolean,
isExpect: Boolean,
isFakeOverride: Boolean,
): IrProperty =
PersistentIrProperty(
startOffset, endOffset, origin, symbol, name, visibility, modality,
isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride,
)
override fun createFakeOverrideProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
name: Name,
visibility: Visibility,
modality: Modality,
isVar: Boolean,
isConst: Boolean,
isLateinit: Boolean,
isDelegated: Boolean,
isExternal: Boolean,
isExpect: Boolean,
): IrFakeOverrideProperty =
PersistentIrFakeOverrideProperty(
startOffset, endOffset, origin, name, visibility, modality,
isVar, isConst, isLateinit, isDelegated, isExternal, isExpect,
)
override fun createTypeAlias(
startOffset: Int,
endOffset: Int,
symbol: IrTypeAliasSymbol,
name: Name,
visibility: Visibility,
expandedType: IrType,
isActual: Boolean,
origin: IrDeclarationOrigin,
): IrTypeAlias =
PersistentIrTypeAlias(startOffset, endOffset, symbol, name, visibility, expandedType, isActual, origin)
override fun createTypeParameter(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrTypeParameterSymbol,
name: Name,
index: Int,
isReified: Boolean,
variance: Variance,
): IrTypeParameter =
PersistentIrTypeParameter(startOffset, endOffset, origin, symbol, name, index, isReified, variance)
override fun createValueParameter(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrValueParameterSymbol,
name: Name,
index: Int,
type: IrType,
varargElementType: IrType?,
isCrossinline: Boolean,
isNoinline: Boolean,
): IrValueParameter =
PersistentIrValueParameter(startOffset, endOffset, origin, symbol, name, index, type, varargElementType, isCrossinline, isNoinline)
override fun createExpressionBody(
startOffset: Int,
endOffset: Int,
initializer: IrExpressionBody.() -> Unit,
): IrExpressionBody =
PersistentIrExpressionBody(startOffset, endOffset, initializer)
override fun createExpressionBody(
startOffset: Int,
endOffset: Int,
expression: IrExpression,
): IrExpressionBody =
PersistentIrExpressionBody(startOffset, endOffset, expression)
override fun createExpressionBody(
expression: IrExpression,
): IrExpressionBody =
PersistentIrExpressionBody(expression)
override fun createBlockBody(
startOffset: Int,
endOffset: Int,
): IrBlockBody =
PersistentIrBlockBody(startOffset, endOffset)
override fun createBlockBody(
startOffset: Int,
endOffset: Int,
statements: List<IrStatement>,
): IrBlockBody =
PersistentIrBlockBody(startOffset, endOffset, statements)
override fun createBlockBody(
startOffset: Int,
endOffset: Int,
initializer: IrBlockBody.() -> Unit,
): IrBlockBody =
PersistentIrBlockBody(startOffset, endOffset, initializer)
}
@@ -0,0 +1,87 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FieldCarrier
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
class PersistentIrField(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrFieldSymbol,
override val name: Name,
override val type: IrType,
override var visibility: Visibility,
override val isFinal: Boolean,
override val isExternal: Boolean,
override val isStatic: Boolean
) : PersistentIrDeclarationBase<FieldCarrier>(startOffset, endOffset, origin),
IrField,
FieldCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: PropertyDescriptor
get() = symbol.descriptor
override var initializerField: IrExpressionBody? = null
override var initializer: IrExpressionBody?
get() = getCarrier().initializerField
set(v) {
if (initializer !== v) {
if (v is PersistentIrBodyBase<*>) {
v.container = this
}
setCarrier().initializerField = v
}
}
override var correspondingPropertySymbolField: IrPropertySymbol? = null
override var correspondingPropertySymbol: IrPropertySymbol?
get() = getCarrier().correspondingPropertySymbolField
set(v) {
if (correspondingPropertySymbol !== v) {
setCarrier().correspondingPropertySymbolField = v
}
}
override var metadataField: MetadataSource? = null
override var metadata: MetadataSource?
get() = getCarrier().metadataField
set(v) {
if (metadata !== v) {
setCarrier().metadataField = v
}
}
}
@@ -0,0 +1,142 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFakeOverrideFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionCarrier
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
abstract class PersistentIrFunctionCommon(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
name: Name,
visibility: Visibility,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
override val isTailrec: Boolean,
override val isSuspend: Boolean,
override val isOperator: Boolean,
override val isInfix: Boolean,
isExpect: Boolean,
) :
PersistentIrFunctionBase<FunctionCarrier>(startOffset, endOffset, origin, name, visibility, isInline, isExternal, isExpect, returnType),
IrSimpleFunction,
FunctionCarrier {
override var overriddenSymbolsField: List<IrSimpleFunctionSymbol> = emptyList()
override var overriddenSymbols: List<IrSimpleFunctionSymbol>
get() = getCarrier().overriddenSymbolsField
set(v) {
if (overriddenSymbols !== v) {
setCarrier().overriddenSymbolsField = v
}
}
@Suppress("LeakingThis")
override var attributeOwnerIdField: IrAttributeContainer = this
override var attributeOwnerId: IrAttributeContainer
get() = getCarrier().attributeOwnerIdField
set(v) {
if (attributeOwnerId !== v) {
setCarrier().attributeOwnerIdField = v
}
}
override var correspondingPropertySymbolField: IrPropertySymbol? = null
override var correspondingPropertySymbol: IrPropertySymbol?
get() = getCarrier().correspondingPropertySymbolField
set(v) {
if (correspondingPropertySymbol !== v) {
setCarrier().correspondingPropertySymbolField = v
}
}
}
class PersistentIrFunction(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrSimpleFunctionSymbol,
name: Name,
visibility: Visibility,
override val modality: Modality,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
isTailrec: Boolean,
isSuspend: Boolean,
isOperator: Boolean,
isInfix: Boolean,
isExpect: Boolean,
override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
) : PersistentIrFunctionCommon(
startOffset, endOffset, origin, name, visibility, returnType, isInline,
isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect,
) {
@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor
get() = symbol.descriptor
init {
symbol.bind(this)
}
}
class PersistentIrFakeOverrideFunction(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
name: Name,
override var visibility: Visibility,
override var modality: Modality,
returnType: IrType,
isInline: Boolean,
isExternal: Boolean,
isTailrec: Boolean,
isSuspend: Boolean,
isOperator: Boolean,
isInfix: Boolean,
isExpect: Boolean,
) : PersistentIrFunctionCommon(
startOffset, endOffset, origin, name, visibility, returnType, isInline,
isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect,
), IrFakeOverrideFunction {
override val isFakeOverride: Boolean
get() = true
private var _symbol: IrSimpleFunctionSymbol? = null
override val symbol: IrSimpleFunctionSymbol
get() = _symbol ?: error("$this has not acquired a symbol yet")
@ObsoleteDescriptorBasedAPI
override val descriptor
get() = _symbol?.descriptor ?: WrappedSimpleFunctionDescriptor()
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol) {
assert(_symbol == null) { "$this already has symbol _symbol" }
_symbol = symbol
symbol.bind(this)
(symbol.descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this)
}
}
@@ -0,0 +1,132 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionBaseCarrier
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
abstract class PersistentIrFunctionBase<T : FunctionBaseCarrier>(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val name: Name,
visibility: Visibility,
override val isInline: Boolean,
override val isExternal: Boolean,
override val isExpect: Boolean,
returnType: IrType
) :
PersistentIrDeclarationBase<T>(startOffset, endOffset, origin),
IrFunction,
FunctionBaseCarrier {
override var returnTypeFieldField: IrType = returnType
private var returnTypeField: IrType
get() = getCarrier().returnTypeFieldField
set(v) {
if (returnTypeField !== v) {
setCarrier().returnTypeFieldField = v
}
}
@Suppress("DEPRECATION")
final override var returnType: IrType
get() = returnTypeField.let {
if (it !== org.jetbrains.kotlin.ir.types.impl.IrUninitializedType) it else error("Return type is not initialized")
}
set(c) {
returnTypeField = c
}
override var typeParametersField: List<IrTypeParameter> = emptyList()
override var typeParameters: List<IrTypeParameter>
get() = getCarrier().typeParametersField
set(v) {
if (typeParameters !== v) {
setCarrier().typeParametersField = v
}
}
override var dispatchReceiverParameterField: IrValueParameter? = null
override var dispatchReceiverParameter: IrValueParameter?
get() = getCarrier().dispatchReceiverParameterField
set(v) {
if (dispatchReceiverParameter !== v) {
setCarrier().dispatchReceiverParameterField = v
}
}
override var extensionReceiverParameterField: IrValueParameter? = null
override var extensionReceiverParameter: IrValueParameter?
get() = getCarrier().extensionReceiverParameterField
set(v) {
if (extensionReceiverParameter !== v) {
setCarrier().extensionReceiverParameterField = v
}
}
override var valueParametersField: List<IrValueParameter> = emptyList()
override var valueParameters: List<IrValueParameter>
get() = getCarrier().valueParametersField
set(v) {
if (valueParameters !== v) {
setCarrier().valueParametersField = v
}
}
override var bodyField: IrBody? = null
final override var body: IrBody?
get() = getCarrier().bodyField
set(v) {
if (body !== v) {
if (v is PersistentIrBodyBase<*>) {
v.container = this
}
setCarrier().bodyField = v
}
}
override var metadataField: MetadataSource? = null
override var metadata: MetadataSource?
get() = getCarrier().metadataField
set(v) {
if (metadata !== v) {
setCarrier().metadataField = v
}
}
override var visibilityField: Visibility = visibility
override var visibility: Visibility
get() = getCarrier().visibilityField
set(v) {
if (visibility !== v) {
setCarrier().visibilityField = v
}
}
}
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.LocalDelegatedPropertyCarrier
import org.jetbrains.kotlin.ir.symbols.IrLocalDelegatedPropertySymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
// TODO make not persistent
class PersistentIrLocalDelegatedProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrLocalDelegatedPropertySymbol,
override val name: Name,
override val type: IrType,
override val isVar: Boolean
) :
PersistentIrDeclarationBase<LocalDelegatedPropertyCarrier>(startOffset, endOffset, origin),
IrLocalDelegatedProperty,
LocalDelegatedPropertyCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: VariableDescriptorWithAccessors
get() = symbol.descriptor
override var delegateField: IrVariable? = null
override var delegate: IrVariable
get() = getCarrier().delegateField!!
set(v) {
if (getCarrier().delegateField !== v) {
setCarrier().delegateField = v
}
}
override var getterField: IrFunction? = null
override var getter: IrFunction
get() = getCarrier().getterField!!
set(v) {
if (getCarrier().getterField !== v) {
setCarrier().getterField = v
}
}
override var setterField: IrFunction? = null
override var setter: IrFunction?
get() = getCarrier().setterField
set(v) {
if (setter !== v) {
setCarrier().setterField = v
}
}
override var metadataField: MetadataSource? = null
override var metadata: MetadataSource?
get() = getCarrier().metadataField
set(v) {
if (metadata !== v) {
setCarrier().metadataField = v
}
}
}
@@ -0,0 +1,149 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.PropertyCarrier
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.name.Name
abstract class PersistentIrPropertyCommon(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val name: Name,
override var visibility: Visibility,
override val isVar: Boolean,
override val isConst: Boolean,
override val isLateinit: Boolean,
override val isDelegated: Boolean,
override val isExternal: Boolean,
override val isExpect: Boolean,
) : PersistentIrDeclarationBase<PropertyCarrier>(startOffset, endOffset, origin),
IrProperty,
PropertyCarrier {
override var backingFieldField: IrField? = null
override var backingField: IrField?
get() = getCarrier().backingFieldField
set(v) {
if (backingField !== v) {
setCarrier().backingFieldField = v
}
}
override var getterField: IrSimpleFunction? = null
override var getter: IrSimpleFunction?
get() = getCarrier().getterField
set(v) {
if (getter !== v) {
setCarrier().getterField = v
}
}
override var setterField: IrSimpleFunction? = null
override var setter: IrSimpleFunction?
get() = getCarrier().setterField
set(v) {
if (setter !== v) {
setCarrier().setterField = v
}
}
override var metadataField: MetadataSource? = null
override var metadata: MetadataSource?
get() = getCarrier().metadataField
set(v) {
if (metadata !== v) {
setCarrier().metadataField = v
}
}
}
class PersistentIrProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrPropertySymbol,
name: Name,
visibility: Visibility,
override val modality: Modality,
isVar: Boolean,
isConst: Boolean,
isLateinit: Boolean,
isDelegated: Boolean,
isExternal: Boolean,
isExpect: Boolean = false,
override val isFakeOverride: Boolean = origin == IrDeclarationOrigin.FAKE_OVERRIDE,
) : PersistentIrPropertyCommon(
startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit, isDelegated, isExternal, isExpect,
) {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: PropertyDescriptor
get() = symbol.descriptor
}
class PersistentIrFakeOverrideProperty(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
name: Name,
visibility: Visibility,
override var modality: Modality,
isVar: Boolean,
isConst: Boolean,
isLateinit: Boolean,
isDelegated: Boolean,
isExternal: Boolean,
isExpect: Boolean,
) : PersistentIrPropertyCommon(
startOffset, endOffset, origin, name, visibility, isVar, isConst, isLateinit,
isDelegated, isExternal, isExpect
), IrFakeOverrideProperty {
override val isFakeOverride: Boolean
get() = true
private var _symbol: IrPropertySymbol? = null
override val symbol: IrPropertySymbol
get() = _symbol ?: error("$this has not acquired a symbol yet")
@ObsoleteDescriptorBasedAPI
override val descriptor
get() = _symbol?.descriptor ?: WrappedPropertyDescriptor()
@OptIn(ObsoleteDescriptorBasedAPI::class)
override fun acquireSymbol(symbol: IrPropertySymbol) {
assert(_symbol == null) { "$this already has symbol _symbol" }
_symbol = symbol
symbol.bind(this)
(symbol.descriptor as? WrappedPropertyDescriptor)?.bind(this)
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrTypeAlias
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.TypeAliasCarrier
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
class PersistentIrTypeAlias(
startOffset: Int,
endOffset: Int,
override val symbol: IrTypeAliasSymbol,
override val name: Name,
override var visibility: Visibility,
override val expandedType: IrType,
override val isActual: Boolean,
origin: IrDeclarationOrigin
) :
PersistentIrDeclarationBase<TypeAliasCarrier>(startOffset, endOffset, origin),
IrTypeAlias,
TypeAliasCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: TypeAliasDescriptor
get() = symbol.descriptor
override var typeParametersField: List<IrTypeParameter> = emptyList()
override var typeParameters: List<IrTypeParameter>
get() = getCarrier().typeParametersField
set(v) {
if (typeParameters !== v) {
setCarrier().typeParametersField = v
}
}
}
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.TypeParameterCarrier
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.SmartList
class PersistentIrTypeParameter(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrTypeParameterSymbol,
override val name: Name,
override val index: Int,
override val isReified: Boolean,
override val variance: Variance
) :
PersistentIrDeclarationBase<TypeParameterCarrier>(startOffset, endOffset, origin),
IrTypeParameter,
TypeParameterCarrier {
init {
symbol.bind(this)
}
@ObsoleteDescriptorBasedAPI
override val descriptor: TypeParameterDescriptor
get() = symbol.descriptor
override val superTypes: MutableList<IrType> = SmartList()
}
@@ -0,0 +1,65 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ValueParameterCarrier
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
class PersistentIrValueParameter(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
override val symbol: IrValueParameterSymbol,
override val name: Name,
override val index: Int,
override val type: IrType,
override val varargElementType: IrType?,
override val isCrossinline: Boolean,
override val isNoinline: Boolean
) :
PersistentIrDeclarationBase<ValueParameterCarrier>(startOffset, endOffset, origin),
IrValueParameter,
ValueParameterCarrier {
@ObsoleteDescriptorBasedAPI
override val descriptor: ParameterDescriptor
get() = symbol.descriptor
init {
symbol.bind(this)
}
override var defaultValueField: IrExpressionBody? = null
override var defaultValue: IrExpressionBody?
get() = getCarrier().defaultValueField
set(v) {
if (defaultValue !== v) {
if (v is PersistentIrBodyBase<*>) {
v.container = this
}
setCarrier().defaultValueField = v
}
}
}
@@ -0,0 +1,33 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface AnonymousInitializerCarrier : DeclarationCarrier {
var bodyField: IrBlockBody?
override fun clone(): AnonymousInitializerCarrier {
return AnonymousInitializerCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
bodyField
)
}
}
class AnonymousInitializerCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var bodyField: IrBlockBody?
) : AnonymousInitializerCarrier
@@ -0,0 +1,22 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
interface BodyCarrier : Carrier {
var containerField: IrDeclaration?
override fun clone(): BodyCarrier {
return BodyCarrierImpl(lastModified, containerField)
}
}
class BodyCarrierImpl(
override val lastModified: Int,
override var containerField: IrDeclaration?
) : BodyCarrier
@@ -0,0 +1,12 @@
/*
* 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.ir.declarations.persistent.carriers
interface Carrier {
val lastModified: Int
fun clone(): Carrier
}
@@ -0,0 +1,52 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.types.IrType
interface ClassCarrier : DeclarationCarrier {
var thisReceiverField: IrValueParameter?
var metadataField: MetadataSource?
var visibilityField: Visibility
var modalityField: Modality
var attributeOwnerIdField: IrAttributeContainer
var typeParametersField: List<IrTypeParameter>
var superTypesField: List<IrType>
override fun clone(): ClassCarrier {
return ClassCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
thisReceiverField,
metadataField,
visibilityField,
modalityField,
attributeOwnerIdField,
typeParametersField,
superTypesField
)
}
}
class ClassCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var thisReceiverField: IrValueParameter?,
override var metadataField: MetadataSource?,
override var visibilityField: Visibility,
override var modalityField: Modality,
override var attributeOwnerIdField: IrAttributeContainer,
override var typeParametersField: List<IrTypeParameter>,
override var superTypesField: List<IrType>
) : ClassCarrier
@@ -0,0 +1,47 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.types.IrType
interface ConstructorCarrier : FunctionBaseCarrier {
override fun clone(): ConstructorCarrier {
return ConstructorCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
returnTypeFieldField,
dispatchReceiverParameterField,
extensionReceiverParameterField,
bodyField,
metadataField,
visibilityField,
typeParametersField,
valueParametersField
)
}
}
class ConstructorCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var returnTypeFieldField: IrType,
override var dispatchReceiverParameterField: IrValueParameter?,
override var extensionReceiverParameterField: IrValueParameter?,
override var bodyField: IrBody?,
override var metadataField: MetadataSource?,
override var visibilityField: Visibility,
override var typeParametersField: List<IrTypeParameter>,
override var valueParametersField: List<IrValueParameter>
) : ConstructorCarrier
@@ -0,0 +1,16 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface DeclarationCarrier: Carrier {
var parentField: IrDeclarationParent?
var originField: IrDeclarationOrigin
var annotationsField: List<IrConstructorCall>
}
@@ -0,0 +1,37 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
interface EnumEntryCarrier : DeclarationCarrier {
var correspondingClassField: IrClass?
var initializerExpressionField: IrExpressionBody?
override fun clone(): EnumEntryCarrier {
return EnumEntryCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
correspondingClassField,
initializerExpressionField
)
}
}
class EnumEntryCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var correspondingClassField: IrClass?,
override var initializerExpressionField: IrExpressionBody?
) : EnumEntryCarrier
@@ -0,0 +1,24 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface ErrorCarrier : DeclarationCarrier {
override fun clone(): ErrorCarrier {
return ErrorCarrierImpl(lastModified, parentField, originField, annotationsField)
}
}
class ErrorCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>
) : ErrorCarrier
@@ -0,0 +1,41 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
interface FieldCarrier : DeclarationCarrier {
var initializerField: IrExpressionBody?
var correspondingPropertySymbolField: IrPropertySymbol?
var metadataField: MetadataSource?
override fun clone(): FieldCarrier {
return FieldCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
initializerField,
correspondingPropertySymbolField,
metadataField
)
}
}
class FieldCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var initializerField: IrExpressionBody?,
override var correspondingPropertySymbolField: IrPropertySymbol?,
override var metadataField: MetadataSource?
): FieldCarrier
@@ -0,0 +1,24 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.types.IrType
interface FunctionBaseCarrier : DeclarationCarrier {
var returnTypeFieldField: IrType
var dispatchReceiverParameterField: IrValueParameter?
var extensionReceiverParameterField: IrValueParameter?
var bodyField: IrBody?
var metadataField: MetadataSource?
var visibilityField: Visibility
var typeParametersField: List<IrTypeParameter>
var valueParametersField: List<IrValueParameter>
}
@@ -0,0 +1,58 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
interface FunctionCarrier : FunctionBaseCarrier {
var correspondingPropertySymbolField: IrPropertySymbol?
var overriddenSymbolsField: List<IrSimpleFunctionSymbol>
var attributeOwnerIdField: IrAttributeContainer
override fun clone(): FunctionCarrier {
return FunctionCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
returnTypeFieldField,
dispatchReceiverParameterField,
extensionReceiverParameterField,
bodyField,
metadataField,
visibilityField,
typeParametersField,
valueParametersField,
correspondingPropertySymbolField,
overriddenSymbolsField,
attributeOwnerIdField
)
}
}
class FunctionCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var returnTypeFieldField: IrType,
override var dispatchReceiverParameterField: IrValueParameter?,
override var extensionReceiverParameterField: IrValueParameter?,
override var bodyField: IrBody?,
override var metadataField: MetadataSource?,
override var visibilityField: Visibility,
override var typeParametersField: List<IrTypeParameter>,
override var valueParametersField: List<IrValueParameter>,
override var correspondingPropertySymbolField: IrPropertySymbol?,
override var overriddenSymbolsField: List<IrSimpleFunctionSymbol>,
override var attributeOwnerIdField: IrAttributeContainer
) : FunctionCarrier
@@ -0,0 +1,40 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface LocalDelegatedPropertyCarrier : DeclarationCarrier {
var delegateField: IrVariable?
var getterField: IrFunction?
var setterField: IrFunction?
var metadataField: MetadataSource?
override fun clone(): LocalDelegatedPropertyCarrier {
return LocalDelegatedPropertyCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
delegateField,
getterField,
setterField,
metadataField
)
}
}
class LocalDelegatedPropertyCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var delegateField: IrVariable?,
override var getterField: IrFunction?,
override var setterField: IrFunction?,
override var metadataField: MetadataSource?
) : LocalDelegatedPropertyCarrier
@@ -0,0 +1,40 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface PropertyCarrier : DeclarationCarrier {
var backingFieldField: IrField?
var getterField: IrSimpleFunction?
var setterField: IrSimpleFunction?
var metadataField: MetadataSource?
override fun clone(): PropertyCarrier {
return PropertyCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
backingFieldField,
getterField,
setterField,
metadataField
)
}
}
class PropertyCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var backingFieldField: IrField?,
override var getterField: IrSimpleFunction?,
override var setterField: IrSimpleFunction?,
override var metadataField: MetadataSource?
) : PropertyCarrier
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface TypeAliasCarrier : DeclarationCarrier {
var typeParametersField: List<IrTypeParameter>
override fun clone(): TypeAliasCarrier {
return TypeAliasCarrierImpl(
lastModified,
parentField,
originField,
annotationsField,
typeParametersField
)
}
}
class TypeAliasCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var typeParametersField: List<IrTypeParameter>
) : TypeAliasCarrier
@@ -0,0 +1,24 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
interface TypeParameterCarrier : DeclarationCarrier {
override fun clone(): TypeParameterCarrier {
return TypeParameterCarrierImpl(lastModified, parentField, originField, annotationsField)
}
}
class TypeParameterCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>
) : TypeParameterCarrier
@@ -0,0 +1,27 @@
/*
* 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.ir.declarations.persistent.carriers
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
interface ValueParameterCarrier : DeclarationCarrier {
var defaultValueField: IrExpressionBody?
override fun clone(): ValueParameterCarrier {
return ValueParameterCarrierImpl(lastModified, parentField, originField, annotationsField, defaultValueField)
}
}
class ValueParameterCarrierImpl(
override val lastModified: Int,
override var parentField: IrDeclarationParent?,
override var originField: IrDeclarationOrigin,
override var annotationsField: List<IrConstructorCall>,
override var defaultValueField: IrExpressionBody?
) : ValueParameterCarrier
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.expressions.persistent
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
class PersistentIrBlockBody(
startOffset: Int,
endOffset: Int,
initializer: (IrBlockBody.() -> Unit)? = null
) :
PersistentIrBodyBase<PersistentIrBlockBody>(startOffset, endOffset, initializer),
IrBlockBody {
constructor(startOffset: Int, endOffset: Int, statements: List<IrStatement>) : this(startOffset, endOffset) {
statementsField.addAll(statements)
}
private var statementsField: MutableList<IrStatement> = ArrayList()
override val statements: MutableList<IrStatement>
get() = checkEnabled { statementsField }
override val factory: IrFactory
get() = PersistentIrFactory
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.ir.expressions.persistent
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
class PersistentIrExpressionBody private constructor(
startOffset: Int,
endOffset: Int,
private var expressionField: IrExpression? = null,
initializer: (IrExpressionBody.() -> Unit)? = null
) :
PersistentIrBodyBase<PersistentIrExpressionBody>(startOffset, endOffset, initializer),
IrExpressionBody {
constructor(expression: IrExpression) : this(expression.startOffset, expression.endOffset, expression, null)
constructor(startOffset: Int, endOffset: Int, expression: IrExpression) : this(startOffset, endOffset, expression, null)
constructor(startOffset: Int, endOffset: Int, initializer: IrExpressionBody.() -> Unit) :
this(startOffset, endOffset, null, initializer)
override var expression: IrExpression
get() = checkEnabled { expressionField!! }
set(e) {
checkEnabled { expressionField = e }
}
override val factory: IrFactory
get() = PersistentIrFactory
}