Do not use IR_EXTERNAL_JAVA_DECLARATION_STUB in DeclarationStubGenerator
This code is common across backends and it should not depend on JVM-specific behavior. Introduce GeneratorExtensions to reverse the dependency here
This commit is contained in:
@@ -20,13 +20,14 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi2ir.generators.AnnotationGenerator
|
||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
|
||||
import org.jetbrains.kotlin.psi2ir.generators.ModuleGenerator
|
||||
import org.jetbrains.kotlin.psi2ir.transformations.insertImplicitCasts
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -46,13 +47,23 @@ class Psi2IrTranslator(
|
||||
postprocessingSteps.add(step)
|
||||
}
|
||||
|
||||
fun generateModule(moduleDescriptor: ModuleDescriptor, ktFiles: Collection<KtFile>, bindingContext: BindingContext): IrModuleFragment {
|
||||
val context = createGeneratorContext(moduleDescriptor, bindingContext)
|
||||
fun generateModule(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
ktFiles: Collection<KtFile>,
|
||||
bindingContext: BindingContext,
|
||||
generatorExtensions: GeneratorExtensions
|
||||
): IrModuleFragment {
|
||||
val context = createGeneratorContext(moduleDescriptor, bindingContext, extensions = generatorExtensions)
|
||||
return generateModuleFragment(context, ktFiles)
|
||||
}
|
||||
|
||||
fun createGeneratorContext(moduleDescriptor: ModuleDescriptor, bindingContext: BindingContext, symbolTable: SymbolTable = SymbolTable()) =
|
||||
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable)
|
||||
fun createGeneratorContext(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
bindingContext: BindingContext,
|
||||
symbolTable: SymbolTable = SymbolTable(),
|
||||
extensions: GeneratorExtensions = GeneratorExtensions()
|
||||
): GeneratorContext =
|
||||
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable, extensions)
|
||||
|
||||
fun generateModuleFragment(context: GeneratorContext, ktFiles: Collection<KtFile>, deserializer: IrDeserializer? = null): IrModuleFragment {
|
||||
val moduleGenerator = ModuleGenerator(context)
|
||||
|
||||
+2
-1
@@ -35,7 +35,8 @@ class GeneratorContext(
|
||||
val moduleDescriptor: ModuleDescriptor,
|
||||
val bindingContext: BindingContext,
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val symbolTable: SymbolTable = SymbolTable()
|
||||
val symbolTable: SymbolTable,
|
||||
val extensions: GeneratorExtensions
|
||||
) : IrGeneratorContext() {
|
||||
|
||||
val constantValueGenerator: ConstantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. 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.psi2ir.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
|
||||
open class GeneratorExtensions {
|
||||
open val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)?
|
||||
get() = null
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
||||
|
||||
fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment, deserializer: IrDeserializer? = null) {
|
||||
ExternalDependenciesGenerator(
|
||||
irModule.descriptor, context.symbolTable, context.irBuiltIns, deserializer
|
||||
irModule.descriptor, context.symbolTable, context.irBuiltIns, context.extensions.externalDeclarationOrigin, deserializer
|
||||
).generateUnboundSymbolsAsDependencies(irModule, context.bindingContext)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user