Implement support for "resX" result fields in REPL

This commit is contained in:
vitaly.khudobakhshov
2018-12-03 13:09:43 +01:00
committed by Ilya Chernikov
parent 79e577ae27
commit c901d6cebc
10 changed files with 128 additions and 32 deletions
@@ -48,13 +48,19 @@ class ScriptContext(
val resultFieldInfo: FieldInfo
get() {
assert(state.replSpecific.shouldGenerateScriptResultValue) { "Should not be called unless 'scriptResultFieldName' is set" }
assert(state.replSpecific.shouldGenerateScriptResultValue) { "Should not be called unless 'resultFieldName' is set" }
val scriptResultFieldName = state.replSpecific.scriptResultFieldName!!
return FieldInfo.createForHiddenField(state.typeMapper.mapClass(scriptDescriptor), AsmTypes.OBJECT_TYPE, scriptResultFieldName)
val fieldType = state.replSpecific.resultType?.let { state.typeMapper.mapType(it) } ?: AsmTypes.OBJECT_TYPE
return FieldInfo.createForHiddenField(
state.typeMapper.mapClass(scriptDescriptor),
fieldType,
state.replSpecific.resultType,
scriptResultFieldName
)
}
val script = DescriptorToSourceUtils.getSourceFromDescriptor(scriptDescriptor) as KtScript?
?: error("Declaration should be present for script: $scriptDescriptor")
?: error("Declaration should be present for script: $scriptDescriptor")
init {
val lastDeclaration = script.declarations.lastOrNull()
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind.*
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
import java.io.File
class GenerationState private constructor(
@@ -214,6 +215,7 @@ class GenerationState private constructor(
var earlierScriptsForReplInterpreter: List<ScriptDescriptor>? = null
var scriptResultFieldName: String? = null
val shouldGenerateScriptResultValue: Boolean get() = scriptResultFieldName != null
var resultType: KotlinType? = null
var hasResult: Boolean = false
}