Extend GeneratorExtensions with previous script, implemt it for JS REPL
also refactor JS REPL for better compatibility with the generic REPL/scripting infrastructure
This commit is contained in:
+3
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrDelegatingConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrScriptSymbol
|
||||
import org.jetbrains.kotlin.ir.util.StubGeneratorExtensions
|
||||
import org.jetbrains.kotlin.psi.KtPureClassOrObject
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -39,4 +40,6 @@ open class GeneratorExtensions : StubGeneratorExtensions() {
|
||||
|
||||
open val shouldPreventDeprecatedIntegerValueTypeLiteralConversion: Boolean
|
||||
get() = false
|
||||
|
||||
open fun getPreviousScripts(): List<IrScriptSymbol> = emptyList()
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
||||
fun generateScriptDeclaration(ktScript: KtScript): IrDeclaration? {
|
||||
val descriptor = getOrFail(BindingContext.DECLARATION_TO_DESCRIPTOR, ktScript) as ScriptDescriptor
|
||||
|
||||
val existedScripts = context.symbolTable.listExistedScripts()
|
||||
val previousScripts = context.extensions.getPreviousScripts()
|
||||
|
||||
return context.symbolTable.declareScript(descriptor).buildWithScope { irScript ->
|
||||
|
||||
@@ -54,7 +54,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
||||
|
||||
// TODO: since script could reference instances of previous one their receivers have to be enlisted in its scope
|
||||
// Remove this code once script is no longer represented by Class
|
||||
existedScripts.forEach {
|
||||
previousScripts.forEach {
|
||||
if (it.owner != irScript && it.descriptor !in importedScripts) {
|
||||
context.symbolTable.introduceValueParameter(it.owner.thisReceiver)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
||||
valueParameter to irProperty.symbol
|
||||
}
|
||||
|
||||
irScript.earlierScripts = existedScripts
|
||||
irScript.earlierScripts = previousScripts
|
||||
|
||||
for (d in ktScript.declarations) {
|
||||
when (d) {
|
||||
|
||||
Reference in New Issue
Block a user