org.jetbrains.kotlin.ir.IrBuiltIns.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2021 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.ir
import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.builtins.UnsignedType
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
import org.jetbrains.kotlin.ir.util.addFakeOverrides
import org.jetbrains.kotlin.ir.util.createImplicitParameterDeclarationWithWrappedDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.StandardClassIds
/**
* Symbols for builtins that are available without any context and are not specific to any backend
* (but specific to the frontend)
*/
abstract class IrBuiltIns {
abstract val languageVersionSettings: LanguageVersionSettings
abstract val irFactory: IrFactory
abstract val anyType: IrType
abstract val anyClass: IrClassSymbol
abstract val anyNType: IrType
abstract val booleanType: IrType
abstract val booleanClass: IrClassSymbol
abstract val charType: IrType
abstract val charClass: IrClassSymbol
abstract val numberType: IrType
abstract val numberClass: IrClassSymbol
abstract val byteType: IrType
abstract val byteClass: IrClassSymbol
abstract val shortType: IrType
abstract val shortClass: IrClassSymbol
abstract val intType: IrType
abstract val intClass: IrClassSymbol
abstract val longType: IrType
abstract val longClass: IrClassSymbol
abstract val floatType: IrType
abstract val floatClass: IrClassSymbol
abstract val doubleType: IrType
abstract val doubleClass: IrClassSymbol
abstract val nothingType: IrType
abstract val nothingClass: IrClassSymbol
abstract val nothingNType: IrType
abstract val unitType: IrType
abstract val unitClass: IrClassSymbol
abstract val stringType: IrType
abstract val stringClass: IrClassSymbol
abstract val charSequenceClass: IrClassSymbol
abstract val collectionClass: IrClassSymbol
abstract val arrayClass: IrClassSymbol
abstract val setClass: IrClassSymbol
abstract val listClass: IrClassSymbol
abstract val mapClass: IrClassSymbol
abstract val mapEntryClass: IrClassSymbol
abstract val iterableClass: IrClassSymbol
abstract val iteratorClass: IrClassSymbol
abstract val listIteratorClass: IrClassSymbol
abstract val mutableCollectionClass: IrClassSymbol
abstract val mutableSetClass: IrClassSymbol
abstract val mutableListClass: IrClassSymbol
abstract val mutableMapClass: IrClassSymbol
abstract val mutableMapEntryClass: IrClassSymbol
abstract val mutableIterableClass: IrClassSymbol
abstract val mutableIteratorClass: IrClassSymbol
abstract val mutableListIteratorClass: IrClassSymbol
abstract val comparableClass: IrClassSymbol
abstract val throwableType: IrType
abstract val throwableClass: IrClassSymbol
abstract val kCallableClass: IrClassSymbol
abstract val kPropertyClass: IrClassSymbol
abstract val kClassClass: IrClassSymbol
abstract val kTypeClass: IrClassSymbol
abstract val kProperty0Class: IrClassSymbol
abstract val kProperty1Class: IrClassSymbol
abstract val kProperty2Class: IrClassSymbol
abstract val kMutableProperty0Class: IrClassSymbol
abstract val kMutableProperty1Class: IrClassSymbol
abstract val kMutableProperty2Class: IrClassSymbol
abstract val functionClass: IrClassSymbol
abstract val kFunctionClass: IrClassSymbol
abstract val annotationType: IrType
abstract val annotationClass: IrClassSymbol
// TODO: consider removing to get rid of descriptor-related dependencies
abstract val primitiveTypeToIrType: Map
abstract val primitiveIrTypes: List
abstract val primitiveIrTypesWithComparisons: List
abstract val primitiveFloatingPointIrTypes: List
abstract val byteIterator: IrClassSymbol
abstract val charIterator: IrClassSymbol
abstract val shortIterator: IrClassSymbol
abstract val intIterator: IrClassSymbol
abstract val longIterator: IrClassSymbol
abstract val floatIterator: IrClassSymbol
abstract val doubleIterator: IrClassSymbol
abstract val booleanIterator: IrClassSymbol
abstract val byteArray: IrClassSymbol
abstract val charArray: IrClassSymbol
abstract val shortArray: IrClassSymbol
abstract val intArray: IrClassSymbol
abstract val longArray: IrClassSymbol
abstract val floatArray: IrClassSymbol
abstract val doubleArray: IrClassSymbol
abstract val booleanArray: IrClassSymbol
abstract val primitiveArraysToPrimitiveTypes: Map
abstract val primitiveTypesToPrimitiveArrays: Map
abstract val primitiveArrayElementTypes: Map
abstract val primitiveArrayForType: Map
abstract val unsignedTypesToUnsignedArrays: Map
abstract val unsignedArraysElementTypes: Map
abstract val lessFunByOperandType: Map
abstract val lessOrEqualFunByOperandType: Map
abstract val greaterOrEqualFunByOperandType: Map
abstract val greaterFunByOperandType: Map
abstract val ieee754equalsFunByOperandType: Map
abstract val booleanNotSymbol: IrSimpleFunctionSymbol
abstract val eqeqeqSymbol: IrSimpleFunctionSymbol
abstract val eqeqSymbol: IrSimpleFunctionSymbol
abstract val throwCceSymbol: IrSimpleFunctionSymbol
abstract val throwIseSymbol: IrSimpleFunctionSymbol
abstract val andandSymbol: IrSimpleFunctionSymbol
abstract val ororSymbol: IrSimpleFunctionSymbol
abstract val noWhenBranchMatchedExceptionSymbol: IrSimpleFunctionSymbol
abstract val illegalArgumentExceptionSymbol: IrSimpleFunctionSymbol
abstract val checkNotNullSymbol: IrSimpleFunctionSymbol
abstract val dataClassArrayMemberHashCodeSymbol: IrSimpleFunctionSymbol
abstract val dataClassArrayMemberToStringSymbol: IrSimpleFunctionSymbol
abstract val enumClass: IrClassSymbol
abstract val intPlusSymbol: IrSimpleFunctionSymbol
abstract val intTimesSymbol: IrSimpleFunctionSymbol
abstract val intXorSymbol: IrSimpleFunctionSymbol
abstract val extensionToString: IrSimpleFunctionSymbol
abstract val memberToString: IrSimpleFunctionSymbol
abstract val extensionStringPlus: IrSimpleFunctionSymbol
abstract val memberStringPlus: IrSimpleFunctionSymbol
abstract val arrayOf: IrSimpleFunctionSymbol
abstract val arrayOfNulls: IrSimpleFunctionSymbol
abstract val linkageErrorSymbol: IrSimpleFunctionSymbol
abstract fun functionN(arity: Int): IrClass
abstract fun kFunctionN(arity: Int): IrClass
abstract fun suspendFunctionN(arity: Int): IrClass
abstract fun kSuspendFunctionN(arity: Int): IrClass
// TODO: drop variants from segments, add helper from whole fqn
abstract fun findFunctions(name: Name, vararg packageNameSegments: String = arrayOf("kotlin")): Iterable
abstract fun findFunctions(name: Name, packageFqName: FqName): Iterable
abstract fun findProperties(name: Name, packageFqName: FqName): Iterable
abstract fun findClass(name: Name, vararg packageNameSegments: String = arrayOf("kotlin")): IrClassSymbol?
abstract fun findClass(name: Name, packageFqName: FqName): IrClassSymbol?
abstract fun getKPropertyClass(mutable: Boolean, n: Int): IrClassSymbol
abstract fun findBuiltInClassMemberFunctions(builtInClass: IrClassSymbol, name: Name): Iterable
abstract fun getNonBuiltInFunctionsByExtensionReceiver(
name: Name, vararg packageNameSegments: String
): Map
abstract fun getNonBuiltinFunctionsByReturnType(
name: Name, vararg packageNameSegments: String
): Map
abstract fun getBinaryOperator(name: Name, lhsType: IrType, rhsType: IrType): IrSimpleFunctionSymbol
abstract fun getUnaryOperator(name: Name, receiverType: IrType): IrSimpleFunctionSymbol
abstract val operatorsPackageFragment: IrExternalPackageFragment
abstract val kotlinInternalPackageFragment: IrExternalPackageFragment
protected fun createIntrinsicConstEvaluationClass(): IrClass {
return irFactory.buildClass {
name = StandardClassIds.Annotations.IntrinsicConstEvaluation.shortClassName
kind = ClassKind.ANNOTATION_CLASS
modality = Modality.FINAL
}.apply {
parent = kotlinInternalPackageFragment
createImplicitParameterDeclarationWithWrappedDescriptor()
addConstructor { isPrimary = true }
addFakeOverrides(IrTypeSystemContextImpl(this@IrBuiltIns))
}
}
companion object {
val KOTLIN_INTERNAL_IR_FQN = FqName("kotlin.internal.ir")
val BUILTIN_OPERATOR = IrDeclarationOriginImpl("OPERATOR")
}
}
object BuiltInOperatorNames {
const val LESS = "less"
const val LESS_OR_EQUAL = "lessOrEqual"
const val GREATER = "greater"
const val GREATER_OR_EQUAL = "greaterOrEqual"
const val EQEQ = "EQEQ"
const val EQEQEQ = "EQEQEQ"
const val IEEE754_EQUALS = "ieee754equals"
const val THROW_CCE = "THROW_CCE"
const val THROW_ISE = "THROW_ISE"
const val NO_WHEN_BRANCH_MATCHED_EXCEPTION = "noWhenBranchMatchedException"
const val ILLEGAL_ARGUMENT_EXCEPTION = "illegalArgumentException"
const val ANDAND = "ANDAND"
const val OROR = "OROR"
const val CHECK_NOT_NULL = "CHECK_NOT_NULL"
}