store references to instruction copies
inside instruction
This commit is contained in:
+7
-3
@@ -51,10 +51,14 @@ public abstract class AbstractJumpInstruction extends InstructionImpl {
|
||||
this.resolvedTarget = outgoingEdgeTo(resolvedTarget);
|
||||
}
|
||||
|
||||
abstract AbstractJumpInstruction copy(@NotNull Label newLabel);
|
||||
protected abstract AbstractJumpInstruction createCopy(@NotNull Label newLabel);
|
||||
|
||||
final public Instruction copy(@NotNull Label newLabel) {
|
||||
return updateCopyInfo(createCopy(newLabel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
return copy(targetLabel);
|
||||
protected Instruction createCopy() {
|
||||
return createCopy(targetLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class ConditionalJumpInstruction extends AbstractJumpInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
AbstractJumpInstruction copy(@NotNull Label newLabel) {
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ConditionalJumpInstruction(onTrue, newLabel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,7 @@ public interface Instruction {
|
||||
Collection<Instruction> getNextInstructions();
|
||||
|
||||
void accept(InstructionVisitor visitor);
|
||||
|
||||
@NotNull
|
||||
Collection<Instruction> getCopies();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.cfg.pseudocode;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -28,6 +29,7 @@ import java.util.LinkedHashSet;
|
||||
public abstract class InstructionImpl implements Instruction {
|
||||
private Pseudocode owner;
|
||||
private final Collection<Instruction> previousInstructions = new LinkedHashSet<Instruction>();
|
||||
private final Collection<Instruction> copies = Sets.newHashSet();
|
||||
protected boolean isDead = false;
|
||||
|
||||
protected InstructionImpl() {
|
||||
@@ -67,5 +69,29 @@ public abstract class InstructionImpl implements Instruction {
|
||||
return isDead;
|
||||
}
|
||||
|
||||
public abstract Instruction copy();
|
||||
public final Instruction copy() {
|
||||
return updateCopyInfo(createCopy());
|
||||
}
|
||||
|
||||
protected abstract Instruction createCopy();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Instruction> getCopies() {
|
||||
return copies;
|
||||
}
|
||||
|
||||
private void addCopy(@NotNull Instruction instruction) {
|
||||
copies.add(instruction);
|
||||
}
|
||||
|
||||
protected Instruction updateCopyInfo(@NotNull Instruction instruction) {
|
||||
for (Instruction copy : copies) {
|
||||
((InstructionImpl)copy).addCopy(instruction);
|
||||
((InstructionImpl)instruction).addCopy(copy);
|
||||
}
|
||||
addCopy(instruction);
|
||||
((InstructionImpl)instruction).addCopy(this);
|
||||
return instruction;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class LocalDeclarationInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new LocalDeclarationInstruction((JetDeclaration) element, body);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -69,7 +69,7 @@ public class NondeterministicJumpInstruction extends InstructionImpl{
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Instruction> getNextInstructions() {
|
||||
ArrayList<Instruction> targetInstructions = Lists.newArrayList(getResolvedTargets().values());
|
||||
List<Instruction> targetInstructions = Lists.newArrayList(getResolvedTargets().values());
|
||||
targetInstructions.add(getNext());
|
||||
return targetInstructions;
|
||||
}
|
||||
@@ -90,7 +90,16 @@ public class NondeterministicJumpInstruction extends InstructionImpl{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
return new NondeterministicJumpInstruction(getTargetLabels());
|
||||
protected Instruction createCopy() {
|
||||
return createCopy(getTargetLabels());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final Instruction copy(@NotNull List<Label> newTargetLabels) {
|
||||
return updateCopyInfo(createCopy(newTargetLabels));
|
||||
}
|
||||
|
||||
private Instruction createCopy(@NotNull List<Label> newTargetLabels) {
|
||||
return new NondeterministicJumpInstruction(newTargetLabels);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class ReadUnitValueInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new ReadUnitValueInstruction((JetExpression) element);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class ReadValueInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new ReadValueInstruction(element);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class ReturnNoValueInstruction extends AbstractJumpInstruction implements
|
||||
}
|
||||
|
||||
@Override
|
||||
AbstractJumpInstruction copy(@NotNull Label newLabel) {
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ReturnNoValueInstruction(element, newLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class ReturnValueInstruction extends AbstractJumpInstruction implements J
|
||||
}
|
||||
|
||||
@Override
|
||||
AbstractJumpInstruction copy(@NotNull Label newLabel) {
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new ReturnValueInstruction((JetExpression) element, newLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class SubroutineEnterInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new SubroutineEnterInstruction(subroutine);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class SubroutineExitInstruction extends InstructionImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new SubroutineExitInstruction(subroutine, debugLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class SubroutineSinkInstruction extends InstructionImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new SubroutineSinkInstruction(subroutine, debugLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class UnconditionalJumpInstruction extends AbstractJumpInstruction {
|
||||
}
|
||||
|
||||
@Override
|
||||
AbstractJumpInstruction copy(@NotNull Label newLabel) {
|
||||
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||
return new UnconditionalJumpInstruction(newLabel);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class UnsupportedElementInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new UnsupportedElementInstruction(element);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class VariableDeclarationInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
if (element instanceof JetParameter) {
|
||||
return new VariableDeclarationInstruction((JetParameter) element);
|
||||
}
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class WriteValueInstruction extends InstructionWithNext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction copy() {
|
||||
protected Instruction createCopy() {
|
||||
return new WriteValueInstruction(element, lValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user