IR: declaration builders, initial iteration, use in some JVM lowerings
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.builders
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
|
||||
abstract class IrElementBuilder {
|
||||
|
||||
var startOffset: Int = UNDEFINED_OFFSET
|
||||
var endOffset: Int = UNDEFINED_OFFSET
|
||||
|
||||
fun updateFrom(from: IrElement) {
|
||||
startOffset = from.startOffset
|
||||
endOffset = from.endOffset
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun IrElementBuilder.setSourceRange(from: IrElement) {
|
||||
startOffset = from.startOffset
|
||||
endOffset = from.endOffset
|
||||
}
|
||||
+33
@@ -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.builders.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
|
||||
class IrClassBuilder : IrDeclarationBuilder() {
|
||||
var kind: ClassKind = ClassKind.CLASS
|
||||
var modality: Modality = Modality.FINAL
|
||||
|
||||
var isCompanion: Boolean = false
|
||||
var isInner: Boolean = false
|
||||
var isData: Boolean = false
|
||||
var isExternal: Boolean = false
|
||||
var isInline: Boolean = false
|
||||
|
||||
fun updateFrom(from: IrClass) {
|
||||
super.updateFrom(from)
|
||||
|
||||
kind = from.kind
|
||||
modality = from.modality
|
||||
isCompanion = from.isCompanion
|
||||
isInner = from.isInner
|
||||
isData = from.isData
|
||||
isExternal = from.isExternal
|
||||
isInline = from.isInline
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.builders.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.ir.builders.IrElementBuilder
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class IrDeclarationBuilder : IrElementBuilder() {
|
||||
|
||||
var origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED
|
||||
var visibility: Visibility = Visibilities.PUBLIC
|
||||
|
||||
lateinit var name: Name
|
||||
|
||||
fun updateFrom(from: IrDeclaration) {
|
||||
super.updateFrom(from)
|
||||
|
||||
origin = from.origin
|
||||
visibility = if (from is IrDeclarationWithVisibility) from.visibility else Visibilities.PUBLIC
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -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.builders.declarations
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
|
||||
class IrFieldBuilder : IrDeclarationBuilder() {
|
||||
|
||||
lateinit var type: IrType
|
||||
|
||||
var isFinal: Boolean = false
|
||||
var isExternal: Boolean = false
|
||||
var isStatic: Boolean = false
|
||||
|
||||
fun updateFrom(from: IrField) {
|
||||
super.updateFrom(from)
|
||||
|
||||
type = from.type
|
||||
isFinal = from.isFinal
|
||||
isExternal = from.isExternal
|
||||
isStatic = from.isStatic
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.builders.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
|
||||
class IrFunctionBuilder : IrDeclarationBuilder() {
|
||||
|
||||
var isInline: Boolean = false
|
||||
var isExternal: Boolean = false
|
||||
|
||||
var returnType: IrType = IrUninitializedType
|
||||
|
||||
var modality: Modality = Modality.FINAL
|
||||
var isTailrec: Boolean = false
|
||||
var isSuspend: Boolean = false
|
||||
|
||||
var isPrimary: Boolean = false
|
||||
|
||||
fun updateFrom(from: IrFunction) {
|
||||
super.updateFrom(from)
|
||||
|
||||
isInline = from.isInline
|
||||
isExternal = from.isExternal
|
||||
|
||||
if (from is IrSimpleFunction) {
|
||||
modality = from.modality
|
||||
isTailrec = from.isTailrec
|
||||
isSuspend = from.isSuspend
|
||||
} else {
|
||||
modality = Modality.FINAL
|
||||
isTailrec = false
|
||||
isSuspend = false
|
||||
}
|
||||
|
||||
if (from is IrConstructor) {
|
||||
isPrimary = from.isPrimary
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.builders.declarations
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
|
||||
const val UNDEFINED_PARAMETER_INDEX = -1
|
||||
|
||||
class IrValueParameterBuilder : IrDeclarationBuilder() {
|
||||
lateinit var type: IrType
|
||||
|
||||
var index: Int = UNDEFINED_PARAMETER_INDEX
|
||||
var varargElementType: IrType? = null
|
||||
var isCrossInline = false
|
||||
var isNoinline = false
|
||||
|
||||
fun updateFrom(from: IrValueParameter) {
|
||||
super.updateFrom(from)
|
||||
|
||||
type = from.type
|
||||
index = from.index
|
||||
varargElementType = from.varargElementType
|
||||
isCrossInline = from.isCrossinline
|
||||
isNoinline = from.isNoinline
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user