Declaration IR refactoring.
This commit is contained in:
committed by
Dmitry Petrov
parent
4f469c798c
commit
5e609c7de4
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBodyBase
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBodyImpl
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBodyImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrReturnExpressionImpl
|
import org.jetbrains.kotlin.ir.expressions.IrReturnExpressionImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.returnedExpression
|
import org.jetbrains.kotlin.ir.expressions.returnedExpression
|
||||||
@@ -91,7 +91,7 @@ abstract class IrDeclarationGeneratorBase(
|
|||||||
return propertyDescriptor
|
return propertyDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateExpressionBody(ktBody: KtExpression): IrBodyBase {
|
fun generateExpressionBody(ktBody: KtExpression): IrBody {
|
||||||
val sourceLocation = fileElementFactory.getLocationInFile(ktBody)
|
val sourceLocation = fileElementFactory.getLocationInFile(ktBody)
|
||||||
val irExpression = irExpressionGenerator.generateExpression(ktBody)
|
val irExpression = irExpressionGenerator.generateExpression(ktBody)
|
||||||
|
|
||||||
@@ -102,6 +102,6 @@ abstract class IrDeclarationGeneratorBase(
|
|||||||
IrReturnExpressionImpl(sourceLocation, irExpression.type)
|
IrReturnExpressionImpl(sourceLocation, irExpression.type)
|
||||||
.apply { returnedExpression = irExpression }
|
.apply { returnedExpression = irExpression }
|
||||||
|
|
||||||
return IrExpressionBodyImpl(sourceLocation).apply { childExpression = bodyExpression }
|
return IrExpressionBodyImpl(sourceLocation, containingDeclaration).apply { childExpression = bodyExpression }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,11 +41,11 @@ class IrFileElementFactory private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createFunction(ktFunction: KtFunction, functionDescriptor: FunctionDescriptor, body: IrBody): IrFunction =
|
fun createFunction(ktFunction: KtFunction, functionDescriptor: FunctionDescriptor, body: IrBody): IrFunction =
|
||||||
IrFunctionImpl(getLocationInFile(ktFunction), IrDeclarationKind.DEFINED, functionDescriptor, body)
|
IrFunctionImpl(getLocationInFile(ktFunction), IrDeclarationOriginKind.DEFINED, functionDescriptor, body)
|
||||||
.addToContainer()
|
.addToContainer()
|
||||||
|
|
||||||
fun createSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor, valueInitializer: IrBody?): IrSimpleProperty =
|
fun createSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor, valueInitializer: IrBody?): IrSimpleProperty =
|
||||||
IrSimplePropertyImpl(getLocationInFile(ktProperty), IrDeclarationKind.DEFINED, propertyDescriptor, valueInitializer)
|
IrSimplePropertyImpl(getLocationInFile(ktProperty), IrDeclarationOriginKind.DEFINED, propertyDescriptor, valueInitializer)
|
||||||
.addToContainer()
|
.addToContainer()
|
||||||
|
|
||||||
fun createPropertyGetter(
|
fun createPropertyGetter(
|
||||||
@@ -54,7 +54,7 @@ class IrFileElementFactory private constructor(
|
|||||||
getterDescriptor: PropertyGetterDescriptor,
|
getterDescriptor: PropertyGetterDescriptor,
|
||||||
getterBody: IrBody
|
getterBody: IrBody
|
||||||
): IrPropertyGetter =
|
): IrPropertyGetter =
|
||||||
IrPropertyGetterImpl(getLocationInFile(ktPropertyAccessor), IrDeclarationKind.DEFINED, getterDescriptor, getterBody)
|
IrPropertyGetterImpl(getLocationInFile(ktPropertyAccessor), IrDeclarationOriginKind.DEFINED, getterDescriptor, getterBody)
|
||||||
.apply { irProperty.getter = this }
|
.apply { irProperty.getter = this }
|
||||||
.addToContainer()
|
.addToContainer()
|
||||||
|
|
||||||
@@ -64,16 +64,16 @@ class IrFileElementFactory private constructor(
|
|||||||
setterDescriptor: PropertySetterDescriptor,
|
setterDescriptor: PropertySetterDescriptor,
|
||||||
setterBody: IrBody
|
setterBody: IrBody
|
||||||
) : IrPropertySetter =
|
) : IrPropertySetter =
|
||||||
IrPropertySetterImpl(getLocationInFile(ktPropertyAccessor), IrDeclarationKind.DEFINED, setterDescriptor, setterBody)
|
IrPropertySetterImpl(getLocationInFile(ktPropertyAccessor), IrDeclarationOriginKind.DEFINED, setterDescriptor, setterBody)
|
||||||
.apply { irProperty.setter = this }
|
.apply { irProperty.setter = this }
|
||||||
.addToContainer()
|
.addToContainer()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun create(irModule: IrModule, sourceManager: PsiSourceManager, ktFile: KtFile, descriptor: PackageFragmentDescriptor): IrFileElementFactory {
|
fun create(irModule: IrModuleImpl, sourceManager: PsiSourceManager, ktFile: KtFile, descriptor: PackageFragmentDescriptor): IrFileElementFactory {
|
||||||
val fileEntry = sourceManager.getOrCreateFileEntry(ktFile)
|
val fileEntry = sourceManager.getOrCreateFileEntry(ktFile)
|
||||||
val fileSourceLocation = fileEntry.getRootSourceLocation()
|
val fileSourceLocation = fileEntry.getRootSourceLocation()
|
||||||
val fileName = fileEntry.getRecognizableName()
|
val fileName = fileEntry.getRecognizableName()
|
||||||
val irFile = IrFileImpl(fileSourceLocation, irModule, fileName, descriptor)
|
val irFile = IrFileImpl(fileSourceLocation, fileName, descriptor)
|
||||||
irModule.addFile(irFile)
|
irModule.addFile(irFile)
|
||||||
return IrFileElementFactory(fileEntry, irFile, irFile)
|
return IrFileElementFactory(fileEntry, irFile, irFile)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ typealias SourceLocation = Long
|
|||||||
fun SourceLocation(index: Int, offset: Int) =
|
fun SourceLocation(index: Int, offset: Int) =
|
||||||
(index.toLong() shl 32) + offset.toLong()
|
(index.toLong() shl 32) + offset.toLong()
|
||||||
|
|
||||||
const val NO_LOCATION: SourceLocation = -1L
|
const val NO_LOCATION: SourceLocation = Long.MIN_VALUE
|
||||||
const val UNDEFINED_INDEX: Int = -1
|
const val UNDEFINED_INDEX: Int = -1
|
||||||
const val UNDEFINED_OFFSET: Int = -1
|
const val UNDEFINED_OFFSET: Int = -1
|
||||||
|
|
||||||
|
|||||||
@@ -22,20 +22,16 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
|||||||
|
|
||||||
interface IrClass : IrCompoundDeclaration, IrMemberDeclaration {
|
interface IrClass : IrCompoundDeclaration, IrMemberDeclaration {
|
||||||
override val descriptor: ClassDescriptor
|
override val descriptor: ClassDescriptor
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.MODULE
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrClassImpl(
|
class IrClassImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
override val descriptor: ClassDescriptor
|
override val descriptor: ClassDescriptor
|
||||||
) : IrCompoundDeclarationBase(sourceLocation, kind), IrClass {
|
) : IrCompoundMemberDeclarationBase(sourceLocation, originKind), IrClass {
|
||||||
override var parent: IrCompoundDeclaration? = null
|
|
||||||
|
|
||||||
override fun setTreeLocation(parent: IrCompoundDeclaration?, index: Int) {
|
|
||||||
this.parent = parent
|
|
||||||
this.index = index
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitClass(this, data)
|
visitor.visitClass(this, data)
|
||||||
}
|
}
|
||||||
|
|||||||
+73
-21
@@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.declarations
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
|
import org.jetbrains.kotlin.ir.IrElementBase
|
||||||
import org.jetbrains.kotlin.ir.SourceLocation
|
import org.jetbrains.kotlin.ir.SourceLocation
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
interface IrCompoundDeclaration : IrDeclaration {
|
interface IrDeclarationOwner : IrElement {
|
||||||
|
val childrenCount: Int
|
||||||
fun getChildDeclaration(index: Int): IrMemberDeclaration?
|
fun getChildDeclaration(index: Int): IrMemberDeclaration?
|
||||||
fun addChildDeclaration(child: IrMemberDeclaration)
|
fun addChildDeclaration(child: IrMemberDeclaration)
|
||||||
fun replaceChildDeclaration(oldChild: IrMemberDeclaration, newChild: IrMemberDeclaration)
|
fun replaceChildDeclaration(oldChild: IrMemberDeclaration, newChild: IrMemberDeclaration)
|
||||||
@@ -32,28 +35,25 @@ interface IrCompoundDeclaration : IrDeclaration {
|
|||||||
fun <D> acceptChildDeclarations(visitor: IrElementVisitor<Unit, D>, data: D)
|
fun <D> acceptChildDeclarations(visitor: IrElementVisitor<Unit, D>, data: D)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IrCompoundDeclaration : IrDeclaration, IrDeclarationOwner
|
||||||
|
|
||||||
interface IrMemberDeclaration : IrDeclaration {
|
interface IrMemberDeclaration : IrDeclaration {
|
||||||
fun setTreeLocation(parent: IrCompoundDeclaration?, index: Int)
|
override val parent: IrDeclarationOwner
|
||||||
|
|
||||||
|
fun setTreeLocation(parent: IrDeclarationOwner?, index: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO synchronization?
|
abstract class IrDeclarationOwnerBase(
|
||||||
abstract class IrCompoundDeclarationBase(
|
sourceLocation: SourceLocation
|
||||||
sourceLocation: SourceLocation,
|
) : IrElementBase(sourceLocation), IrDeclarationOwner {
|
||||||
kind: IrDeclarationKind
|
|
||||||
) : IrDeclarationBase(sourceLocation, kind), IrCompoundDeclaration {
|
|
||||||
protected val childDeclarations: MutableList<IrMemberDeclaration> = ArrayList()
|
protected val childDeclarations: MutableList<IrMemberDeclaration> = ArrayList()
|
||||||
|
|
||||||
|
override val childrenCount: Int
|
||||||
|
get() = childDeclarations.size
|
||||||
|
|
||||||
override fun getChildDeclaration(index: Int): IrMemberDeclaration? =
|
override fun getChildDeclaration(index: Int): IrMemberDeclaration? =
|
||||||
childDeclarations.getOrNull(index)
|
childDeclarations.getOrNull(index)
|
||||||
|
|
||||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
|
||||||
acceptChildDeclarations(visitor, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <D> acceptChildDeclarations(visitor: IrElementVisitor<Unit, D>, data: D) {
|
|
||||||
childDeclarations.forEach { it.accept(visitor, data) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addChildDeclaration(child: IrMemberDeclaration) {
|
override fun addChildDeclaration(child: IrMemberDeclaration) {
|
||||||
child.setTreeLocation(this, childDeclarations.size)
|
child.setTreeLocation(this, childDeclarations.size)
|
||||||
childDeclarations.add(child)
|
childDeclarations.add(child)
|
||||||
@@ -61,8 +61,8 @@ abstract class IrCompoundDeclarationBase(
|
|||||||
|
|
||||||
override fun removeChildDeclaration(child: IrMemberDeclaration) {
|
override fun removeChildDeclaration(child: IrMemberDeclaration) {
|
||||||
validateChild(child)
|
validateChild(child)
|
||||||
childDeclarations.removeAt(child.index)
|
childDeclarations.removeAt(child.indexInParent)
|
||||||
for (i in child.index ..childDeclarations.size - 1) {
|
for (i in child.indexInParent..childDeclarations.size - 1) {
|
||||||
childDeclarations[i].setTreeLocation(this, i)
|
childDeclarations[i].setTreeLocation(this, i)
|
||||||
}
|
}
|
||||||
child.detach()
|
child.detach()
|
||||||
@@ -75,16 +75,68 @@ abstract class IrCompoundDeclarationBase(
|
|||||||
|
|
||||||
override fun replaceChildDeclaration(oldChild: IrMemberDeclaration, newChild: IrMemberDeclaration) {
|
override fun replaceChildDeclaration(oldChild: IrMemberDeclaration, newChild: IrMemberDeclaration) {
|
||||||
validateChild(oldChild)
|
validateChild(oldChild)
|
||||||
childDeclarations[oldChild.index] = newChild
|
childDeclarations[oldChild.indexInParent] = newChild
|
||||||
newChild.setTreeLocation(this, oldChild.index)
|
newChild.setTreeLocation(this, oldChild.indexInParent)
|
||||||
oldChild.detach()
|
oldChild.detach()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun <D> acceptChildDeclarations(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
childDeclarations.forEach { it.accept(visitor, data) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO synchronization?
|
||||||
|
abstract class IrCompoundDeclarationBase(
|
||||||
|
sourceLocation: SourceLocation,
|
||||||
|
override val originKind: IrDeclarationOriginKind
|
||||||
|
) : IrDeclarationOwnerBase(sourceLocation), IrCompoundDeclaration {
|
||||||
|
override var indexInParent: Int = IrDeclaration.DETACHED_INDEX
|
||||||
|
|
||||||
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
acceptChildDeclarations(visitor, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class IrCompoundMemberDeclarationBase(
|
||||||
|
sourceLocation: SourceLocation,
|
||||||
|
originKind: IrDeclarationOriginKind
|
||||||
|
) : IrCompoundDeclarationBase(sourceLocation, originKind), IrMemberDeclaration {
|
||||||
|
private var parentImpl: IrDeclarationOwner? = null
|
||||||
|
|
||||||
|
override var parent: IrDeclarationOwner
|
||||||
|
get() = parentImpl!!
|
||||||
|
set(newParent) {
|
||||||
|
parentImpl = newParent
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTreeLocation(parent: IrDeclarationOwner?, index: Int) {
|
||||||
|
this.parentImpl = parent
|
||||||
|
this.indexInParent = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class IrMemberDeclarationBase(
|
||||||
|
sourceLocation: SourceLocation,
|
||||||
|
originKind: IrDeclarationOriginKind
|
||||||
|
) : IrDeclarationBase(sourceLocation, originKind), IrMemberDeclaration {
|
||||||
|
private var parentImpl: IrDeclarationOwner? = null
|
||||||
|
|
||||||
|
override var parent: IrDeclarationOwner
|
||||||
|
get() = parentImpl!!
|
||||||
|
set(newParent) {
|
||||||
|
parentImpl = newParent
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTreeLocation(parent: IrDeclarationOwner?, index: Int) {
|
||||||
|
this.parentImpl = parent
|
||||||
|
this.indexInParent = index
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrMemberDeclaration.detach() {
|
fun IrMemberDeclaration.detach() {
|
||||||
setTreeLocation(null, IrDeclaration.DETACHED_INDEX)
|
setTreeLocation(null, IrDeclaration.DETACHED_INDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrCompoundDeclaration.validateChild(child: IrMemberDeclaration) {
|
fun IrDeclarationOwner.validateChild(child: IrMemberDeclaration) {
|
||||||
assert(child.parent == this && getChildDeclaration(child.index) == child) { "Invalid child: $child" }
|
assert(child.parent == this && getChildDeclaration(child.indexInParent) == child) { "Invalid child: $child" }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ import org.jetbrains.kotlin.ir.IrElementBase
|
|||||||
import org.jetbrains.kotlin.ir.SourceLocation
|
import org.jetbrains.kotlin.ir.SourceLocation
|
||||||
|
|
||||||
interface IrDeclaration : IrElement {
|
interface IrDeclaration : IrElement {
|
||||||
override val parent: IrCompoundDeclaration?
|
override val parent: IrDeclarationOwner?
|
||||||
val index: Int
|
val indexInParent: Int
|
||||||
|
|
||||||
val descriptor: DeclarationDescriptor?
|
val descriptor: DeclarationDescriptor?
|
||||||
val kind: IrDeclarationKind
|
|
||||||
|
val declarationKind: IrDeclarationKind
|
||||||
|
val originKind: IrDeclarationOriginKind
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val DETACHED_INDEX = Int.MIN_VALUE
|
const val DETACHED_INDEX = Int.MIN_VALUE
|
||||||
@@ -34,17 +36,23 @@ interface IrDeclaration : IrElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class IrDeclarationKind {
|
enum class IrDeclarationKind {
|
||||||
|
MODULE,
|
||||||
|
FILE,
|
||||||
|
FUNCTION,
|
||||||
|
PROPERTY,
|
||||||
|
PROPERTY_GETTER,
|
||||||
|
PROPERTY_SETTER,
|
||||||
|
CLASS
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class IrDeclarationOriginKind {
|
||||||
DEFINED,
|
DEFINED,
|
||||||
DEFAULT_PROPERTY_ACCESSOR,
|
DEFAULT_PROPERTY_ACCESSOR,
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IrDeclarationBase(
|
abstract class IrDeclarationBase(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
override val kind: IrDeclarationKind
|
override val originKind: IrDeclarationOriginKind
|
||||||
) : IrElementBase(sourceLocation), IrDeclaration {
|
) : IrElementBase(sourceLocation), IrDeclaration {
|
||||||
override var index: Int = IrDeclaration.DETACHED_INDEX
|
override var indexInParent: Int = IrDeclaration.DETACHED_INDEX
|
||||||
}
|
}
|
||||||
|
|
||||||
val IrDeclaration.containingDeclaration: IrDeclaration?
|
|
||||||
get() = parent
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,16 +22,21 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
|||||||
|
|
||||||
interface IrFile : IrCompoundDeclaration {
|
interface IrFile : IrCompoundDeclaration {
|
||||||
val name: String
|
val name: String
|
||||||
|
val module: IrModule
|
||||||
override val descriptor: PackageFragmentDescriptor
|
override val descriptor: PackageFragmentDescriptor
|
||||||
|
|
||||||
|
override val parent: Nothing? get() = null
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrFileImpl(
|
class IrFileImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
val module: IrModule,
|
|
||||||
override val name: String,
|
override val name: String,
|
||||||
override val descriptor: PackageFragmentDescriptor
|
override val descriptor: PackageFragmentDescriptor
|
||||||
) : IrCompoundDeclarationBase(sourceLocation, IrDeclarationKind.DEFINED), IrFile {
|
) : IrCompoundDeclarationBase(sourceLocation, IrDeclarationOriginKind.DEFINED), IrFile {
|
||||||
override val parent: IrCompoundDeclaration? = null
|
override lateinit var module: IrModule
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitFile(this, data)
|
visitor.visitFile(this, data)
|
||||||
|
|||||||
@@ -24,31 +24,26 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
|||||||
interface IrFunction : IrMemberDeclaration {
|
interface IrFunction : IrMemberDeclaration {
|
||||||
override val descriptor: FunctionDescriptor
|
override val descriptor: FunctionDescriptor
|
||||||
val body: IrBody
|
val body: IrBody
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.FUNCTION
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IrFunctionBase(
|
abstract class IrFunctionBase(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind
|
originKind: IrDeclarationOriginKind
|
||||||
) : IrCompoundDeclarationBase(sourceLocation, kind), IrFunction {
|
) : IrMemberDeclarationBase(sourceLocation, originKind), IrFunction {
|
||||||
override var parent: IrCompoundDeclaration? = null
|
|
||||||
|
|
||||||
override fun setTreeLocation(parent: IrCompoundDeclaration?, index: Int) {
|
|
||||||
this.parent = parent
|
|
||||||
this.index = index
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
super.acceptChildDeclarations(visitor, data)
|
|
||||||
body.accept(visitor, data)
|
body.accept(visitor, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrFunctionImpl(
|
class IrFunctionImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
override val descriptor: FunctionDescriptor,
|
override val descriptor: FunctionDescriptor,
|
||||||
override val body: IrBody
|
override val body: IrBody
|
||||||
) : IrFunctionBase(sourceLocation, kind) {
|
) : IrFunctionBase(sourceLocation, originKind) {
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitFunction(this, data)
|
visitor.visitFunction(this, data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,24 +25,33 @@ import java.util.*
|
|||||||
interface IrModule : IrDeclaration {
|
interface IrModule : IrDeclaration {
|
||||||
override val descriptor: ModuleDescriptor
|
override val descriptor: ModuleDescriptor
|
||||||
|
|
||||||
|
override val parent: Nothing? get() = null
|
||||||
|
override val indexInParent: Int get() = MODULE_INDEX
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.MODULE
|
||||||
|
|
||||||
val files: List<IrFile>
|
val files: List<IrFile>
|
||||||
|
|
||||||
fun addFile(file: IrFile)
|
companion object {
|
||||||
|
const val MODULE_INDEX = -1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrModuleImpl(
|
class IrModuleImpl(
|
||||||
override val descriptor: ModuleDescriptor
|
override val descriptor: ModuleDescriptor
|
||||||
) : IrDeclarationBase(NO_LOCATION, IrDeclarationKind.DEFINED), IrModule {
|
) : IrModule {
|
||||||
init {
|
override val sourceLocation: Long
|
||||||
index = 0
|
get() = NO_LOCATION
|
||||||
}
|
|
||||||
|
|
||||||
override val parent: IrCompoundDeclaration? get() = null
|
override val originKind: IrDeclarationOriginKind
|
||||||
|
get() = IrDeclarationOriginKind.DEFINED
|
||||||
|
|
||||||
override val files: MutableList<IrFile> = ArrayList()
|
override val files: MutableList<IrFile> = ArrayList()
|
||||||
|
|
||||||
override fun addFile(file: IrFile) {
|
fun addFile(file: IrFileImpl) {
|
||||||
files.add(file)
|
files.add(file)
|
||||||
|
file.module = this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ interface IrProperty : IrMemberDeclaration {
|
|||||||
var getter: IrPropertyGetter?
|
var getter: IrPropertyGetter?
|
||||||
var setter: IrPropertySetter?
|
var setter: IrPropertySetter?
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.PROPERTY
|
||||||
|
|
||||||
fun <D> acceptAccessors(visitor: IrElementVisitor<Unit, D>, data: D)
|
fun <D> acceptAccessors(visitor: IrElementVisitor<Unit, D>, data: D)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,16 +43,9 @@ interface IrDelegatedProperty : IrProperty {
|
|||||||
// TODO synchronization?
|
// TODO synchronization?
|
||||||
abstract class IrPropertyBase(
|
abstract class IrPropertyBase(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
override val descriptor: PropertyDescriptor
|
override val descriptor: PropertyDescriptor
|
||||||
) : IrDeclarationBase(sourceLocation, kind), IrProperty {
|
) : IrMemberDeclarationBase(sourceLocation, originKind), IrProperty {
|
||||||
override var parent: IrCompoundDeclaration? = null
|
|
||||||
|
|
||||||
override fun setTreeLocation(parent: IrCompoundDeclaration?, index: Int) {
|
|
||||||
this.parent = parent
|
|
||||||
this.index = index
|
|
||||||
}
|
|
||||||
|
|
||||||
override var getter: IrPropertyGetter? = null
|
override var getter: IrPropertyGetter? = null
|
||||||
set(newGetter) {
|
set(newGetter) {
|
||||||
newGetter?.property = this
|
newGetter?.property = this
|
||||||
@@ -70,10 +66,10 @@ abstract class IrPropertyBase(
|
|||||||
|
|
||||||
class IrSimplePropertyImpl(
|
class IrSimplePropertyImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
descriptor: PropertyDescriptor,
|
descriptor: PropertyDescriptor,
|
||||||
override val valueInitializer: IrBody?
|
override val valueInitializer: IrBody?
|
||||||
) : IrPropertyBase(sourceLocation, kind, descriptor), IrSimpleProperty {
|
) : IrPropertyBase(sourceLocation, originKind, descriptor), IrSimpleProperty {
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitSimpleProperty(this, data)
|
visitor.visitSimpleProperty(this, data)
|
||||||
|
|
||||||
@@ -84,10 +80,10 @@ class IrSimplePropertyImpl(
|
|||||||
|
|
||||||
class IrDelegatedPropertyImpl(
|
class IrDelegatedPropertyImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
descriptor: PropertyDescriptor,
|
descriptor: PropertyDescriptor,
|
||||||
override val delegateInitializer: IrBody
|
override val delegateInitializer: IrBody
|
||||||
) : IrPropertyBase(sourceLocation, kind, descriptor), IrDelegatedProperty {
|
) : IrPropertyBase(sourceLocation, originKind, descriptor), IrDelegatedProperty {
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitDelegatedProperty(this, data)
|
visitor.visitDelegatedProperty(this, data)
|
||||||
|
|
||||||
|
|||||||
@@ -30,36 +30,42 @@ interface IrPropertyAccessor : IrFunction {
|
|||||||
|
|
||||||
interface IrPropertyGetter : IrPropertyAccessor {
|
interface IrPropertyGetter : IrPropertyAccessor {
|
||||||
override val descriptor: PropertyGetterDescriptor
|
override val descriptor: PropertyGetterDescriptor
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.PROPERTY_GETTER
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IrPropertySetter : IrPropertyAccessor {
|
interface IrPropertySetter : IrPropertyAccessor {
|
||||||
override val descriptor: PropertySetterDescriptor
|
override val descriptor: PropertySetterDescriptor
|
||||||
|
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.PROPERTY_SETTER
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class IrPropertyAccessorBase(
|
abstract class IrPropertyAccessorBase(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
override val body: IrBody
|
override val body: IrBody
|
||||||
) : IrFunctionBase(sourceLocation, kind), IrPropertyAccessor {
|
) : IrFunctionBase(sourceLocation, originKind), IrPropertyAccessor {
|
||||||
override var property: IrProperty? = null
|
override var property: IrProperty? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrPropertyGetterImpl(
|
class IrPropertyGetterImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
override val descriptor: PropertyGetterDescriptor,
|
override val descriptor: PropertyGetterDescriptor,
|
||||||
body: IrBody
|
body: IrBody
|
||||||
) : IrPropertyAccessorBase(sourceLocation, kind, body), IrPropertyGetter {
|
) : IrPropertyAccessorBase(sourceLocation, originKind, body), IrPropertyGetter {
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitPropertyGetter(this, data)
|
visitor.visitPropertyGetter(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrPropertySetterImpl(
|
class IrPropertySetterImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
kind: IrDeclarationKind,
|
originKind: IrDeclarationOriginKind,
|
||||||
override val descriptor: PropertySetterDescriptor,
|
override val descriptor: PropertySetterDescriptor,
|
||||||
body: IrBody
|
body: IrBody
|
||||||
) : IrPropertyAccessorBase(sourceLocation, kind, body), IrPropertySetter {
|
) : IrPropertyAccessorBase(sourceLocation, originKind, body), IrPropertySetter {
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitPropertySetter(this, data)
|
visitor.visitPropertySetter(this, data)
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.ir.IrElement
|
|||||||
import org.jetbrains.kotlin.ir.IrElementBase
|
import org.jetbrains.kotlin.ir.IrElementBase
|
||||||
import org.jetbrains.kotlin.ir.SourceLocation
|
import org.jetbrains.kotlin.ir.SourceLocation
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOwner
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOwnerBase
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
|
||||||
@@ -27,14 +29,13 @@ interface IrBody : IrElement {
|
|||||||
override val parent: IrDeclaration
|
override val parent: IrDeclaration
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IrExpressionBody : IrBody, IrExpressionOwner1
|
interface IrExpressionBody : IrBody, IrExpressionOwner1, IrDeclarationOwner
|
||||||
|
|
||||||
abstract class IrBodyBase(sourceLocation: SourceLocation): IrElementBase(sourceLocation), IrBody {
|
|
||||||
override lateinit var parent: IrDeclaration
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO IrExpressionBodyImpl vs IrCompoundExpression1Impl: extract common base class?
|
// TODO IrExpressionBodyImpl vs IrCompoundExpression1Impl: extract common base class?
|
||||||
class IrExpressionBodyImpl(sourceLocation: SourceLocation) : IrBodyBase(sourceLocation), IrExpressionBody {
|
class IrExpressionBodyImpl(
|
||||||
|
sourceLocation: SourceLocation,
|
||||||
|
override val parent: IrDeclaration
|
||||||
|
) : IrDeclarationOwnerBase(sourceLocation), IrExpressionBody {
|
||||||
override var childExpression: IrExpression? = null
|
override var childExpression: IrExpression? = null
|
||||||
set(newExpression) {
|
set(newExpression) {
|
||||||
field?.detach()
|
field?.detach()
|
||||||
|
|||||||
@@ -21,11 +21,13 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
|
|
||||||
interface IrReturnExpression : IrExpression, IrExpressionOwner1
|
interface IrReturnExpression : IrCompoundExpression1
|
||||||
|
|
||||||
var IrReturnExpression.returnedExpression: IrExpression?
|
var IrReturnExpression.returnedExpression: IrExpression?
|
||||||
get() = childExpression
|
get() = childExpression
|
||||||
set(newReturnedExpression) { childExpression = newReturnedExpression }
|
set(newReturnedExpression) {
|
||||||
|
childExpression = newReturnedExpression
|
||||||
|
}
|
||||||
|
|
||||||
class IrReturnExpressionImpl(
|
class IrReturnExpressionImpl(
|
||||||
sourceLocation: SourceLocation,
|
sourceLocation: SourceLocation,
|
||||||
|
|||||||
Reference in New Issue
Block a user