Cleanup Symbols and JvmIr.JvmSymbols
This commit is contained in:
@@ -39,6 +39,8 @@ abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: Ir
|
||||
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
|
||||
}
|
||||
|
||||
// Some symbols below are used in kotlin-native, so they can't be private
|
||||
@Suppress("MemberVisibilityCanBePrivate", "PropertyName")
|
||||
abstract class Symbols<out T : CommonBackendContext>(val context: T, private val symbolTable: ReferenceSymbolTable) {
|
||||
|
||||
protected val builtIns
|
||||
@@ -48,24 +50,12 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
||||
context.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||
|
||||
|
||||
// This hack allows to disable related symbol instantiation in descendants
|
||||
// TODO move relevant symbols to non-common code
|
||||
open fun calc(initializer: () -> IrClassSymbol): IrClassSymbol {
|
||||
return initializer()
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this table to reference external dependencies.
|
||||
*/
|
||||
open val externalSymbolTable: ReferenceSymbolTable
|
||||
get() = symbolTable
|
||||
|
||||
// val refClass = calc { symbolTable.referenceClass(context.getInternalClass("Ref")) }
|
||||
|
||||
//abstract val areEqualByValue: List<IrFunctionSymbol>
|
||||
|
||||
abstract val areEqual: IrFunctionSymbol
|
||||
|
||||
abstract val ThrowNullPointerException: IrFunctionSymbol
|
||||
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
|
||||
abstract val ThrowTypeCastException: IrFunctionSymbol
|
||||
@@ -96,11 +86,6 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
||||
val progressionClasses = listOf(charProgression, intProgression, longProgression)
|
||||
val progressionClassesTypes = progressionClasses.map { it.descriptor.defaultType }.toSet()
|
||||
|
||||
// val checkProgressionStep = context.getInternalFunctions("checkProgressionStep")
|
||||
// .map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
||||
// val getProgressionLast = context.getInternalFunctions("getProgressionLast")
|
||||
// .map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
||||
|
||||
val defaultConstructorMarker = symbolTable.referenceClass(context.getInternalClass("DefaultConstructorMarker"))
|
||||
|
||||
val any = symbolTable.referenceClass(builtIns.any)
|
||||
@@ -158,39 +143,18 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
||||
.firstOrNull {
|
||||
it.valueParameters.isEmpty()
|
||||
&& (it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.defaultType == type
|
||||
}
|
||||
?: throw Error(type.toString())
|
||||
} ?: throw Error(type.toString())
|
||||
return symbolTable.referenceSimpleFunction(descriptor)
|
||||
}
|
||||
|
||||
abstract val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
|
||||
|
||||
// val valuesForEnum = symbolTable.referenceSimpleFunction(
|
||||
// context.getInternalFunctions("valuesForEnum").single())
|
||||
//
|
||||
// val valueOfForEnum = symbolTable.referenceSimpleFunction(
|
||||
// context.getInternalFunctions("valueOfForEnum").single())
|
||||
|
||||
// val getContinuation = symbolTable.referenceSimpleFunction(
|
||||
// context.getInternalFunctions("getContinuation").single())
|
||||
|
||||
abstract val coroutineImpl: IrClassSymbol
|
||||
|
||||
abstract val coroutineSuspendedGetter: IrSimpleFunctionSymbol
|
||||
|
||||
fun getFunction(parameterCount: Int) = symbolTable.referenceClass(context.builtIns.getFunction(parameterCount))
|
||||
|
||||
val functionReference = calc { symbolTable.referenceClass(context.getInternalClass("FunctionReference")) }
|
||||
|
||||
fun getFunction(name: Name, receiverType: KotlinType, vararg argTypes: KotlinType) =
|
||||
symbolTable.referenceFunction(receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)
|
||||
.first {
|
||||
var i = 0
|
||||
it.valueParameters.size == argTypes.size && it.valueParameters.all { type -> type == argTypes[i++] }
|
||||
}
|
||||
)
|
||||
|
||||
private val binaryOperatorCache = mutableMapOf<Triple<Name, KotlinType, KotlinType>, IrFunctionSymbol>()
|
||||
|
||||
fun getBinaryOperator(name: Name, lhsType: KotlinType, rhsType: KotlinType): IrFunctionSymbol {
|
||||
val key = Triple(name, lhsType, rhsType)
|
||||
var result = binaryOperatorCache[key]
|
||||
@@ -204,6 +168,7 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
||||
}
|
||||
|
||||
private val unaryOperatorCache = mutableMapOf<Pair<Name, KotlinType>, IrFunctionSymbol>()
|
||||
|
||||
fun getUnaryOperator(name: Name, receiverType: KotlinType): IrFunctionSymbol {
|
||||
val key = name to receiverType
|
||||
var result = unaryOperatorCache[key]
|
||||
|
||||
Reference in New Issue
Block a user