diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt index a80fef37b65..a37de877b43 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeTraverser.kt @@ -208,7 +208,7 @@ fun Pseudocode.getStartInstruction(traversalOrder: TraversalOrder): Instruction fun Pseudocode.getLastInstruction(traversalOrder: TraversalOrder): Instruction = if (traversalOrder == FORWARD) sinkInstruction else enterInstruction -fun Pseudocode.getInstructions(traversalOrder: TraversalOrder): MutableList = +fun Pseudocode.getInstructions(traversalOrder: TraversalOrder): List = if (traversalOrder == FORWARD) instructions else reversedInstructions fun Instruction.getNextInstructions(traversalOrder: TraversalOrder): Collection = diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/Pseudocode.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/Pseudocode.kt index 561f97f594f..b7bb5390131 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/Pseudocode.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/Pseudocode.kt @@ -14,58 +14,41 @@ * limitations under the License. */ -package org.jetbrains.kotlin.cfg.pseudocode; +package org.jetbrains.kotlin.cfg.pseudocode -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction; -import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction; -import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction; -import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction; -import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction; -import org.jetbrains.kotlin.psi.KtElement; +import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction +import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction +import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction +import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction +import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction +import org.jetbrains.kotlin.psi.KtElement -import java.util.List; -import java.util.Set; +interface Pseudocode { + val correspondingElement: KtElement -public interface Pseudocode { - @NotNull - KtElement getCorrespondingElement(); + val parent: Pseudocode? - @Nullable - Pseudocode getParent(); + val localDeclarations: Set - @NotNull - Set getLocalDeclarations(); + val instructions: List - @NotNull - List getInstructions(); + val reversedInstructions: List - @NotNull - List getReversedInstructions(); + val instructionsIncludingDeadCode: List - @NotNull - List getInstructionsIncludingDeadCode(); + val exitInstruction: SubroutineExitInstruction - @NotNull - SubroutineExitInstruction getExitInstruction(); + val sinkInstruction: SubroutineSinkInstruction - @NotNull - SubroutineSinkInstruction getSinkInstruction(); + val enterInstruction: SubroutineEnterInstruction - @NotNull - SubroutineEnterInstruction getEnterInstruction(); + fun getElementValue(element: KtElement?): PseudoValue? - @Nullable - PseudoValue getElementValue(@Nullable KtElement element); + fun getValueElements(value: PseudoValue?): List - @NotNull - List getValueElements(@Nullable PseudoValue value); + fun getUsages(value: PseudoValue?): List - @NotNull - List getUsages(@Nullable PseudoValue value); + fun isSideEffectFree(instruction: Instruction): Boolean - boolean isSideEffectFree(@NotNull Instruction instruction); - - Pseudocode copy(); + fun copy(): Pseudocode } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeImpl.java index 7861364af13..ade52174200 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/PseudocodeImpl.java @@ -278,15 +278,15 @@ public class PseudocodeImpl implements Pseudocode { @NotNull @Override - public List getValueElements(@Nullable PseudoValue value) { - List result = elementsToValues.getKeysByValue(value); + public List getValueElements(@Nullable PseudoValue value) { + List result = elementsToValues.getKeysByValue(value); return result != null ? result : Collections.emptyList(); } @NotNull @Override - public List getUsages(@Nullable PseudoValue value) { - List result = valueUsages.get(value); + public List getUsages(@Nullable PseudoValue value) { + List result = valueUsages.get(value); return result != null ? result : Collections.emptyList(); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt index 906745545c6..4b192b28388 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt @@ -149,7 +149,7 @@ fun getExpectedTypePredicate( val returnElement = it.element val functionDescriptor = when(returnElement) { is KtReturnExpression -> returnElement.getTargetFunctionDescriptor(bindingContext) - else -> bindingContext[DECLARATION_TO_DESCRIPTOR, pseudocode.getCorrespondingElement()] + else -> bindingContext[DECLARATION_TO_DESCRIPTOR, pseudocode.correspondingElement] } addSubtypesOf((functionDescriptor as? CallableDescriptor)?.getReturnType()) } @@ -278,7 +278,7 @@ fun Pseudocode.getElementValuesRecursively(element: KtElement): List decl.body.getPseudocodeByElement(element)?.let { return it } } + localDeclarations.forEach { decl -> decl.body.getPseudocodeByElement(element)?.let { return it } } return null } \ No newline at end of file