mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 23:31:05 +07:00
PY-48760 Implement CFG for PEP-634 match statements
I introduced a new type of CFG instructions, similar to ConditionalInstruction, called RefutablePatternInstruction. The idea is that every pattern that can possibly fail to match is surrounded with a pair of such instructions, helping to describe how the control flow moves in each case. The PEP calls the opposite type of patterns that always match "irrefutable", hence the name. We need these synthetic instructions because otherwise some refutable patterns such as literal ones (e.g. "42") don't leave any nodes in the graph. Incorporating the information about irrefutable patterns right into the graph allows catching cases such as "wildcard/name capture makes remaining patterns unreachable", both in OR patterns and independent case clauses. GitOrigin-RevId: beebe1890a6a824b188e6954a2c92f7ec52079e0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
79999b52e4
commit
cb08d4de98
@@ -1,4 +1,7 @@
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PyAsPattern extends PyPattern {
|
||||
@NotNull PyPattern getPattern();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PyCaseClause extends PyStatementPart {
|
||||
@Nullable PyPattern getPattern();
|
||||
@Nullable PyExpression getGuardCondition();
|
||||
}
|
||||
|
||||
@@ -326,6 +326,10 @@ public class PyElementVisitor extends PsiElementVisitor {
|
||||
visitPyPattern(node);
|
||||
}
|
||||
|
||||
public void visitWildcardPattern(@NotNull PyWildcardPattern node) {
|
||||
visitPyPattern(node);
|
||||
}
|
||||
|
||||
public void visitPyClassPattern(@NotNull PyClassPattern node) {
|
||||
visitPyPattern(node);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PyGroupPattern extends PyPattern {
|
||||
@NotNull PyPattern getPattern();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PyMatchStatement extends PyStatement {
|
||||
@Nullable PyExpression getSubject();
|
||||
@NotNull List<PyCaseClause> getCaseClauses();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PyOrPattern extends PyPattern {
|
||||
@NotNull List<PyPattern> getAlternatives();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user