[FIR] add debug info instead of CCE to some FirBasedSymbol
This commit is contained in:
committed by
Space Team
parent
c6d8876f9f
commit
d68cb73930
@@ -19,22 +19,34 @@ abstract class FirCallableSymbol<D : FirCallableDeclaration> : FirBasedSymbol<D>
|
|||||||
val resolvedReturnTypeRef: FirResolvedTypeRef
|
val resolvedReturnTypeRef: FirResolvedTypeRef
|
||||||
get() {
|
get() {
|
||||||
ensureType(fir.returnTypeRef)
|
ensureType(fir.returnTypeRef)
|
||||||
return fir.returnTypeRef as FirResolvedTypeRef
|
val returnTypeRef = fir.returnTypeRef
|
||||||
|
if (returnTypeRef !is FirResolvedTypeRef) {
|
||||||
|
errorInLazyResolve("returnTypeRef", returnTypeRef::class, FirResolvedTypeRef::class)
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnTypeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolvedReturnType: ConeKotlinType
|
val resolvedReturnType: ConeKotlinType
|
||||||
get() = resolvedReturnTypeRef.coneType
|
get() = resolvedReturnTypeRef.coneType
|
||||||
|
|
||||||
|
|
||||||
val resolvedReceiverTypeRef: FirResolvedTypeRef?
|
val resolvedReceiverTypeRef: FirResolvedTypeRef?
|
||||||
get() {
|
get() = calculateReceiverTypeRef()
|
||||||
ensureType(fir.receiverParameter?.typeRef)
|
|
||||||
return fir.receiverParameter?.typeRef as FirResolvedTypeRef?
|
private fun calculateReceiverTypeRef(): FirResolvedTypeRef? {
|
||||||
|
val receiverParameter = fir.receiverParameter ?: return null
|
||||||
|
ensureType(receiverParameter.typeRef)
|
||||||
|
val receiverTypeRef = receiverParameter.typeRef
|
||||||
|
if (receiverTypeRef !is FirResolvedTypeRef) {
|
||||||
|
errorInLazyResolve("receiverTypeRef", receiverTypeRef::class, FirResolvedTypeRef::class)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return receiverTypeRef
|
||||||
|
}
|
||||||
|
|
||||||
val receiverParameter: FirReceiverParameter?
|
val receiverParameter: FirReceiverParameter?
|
||||||
get() {
|
get() {
|
||||||
ensureType(fir.receiverParameter?.typeRef)
|
calculateReceiverTypeRef()
|
||||||
return fir.receiverParameter
|
return fir.receiverParameter
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,19 +58,13 @@ abstract class FirCallableSymbol<D : FirCallableDeclaration> : FirBasedSymbol<D>
|
|||||||
}
|
}
|
||||||
|
|
||||||
val resolvedStatus: FirResolvedDeclarationStatus
|
val resolvedStatus: FirResolvedDeclarationStatus
|
||||||
get() {
|
get() = fir.resolvedStatus()
|
||||||
lazyResolveToPhase(FirResolvePhase.STATUS)
|
|
||||||
return fir.status as FirResolvedDeclarationStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
val rawStatus: FirDeclarationStatus
|
val rawStatus: FirDeclarationStatus
|
||||||
get() = fir.status
|
get() = fir.status
|
||||||
|
|
||||||
|
|
||||||
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
||||||
get() {
|
get() = fir.typeParameters.map { it.symbol }
|
||||||
return fir.typeParameters.map { it.symbol }
|
|
||||||
}
|
|
||||||
|
|
||||||
val dispatchReceiverType: ConeSimpleKotlinType?
|
val dispatchReceiverType: ConeSimpleKotlinType?
|
||||||
get() = fir.dispatchReceiverType
|
get() = fir.dispatchReceiverType
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -20,13 +20,13 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
|
|
||||||
sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration>(
|
sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration>(
|
||||||
val classId: ClassId
|
val classId: ClassId,
|
||||||
) : FirClassifierSymbol<D>() {
|
) : FirClassifierSymbol<D>() {
|
||||||
abstract override fun toLookupTag(): ConeClassLikeLookupTag
|
abstract override fun toLookupTag(): ConeClassLikeLookupTag
|
||||||
|
|
||||||
val name get() = classId.shortClassName
|
val name get() = classId.shortClassName
|
||||||
|
|
||||||
fun getDeprecation(apiVersion: ApiVersion): DeprecationsPerUseSite? {
|
fun getDeprecation(apiVersion: ApiVersion): DeprecationsPerUseSite? {
|
||||||
if (annotations.isEmpty()) return null
|
if (annotations.isEmpty()) return null
|
||||||
lazyResolveToPhase(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS)
|
lazyResolveToPhase(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS)
|
||||||
return fir.deprecationsProvider.getDeprecationsInfo(apiVersion)
|
return fir.deprecationsProvider.getDeprecationsInfo(apiVersion)
|
||||||
@@ -36,15 +36,10 @@ sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration>(
|
|||||||
get() = fir.status
|
get() = fir.status
|
||||||
|
|
||||||
val resolvedStatus: FirResolvedDeclarationStatus
|
val resolvedStatus: FirResolvedDeclarationStatus
|
||||||
get() {
|
get() = fir.resolvedStatus()
|
||||||
lazyResolveToPhase(FirResolvePhase.STATUS)
|
|
||||||
return fir.status as FirResolvedDeclarationStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
val typeParameterSymbols: List<FirTypeParameterSymbol>
|
||||||
get() {
|
get() = fir.typeParameters.map { it.symbol }
|
||||||
return fir.typeParameters.map { it.symbol }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String = "${this::class.simpleName} ${classId.asString()}"
|
override fun toString(): String = "${this::class.simpleName} ${classId.asString()}"
|
||||||
}
|
}
|
||||||
@@ -67,9 +62,7 @@ sealed class FirClassSymbol<C : FirClass>(classId: ClassId) : FirClassLikeSymbol
|
|||||||
get() = resolvedSuperTypeRefs.map { it.coneType }
|
get() = resolvedSuperTypeRefs.map { it.coneType }
|
||||||
|
|
||||||
val declarationSymbols: List<FirBasedSymbol<*>>
|
val declarationSymbols: List<FirBasedSymbol<*>>
|
||||||
get() {
|
get() = fir.declarations.map { it.symbol }
|
||||||
return fir.declarations.map { it.symbol }
|
|
||||||
}
|
|
||||||
|
|
||||||
val classKind: ClassKind
|
val classKind: ClassKind
|
||||||
get() = fir.classKind
|
get() = fir.classKind
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
|||||||
import org.jetbrains.kotlin.name.*
|
import org.jetbrains.kotlin.name.*
|
||||||
|
|
||||||
sealed class FirFunctionSymbol<D : FirFunction>(
|
sealed class FirFunctionSymbol<D : FirFunction>(
|
||||||
override val callableId: CallableId
|
override val callableId: CallableId,
|
||||||
) : FirCallableSymbol<D>() {
|
) : FirCallableSymbol<D>() {
|
||||||
val valueParameterSymbols: List<FirValueParameterSymbol>
|
val valueParameterSymbols: List<FirValueParameterSymbol>
|
||||||
get() = fir.valueParameters.map { it.symbol }
|
get() = fir.valueParameters.map { it.symbol }
|
||||||
@@ -49,11 +49,11 @@ interface FirIntersectionCallableSymbol {
|
|||||||
|
|
||||||
class FirIntersectionOverrideFunctionSymbol(
|
class FirIntersectionOverrideFunctionSymbol(
|
||||||
callableId: CallableId,
|
callableId: CallableId,
|
||||||
override val intersections: Collection<FirCallableSymbol<*>>
|
override val intersections: Collection<FirCallableSymbol<*>>,
|
||||||
) : FirNamedFunctionSymbol(callableId), FirIntersectionCallableSymbol
|
) : FirNamedFunctionSymbol(callableId), FirIntersectionCallableSymbol
|
||||||
|
|
||||||
class FirConstructorSymbol(
|
class FirConstructorSymbol(
|
||||||
callableId: CallableId
|
callableId: CallableId,
|
||||||
) : FirFunctionSymbol<FirConstructor>(callableId) {
|
) : FirFunctionSymbol<FirConstructor>(callableId) {
|
||||||
constructor(classId: ClassId) : this(classId.callableIdForConstructor())
|
constructor(classId: ClassId) : this(classId.callableIdForConstructor())
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ class FirConstructorSymbol(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val delegatedConstructorCallIsThis: Boolean
|
val delegatedConstructorCallIsThis: Boolean
|
||||||
get() = fir.delegatedConstructor?.isThis ?: false
|
get() = fir.delegatedConstructor?.isThis == true
|
||||||
|
|
||||||
val delegatedConstructorCallIsSuper: Boolean
|
val delegatedConstructorCallIsSuper: Boolean
|
||||||
get() = fir.delegatedConstructor?.isSuper ?: false
|
get() = fir.delegatedConstructor?.isSuper == true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +86,7 @@ class FirConstructorSymbol(
|
|||||||
*/
|
*/
|
||||||
abstract class FirSyntheticPropertySymbol(
|
abstract class FirSyntheticPropertySymbol(
|
||||||
propertyId: CallableId,
|
propertyId: CallableId,
|
||||||
val getterId: CallableId
|
val getterId: CallableId,
|
||||||
) : FirPropertySymbol(propertyId) {
|
) : FirPropertySymbol(propertyId) {
|
||||||
abstract fun copy(): FirSyntheticPropertySymbol
|
abstract fun copy(): FirSyntheticPropertySymbol
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ abstract class FirSyntheticPropertySymbol(
|
|||||||
// ------------------------ unnamed ------------------------
|
// ------------------------ unnamed ------------------------
|
||||||
|
|
||||||
sealed class FirFunctionWithoutNameSymbol<F : FirFunction>(
|
sealed class FirFunctionWithoutNameSymbol<F : FirFunction>(
|
||||||
stubName: Name
|
stubName: Name,
|
||||||
) : FirFunctionSymbol<F>(CallableId(FqName("special"), stubName))
|
) : FirFunctionSymbol<F>(CallableId(FqName("special"), stubName))
|
||||||
|
|
||||||
class FirAnonymousFunctionSymbol : FirFunctionWithoutNameSymbol<FirAnonymousFunction>(Name.identifier("anonymous")) {
|
class FirAnonymousFunctionSymbol : FirFunctionWithoutNameSymbol<FirAnonymousFunction>(Name.identifier("anonymous")) {
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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.fir.symbols.impl
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvedDeclarationStatus
|
||||||
|
import org.jetbrains.kotlin.fir.psi
|
||||||
|
import org.jetbrains.kotlin.fir.renderer.FirDeclarationRendererWithAttributes
|
||||||
|
import org.jetbrains.kotlin.fir.renderer.FirFileAnnotationsContainerRenderer
|
||||||
|
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||||
|
import org.jetbrains.kotlin.fir.renderer.FirResolvePhaseRenderer
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||||
|
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||||
|
|
||||||
|
internal fun FirBasedSymbol<*>.errorInLazyResolve(name: String, actualClass: KClass<*>, expected: KClass<*>): Nothing {
|
||||||
|
throw KotlinExceptionWithAttachments("Unexpected $name. Expected is ${expected.simpleName}, but was ${actualClass.simpleName}").apply {
|
||||||
|
withAttachment(
|
||||||
|
"FirElement.txt",
|
||||||
|
FirRenderer(
|
||||||
|
resolvePhaseRenderer = FirResolvePhaseRenderer(),
|
||||||
|
declarationRenderer = FirDeclarationRendererWithAttributes(),
|
||||||
|
fileAnnotationsContainerRenderer = FirFileAnnotationsContainerRenderer(),
|
||||||
|
).renderElementAsString(fir),
|
||||||
|
)
|
||||||
|
|
||||||
|
withAttachment("FirBasedSymbol.txt", this::class.simpleName)
|
||||||
|
withAttachment("KtSourceElementKind.txt", fir.source?.kind?.let { it::class.simpleName })
|
||||||
|
withPsiAttachment("PsiElement.txt", fir.psi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun FirMemberDeclaration.resolvedStatus(): FirResolvedDeclarationStatus {
|
||||||
|
lazyResolveToPhase(FirResolvePhase.STATUS)
|
||||||
|
|
||||||
|
val status = status
|
||||||
|
if (status !is FirResolvedDeclarationStatus) {
|
||||||
|
symbol.errorInLazyResolve("status", status::class, FirResolvedDeclarationStatus::class)
|
||||||
|
}
|
||||||
|
|
||||||
|
return status
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user