Remove CommonBackendContext.getInternalFunctions

Similarly to getInternalClass, move to subclasses
This commit is contained in:
Alexander Udalov
2019-03-12 17:16:52 +01:00
parent bd694105e9
commit e13b8eb039
4 changed files with 29 additions and 40 deletions
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.common
import org.jetbrains.kotlin.backend.common.ir.Ir
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.name.FqName
@@ -23,9 +22,6 @@ interface CommonBackendContext : BackendContext, LoggingContext {
fun getClass(fqName: FqName): ClassDescriptor
//TODO move to builtins
fun getInternalFunctions(name: String): List<FunctionDescriptor>
fun report(element: IrElement?, irFile: IrFile?, message: String, isError: Boolean)
val configuration: CompilerConfiguration
@@ -158,10 +158,7 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
val jsCoroutineContext = context.symbolTable.referenceSimpleFunction(context.coroutineContextProperty.getter!!)
val jsGetContinuation = context.run {
val f = getInternalFunctions("getContinuation")
symbolTable.referenceSimpleFunction(f.single())
}
val jsGetContinuation = getInternalFunction("getContinuation")
val jsGetKClass = getInternalWithoutPackage("getKClass")
val jsGetKClassFromExpression = getInternalWithoutPackage("getKClassFromExpression")
val jsClass = getInternalFunction("jsClass")
@@ -274,7 +271,7 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
// Helpers:
private fun getInternalFunction(name: String) =
context.symbolTable.referenceSimpleFunction(context.getInternalFunctions(name).single())
context.symbolTable.referenceSimpleFunction(context.getJsInternalFunction(name))
private fun getInternalWithoutPackage(name: String) =
context.symbolTable.referenceSimpleFunction(context.getFunctions(FqName(name)).single())
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.ir.IrElement
@@ -204,7 +205,7 @@ class JsIrBackendContext(
// Top-level functions forced to be loaded
val coroutineSuspendOrReturn = symbolTable.referenceSimpleFunction(getInternalFunctions(COROUTINE_SUSPEND_OR_RETURN_JS_NAME).single())
val coroutineSuspendOrReturn = symbolTable.referenceSimpleFunction(getJsInternalFunction(COROUTINE_SUSPEND_OR_RETURN_JS_NAME))
val coroutineSuspendGetter = ir.symbols.coroutineSuspendedGetter
val coroutineGetContext: IrFunctionSymbol
get() {
@@ -214,7 +215,7 @@ class JsIrBackendContext(
return contextGetter.symbol
}
val coroutineGetContextJs = symbolTable.referenceSimpleFunction(getInternalFunctions(GET_COROUTINE_CONTEXT_NAME).single())
val coroutineGetContextJs = symbolTable.referenceSimpleFunction(getJsInternalFunction(GET_COROUTINE_CONTEXT_NAME))
val coroutineContextProperty: PropertyDescriptor
get() {
@@ -225,8 +226,8 @@ class JsIrBackendContext(
return vars.single()
}
val captureStackSymbol = symbolTable.referenceSimpleFunction(getInternalFunctions("captureStack").single())
val newThrowableSymbol = symbolTable.referenceSimpleFunction(getInternalFunctions("newThrowable").single())
val captureStackSymbol = symbolTable.referenceSimpleFunction(getJsInternalFunction("captureStack"))
val newThrowableSymbol = symbolTable.referenceSimpleFunction(getJsInternalFunction("newThrowable"))
val throwISEymbol = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))).single())
val throwNPESymbol = ir.symbols.ThrowNullPointerException
@@ -265,23 +266,23 @@ class JsIrBackendContext(
}
}.toMap()
private fun findClass(memberScope: MemberScope, name: Name) =
private fun findClass(memberScope: MemberScope, name: Name): ClassDescriptor =
memberScope.getContributedClassifier(name, NoLookupLocation.FROM_BACKEND) as ClassDescriptor
private fun findFunctions(memberScope: MemberScope, className: String) =
findFunctions(memberScope, Name.identifier(className))
private fun findFunctions(memberScope: MemberScope, name: Name) =
private fun findFunctions(memberScope: MemberScope, name: Name): List<SimpleFunctionDescriptor> =
memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND).toList()
internal fun getJsInternalClass(name: String): ClassDescriptor =
findClass(internalPackage.memberScope, Name.identifier(name))
override fun getClass(fqName: FqName) = findClass(module.getPackage(fqName.parent()).memberScope, fqName.shortName())
override fun getClass(fqName: FqName): ClassDescriptor =
findClass(module.getPackage(fqName.parent()).memberScope, fqName.shortName())
override fun getInternalFunctions(name: String) = findFunctions(internalPackage.memberScope, name)
internal fun getJsInternalFunction(name: String): SimpleFunctionDescriptor =
findFunctions(internalPackage.memberScope, Name.identifier(name)).single()
fun getFunctions(fqName: FqName) = findFunctions(module.getPackage(fqName.parent()).memberScope, fqName.shortName())
fun getFunctions(fqName: FqName): List<SimpleFunctionDescriptor> =
findFunctions(module.getPackage(fqName.parent()).memberScope, fqName.shortName())
override fun log(message: () -> String) {
/*TODO*/
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrFile
@@ -71,17 +70,6 @@ class JvmBackendContext(
return ir.symbols.externalSymbolTable.referenceClass(getClass(fqName))
}
override fun getInternalFunctions(name: String): List<FunctionDescriptor> {
return when (name) {
"ThrowUninitializedPropertyAccessException" ->
getJvmInternalClass("Intrinsics").staticScope.getContributedFunctions(
Name.identifier("throwUninitializedPropertyAccessException"),
NoLookupLocation.FROM_BACKEND
).toList()
else -> TODO(name)
}
}
override fun log(message: () -> String) {
/*TODO*/
if (inVerbosePhase) {
@@ -102,16 +90,21 @@ class JvmBackendContext(
inner class JvmSymbols : Symbols<JvmBackendContext>(this@JvmBackendContext, symbolTable.lazyWrapper) {
override val ThrowNullPointerException: IrSimpleFunctionSymbol
get() = symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowNullPointerException").single())
get() = error("Unused in JVM IR")
override val ThrowNoWhenBranchMatchedException: IrSimpleFunctionSymbol
get() = symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowNoWhenBranchMatchedException").single())
get() = error("Unused in JVM IR")
override val ThrowTypeCastException: IrSimpleFunctionSymbol
get() = symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowTypeCastException").single())
get() = error("Unused in JVM IR")
override val ThrowUninitializedPropertyAccessException: IrSimpleFunctionSymbol =
symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowUninitializedPropertyAccessException").single())
symbolTable.referenceSimpleFunction(
getJvmInternalClass("Intrinsics").staticScope.getContributedFunctions(
Name.identifier("throwUninitializedPropertyAccessException"),
NoLookupLocation.FROM_BACKEND
).single()
)
override val stringBuilder: IrClassSymbol
get() = symbolTable.referenceClass(context.getClass(FqName("java.lang.StringBuilder")))
@@ -120,11 +113,13 @@ class JvmBackendContext(
symbolTable.referenceClass(context.getJvmInternalClass("DefaultConstructorMarker"))
override val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
get() = error("Unused in JVM IR")
override val coroutineImpl: IrClassSymbol
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
get() = TODO("not implemented")
override val coroutineSuspendedGetter: IrSimpleFunctionSymbol
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
get() = TODO("not implemented")
val lambdaClass: IrClassSymbol =
symbolTable.referenceClass(context.getJvmInternalClass("Lambda"))