IR: add ClassifierDescriptor.toIrType and KotlinType.toIrType
(cherry picked from commit 3e09659)
This commit is contained in:
committed by
Dmitry Petrov
parent
fa51b962b8
commit
6bc86bd42f
@@ -6,9 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.ir.types
|
package org.jetbrains.kotlin.ir.types
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||||
|
import org.jetbrains.kotlin.ir.types.impl.*
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
@@ -76,3 +79,32 @@ fun IrType.toKotlinType(): KotlinType {
|
|||||||
else -> TODO(toString())
|
else -> TODO(toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ClassifierDescriptor.toIrType(hasQuestionMark: Boolean = false): IrType {
|
||||||
|
val symbol = getSymbol()
|
||||||
|
return IrSimpleTypeImpl(defaultType, symbol, hasQuestionMark, listOf(), listOf())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun KotlinType.toIrType(): IrType? {
|
||||||
|
if (isDynamic()) return IrDynamicTypeImpl(this, listOf(), Variance.INVARIANT)
|
||||||
|
|
||||||
|
val symbol = constructor.declarationDescriptor?.getSymbol() ?: return null
|
||||||
|
|
||||||
|
val arguments = this.arguments.mapIndexed { i, projection ->
|
||||||
|
when (projection) {
|
||||||
|
is TypeProjectionImpl -> IrTypeProjectionImpl(projection.type.toIrType()!!, projection.projectionKind)
|
||||||
|
is StarProjectionImpl -> IrStarProjectionImpl
|
||||||
|
else -> error(projection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
val annotations = listOf()
|
||||||
|
return IrSimpleTypeImpl(this, symbol, isMarkedNullable, arguments, annotations)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ClassifierDescriptor.getSymbol(): IrClassifierSymbol = when (this) {
|
||||||
|
is ClassDescriptor -> IrClassSymbolImpl(this)
|
||||||
|
is TypeParameterDescriptor -> IrTypeParameterSymbolImpl(this)
|
||||||
|
else -> TODO()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user