From d1fe32a4867ac001fa854aa078dc92190870969f Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 10 Apr 2018 14:56:45 +0300 Subject: [PATCH] IrType: basic interface & implementation --- .../org/jetbrains/kotlin/ir/types/IrType.kt | 22 ++++++++++ .../kotlin/ir/types/impl/IrTypeImpl.kt | 42 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt create mode 100644 compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeImpl.kt diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt new file mode 100644 index 00000000000..0e8f5713a5a --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrType.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.ir.types + +import org.jetbrains.kotlin.ir.expressions.IrCall +import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol +import org.jetbrains.kotlin.types.Variance + +interface IrType { + val classifier: IrClassifierSymbol + val hasQuestionMark: Boolean + val arguments: List + val annotations: List +} + +interface IrTypeProjection { + val variance: Variance + val type: IrType +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeImpl.kt new file mode 100644 index 00000000000..3b30fa16a5c --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/impl/IrTypeImpl.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. 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.ir.types.impl + +import org.jetbrains.kotlin.ir.expressions.IrCall +import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol +import org.jetbrains.kotlin.ir.types.IrType +import org.jetbrains.kotlin.ir.types.IrTypeProjection +import org.jetbrains.kotlin.types.Variance + +class IrTypeImpl( + override val classifier: IrClassifierSymbol, + override val hasQuestionMark: Boolean, + override val arguments: List, + override val annotations: List, + override val variance: Variance +) : IrType, IrTypeProjection { + + constructor( + classifier: IrClassifierSymbol, + hasQuestionMark: Boolean, + arguments: List, + annotations: List + ) : this(classifier, hasQuestionMark, arguments, annotations, Variance.INVARIANT) + + override val type: IrType get() = this +} + +fun makeTypeProjection(type: IrType, variance: Variance): IrTypeProjection = + if (type !is IrTypeImpl || type.variance != variance) + IrTypeImpl( + type.classifier, + type.hasQuestionMark, + type.arguments, + type.annotations, + variance + ) + else + type \ No newline at end of file