FIR: refactor cone types (arguments, projections)

This commit is contained in:
Simon Ogorodnik
2018-04-03 19:25:22 +03:00
committed by Mikhail Glukhikh
parent 02bedeca05
commit 6c3fe5dc98
6 changed files with 49 additions and 29 deletions
@@ -9,27 +9,46 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterSymbol
sealed class ConeKotlinTypeProjection(val kind: ProjectionKind)
sealed class ConeKotlinTypeProjection {
abstract val kind: ProjectionKind
companion object {
val EMPTY_ARRAY = arrayOf<ConeKotlinTypeProjection>()
}
}
enum class ProjectionKind {
STAR, IN, OUT, INVARIANT
}
object StarProjection : ConeKotlinTypeProjection(ProjectionKind.STAR)
abstract class ConeKotlinTypeProjectionIn : ConeKotlinTypeProjection(ProjectionKind.IN) {
abstract val type: ConeKotlinType
object StarProjection : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.STAR
}
abstract class ConeKotlinTypeProjectionOut : ConeKotlinTypeProjection(ProjectionKind.OUT) {
abstract val type: ConeKotlinType
class ConeKotlinTypeProjectionIn(val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.IN
}
class ConeKotlinTypeProjectionOut(val type: ConeKotlinType) : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.OUT
}
// We assume type IS an invariant type projection to prevent additional wrapper here
// (more exactly, invariant type projection contains type)
sealed class ConeKotlinType : ConeKotlinTypeProjection(ProjectionKind.INVARIANT)
sealed class ConeKotlinType : ConeKotlinTypeProjection() {
override val kind: ProjectionKind
get() = ProjectionKind.INVARIANT
abstract val typeArguments: Array<out ConeKotlinTypeProjection>
}
class ConeKotlinErrorType(val reason: String) : ConeKotlinType() {
override val typeArguments: Array<out ConeKotlinTypeProjection>
get() = EMPTY_ARRAY
override fun toString(): String {
return "<ERROR TYPE: $reason>"
}
@@ -38,8 +57,9 @@ class ConeKotlinErrorType(val reason: String) : ConeKotlinType() {
class ConeClassErrorType(val reason: String) : ConeClassLikeType() {
override val symbol: ConeClassLikeSymbol
get() = error("!")
override val typeArguments: List<ConeKotlinTypeProjection>
get() = emptyList()
override val typeArguments: Array<out ConeKotlinTypeProjection>
get() = EMPTY_ARRAY
override fun toString(): String {
return "<ERROR CLASS: $reason>"
@@ -52,8 +72,6 @@ sealed class ConeSymbolBasedType : ConeKotlinType() {
abstract class ConeClassLikeType : ConeSymbolBasedType() {
abstract override val symbol: ConeClassLikeSymbol
abstract val typeArguments: List<ConeKotlinTypeProjection>
}
abstract class ConeAbbreviatedType : ConeClassLikeType() {
@@ -7,9 +7,13 @@ package org.jetbrains.kotlin.fir.types.impl
import org.jetbrains.kotlin.fir.types.ConeFunctionType
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
class ConeFunctionTypeImpl(
override val receiverType: ConeKotlinType?,
override val parameterTypes: List<ConeKotlinType>,
override val returnType: ConeKotlinType
) : ConeFunctionType()
) : ConeFunctionType() {
override val typeArguments: Array<out ConeKotlinTypeProjection>
get() = EMPTY_ARRAY
}
@@ -11,20 +11,19 @@ import org.jetbrains.kotlin.fir.types.*
open class ConeClassTypeImpl(
override val symbol: ConeClassLikeSymbol,
override val typeArguments: List<ConeKotlinTypeProjection>
override val typeArguments: Array<ConeKotlinTypeProjection>
) : ConeClassLikeType()
class ConeKotlinTypeProjectionInImpl(override val type: ConeKotlinType) : ConeKotlinTypeProjectionIn()
class ConeKotlinTypeProjectionOutImpl(override val type: ConeKotlinType) : ConeKotlinTypeProjectionOut()
class ConeAbbreviatedTypeImpl(
override val abbreviationSymbol: ConeClassLikeSymbol,
override val typeArguments: List<ConeKotlinTypeProjection>,
override val typeArguments: Array<ConeKotlinTypeProjection>,
override val directExpansion: ConeClassLikeType
) : ConeAbbreviatedType() {
override val symbol: ConeClassLikeSymbol
get() = abbreviationSymbol
}
class ConeTypeParameterTypeImpl(override val symbol: ConeTypeParameterSymbol) : ConeTypeParameterType()
class ConeTypeParameterTypeImpl(override val symbol: ConeTypeParameterSymbol) : ConeTypeParameterType() {
override val typeArguments: Array<out ConeKotlinTypeProjection>
get() = EMPTY_ARRAY
}