Use source offset ranges instead of source locations.

This commit is contained in:
Dmitry Petrov
2016-08-08 18:56:12 +03:00
committed by Dmitry Petrov
parent 5e609c7de4
commit 7b3ae8ffec
23 changed files with 172 additions and 169 deletions
@@ -25,6 +25,8 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBodyImpl
import org.jetbrains.kotlin.ir.expressions.IrReturnExpressionImpl
import org.jetbrains.kotlin.ir.expressions.returnedExpression
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.BindingContext
interface IrDeclarationGenerator : IrGenerator {
@@ -92,16 +94,18 @@ abstract class IrDeclarationGeneratorBase(
}
fun generateExpressionBody(ktBody: KtExpression): IrBody {
val sourceLocation = fileElementFactory.getLocationInFile(ktBody)
val irExpression = irExpressionGenerator.generateExpression(ktBody)
val startOffset = ktBody.startOffset
val endOffset = ktBody.endOffset
val bodyExpression =
if (ktBody is KtBlockExpression)
irExpression
else
IrReturnExpressionImpl(sourceLocation, irExpression.type)
IrReturnExpressionImpl(startOffset, endOffset, irExpression.type)
.apply { returnedExpression = irExpression }
return IrExpressionBodyImpl(sourceLocation, containingDeclaration).apply { childExpression = bodyExpression }
return IrExpressionBodyImpl(startOffset, endOffset, containingDeclaration).apply { childExpression = bodyExpression }
}
}
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.psi2ir
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.constants.IntValue
import org.jetbrains.kotlin.resolve.constants.StringValue
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
@@ -26,24 +28,23 @@ class IrExpressionGenerator(
override val context: IrGeneratorContext,
val fileElementFactory: IrFileElementFactory
) : KtVisitor<IrExpressionBase, Nothing?>(), IrGenerator {
fun generateExpression(ktExpression: KtExpression) = ktExpression.irExpr()
fun generateExpression(ktExpression: KtExpression) = ktExpression.generate()
private fun KtElement.irExpr(): IrExpressionBase = accept(this@IrExpressionGenerator, null)
private fun KtElement.loc() = this@IrExpressionGenerator.fileElementFactory.getLocationInFile(this)
private fun KtElement.generate(): IrExpressionBase = accept(this@IrExpressionGenerator, null)
private fun KtExpression.type() = getType(this) ?: TODO("no type for expression")
override fun visitExpression(expression: KtExpression, data: Nothing?): IrExpressionBase =
IrDummyExpression(expression.loc(), expression.type())
IrDummyExpression(expression.startOffset, expression.endOffset, expression.type())
override fun visitBlockExpression(expression: KtBlockExpression, data: Nothing?): IrExpressionBase {
val irBlock = IrBlockExpressionImpl(expression.loc(), expression.type())
expression.statements.forEach { irBlock.childExpressions.add(it.irExpr()) }
val irBlock = IrBlockExpressionImpl(expression.startOffset, expression.endOffset, expression.type())
expression.statements.forEach { irBlock.childExpressions.add(it.generate()) }
return irBlock
}
override fun visitReturnExpression(expression: KtReturnExpression, data: Nothing?): IrExpressionBase =
IrReturnExpressionImpl(expression.loc(), expression.type())
.apply { this.childExpression = expression.returnedExpression?.irExpr() }
IrReturnExpressionImpl(expression.startOffset, expression.endOffset, expression.type())
.apply { this.childExpression = expression.returnedExpression?.generate() }
override fun visitConstantExpression(expression: KtConstantExpression, data: Nothing?): IrExpressionBase {
val compileTimeConstant = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext)
@@ -53,9 +54,9 @@ class IrExpressionGenerator(
return when (constantValue) {
is StringValue ->
IrLiteralExpressionImpl.string(expression.loc(), constantType, constantValue.value)
IrLiteralExpressionImpl.string(expression.startOffset, expression.endOffset, constantType, constantValue.value)
is IntValue ->
IrLiteralExpressionImpl.int(expression.loc(), constantType, constantValue.value)
IrLiteralExpressionImpl.int(expression.startOffset, expression.endOffset, constantType, constantValue.value)
else ->
TODO("handle other literal types: ${constantValue.type}")
}
@@ -63,14 +64,14 @@ class IrExpressionGenerator(
override fun visitStringTemplateExpression(expression: KtStringTemplateExpression, data: Nothing?): IrExpressionBase {
if (expression.entries.size == 1 && expression.entries[0] is KtLiteralStringTemplateEntry) {
return expression.entries[0].irExpr()
return expression.entries[0].generate()
}
val irStringTemplate = IrStringConcatenationExpressionImpl(expression.loc(), expression.type())
expression.entries.forEach { irStringTemplate.addChildExpression(it.irExpr()) }
val irStringTemplate = IrStringConcatenationExpressionImpl(expression.startOffset, expression.endOffset, expression.type())
expression.entries.forEach { irStringTemplate.addChildExpression(it.generate()) }
return irStringTemplate
}
override fun visitLiteralStringTemplateEntry(entry: KtLiteralStringTemplateEntry, data: Nothing?): IrExpressionBase =
IrLiteralExpressionImpl.string(entry.loc(), context.builtIns.stringType, entry.text)
IrLiteralExpressionImpl.string(entry.startOffset, entry.endOffset, context.builtIns.stringType, entry.text)
}
@@ -20,6 +20,8 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
class IrFileElementFactory private constructor(
val fileEntry: PsiSourceManager.PsiFileEntry,
@@ -29,23 +31,17 @@ class IrFileElementFactory private constructor(
fun createChild(containingDeclaration: IrCompoundDeclaration) =
IrFileElementFactory(fileEntry, irFileImpl, containingDeclaration)
fun getRootLocationInFile() =
fileEntry.getRootSourceLocation()
fun getLocationInFile(ktElement: KtElement) =
fileEntry.getSourceLocationForElement(ktElement)
private fun <D : IrMemberDeclaration> D.addToContainer(): D =
apply {
this@IrFileElementFactory.containingDeclaration.addChildDeclaration(this)
}
apply { containingDeclaration.addChildDeclaration(this) }
fun createFunction(ktFunction: KtFunction, functionDescriptor: FunctionDescriptor, body: IrBody): IrFunction =
IrFunctionImpl(getLocationInFile(ktFunction), IrDeclarationOriginKind.DEFINED, functionDescriptor, body)
IrFunctionImpl(ktFunction.startOffset, ktFunction.endOffset,
IrDeclarationOriginKind.DEFINED, functionDescriptor, body)
.addToContainer()
fun createSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor, valueInitializer: IrBody?): IrSimpleProperty =
IrSimplePropertyImpl(getLocationInFile(ktProperty), IrDeclarationOriginKind.DEFINED, propertyDescriptor, valueInitializer)
IrSimplePropertyImpl(ktProperty.startOffset, ktProperty.endOffset,
IrDeclarationOriginKind.DEFINED, propertyDescriptor, valueInitializer)
.addToContainer()
fun createPropertyGetter(
@@ -54,7 +50,8 @@ class IrFileElementFactory private constructor(
getterDescriptor: PropertyGetterDescriptor,
getterBody: IrBody
): IrPropertyGetter =
IrPropertyGetterImpl(getLocationInFile(ktPropertyAccessor), IrDeclarationOriginKind.DEFINED, getterDescriptor, getterBody)
IrPropertyGetterImpl(ktPropertyAccessor.startOffset, ktPropertyAccessor.endOffset,
IrDeclarationOriginKind.DEFINED, getterDescriptor, getterBody)
.apply { irProperty.getter = this }
.addToContainer()
@@ -64,16 +61,17 @@ class IrFileElementFactory private constructor(
setterDescriptor: PropertySetterDescriptor,
setterBody: IrBody
) : IrPropertySetter =
IrPropertySetterImpl(getLocationInFile(ktPropertyAccessor), IrDeclarationOriginKind.DEFINED, setterDescriptor, setterBody)
IrPropertySetterImpl(ktPropertyAccessor.startOffset, ktPropertyAccessor.endOffset,
IrDeclarationOriginKind.DEFINED, setterDescriptor, setterBody)
.apply { irProperty.setter = this }
.addToContainer()
companion object {
fun create(irModule: IrModuleImpl, sourceManager: PsiSourceManager, ktFile: KtFile, descriptor: PackageFragmentDescriptor): IrFileElementFactory {
val fileEntry = sourceManager.getOrCreateFileEntry(ktFile)
val fileSourceLocation = fileEntry.getRootSourceLocation()
val fileName = fileEntry.getRecognizableName()
val irFile = IrFileImpl(fileSourceLocation, fileName, descriptor)
val irFile = IrFileImpl(fileEntry, fileName, descriptor)
sourceManager.putFileEntry(irFile, fileEntry)
irModule.addFile(irFile)
return IrFileElementFactory(fileEntry, irFile, irFile)
}
@@ -16,52 +16,63 @@
package org.jetbrains.kotlin.psi2ir
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.SourceLocationManager
import org.jetbrains.kotlin.ir.fileIndex
import org.jetbrains.kotlin.ir.fileOffset
import org.jetbrains.kotlin.ir.SourceRangeInfo
import org.jetbrains.kotlin.ir.declarations.IrFile
import java.util.*
class PsiSourceManager : SourceLocationManager {
class PsiFileEntry (val index: Int, val file: PsiFile) : SourceLocationManager.FileEntry {
private val document = file.viewProvider.document
class PsiFileEntry(val psiFile: PsiFile) : SourceLocationManager.FileEntry {
private val document = psiFile.viewProvider.document
override fun getLineNumber(sourceLocation: SourceLocation): Int =
document?.getLineNumber(sourceLocation.fileOffset) ?: -1
override val maxOffset: Int
get() = document?.textLength ?: Int.MAX_VALUE
override fun getColumnNumber(sourceLocation: SourceLocation): Int =
document?.getLineStartOffset(sourceLocation.fileOffset) ?: -1
override fun getLineNumber(offset: Int): Int =
document?.getLineNumber(offset) ?: -1
fun getRootSourceLocation(): SourceLocation =
SourceLocation(index, 0)
override fun getColumnNumber(offset: Int): Int {
val startOffset = document?.getLineStartOffset(offset) ?: return -1
return offset - startOffset
}
fun getSourceLocationForElement(element: PsiElement): SourceLocation =
SourceLocation(index, element.textOffset)
override fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo =
SourceRangeInfo(
filePath = getRecognizableName(),
startOffset = beginOffset,
startLineNumber = getLineNumber(beginOffset),
startColumnNumber = getColumnNumber(beginOffset),
endOffset = endOffset,
endLineNumber = getLineNumber(endOffset),
endColumnNumber = getColumnNumber(endOffset)
)
fun getRecognizableName(): String = file.virtualFile?.path ?: file.name
fun getRecognizableName(): String = psiFile.virtualFile?.path ?: psiFile.name
override fun toString(): String = "#$index: ${getRecognizableName()}"
override fun toString(): String = "${getRecognizableName()}"
}
private val fileEntries = ArrayList<PsiFileEntry>()
private val fileEntriesByPsiFile = HashMap<PsiFile, PsiFileEntry>()
override fun getFileEntry(sourceLocation: Long): PsiFileEntry? =
fileEntries.getOrNull(sourceLocation.fileIndex)
private val fileEntriesByIrFile = HashMap<IrFile, PsiFileEntry>()
fun createFileEntry(psiFile: PsiFile): PsiFileEntry {
if (psiFile in fileEntriesByPsiFile) error("PsiFileEntry is already created for $psiFile")
val newEntry = PsiFileEntry(fileEntries.size, psiFile)
fileEntries.add(newEntry)
val newEntry = PsiFileEntry(psiFile)
fileEntriesByPsiFile[psiFile] = newEntry
return newEntry
}
fun putFileEntry(irFile: IrFile, fileEntry: PsiFileEntry) {
fileEntriesByIrFile[irFile] = fileEntry
}
fun getOrCreateFileEntry(psiFile: PsiFile): PsiFileEntry =
fileEntriesByPsiFile.getOrElse(psiFile) { createFileEntry(psiFile) }
fun getFileEntry(psiFile: PsiFile): PsiFileEntry? = fileEntriesByPsiFile[psiFile]
fun getFileEntry(psiFile: PsiFile): PsiFileEntry? =
fileEntriesByPsiFile[psiFile]
override fun getFileEntry(irFile: IrFile): SourceLocationManager.FileEntry =
fileEntriesByIrFile[irFile]!!
}
@@ -19,11 +19,12 @@ package org.jetbrains.kotlin.ir
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrElement {
val sourceLocation: SourceLocation
val startOffset: Int
val endOffset: Int
val parent: IrElement?
fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R
fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D): Unit
}
abstract class IrElementBase(override val sourceLocation: SourceLocation) : IrElement
abstract class IrElementBase(override val startOffset: Int, override val endOffset: Int) : IrElement
@@ -1,32 +0,0 @@
/*
* 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
typealias SourceLocation = Long
fun SourceLocation(index: Int, offset: Int) =
(index.toLong() shl 32) + offset.toLong()
const val NO_LOCATION: SourceLocation = Long.MIN_VALUE
const val UNDEFINED_INDEX: Int = -1
const val UNDEFINED_OFFSET: Int = -1
val SourceLocation.fileIndex: Int
get() = if (this == NO_LOCATION) UNDEFINED_INDEX else (this ushr 32).toInt()
val SourceLocation.fileOffset: Int
get() = if (this == NO_LOCATION) UNDEFINED_OFFSET else (this and 0xFFFFFFFFL).toInt()
@@ -16,11 +16,27 @@
package org.jetbrains.kotlin.ir
import org.jetbrains.kotlin.ir.declarations.IrFile
const val UNDEFINED_OFFSET: Int = -1
data class SourceRangeInfo(
val filePath: String,
val startOffset: Int,
val startLineNumber: Int,
val startColumnNumber: Int,
val endOffset: Int,
val endLineNumber: Int,
val endColumnNumber: Int
)
interface SourceLocationManager {
interface FileEntry {
fun getLineNumber(sourceLocation: SourceLocation): Int
fun getColumnNumber(sourceLocation: SourceLocation): Int
val maxOffset: Int
fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo
fun getLineNumber(offset: Int): Int
fun getColumnNumber(offset: Int): Int
}
fun getFileEntry(sourceLocation: SourceLocation): FileEntry?
fun getFileEntry(irFile: IrFile): FileEntry?
}
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrClass : IrCompoundDeclaration, IrMemberDeclaration {
@@ -28,10 +27,11 @@ interface IrClass : IrCompoundDeclaration, IrMemberDeclaration {
}
class IrClassImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
override val descriptor: ClassDescriptor
) : IrCompoundMemberDeclarationBase(sourceLocation, originKind), IrClass {
) : IrCompoundMemberDeclarationBase(startOffset, endOffset, originKind), IrClass {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitClass(this, data)
}
@@ -18,7 +18,6 @@ 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.visitors.IrElementVisitor
import java.util.*
@@ -44,8 +43,9 @@ interface IrMemberDeclaration : IrDeclaration {
}
abstract class IrDeclarationOwnerBase(
sourceLocation: SourceLocation
) : IrElementBase(sourceLocation), IrDeclarationOwner {
startOffset: Int,
endOffset: Int
) : IrElementBase(startOffset, endOffset), IrDeclarationOwner {
protected val childDeclarations: MutableList<IrMemberDeclaration> = ArrayList()
override val childrenCount: Int
@@ -87,9 +87,10 @@ abstract class IrDeclarationOwnerBase(
// TODO synchronization?
abstract class IrCompoundDeclarationBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
override val originKind: IrDeclarationOriginKind
) : IrDeclarationOwnerBase(sourceLocation), IrCompoundDeclaration {
) : IrDeclarationOwnerBase(startOffset, endOffset), IrCompoundDeclaration {
override var indexInParent: Int = IrDeclaration.DETACHED_INDEX
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
@@ -98,9 +99,10 @@ abstract class IrCompoundDeclarationBase(
}
abstract class IrCompoundMemberDeclarationBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind
) : IrCompoundDeclarationBase(sourceLocation, originKind), IrMemberDeclaration {
) : IrCompoundDeclarationBase(startOffset, endOffset, originKind), IrMemberDeclaration {
private var parentImpl: IrDeclarationOwner? = null
override var parent: IrDeclarationOwner
@@ -116,9 +118,10 @@ abstract class IrCompoundMemberDeclarationBase(
}
abstract class IrMemberDeclarationBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind
) : IrDeclarationBase(sourceLocation, originKind), IrMemberDeclaration {
) : IrDeclarationBase(startOffset, endOffset, originKind), IrMemberDeclaration {
private var parentImpl: IrDeclarationOwner? = null
override var parent: IrDeclarationOwner
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.SourceLocation
interface IrDeclaration : IrElement {
override val parent: IrDeclarationOwner?
@@ -51,8 +50,9 @@ enum class IrDeclarationOriginKind {
}
abstract class IrDeclarationBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
override val originKind: IrDeclarationOriginKind
) : IrElementBase(sourceLocation), IrDeclaration {
) : IrElementBase(startOffset, endOffset), IrDeclaration {
override var indexInParent: Int = IrDeclaration.DETACHED_INDEX
}
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.SourceLocationManager
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrFile : IrCompoundDeclaration {
@@ -32,10 +32,10 @@ interface IrFile : IrCompoundDeclaration {
}
class IrFileImpl(
sourceLocation: SourceLocation,
val fileEntry: SourceLocationManager.FileEntry,
override val name: String,
override val descriptor: PackageFragmentDescriptor
) : IrCompoundDeclarationBase(sourceLocation, IrDeclarationOriginKind.DEFINED), IrFile {
) : IrCompoundDeclarationBase(0, fileEntry.maxOffset, IrDeclarationOriginKind.DEFINED), IrFile {
override lateinit var module: IrModule
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -30,20 +29,22 @@ interface IrFunction : IrMemberDeclaration {
}
abstract class IrFunctionBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind
) : IrMemberDeclarationBase(sourceLocation, originKind), IrFunction {
) : IrMemberDeclarationBase(startOffset, endOffset, originKind), IrFunction {
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
body.accept(visitor, data)
}
}
class IrFunctionImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
override val descriptor: FunctionDescriptor,
override val body: IrBody
) : IrFunctionBase(sourceLocation, originKind) {
) : IrFunctionBase(startOffset, endOffset, originKind) {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitFunction(this, data)
}
@@ -17,14 +17,16 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.NO_LOCATION
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.util.*
interface IrModule : IrDeclaration {
override val descriptor: ModuleDescriptor
override val startOffset: Int get() = UNDEFINED_OFFSET
override val endOffset: Int get() = UNDEFINED_OFFSET
override val parent: Nothing? get() = null
override val indexInParent: Int get() = MODULE_INDEX
@@ -41,8 +43,6 @@ interface IrModule : IrDeclaration {
class IrModuleImpl(
override val descriptor: ModuleDescriptor
) : IrModule {
override val sourceLocation: Long
get() = NO_LOCATION
override val originKind: IrDeclarationOriginKind
get() = IrDeclarationOriginKind.DEFINED
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -42,10 +41,11 @@ interface IrDelegatedProperty : IrProperty {
// TODO synchronization?
abstract class IrPropertyBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
override val descriptor: PropertyDescriptor
) : IrMemberDeclarationBase(sourceLocation, originKind), IrProperty {
) : IrMemberDeclarationBase(startOffset, endOffset, originKind), IrProperty {
override var getter: IrPropertyGetter? = null
set(newGetter) {
newGetter?.property = this
@@ -65,11 +65,12 @@ abstract class IrPropertyBase(
}
class IrSimplePropertyImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
descriptor: PropertyDescriptor,
override val valueInitializer: IrBody?
) : IrPropertyBase(sourceLocation, originKind, descriptor), IrSimpleProperty {
) : IrPropertyBase(startOffset, endOffset, originKind, descriptor), IrSimpleProperty {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitSimpleProperty(this, data)
@@ -79,11 +80,12 @@ class IrSimplePropertyImpl(
}
class IrDelegatedPropertyImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
descriptor: PropertyDescriptor,
override val delegateInitializer: IrBody
) : IrPropertyBase(sourceLocation, originKind, descriptor), IrDelegatedProperty {
) : IrPropertyBase(startOffset, endOffset, originKind, descriptor), IrDelegatedProperty {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitDelegatedProperty(this, data)
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -43,29 +42,32 @@ interface IrPropertySetter : IrPropertyAccessor {
}
abstract class IrPropertyAccessorBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
override val body: IrBody
) : IrFunctionBase(sourceLocation, originKind), IrPropertyAccessor {
) : IrFunctionBase(startOffset, endOffset, originKind), IrPropertyAccessor {
override var property: IrProperty? = null
}
class IrPropertyGetterImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
override val descriptor: PropertyGetterDescriptor,
body: IrBody
) : IrPropertyAccessorBase(sourceLocation, originKind, body), IrPropertyGetter {
) : IrPropertyAccessorBase(startOffset, endOffset, originKind, body), IrPropertyGetter {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertyGetter(this, data)
}
class IrPropertySetterImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
originKind: IrDeclarationOriginKind,
override val descriptor: PropertySetterDescriptor,
body: IrBody
) : IrPropertyAccessorBase(sourceLocation, originKind, body), IrPropertySetter {
) : IrPropertyAccessorBase(startOffset, endOffset, originKind, body), IrPropertySetter {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertySetter(this, data)
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
@@ -24,9 +23,10 @@ import org.jetbrains.kotlin.types.KotlinType
interface IrBlockExpression : IrCompoundExpressionN
class IrBlockExpressionImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
type: KotlinType
) : IrCompoundExpressionNBase(sourceLocation, type), IrBlockExpression {
) : IrCompoundExpressionNBase(startOffset, endOffset, type), IrBlockExpression {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitBlockExpression(this, data)
@@ -17,12 +17,9 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.SourceLocation
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.visitors.IrElementVisitor
interface IrBody : IrElement {
@@ -33,9 +30,10 @@ interface IrExpressionBody : IrBody, IrExpressionOwner1, IrDeclarationOwner
// TODO IrExpressionBodyImpl vs IrCompoundExpression1Impl: extract common base class?
class IrExpressionBodyImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
override val parent: IrDeclaration
) : IrDeclarationOwnerBase(sourceLocation), IrExpressionBody {
) : IrDeclarationOwnerBase(startOffset, endOffset), IrExpressionBody {
override var childExpression: IrExpression? = null
set(newExpression) {
field?.detach()
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
@@ -28,9 +27,10 @@ interface IrCompoundExpression1 : IrCompoundExpression, IrExpressionOwner1
interface IrCompoundExpressionN : IrCompoundExpression, IrExpressionOwnerN
abstract class IrCompoundExpressionNBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
override val type: KotlinType
) : IrExpressionBase(sourceLocation, type), IrCompoundExpressionN {
) : IrExpressionBase(startOffset, endOffset, type), IrCompoundExpressionN {
override val childExpressions: MutableList<IrExpression> = ArrayList()
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
@@ -68,9 +68,10 @@ abstract class IrCompoundExpressionNBase(
// TODO IrExpressionBodyImpl vs IrCompoundExpression1Impl: extract common base class?
abstract class IrCompoundExpression1Base(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
override val type: KotlinType
) : IrExpressionBase(sourceLocation, type), IrCompoundExpression1 {
) : IrExpressionBase(startOffset, endOffset, type), IrCompoundExpression1 {
override var childExpression: IrExpression? = null
set(newExpression) {
field?.detach()
@@ -16,14 +16,14 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
class IrDummyExpression(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
type: KotlinType
) : IrExpressionBase(sourceLocation, type) {
) : IrExpressionBase(startOffset, endOffset, type) {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitElement(this, data)
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.types.KotlinType
@@ -43,9 +42,10 @@ fun IrExpressionOwner.validateChild(child: IrExpression) {
}
abstract class IrExpressionBase(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
override val type: KotlinType
) : IrElementBase(sourceLocation), IrExpression {
) : IrElementBase(startOffset, endOffset), IrExpression {
override var parent: IrExpressionOwner? = null
override var index: Int = IrExpression.DETACHED_INDEX
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
@@ -45,11 +43,12 @@ sealed class IrLiteralKind<out T>(val asString: kotlin.String) {
}
class IrLiteralExpressionImpl<out T> (
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
type: KotlinType,
override val kind: IrLiteralKind<T>,
override val value: T
) : IrExpressionBase(sourceLocation, type), IrLiteralExpression<T> {
) : IrExpressionBase(startOffset, endOffset, type), IrLiteralExpression<T> {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitLiteral(this, data)
@@ -58,11 +57,11 @@ class IrLiteralExpressionImpl<out T> (
}
companion object {
fun string(sourceLocation: SourceLocation, type: KotlinType, value: String): IrLiteralExpressionImpl<String> =
IrLiteralExpressionImpl(sourceLocation, type, IrLiteralKind.String, value)
fun string(startOffset: Int, endOffset: Int, type: KotlinType, value: String): IrLiteralExpressionImpl<String> =
IrLiteralExpressionImpl(startOffset, endOffset, type, IrLiteralKind.String, value)
fun int(sourceLocation: SourceLocation, type: KotlinType, value: Int): IrLiteralExpressionImpl<Int> =
IrLiteralExpressionImpl(sourceLocation, type, IrLiteralKind.Int, value)
fun int(startOffset: Int, endOffset: Int, type: KotlinType, value: Int): IrLiteralExpressionImpl<Int> =
IrLiteralExpressionImpl(startOffset, endOffset, type, IrLiteralKind.Int, value)
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
@@ -30,9 +29,10 @@ var IrReturnExpression.returnedExpression: IrExpression?
}
class IrReturnExpressionImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
type: KotlinType
) : IrCompoundExpression1Base(sourceLocation, type), IrReturnExpression {
) : IrCompoundExpression1Base(startOffset, endOffset, type), IrReturnExpression {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitReturnExpression(this, data)
}
@@ -16,18 +16,16 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.SourceLocation
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
interface IrStringConcatenationExpression : IrCompoundExpressionN
class IrStringConcatenationExpressionImpl(
sourceLocation: SourceLocation,
startOffset: Int,
endOffset: Int,
type: KotlinType
) : IrCompoundExpressionNBase(sourceLocation, type), IrStringConcatenationExpression {
) : IrCompoundExpressionNBase(startOffset, endOffset, type), IrStringConcatenationExpression {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitStringTemplate(this, data)
}