mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
More precise CFG for for cycles by using updated evaluator (PY-19856)
This commit is contained in:
@@ -32,7 +32,6 @@ import com.jetbrains.python.psi.impl.PyAugAssignmentStatementNavigator;
|
||||
import com.jetbrains.python.psi.impl.PyEvaluator;
|
||||
import com.jetbrains.python.psi.impl.PyImportStatementNavigator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -476,7 +475,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
}
|
||||
final Instruction head = myBuilder.prevInstruction;
|
||||
final PyElsePart elsePart = node.getElsePart();
|
||||
if (elsePart == null && !nonEmptyIterationSource(source)) {
|
||||
if (elsePart == null && !PyEvaluator.evaluateAsBoolean(source, false)) {
|
||||
myBuilder.addPendingEdge(node, myBuilder.prevInstruction);
|
||||
}
|
||||
final PyStatementList list = forPart.getStatementList();
|
||||
@@ -511,13 +510,6 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
myBuilder.flowAbrupted();
|
||||
}
|
||||
|
||||
private static boolean nonEmptyIterationSource(@Nullable PyExpression source) {
|
||||
return
|
||||
source instanceof PySequenceExpression && !((PySequenceExpression)source).isEmpty() ||
|
||||
source instanceof PyStringLiteralExpression && !((PyStringLiteralExpression)source).getStringValue().isEmpty() ||
|
||||
source instanceof PyParenthesizedExpression && nonEmptyIterationSource(((PyParenthesizedExpression)source).getContainedExpression());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyBreakStatement(final PyBreakStatement node) {
|
||||
myBuilder.startNode(node);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
1(2) element: PyAssignmentStatement
|
||||
2(3) WRITE ACCESS: tests
|
||||
3(4) element: PyForStatement
|
||||
4(5,17) READ ACCESS: tests
|
||||
4(5) READ ACCESS: tests
|
||||
5(6) element: PyTargetExpression: t
|
||||
6(7) WRITE ACCESS: t
|
||||
7(8) element: PyTryExceptStatement
|
||||
|
||||
Reference in New Issue
Block a user