Added 'markedAsDead' flag to InstructionImpl
to be used in tests
This commit is contained in:
@@ -276,7 +276,7 @@ public class JetFlowInformationProvider {
|
||||
if (!isJumpElement) continue;
|
||||
}
|
||||
|
||||
if (PseudocodeUtil.isDeadInAllCopies(instruction)) {
|
||||
if (instruction.getDead()) {
|
||||
unreachableElements.add(element);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -370,7 +370,7 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
Set<Instruction> instructionSet = Sets.newHashSet(instructions);
|
||||
for (Instruction instruction : mutableInstructionList) {
|
||||
if (!instructionSet.contains(instruction)) {
|
||||
((InstructionImpl)instruction).die();
|
||||
((InstructionImpl)instruction).setMarkedAsDead(true);
|
||||
for (Instruction nextInstruction : instruction.getNextInstructions()) {
|
||||
nextInstruction.getPreviousInstructions().remove(instruction);
|
||||
}
|
||||
|
||||
@@ -85,12 +85,4 @@ public class PseudocodeUtil {
|
||||
}
|
||||
return BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, element, onlyReference);
|
||||
}
|
||||
|
||||
public static boolean isDeadInAllCopies(@NotNull Instruction instruction) {
|
||||
boolean allCopiesAreDead = instruction.getDead();
|
||||
for (Instruction copy : instruction.getCopies()) {
|
||||
allCopiesAreDead = allCopiesAreDead && copy.getDead();
|
||||
}
|
||||
return allCopiesAreDead;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -27,7 +27,6 @@ public abstract class InstructionImpl(public override val lexicalScope: LexicalS
|
||||
private var _owner: Pseudocode? = null
|
||||
private val _copies = HashSet<Instruction>()
|
||||
private var original: Instruction? = null
|
||||
protected var _dead: Boolean = false
|
||||
|
||||
private fun setOriginalInstruction(value: Instruction?) {
|
||||
assert(original == null) { "Instruction can't have two originals: this.original = ${original}; new original = $this" }
|
||||
@@ -49,11 +48,9 @@ public abstract class InstructionImpl(public override val lexicalScope: LexicalS
|
||||
|
||||
protected abstract fun createCopy(): InstructionImpl
|
||||
|
||||
public fun die() {
|
||||
_dead = true
|
||||
}
|
||||
public var markedAsDead: Boolean = false
|
||||
|
||||
override val dead: Boolean get() = _dead
|
||||
override val dead: Boolean get() = markedAsDead && getCopies().all { (it as InstructionImpl).markedAsDead }
|
||||
|
||||
public fun copy(): Instruction {
|
||||
return updateCopyInfo(createCopy())
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.Instruction;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionImpl;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
import java.util.*;
|
||||
@@ -108,7 +109,7 @@ public abstract class AbstractControlFlowTest extends AbstractPseudocodeTest {
|
||||
//check edges directions
|
||||
Collection<Instruction> instructions = pseudocode.getInstructionsIncludingDeadCode();
|
||||
for (Instruction instruction : instructions) {
|
||||
if (!instruction.getDead()) {
|
||||
if (!((InstructionImpl)instruction).getMarkedAsDead()) {
|
||||
for (Instruction nextInstruction : instruction.getNextInstructions()) {
|
||||
assertTrue("instruction '" + instruction + "' has '" + nextInstruction + "' among next instructions list, but not vice versa",
|
||||
nextInstruction.getPreviousInstructions().contains(instruction));
|
||||
|
||||
@@ -140,7 +140,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment {
|
||||
@NotNull Set<Instruction> remainedAfterPostProcessInstructions
|
||||
) {
|
||||
boolean isRemovedThroughPostProcess = !remainedAfterPostProcessInstructions.contains(instruction);
|
||||
assert isRemovedThroughPostProcess == ((InstructionImpl)instruction).getDead();
|
||||
assert isRemovedThroughPostProcess == ((InstructionImpl)instruction).getMarkedAsDead();
|
||||
return isRemovedThroughPostProcess ? "-" : " ";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user