refactoring: extracted local function updateEdgeDataForInstruction

This commit is contained in:
Svetlana Isakova
2014-02-26 17:25:40 +04:00
parent 7d46ff951e
commit de4a5bbb5b
@@ -112,6 +112,16 @@ public class PseudocodeVariableDataCollector(
allPreviousInstructions = previousInstructions allPreviousInstructions = previousInstructions
} }
fun updateEdgeDataForInstruction(
previousValue: Edges<Map<VariableDescriptor, D>>?,
newValue: Edges<Map<VariableDescriptor, D>>?
) {
if (previousValue != newValue && newValue != null) {
changed[0] = true
edgesMap.put(instruction, newValue)
}
}
if (shouldLookInside(instruction, lookInside)) { if (shouldLookInside(instruction, lookInside)) {
val functionInstruction = (instruction as LocalFunctionDeclarationInstruction) val functionInstruction = (instruction as LocalFunctionDeclarationInstruction)
val subroutinePseudocode = functionInstruction.getBody() val subroutinePseudocode = functionInstruction.getBody()
@@ -123,12 +133,9 @@ public class PseudocodeVariableDataCollector(
val newValue = edgesMap.get(lastInstruction) val newValue = edgesMap.get(lastInstruction)
val updatedValue = if (newValue == null) null else val updatedValue = if (newValue == null) null else
Edges.create( Edges.create(
filterOutVariablesOutOfScope(lastInstruction, instruction, newValue.`in`), filterOutVariablesOutOfScope(lastInstruction, instruction, newValue.`in`),
filterOutVariablesOutOfScope(lastInstruction, instruction, newValue.out)) filterOutVariablesOutOfScope(lastInstruction, instruction, newValue.out))
if (previousValue != updatedValue && updatedValue != null) { updateEdgeDataForInstruction(previousValue, updatedValue)
changed[0] = true
edgesMap.put(instruction, updatedValue)
}
continue continue
} }
val previousDataValue = edgesMap.get(instruction) val previousDataValue = edgesMap.get(instruction)
@@ -143,10 +150,7 @@ public class PseudocodeVariableDataCollector(
} }
} }
val mergedData = instructionDataMergeStrategy.execute(instruction, incomingEdgesData) val mergedData = instructionDataMergeStrategy.execute(instruction, incomingEdgesData)
if (!mergedData.equals(previousDataValue)) { updateEdgeDataForInstruction(previousDataValue, mergedData)
changed[0] = true
edgesMap.put(instruction, mergedData)
}
} }
} }