removed InstructionDataMergeStrategy, InstructionDataAnalyzeStrategy
interfaces from PseudocodeTraverse (use only in Java as type aliases to simplify function type parameters)
This commit is contained in:
@@ -23,11 +23,11 @@ import com.intellij.psi.PsiElement;
|
|||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
|
import kotlin.Function3;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.Edges;
|
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.Edges;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.InstructionDataAnalyzeStrategy;
|
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.PseudocodeTraverserPackage;
|
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.PseudocodeTraverserPackage;
|
||||||
import org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableInitState;
|
import org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableInitState;
|
||||||
import org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableUseState;
|
import org.jetbrains.jet.lang.cfg.PseudocodeVariablesData.VariableUseState;
|
||||||
@@ -267,7 +267,7 @@ public class JetFlowInformationProvider {
|
|||||||
|
|
||||||
PseudocodeTraverserPackage.traverse(
|
PseudocodeTraverserPackage.traverse(
|
||||||
pseudocode, FORWARD, initializers,
|
pseudocode, FORWARD, initializers,
|
||||||
new InstructionDataAnalyzeStrategyJ<Map<VariableDescriptor, PseudocodeVariablesData.VariableInitState>>() {
|
new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableInitState>>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Instruction instruction,
|
public void execute(@NotNull Instruction instruction,
|
||||||
@Nullable Map<VariableDescriptor, VariableInitState> in,
|
@Nullable Map<VariableDescriptor, VariableInitState> in,
|
||||||
@@ -517,7 +517,7 @@ public class JetFlowInformationProvider {
|
|||||||
Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> variableStatusData = pseudocodeVariablesData.getVariableUseStatusData();
|
Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> variableStatusData = pseudocodeVariablesData.getVariableUseStatusData();
|
||||||
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
|
final Map<Instruction, DiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
|
||||||
InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>> variableStatusAnalyzeStrategy =
|
InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>> variableStatusAnalyzeStrategy =
|
||||||
new InstructionDataAnalyzeStrategyJ<Map<VariableDescriptor, PseudocodeVariablesData.VariableUseState>>() {
|
new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, VariableUseState>>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@NotNull Instruction instruction,
|
public void execute(@NotNull Instruction instruction,
|
||||||
@Nullable Map<VariableDescriptor, VariableUseState> in,
|
@Nullable Map<VariableDescriptor, VariableUseState> in,
|
||||||
@@ -885,7 +885,7 @@ public class JetFlowInformationProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO after KT-4621 rewrite to Kotlin
|
//TODO after KT-4621 rewrite to Kotlin
|
||||||
public abstract static class InstructionDataAnalyzeStrategyJ<D> implements InstructionDataAnalyzeStrategy<D> {
|
public abstract static class InstructionDataAnalyzeStrategy<D> implements Function3<Instruction, D, D, Unit> {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(Instruction instruction, D enterData, D exitData) {
|
public Unit invoke(Instruction instruction, D enterData, D exitData) {
|
||||||
execute(instruction, enterData, exitData);
|
execute(instruction, enterData, exitData);
|
||||||
|
|||||||
@@ -60,16 +60,16 @@ fun Pseudocode.traverse(
|
|||||||
fun <D> Pseudocode.traverse(
|
fun <D> Pseudocode.traverse(
|
||||||
traversalOrder: TraversalOrder,
|
traversalOrder: TraversalOrder,
|
||||||
edgesMap: Map<Instruction, Edges<D>>,
|
edgesMap: Map<Instruction, Edges<D>>,
|
||||||
instructionDataAnalyzeStrategy: InstructionDataAnalyzeStrategy<D>
|
analyzeInstruction: (Instruction, D, D) -> Unit
|
||||||
) {
|
) {
|
||||||
val instructions = getInstructions(traversalOrder)
|
val instructions = getInstructions(traversalOrder)
|
||||||
for (instruction in instructions) {
|
for (instruction in instructions) {
|
||||||
if (instruction is LocalFunctionDeclarationInstruction) {
|
if (instruction is LocalFunctionDeclarationInstruction) {
|
||||||
instruction.getBody().traverse(traversalOrder, edgesMap, instructionDataAnalyzeStrategy)
|
instruction.getBody().traverse(traversalOrder, edgesMap, analyzeInstruction)
|
||||||
}
|
}
|
||||||
val edges = edgesMap.get(instruction)
|
val edges = edgesMap.get(instruction)
|
||||||
if (edges != null) {
|
if (edges != null) {
|
||||||
instructionDataAnalyzeStrategy(instruction, edges.`in`, edges.out)
|
analyzeInstruction(instruction, edges.`in`, edges.out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,9 +185,6 @@ private fun <D> Pseudocode.collectDataFromSubgraph(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait InstructionDataMergeStrategy<D> : (Instruction, Collection<D>) -> Edges<D>
|
|
||||||
trait InstructionDataAnalyzeStrategy<D> : (Instruction, D, D) -> Unit
|
|
||||||
|
|
||||||
data class Edges<T>(val `in`: T, val out: T)
|
data class Edges<T>(val `in`: T, val out: T)
|
||||||
fun <T> createEdges(`in`: T, out: T) = Edges(`in`, out)
|
fun <T> createEdges(`in`: T, out: T) = Edges(`in`, out)
|
||||||
|
|
||||||
|
|||||||
@@ -41,11 +41,13 @@ public class PseudocodeVariableDataCollector(
|
|||||||
public fun <D> collectData(
|
public fun <D> collectData(
|
||||||
traversalOrder: TraversalOrder,
|
traversalOrder: TraversalOrder,
|
||||||
mergeDataWithLocalDeclarations: Boolean,
|
mergeDataWithLocalDeclarations: Boolean,
|
||||||
instructionDataMergeStrategy: InstructionDataMergeStrategy<MutableMap<VariableDescriptor, D>>
|
instructionDataMergeStrategy: InstructionDataMergeStrategy<D>
|
||||||
): MutableMap<Instruction, Edges<MutableMap<VariableDescriptor, D>>> {
|
): MutableMap<Instruction, Edges<MutableMap<VariableDescriptor, D>>> {
|
||||||
val result = pseudocode.collectData(
|
val result = pseudocode.collectData(
|
||||||
traversalOrder, mergeDataWithLocalDeclarations,
|
traversalOrder, mergeDataWithLocalDeclarations,
|
||||||
instructionDataMergeStrategy as InstructionDataMergeStrategy<Map<VariableDescriptor, D>>,
|
//see KT-4605
|
||||||
|
instructionDataMergeStrategy as
|
||||||
|
(Instruction, Collection<Map<VariableDescriptor, D>>) -> Edges<Map<VariableDescriptor, D>>,
|
||||||
{ (from, to, data) -> filterOutVariablesOutOfScope(from, to, data)},
|
{ (from, to, data) -> filterOutVariablesOutOfScope(from, to, data)},
|
||||||
Collections.emptyMap<VariableDescriptor, D>())
|
Collections.emptyMap<VariableDescriptor, D>())
|
||||||
//see KT-4605
|
//see KT-4605
|
||||||
@@ -88,6 +90,10 @@ public class PseudocodeVariableDataCollector(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//todo may be a type alias
|
||||||
|
trait InstructionDataMergeStrategy<D> :
|
||||||
|
(Instruction, Collection<MutableMap<VariableDescriptor, D>>) -> Edges<MutableMap<VariableDescriptor, D>>
|
||||||
|
|
||||||
public trait LexicalScopeVariableInfo {
|
public trait LexicalScopeVariableInfo {
|
||||||
val declaredIn : Map<VariableDescriptor, LexicalScope>
|
val declaredIn : Map<VariableDescriptor, LexicalScope>
|
||||||
val scopeVariables : Map<LexicalScope, Collection<VariableDescriptor>>
|
val scopeVariables : Map<LexicalScope, Collection<VariableDescriptor>>
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import kotlin.Unit;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.Edges;
|
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.Edges;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.InstructionDataMergeStrategy;
|
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.PseudocodeTraverserPackage;
|
import org.jetbrains.jet.lang.cfg.pseudocodeTraverser.PseudocodeTraverserPackage;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.*;
|
import org.jetbrains.jet.lang.cfg.pseudocode.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
@@ -148,7 +147,7 @@ public class PseudocodeVariablesData {
|
|||||||
|
|
||||||
return pseudocodeVariableDataCollector.collectData(
|
return pseudocodeVariableDataCollector.collectData(
|
||||||
FORWARD, /*mergeDataWithLocalDeclarations=*/ false,
|
FORWARD, /*mergeDataWithLocalDeclarations=*/ false,
|
||||||
new InstructionDataMergeStrategy<Map<VariableDescriptor, VariableInitState>>() {
|
new InstructionDataMergeStrategy<VariableInitState>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Edges<Map<VariableDescriptor, VariableInitState>> invoke(
|
public Edges<Map<VariableDescriptor, VariableInitState>> invoke(
|
||||||
@@ -248,7 +247,7 @@ public class PseudocodeVariablesData {
|
|||||||
public Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> getVariableUseStatusData() {
|
public Map<Instruction, Edges<Map<VariableDescriptor, VariableUseState>>> getVariableUseStatusData() {
|
||||||
return pseudocodeVariableDataCollector.collectData(
|
return pseudocodeVariableDataCollector.collectData(
|
||||||
BACKWARD, /*mergeDataWithLocalDeclarations=*/ true,
|
BACKWARD, /*mergeDataWithLocalDeclarations=*/ true,
|
||||||
new InstructionDataMergeStrategy<Map<VariableDescriptor, VariableUseState>>() {
|
new InstructionDataMergeStrategy<VariableUseState>() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Edges<Map<VariableDescriptor, VariableUseState>> invoke(
|
public Edges<Map<VariableDescriptor, VariableUseState>> invoke(
|
||||||
|
|||||||
Reference in New Issue
Block a user