[FIR2IR] Reformat FirBasedSignatureComposer
Move public methods to the top of the class
This commit is contained in:
committed by
Space Team
parent
45d9f9edf9
commit
80ae5f3ec7
+106
-103
@@ -35,55 +35,6 @@ class FirBasedSignatureComposer(val mangler: FirMangler) {
|
|||||||
|
|
||||||
private val signatureCache = mutableMapOf<FirDeclarationWithParentId, IdSignature.CommonSignature>()
|
private val signatureCache = mutableMapOf<FirDeclarationWithParentId, IdSignature.CommonSignature>()
|
||||||
|
|
||||||
inner class SignatureBuilder(private val forceExpect: Boolean) : FirVisitor<Unit, Any?>() {
|
|
||||||
var hashId: Long? = null
|
|
||||||
var mask = 0L
|
|
||||||
|
|
||||||
private fun setExpected(f: Boolean) {
|
|
||||||
mask = mask or IdSignature.Flags.IS_EXPECT.encode(f || forceExpect)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitElement(element: FirElement, data: Any?) {
|
|
||||||
TODO("Should not be here")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitRegularClass(regularClass: FirRegularClass, data: Any?) {
|
|
||||||
setExpected(regularClass.isExpect)
|
|
||||||
//platformSpecificClass(descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitScript(script: FirScript, data: Any?) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitTypeAlias(typeAlias: FirTypeAlias, data: Any?) {
|
|
||||||
setExpected(typeAlias.isExpect)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitConstructor(constructor: FirConstructor, data: Any?) {
|
|
||||||
hashId = mangler.run { constructor.signatureMangle(compatibleMode = false) }
|
|
||||||
setExpected(constructor.isExpect)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: Any?) {
|
|
||||||
hashId = mangler.run { simpleFunction.signatureMangle(compatibleMode = false) }
|
|
||||||
setExpected(simpleFunction.isExpect)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitProperty(property: FirProperty, data: Any?) {
|
|
||||||
hashId = mangler.run { property.signatureMangle(compatibleMode = false) }
|
|
||||||
setExpected(property.isExpect)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitField(field: FirField, data: Any?) {
|
|
||||||
hashId = mangler.run { field.signatureMangle(compatibleMode = false) }
|
|
||||||
setExpected(field.isExpect)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitEnumEntry(enumEntry: FirEnumEntry, data: Any?) {
|
|
||||||
setExpected(enumEntry.isExpect)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun composeSignature(declaration: FirClassLikeDeclaration): IdSignature? {
|
fun composeSignature(declaration: FirClassLikeDeclaration): IdSignature? {
|
||||||
return composeSignatureImpl(declaration, containingClass = null, forceExpect = false)
|
return composeSignatureImpl(declaration, containingClass = null, forceExpect = false)
|
||||||
}
|
}
|
||||||
@@ -100,6 +51,60 @@ class FirBasedSignatureComposer(val mangler: FirMangler) {
|
|||||||
return composeSignatureImpl(declaration, containingClass = null, forceExpect = false)
|
return composeSignatureImpl(declaration, containingClass = null, forceExpect = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun composeTypeParameterSignature(
|
||||||
|
index: Int,
|
||||||
|
containerSignature: IdSignature?
|
||||||
|
): IdSignature? {
|
||||||
|
if (containerSignature == null) return null
|
||||||
|
return IdSignature.CompositeSignature(
|
||||||
|
containerSignature,
|
||||||
|
IdSignature.LocalSignature(MangleConstant.TYPE_PARAMETER_MARKER_NAME, index.toLong(), null)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun composeAccessorSignature(
|
||||||
|
property: FirProperty,
|
||||||
|
isSetter: Boolean,
|
||||||
|
containingClass: ConeClassLikeLookupTag? = null
|
||||||
|
): IdSignature? {
|
||||||
|
val propSig: IdSignature.CommonSignature
|
||||||
|
val fileSig: IdSignature.FileSignature?
|
||||||
|
when (val propertySignature = composeSignature(property, containingClass)) {
|
||||||
|
is IdSignature.CompositeSignature -> {
|
||||||
|
propSig = propertySignature.inner as? IdSignature.CommonSignature ?: return null
|
||||||
|
fileSig = propertySignature.container as? IdSignature.FileSignature ?: return null
|
||||||
|
}
|
||||||
|
is IdSignature.CommonSignature -> {
|
||||||
|
propSig = propertySignature
|
||||||
|
fileSig = null
|
||||||
|
}
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
val id = with(mangler) {
|
||||||
|
if (isSetter) {
|
||||||
|
property.setterOrDefault().signatureMangle(compatibleMode = false)
|
||||||
|
} else {
|
||||||
|
property.getterOrDefault().signatureMangle(compatibleMode = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val accessorFqName = if (isSetter) {
|
||||||
|
propSig.declarationFqName + ".<set-${property.name.asString()}>"
|
||||||
|
} else {
|
||||||
|
propSig.declarationFqName + ".<get-${property.name.asString()}>"
|
||||||
|
}
|
||||||
|
val commonSig = IdSignature.CommonSignature(
|
||||||
|
packageFqName = propSig.packageFqName,
|
||||||
|
declarationFqName = accessorFqName,
|
||||||
|
id = id,
|
||||||
|
mask = propSig.mask,
|
||||||
|
description = null, // TODO(KT-59486): Save mangled name here
|
||||||
|
)
|
||||||
|
val accessorSig = IdSignature.AccessorSignature(propSig, commonSig)
|
||||||
|
return if (fileSig != null) {
|
||||||
|
IdSignature.CompositeSignature(fileSig, accessorSig)
|
||||||
|
} else accessorSig
|
||||||
|
}
|
||||||
|
|
||||||
private fun composeSignatureImpl(
|
private fun composeSignatureImpl(
|
||||||
declaration: FirDeclaration,
|
declaration: FirDeclaration,
|
||||||
containingClass: ConeClassLikeLookupTag?,
|
containingClass: ConeClassLikeLookupTag?,
|
||||||
@@ -182,58 +187,53 @@ class FirBasedSignatureComposer(val mangler: FirMangler) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun composeTypeParameterSignature(
|
private inner class SignatureBuilder(private val forceExpect: Boolean) : FirVisitor<Unit, Any?>() {
|
||||||
index: Int,
|
var hashId: Long? = null
|
||||||
containerSignature: IdSignature?
|
var mask = 0L
|
||||||
): IdSignature? {
|
|
||||||
if (containerSignature == null) return null
|
|
||||||
return IdSignature.CompositeSignature(
|
|
||||||
containerSignature,
|
|
||||||
IdSignature.LocalSignature(MangleConstant.TYPE_PARAMETER_MARKER_NAME, index.toLong(), null)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun composeAccessorSignature(
|
private fun setExpected(f: Boolean) {
|
||||||
property: FirProperty,
|
mask = mask or IdSignature.Flags.IS_EXPECT.encode(f || forceExpect)
|
||||||
isSetter: Boolean,
|
|
||||||
containingClass: ConeClassLikeLookupTag? = null
|
|
||||||
): IdSignature? {
|
|
||||||
val propSig: IdSignature.CommonSignature
|
|
||||||
val fileSig: IdSignature.FileSignature?
|
|
||||||
when (val propertySignature = composeSignature(property, containingClass)) {
|
|
||||||
is IdSignature.CompositeSignature -> {
|
|
||||||
propSig = propertySignature.inner as? IdSignature.CommonSignature ?: return null
|
|
||||||
fileSig = propertySignature.container as? IdSignature.FileSignature ?: return null
|
|
||||||
}
|
|
||||||
is IdSignature.CommonSignature -> {
|
|
||||||
propSig = propertySignature
|
|
||||||
fileSig = null
|
|
||||||
}
|
|
||||||
else -> return null
|
|
||||||
}
|
}
|
||||||
val id = with(mangler) {
|
|
||||||
if (isSetter) {
|
override fun visitElement(element: FirElement, data: Any?) {
|
||||||
property.setterOrDefault().signatureMangle(compatibleMode = false)
|
TODO("Should not be here")
|
||||||
} else {
|
|
||||||
property.getterOrDefault().signatureMangle(compatibleMode = false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val accessorFqName = if (isSetter) {
|
|
||||||
propSig.declarationFqName + ".<set-${property.name.asString()}>"
|
override fun visitRegularClass(regularClass: FirRegularClass, data: Any?) {
|
||||||
} else {
|
setExpected(regularClass.isExpect)
|
||||||
propSig.declarationFqName + ".<get-${property.name.asString()}>"
|
//platformSpecificClass(descriptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitScript(script: FirScript, data: Any?) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitTypeAlias(typeAlias: FirTypeAlias, data: Any?) {
|
||||||
|
setExpected(typeAlias.isExpect)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitConstructor(constructor: FirConstructor, data: Any?) {
|
||||||
|
hashId = mangler.run { constructor.signatureMangle(compatibleMode = false) }
|
||||||
|
setExpected(constructor.isExpect)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: Any?) {
|
||||||
|
hashId = mangler.run { simpleFunction.signatureMangle(compatibleMode = false) }
|
||||||
|
setExpected(simpleFunction.isExpect)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitProperty(property: FirProperty, data: Any?) {
|
||||||
|
hashId = mangler.run { property.signatureMangle(compatibleMode = false) }
|
||||||
|
setExpected(property.isExpect)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitField(field: FirField, data: Any?) {
|
||||||
|
hashId = mangler.run { field.signatureMangle(compatibleMode = false) }
|
||||||
|
setExpected(field.isExpect)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitEnumEntry(enumEntry: FirEnumEntry, data: Any?) {
|
||||||
|
setExpected(enumEntry.isExpect)
|
||||||
}
|
}
|
||||||
val commonSig = IdSignature.CommonSignature(
|
|
||||||
packageFqName = propSig.packageFqName,
|
|
||||||
declarationFqName = accessorFqName,
|
|
||||||
id = id,
|
|
||||||
mask = propSig.mask,
|
|
||||||
description = null, // TODO(KT-59486): Save mangled name here
|
|
||||||
)
|
|
||||||
val accessorSig = IdSignature.AccessorSignature(propSig, commonSig)
|
|
||||||
return if (fileSig != null) {
|
|
||||||
IdSignature.CompositeSignature(fileSig, accessorSig)
|
|
||||||
} else accessorSig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isTopLevelPrivate(declaration: FirDeclaration): Boolean =
|
private fun isTopLevelPrivate(declaration: FirDeclaration): Boolean =
|
||||||
@@ -241,21 +241,24 @@ class FirBasedSignatureComposer(val mangler: FirMangler) {
|
|||||||
|
|
||||||
// We only need file signatures to distinguish between declarations with the same fqName across different files,
|
// We only need file signatures to distinguish between declarations with the same fqName across different files,
|
||||||
// so FirDeclaration itself is an appropriate id.
|
// so FirDeclaration itself is an appropriate id.
|
||||||
private fun FirDeclaration.fakeFileSignature(commonSignature: IdSignature.CommonSignature) =
|
private fun FirDeclaration.fakeFileSignature(commonSignature: IdSignature.CommonSignature): IdSignature.FileSignature {
|
||||||
IdSignature.FileSignature(
|
return IdSignature.FileSignature(
|
||||||
this, FqName(commonSignature.packageFqName + "." + commonSignature.declarationFqName), "<unknown>"
|
this, FqName(commonSignature.packageFqName + "." + commonSignature.declarationFqName), "<unknown>"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun FirProperty.getterOrDefault() =
|
private fun FirProperty.getterOrDefault(): FirPropertyAccessor {
|
||||||
getter ?: FirDefaultPropertyGetter(
|
return getter ?: FirDefaultPropertyGetter(
|
||||||
source = null,
|
source = null,
|
||||||
moduleData, origin, returnTypeRef, visibility, symbol
|
moduleData, origin, returnTypeRef, visibility, symbol
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun FirProperty.setterOrDefault() =
|
private fun FirProperty.setterOrDefault(): FirPropertyAccessor {
|
||||||
setter ?: FirDefaultPropertySetter(
|
return setter ?: FirDefaultPropertySetter(
|
||||||
source = null,
|
source = null,
|
||||||
moduleData, origin, returnTypeRef, visibility, symbol
|
moduleData, origin, returnTypeRef, visibility, symbol
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user