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