Added 'markedAsDead' flag to InstructionImpl

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