[JS IR BE] Fix name clashes between static and top-level functions
This commit is contained in:
@@ -33,6 +33,8 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
|||||||
import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
import org.jetbrains.kotlin.ir.util.getPropertyDeclaration
|
import org.jetbrains.kotlin.ir.util.getPropertyDeclaration
|
||||||
|
import org.jetbrains.kotlin.ir.util.kotlinPackageFqn
|
||||||
|
import org.jetbrains.kotlin.ir.util.referenceFunction
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
@@ -177,14 +179,14 @@ class JsIrBackendContext(
|
|||||||
override val areEqual
|
override val areEqual
|
||||||
get () = TODO("not implemented")
|
get () = TODO("not implemented")
|
||||||
|
|
||||||
override val ThrowNullPointerException
|
override val ThrowNullPointerException = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).singleOrNull()?.let {
|
||||||
get () = irBuiltIns.throwNpeSymbol
|
symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwNpeSymbol
|
||||||
|
|
||||||
override val ThrowNoWhenBranchMatchedException
|
override val ThrowNoWhenBranchMatchedException
|
||||||
get () = irBuiltIns.noWhenBranchMatchedExceptionSymbol
|
get () = irBuiltIns.noWhenBranchMatchedExceptionSymbol
|
||||||
|
|
||||||
override val ThrowTypeCastException
|
override val ThrowTypeCastException = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).singleOrNull()?.let {
|
||||||
get () = irBuiltIns.throwCceSymbol
|
symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwCceSymbol
|
||||||
|
|
||||||
override val ThrowUninitializedPropertyAccessException=
|
override val ThrowUninitializedPropertyAccessException=
|
||||||
symbolTable.referenceSimpleFunction(getFunctions(FqName("kotlin.throwUninitializedPropertyAccessException")).single())
|
symbolTable.referenceSimpleFunction(getFunctions(FqName("kotlin.throwUninitializedPropertyAccessException")).single())
|
||||||
@@ -205,6 +207,9 @@ class JsIrBackendContext(
|
|||||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val throwISEymbol = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).singleOrNull()?.let {
|
||||||
|
symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwIseSymbol
|
||||||
|
|
||||||
val coroutineImplLabelProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("state")!! }
|
val coroutineImplLabelProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("state")!! }
|
||||||
val coroutineImplResultSymbol by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("result")!! }
|
val coroutineImplResultSymbol by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("result")!! }
|
||||||
val coroutineImplExceptionProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("exception")!! }
|
val coroutineImplExceptionProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("exception")!! }
|
||||||
|
|||||||
+2
-1
@@ -60,6 +60,7 @@ class EnumClassTransformer(val context: JsIrBackendContext, private val irClass:
|
|||||||
private val enumEntries = irClass.declarations.filterIsInstance<IrEnumEntry>()
|
private val enumEntries = irClass.declarations.filterIsInstance<IrEnumEntry>()
|
||||||
private val loweredEnumConstructors = HashMap<IrConstructorSymbol, IrConstructor>()
|
private val loweredEnumConstructors = HashMap<IrConstructorSymbol, IrConstructor>()
|
||||||
private val enumName = irClass.name.identifier
|
private val enumName = irClass.name.identifier
|
||||||
|
private val throwISESymbol = context.throwISEymbol
|
||||||
|
|
||||||
fun transform(): List<IrDeclaration> {
|
fun transform(): List<IrDeclaration> {
|
||||||
// Add `name` and `ordinal` parameters to enum class constructors
|
// Add `name` and `ordinal` parameters to enum class constructors
|
||||||
@@ -140,7 +141,7 @@ class EnumClassTransformer(val context: JsIrBackendContext, private val irClass:
|
|||||||
irBranch(
|
irBranch(
|
||||||
irEquals(irString(it.name.identifier), irGet(nameParameter)), irCall(getInstance)
|
irEquals(irString(it.name.identifier), irGet(nameParameter)), irCall(getInstance)
|
||||||
)
|
)
|
||||||
} + irElseBranch(irCall(context.irBuiltIns.throwIseSymbol))
|
} + irElseBranch(irCall(throwISESymbol))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -42,8 +42,8 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
|||||||
private val calculator = JsIrArithBuilder(context)
|
private val calculator = JsIrArithBuilder(context)
|
||||||
|
|
||||||
//NOTE: Should we define JS-own functions similar to current implementation?
|
//NOTE: Should we define JS-own functions similar to current implementation?
|
||||||
private val throwCCE = context.irBuiltIns.throwCceSymbol
|
private val throwCCE = context.ir.symbols.ThrowTypeCastException
|
||||||
private val throwNPE = context.irBuiltIns.throwNpeSymbol
|
private val throwNPE = context.ir.symbols.ThrowNullPointerException
|
||||||
|
|
||||||
private val eqeq = context.irBuiltIns.eqeqSymbol
|
private val eqeq = context.irBuiltIns.eqeqSymbol
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext
|
import org.jetbrains.kotlin.ir.backend.js.utils.JsGenerationContext
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.js.backend.ast.JsDeclarationScope
|
||||||
import org.jetbrains.kotlin.js.backend.ast.JsEmpty
|
import org.jetbrains.kotlin.js.backend.ast.JsEmpty
|
||||||
import org.jetbrains.kotlin.js.backend.ast.JsStatement
|
import org.jetbrains.kotlin.js.backend.ast.JsStatement
|
||||||
import org.jetbrains.kotlin.js.backend.ast.JsVars
|
import org.jetbrains.kotlin.js.backend.ast.JsVars
|
||||||
@@ -23,7 +24,15 @@ class IrDeclarationToJsTransformer : BaseIrElementToJsNodeTransformer<JsStatemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass, context: JsGenerationContext): JsStatement {
|
override fun visitClass(declaration: IrClass, context: JsGenerationContext): JsStatement {
|
||||||
return JsClassGenerator(declaration, context).generate()
|
return JsClassGenerator(
|
||||||
|
declaration,
|
||||||
|
context.newDeclaration(
|
||||||
|
JsDeclarationScope(
|
||||||
|
context.currentScope,
|
||||||
|
"scope for class ${declaration.name.asString()}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitField(declaration: IrField, context: JsGenerationContext): JsStatement {
|
override fun visitField(declaration: IrField, context: JsGenerationContext): JsStatement {
|
||||||
|
|||||||
+3
@@ -181,6 +181,9 @@ class SimpleNameGenerator : NameGenerator {
|
|||||||
nameBuilder.append(getNameForDeclaration(declaration.parent as IrDeclaration, context))
|
nameBuilder.append(getNameForDeclaration(declaration.parent as IrDeclaration, context))
|
||||||
nameBuilder.append('.')
|
nameBuilder.append('.')
|
||||||
}
|
}
|
||||||
|
if (declaration.dispatchReceiverParameter == null) {
|
||||||
|
nameDeclarator = context.staticContext.rootScope::declareFreshName
|
||||||
|
}
|
||||||
|
|
||||||
nameBuilder.append(declaration.name.asString())
|
nameBuilder.append(declaration.name.asString())
|
||||||
// TODO should we skip type parameters and use upper bound of type parameter when print type of value parameters?
|
// TODO should we skip type parameters and use upper bound of type parameter when print type of value parameters?
|
||||||
|
|||||||
Reference in New Issue
Block a user