[JS IR] fix field namer
This commit is contained in:
committed by
TeamCityServer
parent
5100cb058f
commit
e4c668462c
+10
-14
@@ -76,20 +76,12 @@ class JsNameLinkingNamer(private val context: JsIrBackendContext) : IrNamerBase(
|
|||||||
override fun getNameForMemberField(field: IrField): JsName {
|
override fun getNameForMemberField(field: IrField): JsName {
|
||||||
require(!field.isStatic)
|
require(!field.isStatic)
|
||||||
// TODO this looks funny. Rethink.
|
// TODO this looks funny. Rethink.
|
||||||
return JsName(field.parentAsClass.fieldData().pickFieldName(field), false)
|
return JsName(field.parentAsClass.fieldData()[field]!!, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FieldData(private val nameCnt: Map<String, Int>) {
|
private val fieldDataCache = mutableMapOf<IrClass, Map<IrField, String>>()
|
||||||
fun pickFieldName(field: IrField): String {
|
|
||||||
val fieldName = field.safeName()
|
|
||||||
val cnt = nameCnt[fieldName] ?: error("Unexpected field: ${field.render()}")
|
|
||||||
return fieldName + "_$cnt"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val fieldDataCache = mutableMapOf<IrClass, FieldData>()
|
private fun IrClass.fieldData(): Map<IrField, String> {
|
||||||
|
|
||||||
private fun IrClass.fieldData(): FieldData {
|
|
||||||
return fieldDataCache.getOrPut(this) {
|
return fieldDataCache.getOrPut(this) {
|
||||||
val nameCnt = mutableMapOf<String, Int>()
|
val nameCnt = mutableMapOf<String, Int>()
|
||||||
|
|
||||||
@@ -99,12 +91,16 @@ class JsNameLinkingNamer(private val context: JsIrBackendContext) : IrNamerBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allClasses.forEach {
|
val result = mutableMapOf<IrField, String>()
|
||||||
|
|
||||||
|
allClasses.reversed().forEach {
|
||||||
it.declarations.forEach {
|
it.declarations.forEach {
|
||||||
when {
|
when {
|
||||||
it is IrField -> {
|
it is IrField -> {
|
||||||
val safeName = it.safeName()
|
val safeName = it.safeName()
|
||||||
nameCnt[safeName] = nameCnt.getOrDefault(safeName, 0) + 1
|
val suffix = nameCnt.getOrDefault(safeName, 0) + 1
|
||||||
|
nameCnt[safeName] = suffix
|
||||||
|
result[it] = safeName + "_$suffix"
|
||||||
}
|
}
|
||||||
it is IrFunction && it.dispatchReceiverParameter != null -> {
|
it is IrFunction && it.dispatchReceiverParameter != null -> {
|
||||||
nameCnt[jsFunctionSignature(it, context)] = 1 // avoid clashes with member functions
|
nameCnt[jsFunctionSignature(it, context)] = 1 // avoid clashes with member functions
|
||||||
@@ -113,7 +109,7 @@ class JsNameLinkingNamer(private val context: JsIrBackendContext) : IrNamerBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FieldData(nameCnt)
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user