[Commonizer] Refactoring: Clean-up in CirTreeMerger
This commit is contained in:
+4
-4
@@ -16,12 +16,12 @@ class CirClassNode(
|
||||
override val targetDeclarations: CommonizedGroup<CirClass>,
|
||||
override val commonDeclaration: NullableLazyValue<CirClass>,
|
||||
override val classId: ClassId
|
||||
) : CirNodeWithClassId<CirClass, CirClass> {
|
||||
) : CirNodeWithClassId<CirClass, CirClass>, CirNodeWithMembers<CirClass, CirClass> {
|
||||
|
||||
val constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode> = THashMap()
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
|
||||
val classes: MutableMap<Name, CirClassNode> = THashMap()
|
||||
override val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
|
||||
override val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
|
||||
override val classes: MutableMap<Name, CirClassNode> = THashMap()
|
||||
|
||||
override fun <T, R> accept(visitor: CirNodeVisitor<T, R>, data: T): R =
|
||||
visitor.visitClassNode(this, data)
|
||||
|
||||
+24
@@ -5,8 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassifier
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirLiftedUpDeclaration
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue
|
||||
|
||||
interface CirNode<T : CirDeclaration, R : CirDeclaration> {
|
||||
@@ -37,3 +43,21 @@ interface CirNode<T : CirDeclaration, R : CirDeclaration> {
|
||||
}
|
||||
}
|
||||
|
||||
interface CirNodeWithClassId<T : CirClassifier, R : CirClassifier> : CirNode<T, R> {
|
||||
val classId: ClassId
|
||||
}
|
||||
|
||||
interface CirNodeWithFqName<T : CirDeclaration, R : CirDeclaration> : CirNode<T, R> {
|
||||
val fqName: FqName
|
||||
}
|
||||
|
||||
interface CirNodeWithLiftingUp<T : CirDeclaration, R : CirDeclaration> : CirNode<T, R> {
|
||||
val isLiftedUp: Boolean
|
||||
get() = (commonDeclaration() as? CirLiftedUpDeclaration)?.isLiftedUp == true
|
||||
}
|
||||
|
||||
interface CirNodeWithMembers<T : CirDeclaration, R : CirDeclaration> : CirNode<T, R> {
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode>
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode>
|
||||
val classes: MutableMap<Name, CirClassNode>
|
||||
}
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassifier
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
interface CirNodeWithClassId<T : CirClassifier, R : CirClassifier> : CirNode<T, R> {
|
||||
val classId: ClassId
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
interface CirNodeWithFqName<T : CirDeclaration, R : CirDeclaration> : CirNode<T, R> {
|
||||
val fqName: FqName
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirDeclaration
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirLiftedUpDeclaration
|
||||
|
||||
interface CirNodeWithLiftingUp<T : CirDeclaration, R : CirDeclaration> : CirNode<T, R> {
|
||||
val isLiftedUp: Boolean
|
||||
get() = (commonDeclaration() as? CirLiftedUpDeclaration)?.isLiftedUp == true
|
||||
}
|
||||
+4
-4
@@ -17,11 +17,11 @@ class CirPackageNode(
|
||||
override val commonDeclaration: NullableLazyValue<CirPackage>,
|
||||
override val fqName: FqName,
|
||||
val moduleName: Name
|
||||
) : CirNodeWithFqName<CirPackage, CirPackage> {
|
||||
) : CirNodeWithFqName<CirPackage, CirPackage>, CirNodeWithMembers<CirPackage, CirPackage> {
|
||||
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
|
||||
val classes: MutableMap<Name, CirClassNode> = THashMap()
|
||||
override val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
|
||||
override val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
|
||||
override val classes: MutableMap<Name, CirClassNode> = THashMap()
|
||||
val typeAliases: MutableMap<Name, CirTypeAliasNode> = THashMap()
|
||||
|
||||
override fun <T, R> accept(visitor: CirNodeVisitor<T, R>, data: T) =
|
||||
|
||||
+33
-55
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.commonizer.LeafTarget
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider.ModuleInfo
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.CommonizerParameters
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.TargetProvider
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.*
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.intern
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.internedClassId
|
||||
@@ -18,7 +17,6 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
/**
|
||||
@@ -110,16 +108,15 @@ class CirTreeMerger(
|
||||
val allDependeeModules = targetDependeeModules + dependeeModules
|
||||
|
||||
val moduleDescriptors: Map<String, ModuleDescriptor> = targetProvider.modulesProvider.loadModules(allDependeeModules)
|
||||
val modules: MutableMap<Name, CirModuleNode> = rootNode.modules
|
||||
|
||||
moduleDescriptors.forEach { (name, moduleDescriptor) ->
|
||||
val moduleInfo = commonModuleInfos[name] ?: return@forEach
|
||||
processModule(modules, targetIndex, moduleInfo, moduleDescriptor)
|
||||
processModule(rootNode, targetIndex, moduleInfo, moduleDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processModule(
|
||||
modules: MutableMap<Name, CirModuleNode>,
|
||||
rootNode: CirRootNode,
|
||||
targetIndex: Int,
|
||||
moduleInfo: ModuleInfo,
|
||||
moduleDescriptor: ModuleDescriptor
|
||||
@@ -127,114 +124,97 @@ class CirTreeMerger(
|
||||
processCInteropModuleAttributes(moduleInfo)
|
||||
|
||||
val moduleName: Name = moduleDescriptor.name.intern()
|
||||
val moduleNode: CirModuleNode = modules.getOrPut(moduleName) {
|
||||
val moduleNode: CirModuleNode = rootNode.modules.getOrPut(moduleName) {
|
||||
buildModuleNode(storageManager, size)
|
||||
}
|
||||
moduleNode.targetDeclarations[targetIndex] = CirModuleFactory.create(moduleDescriptor)
|
||||
|
||||
val packages: MutableMap<FqName, CirPackageNode> = moduleNode.packages
|
||||
|
||||
moduleDescriptor.collectNonEmptyPackageMemberScopes { packageFqName, packageMemberScope ->
|
||||
processPackage(packages, targetIndex, packageFqName.intern(), packageMemberScope, moduleName)
|
||||
processPackage(moduleNode, targetIndex, packageFqName.intern(), packageMemberScope, moduleName)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processPackage(
|
||||
packages: MutableMap<FqName, CirPackageNode>,
|
||||
moduleNode: CirModuleNode,
|
||||
targetIndex: Int,
|
||||
packageFqName: FqName,
|
||||
packageMemberScope: MemberScope,
|
||||
moduleName: Name
|
||||
) {
|
||||
val packageNode: CirPackageNode = packages.getOrPut(packageFqName) {
|
||||
val packageNode: CirPackageNode = moduleNode.packages.getOrPut(packageFqName) {
|
||||
buildPackageNode(storageManager, size, packageFqName, moduleName)
|
||||
}
|
||||
packageNode.targetDeclarations[targetIndex] = CirPackageFactory.create(packageFqName)
|
||||
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = packageNode.properties
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = packageNode.functions
|
||||
val classes: MutableMap<Name, CirClassNode> = packageNode.classes
|
||||
val typeAliases: MutableMap<Name, CirTypeAliasNode> = packageNode.typeAliases
|
||||
|
||||
packageMemberScope.collectMembers(
|
||||
PropertyCollector { propertyDescriptor ->
|
||||
processProperty(properties, targetIndex, propertyDescriptor, null)
|
||||
processProperty(packageNode, targetIndex, propertyDescriptor)
|
||||
},
|
||||
FunctionCollector { functionDescriptor ->
|
||||
processFunction(functions, targetIndex, functionDescriptor, null)
|
||||
processFunction(packageNode, targetIndex, functionDescriptor)
|
||||
},
|
||||
ClassCollector { classDescriptor ->
|
||||
processClass(classes, targetIndex, classDescriptor, null) { className ->
|
||||
processClass(packageNode, targetIndex, classDescriptor) { className ->
|
||||
internedClassId(packageFqName, className)
|
||||
}
|
||||
},
|
||||
TypeAliasCollector { typeAliasDescriptor ->
|
||||
processTypeAlias(typeAliases, targetIndex, typeAliasDescriptor, packageFqName)
|
||||
processTypeAlias(packageNode, targetIndex, typeAliasDescriptor)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun processProperty(
|
||||
properties: MutableMap<PropertyApproximationKey, CirPropertyNode>,
|
||||
ownerNode: CirNodeWithMembers<*, *>,
|
||||
targetIndex: Int,
|
||||
propertyDescriptor: PropertyDescriptor,
|
||||
parentCommonDeclaration: NullableLazyValue<*>?
|
||||
propertyDescriptor: PropertyDescriptor
|
||||
) {
|
||||
val propertyNode: CirPropertyNode = properties.getOrPut(PropertyApproximationKey(propertyDescriptor)) {
|
||||
buildPropertyNode(storageManager, size, classifiers, parentCommonDeclaration)
|
||||
val propertyNode: CirPropertyNode = ownerNode.properties.getOrPut(PropertyApproximationKey(propertyDescriptor)) {
|
||||
buildPropertyNode(storageManager, size, classifiers, (ownerNode as? CirClassNode)?.commonDeclaration)
|
||||
}
|
||||
propertyNode.targetDeclarations[targetIndex] = CirPropertyFactory.create(propertyDescriptor)
|
||||
}
|
||||
|
||||
private fun processFunction(
|
||||
functions: MutableMap<FunctionApproximationKey, CirFunctionNode>,
|
||||
ownerNode: CirNodeWithMembers<*, *>,
|
||||
targetIndex: Int,
|
||||
functionDescriptor: SimpleFunctionDescriptor,
|
||||
parentCommonDeclaration: NullableLazyValue<*>?
|
||||
functionDescriptor: SimpleFunctionDescriptor
|
||||
) {
|
||||
val functionNode: CirFunctionNode = functions.getOrPut(FunctionApproximationKey(functionDescriptor)) {
|
||||
buildFunctionNode(storageManager, size, classifiers, parentCommonDeclaration)
|
||||
val functionNode: CirFunctionNode = ownerNode.functions.getOrPut(FunctionApproximationKey(functionDescriptor)) {
|
||||
buildFunctionNode(storageManager, size, classifiers, (ownerNode as? CirClassNode)?.commonDeclaration)
|
||||
}
|
||||
functionNode.targetDeclarations[targetIndex] = CirFunctionFactory.create(functionDescriptor)
|
||||
}
|
||||
|
||||
private fun processClass(
|
||||
classes: MutableMap<Name, CirClassNode>,
|
||||
ownerNode: CirNodeWithMembers<*, *>,
|
||||
targetIndex: Int,
|
||||
classDescriptor: ClassDescriptor,
|
||||
parentCommonDeclaration: NullableLazyValue<*>?,
|
||||
classIdFunction: (Name) -> ClassId
|
||||
) {
|
||||
val className = classDescriptor.name.intern()
|
||||
val classId = classIdFunction(className)
|
||||
|
||||
val classNode: CirClassNode = classes.getOrPut(className) {
|
||||
buildClassNode(storageManager, size, classifiers, parentCommonDeclaration, classId)
|
||||
val classNode: CirClassNode = ownerNode.classes.getOrPut(className) {
|
||||
buildClassNode(storageManager, size, classifiers, (ownerNode as? CirClassNode)?.commonDeclaration, classId)
|
||||
}
|
||||
classNode.targetDeclarations[targetIndex] = CirClassFactory.create(classDescriptor)
|
||||
|
||||
val parentCommonDeclarationForMembers: NullableLazyValue<CirClass> = classNode.commonDeclaration
|
||||
|
||||
val constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode> = classNode.constructors
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = classNode.properties
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = classNode.functions
|
||||
val nestedClasses: MutableMap<Name, CirClassNode> = classNode.classes
|
||||
|
||||
if (classDescriptor.kind != ClassKind.ENUM_ENTRY) {
|
||||
classDescriptor.constructors.forEach { constructorDescriptor ->
|
||||
processClassConstructor(constructors, targetIndex, constructorDescriptor, parentCommonDeclarationForMembers)
|
||||
processClassConstructor(classNode, targetIndex, constructorDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
classDescriptor.unsubstitutedMemberScope.collectMembers(
|
||||
PropertyCollector { propertyDescriptor ->
|
||||
processProperty(properties, targetIndex, propertyDescriptor, parentCommonDeclarationForMembers)
|
||||
processProperty(classNode, targetIndex, propertyDescriptor)
|
||||
},
|
||||
FunctionCollector { functionDescriptor ->
|
||||
processFunction(functions, targetIndex, functionDescriptor, parentCommonDeclarationForMembers)
|
||||
processFunction(classNode, targetIndex, functionDescriptor)
|
||||
},
|
||||
ClassCollector { nestedClassDescriptor ->
|
||||
processClass(nestedClasses, targetIndex, nestedClassDescriptor, parentCommonDeclarationForMembers) { nestedClassName ->
|
||||
processClass(classNode, targetIndex, nestedClassDescriptor) { nestedClassName ->
|
||||
internedClassId(classId, nestedClassName)
|
||||
}
|
||||
}
|
||||
@@ -242,27 +222,25 @@ class CirTreeMerger(
|
||||
}
|
||||
|
||||
private fun processClassConstructor(
|
||||
constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode>,
|
||||
classNode: CirClassNode,
|
||||
targetIndex: Int,
|
||||
constructorDescriptor: ClassConstructorDescriptor,
|
||||
parentCommonDeclaration: NullableLazyValue<*>?
|
||||
constructorDescriptor: ClassConstructorDescriptor
|
||||
) {
|
||||
val constructorNode: CirClassConstructorNode = constructors.getOrPut(ConstructorApproximationKey(constructorDescriptor)) {
|
||||
buildClassConstructorNode(storageManager, size, classifiers, parentCommonDeclaration)
|
||||
val constructorNode: CirClassConstructorNode = classNode.constructors.getOrPut(ConstructorApproximationKey(constructorDescriptor)) {
|
||||
buildClassConstructorNode(storageManager, size, classifiers, classNode.commonDeclaration)
|
||||
}
|
||||
constructorNode.targetDeclarations[targetIndex] = CirClassConstructorFactory.create(constructorDescriptor)
|
||||
}
|
||||
|
||||
private fun processTypeAlias(
|
||||
typeAliases: MutableMap<Name, CirTypeAliasNode>,
|
||||
packageNode: CirPackageNode,
|
||||
targetIndex: Int,
|
||||
typeAliasDescriptor: TypeAliasDescriptor,
|
||||
packageFqName: FqName
|
||||
typeAliasDescriptor: TypeAliasDescriptor
|
||||
) {
|
||||
val typeAliasName = typeAliasDescriptor.name.intern()
|
||||
val typeAliasClassId = internedClassId(packageFqName, typeAliasName)
|
||||
val typeAliasClassId = internedClassId(packageNode.fqName, typeAliasName)
|
||||
|
||||
val typeAliasNode: CirTypeAliasNode = typeAliases.getOrPut(typeAliasName) {
|
||||
val typeAliasNode: CirTypeAliasNode = packageNode.typeAliases.getOrPut(typeAliasName) {
|
||||
buildTypeAliasNode(storageManager, size, classifiers, typeAliasClassId)
|
||||
}
|
||||
typeAliasNode.targetDeclarations[targetIndex] = CirTypeAliasFactory.create(typeAliasDescriptor)
|
||||
|
||||
Reference in New Issue
Block a user