[PSI2IR, K/Wasm] Sync start and end offsets on PSI and FIR for primary constructors
This commit is contained in:
+7
@@ -8,9 +8,15 @@ package org.jetbrains.kotlin.backend.wasm.ir2wasm
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
||||
import org.jetbrains.kotlin.ir.LineAndColumn
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
|
||||
import org.jetbrains.kotlin.wasm.ir.WasmExpressionBuilder
|
||||
import org.jetbrains.kotlin.wasm.ir.source.location.SourceLocation
|
||||
|
||||
private val IrElement.hasSyntheticOrUndefinedLocation: Boolean
|
||||
get() = startOffset in SYNTHETIC_OFFSET..UNDEFINED_OFFSET ||
|
||||
endOffset in SYNTHETIC_OFFSET..UNDEFINED_OFFSET
|
||||
|
||||
enum class LocationType {
|
||||
START {
|
||||
override fun getLineAndColumnNumberFor(irElement: IrElement, fileEntry: IrFileEntry) =
|
||||
@@ -26,6 +32,7 @@ enum class LocationType {
|
||||
|
||||
fun IrElement.getSourceLocation(fileEntry: IrFileEntry?, type: LocationType = LocationType.START): SourceLocation {
|
||||
if (fileEntry == null) return SourceLocation.NoLocation("fileEntry is null")
|
||||
if (hasSyntheticOrUndefinedLocation) return SourceLocation.NoLocation("Synthetic declaration")
|
||||
|
||||
val path = fileEntry.name
|
||||
val (line, column) = type.getLineAndColumnNumberFor(this, fileEntry)
|
||||
|
||||
@@ -208,7 +208,7 @@ internal class BodyGenerator(
|
||||
}
|
||||
|
||||
fun generatePrimaryConstructorBody(ktClassOrObject: KtPureClassOrObject, irConstructor: IrConstructor): IrBody {
|
||||
val irBlockBody = context.irFactory.createBlockBody(ktClassOrObject.pureStartOffset, ktClassOrObject.pureEndOffset)
|
||||
val irBlockBody = context.irFactory.createBlockBody(irConstructor.startOffset, irConstructor.endOffset)
|
||||
|
||||
generateSuperConstructorCall(irBlockBody, ktClassOrObject)
|
||||
|
||||
|
||||
+1
-4
@@ -244,7 +244,6 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
ktClassOrObject: KtPureClassOrObject
|
||||
): IrConstructor =
|
||||
declareConstructor(
|
||||
ktClassOrObject,
|
||||
ktClassOrObject.primaryConstructor ?: ktClassOrObject,
|
||||
ktClassOrObject.contextReceivers.mapNotNull { it.typeReference() },
|
||||
primaryConstructorDescriptor
|
||||
@@ -262,7 +261,6 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor, ktClassOrObject: KtPureClassOrObject): IrConstructor {
|
||||
val constructorDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor) as ClassConstructorDescriptor
|
||||
return declareConstructor(
|
||||
ktConstructor,
|
||||
ktConstructor,
|
||||
ktClassOrObject.contextReceivers.mapNotNull { it.typeReference() },
|
||||
constructorDescriptor
|
||||
@@ -282,7 +280,6 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
|
||||
private inline fun declareConstructor(
|
||||
ktConstructorElement: KtPureElement,
|
||||
ktParametersElement: KtPureElement,
|
||||
ktContextReceiversElements: List<KtPureElement>,
|
||||
constructorDescriptor: ClassConstructorDescriptor,
|
||||
generateBody: BodyGenerator.(IrConstructor) -> IrBody?
|
||||
@@ -310,7 +307,7 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
contextReceiverParametersCount = ktContextReceiversElements.size
|
||||
}
|
||||
}.buildWithScope { irConstructor ->
|
||||
generateValueParameterDeclarations(irConstructor, ktParametersElement, null, ktContextReceiversElements)
|
||||
generateValueParameterDeclarations(irConstructor, ktConstructorElement, null, ktContextReceiversElements)
|
||||
if (context.configuration.generateBodies) {
|
||||
irConstructor.body = createBodyGenerator(irConstructor.symbol).generateBody(irConstructor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user