Turn off optimizations in case of do-while presence
This commit is contained in:
@@ -38,6 +38,7 @@ private typealias ImmutableSet<T> = javaslang.collection.Set<T>
|
||||
private typealias ImmutableHashSet<T> = javaslang.collection.HashSet<T>
|
||||
|
||||
class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingContext: BindingContext) {
|
||||
private val containsDoWhile = pseudocode.rootPseudocode.containsDoWhile
|
||||
private val pseudocodeVariableDataCollector = PseudocodeVariableDataCollector(bindingContext, pseudocode)
|
||||
|
||||
private class VariablesForDeclaration(
|
||||
@@ -107,7 +108,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
|
||||
bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, variableDeclarationElement)
|
||||
) ?: continue
|
||||
|
||||
if (isValWithTrivialInitializer(variableDeclarationElement, descriptor)) {
|
||||
if (!containsDoWhile && isValWithTrivialInitializer(variableDeclarationElement, descriptor)) {
|
||||
valsWithTrivialInitializer.add(descriptor)
|
||||
}
|
||||
else {
|
||||
|
||||
+5
-2
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.cfg.pseudocode
|
||||
import com.intellij.util.containers.Stack
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.cfg.*
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.BlockScope
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.*
|
||||
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
|
||||
import java.util.*
|
||||
|
||||
class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() {
|
||||
@@ -113,6 +112,10 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() {
|
||||
override fun createUnboundLabel(name: String): Label = pseudocode.createLabel("L" + labelCount++, name)
|
||||
|
||||
override fun enterLoop(expression: KtLoopExpression): LoopInfo {
|
||||
if (expression is KtDoWhileExpression) {
|
||||
(pseudocode.rootPseudocode as PseudocodeImpl).containsDoWhile = true
|
||||
}
|
||||
|
||||
val info = LoopInfo(
|
||||
expression,
|
||||
createUnboundLabel("loop entry point"),
|
||||
|
||||
@@ -45,6 +45,9 @@ interface Pseudocode {
|
||||
|
||||
val enterInstruction: SubroutineEnterInstruction
|
||||
|
||||
val containsDoWhile: Boolean
|
||||
val rootPseudocode: Pseudocode
|
||||
|
||||
fun getElementValue(element: KtElement?): PseudoValue?
|
||||
|
||||
fun getValueElements(value: PseudoValue?): List<KtElement>
|
||||
|
||||
@@ -77,6 +77,9 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
|
||||
private var postPrecessed = false
|
||||
|
||||
override var containsDoWhile: Boolean = false
|
||||
internal set
|
||||
|
||||
private fun getLocalDeclarations(pseudocode: Pseudocode): Set<LocalFunctionDeclarationInstruction> {
|
||||
val localDeclarations = linkedSetOf<LocalFunctionDeclarationInstruction>()
|
||||
for (instruction in (pseudocode as PseudocodeImpl).mutableInstructionList) {
|
||||
@@ -88,7 +91,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
return localDeclarations
|
||||
}
|
||||
|
||||
val rootPseudocode: Pseudocode
|
||||
override val rootPseudocode: Pseudocode
|
||||
get() {
|
||||
var parent = parent
|
||||
while (parent != null) {
|
||||
|
||||
+1
-1
@@ -2,5 +2,5 @@ fun test(cond1: Boolean) {
|
||||
do {
|
||||
if (cond1) continue
|
||||
val cond2 = false
|
||||
} while (cond2) // cond2 may be not defined here
|
||||
} while (<!UNINITIALIZED_VARIABLE!>cond2<!>) // cond2 may be not defined here
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user