From d45a4f9d27ffe970f1da0eb8f2b5fa94072538b8 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 10 Dec 2012 17:12:53 +0400 Subject: [PATCH] refactoring: traverseForward and traverseBackward instead of boolean parameter 'directOrder' --- .../lang/cfg/JetFlowInformationProvider.java | 10 +++---- .../jet/lang/cfg/PseudocodeTraverser.java | 30 +++++++++++++++++-- .../jet/lang/cfg/PseudocodeVariablesData.java | 2 +- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index e492ed49ba5..407c46b9d53 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -196,7 +196,7 @@ public class JetFlowInformationProvider { final Map reportedDiagnosticMap = Maps.newHashMap(); - PseudocodeTraverser.traverse(pseudocode, true, true, initializers, new InstructionDataAnalyzeStrategy>() { + PseudocodeTraverser.traverseForward(pseudocode, true, initializers, new InstructionDataAnalyzeStrategy>() { @Override public void execute(@NotNull Instruction instruction, @Nullable Map in, @@ -204,7 +204,6 @@ public class JetFlowInformationProvider { assert in != null && out != null; VariableInitContext ctxt = new VariableInitContext(instruction, reportedDiagnosticMap, in, out); if (ctxt.variableDescriptor == null) return; - if (!(instruction instanceof ReadValueInstruction) && !(instruction instanceof WriteValueInstruction)) return; if (instruction instanceof ReadValueInstruction) { JetElement element = ((ReadValueInstruction) instruction).getElement(); boolean error = checkBackingField(ctxt, element); @@ -213,6 +212,7 @@ public class JetFlowInformationProvider { } return; } + if (!(instruction instanceof WriteValueInstruction)) return; JetElement element = ((WriteValueInstruction) instruction).getlValue(); boolean error = checkBackingField(ctxt, element); if (!(element instanceof JetExpression)) return; @@ -502,7 +502,7 @@ public class JetFlowInformationProvider { } } }; - PseudocodeTraverser.traverse(pseudocode, false, true, variableStatusData, variableStatusAnalyzeStrategy); + PseudocodeTraverser.traverseBackward(pseudocode, true, variableStatusData, variableStatusAnalyzeStrategy); } //////////////////////////////////////////////////////////////////////////////// @@ -511,8 +511,8 @@ public class JetFlowInformationProvider { public void markUnusedLiteralsInBlock() { assert pseudocode != null; final Map reportedDiagnosticMap = Maps.newHashMap(); - PseudocodeTraverser.traverse( - pseudocode, true, new InstructionAnalyzeStrategy() { + PseudocodeTraverser.traverseForward( + pseudocode, new InstructionAnalyzeStrategy() { @Override public void execute(@NotNull Instruction instruction) { if (!(instruction instanceof ReadValueInstruction)) return; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeTraverser.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeTraverser.java index 2c31612629b..244c37a9abb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeTraverser.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeTraverser.java @@ -127,7 +127,19 @@ public class PseudocodeTraverser { } } - public static void traverse( + public static void traverseForward( + @NotNull Pseudocode pseudocode, + @NotNull InstructionAnalyzeStrategy instructionAnalyzeStrategy) { + traverse(pseudocode, true, instructionAnalyzeStrategy); + } + + public static void traverseBackward( + @NotNull Pseudocode pseudocode, + @NotNull InstructionAnalyzeStrategy instructionAnalyzeStrategy) { + traverse(pseudocode, false, instructionAnalyzeStrategy); + } + + private static void traverse( @NotNull Pseudocode pseudocode, boolean directOrder, InstructionAnalyzeStrategy instructionAnalyzeStrategy) { @@ -140,7 +152,21 @@ public class PseudocodeTraverser { } } - public static void traverse( + public static void traverseForward( + @NotNull Pseudocode pseudocode, boolean lookInside, + @NotNull Map> edgesMap, + @NotNull InstructionDataAnalyzeStrategy instructionDataAnalyzeStrategy) { + traverse(pseudocode, true, lookInside, edgesMap, instructionDataAnalyzeStrategy); + } + + public static void traverseBackward( + @NotNull Pseudocode pseudocode, boolean lookInside, + @NotNull Map> edgesMap, + @NotNull InstructionDataAnalyzeStrategy instructionDataAnalyzeStrategy) { + traverse(pseudocode, false, lookInside, edgesMap, instructionDataAnalyzeStrategy); + } + + private static void traverse( @NotNull Pseudocode pseudocode, boolean directOrder, boolean lookInside, @NotNull Map> edgesMap, @NotNull InstructionDataAnalyzeStrategy instructionDataAnalyzeStrategy) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeVariablesData.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeVariablesData.java index 92f84ca62cd..0d01da4e0e4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeVariablesData.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/PseudocodeVariablesData.java @@ -62,7 +62,7 @@ public class PseudocodeVariablesData { Set usedVariables = usedVariablesInEachDeclaration.get(pseudocode); if (usedVariables == null) { final Set result = Sets.newHashSet(); - PseudocodeTraverser.traverse(pseudocode, true, new InstructionAnalyzeStrategy() { + PseudocodeTraverser.traverseForward(pseudocode, new InstructionAnalyzeStrategy() { @Override public void execute(@NotNull Instruction instruction) { VariableDescriptor variableDescriptor = PseudocodeUtil.extractVariableDescriptorIfAny(instruction, false,