mirror of
https://github.com/syssec-utd/pylingual.git
synced 2026-05-10 18:39:03 -07:00
Assertion/TryExceptFinally Fix
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from ..cft import ControlFlowTemplate, EdgeKind, register_template
|
||||
<<<<<<< Updated upstream
|
||||
from ..utils import T, N, defer_source_to, run_is, with_instructions, has_instval, starting_instructions, to_indented_source, make_try_match, without_top_level_instructions
|
||||
=======
|
||||
from ..utils import T, N, defer_source_to, run_is, has_no_lines, with_instructions, has_instval, starting_instructions, to_indented_source, make_try_match, without_top_level_instructions
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
|
||||
@register_template(1, 40)
|
||||
@@ -46,10 +50,17 @@ class IfThen(ControlFlowTemplate):
|
||||
class Assertion(ControlFlowTemplate):
|
||||
template = T(
|
||||
assertion=~N("fail", "tail"),
|
||||
<<<<<<< Updated upstream
|
||||
fail=+N().with_cond(starting_instructions("LOAD_ASSERTION_ERROR"), has_instval("LOAD_GLOBAL", argval = "AssertionError")),
|
||||
tail=N.tail(),
|
||||
=======
|
||||
fail=+N().with_cond(starting_instructions("LOAD_ASSERTION_ERROR"), has_instval("LOAD_GLOBAL", argval = "AssertionError")).with_cond(has_no_lines),
|
||||
tail=N.tail().with_cond(without_top_level_instructions("RERAISE", "END_FINALLY")),
|
||||
>>>>>>> Stashed changes
|
||||
)
|
||||
|
||||
|
||||
|
||||
try_match = make_try_match({EdgeKind.Fall: "tail"}, "assertion", "fail")
|
||||
|
||||
to_indented_source = defer_source_to("assertion")
|
||||
|
||||
@@ -695,7 +695,7 @@ class TryFinally3_6(ControlFlowTemplate):
|
||||
try_except=N("finally_tail", None, "fail_body").of_type(TryElse3_6, Try3_6),
|
||||
finally_tail=N("finally_body", None, "fail_body"),
|
||||
finally_body=~N("fail_body").with_in_deg(1).with_cond(no_back_edges),
|
||||
fail_body=N("tail.").with_cond(with_instructions("POP_TOP", "END_FINALLY"), with_instructions("DELETE_SUBSCR", "END_FINALLY")),
|
||||
fail_body=N("tail.").with_cond(with_instructions("POP_TOP", "END_FINALLY")),
|
||||
tail=N.tail(),
|
||||
)
|
||||
|
||||
@@ -711,7 +711,7 @@ class TryFinally3_6(ControlFlowTemplate):
|
||||
return None
|
||||
mapping["try_header"] = mapping.pop("try_except")
|
||||
|
||||
cutoff = next((i for i, x in enumerate(mapping["fail_body"].get_instructions())), None)
|
||||
cutoff = next((i for i, x in enumerate(mapping["fail_body"].get_instructions()) if x.opname == "END_FINALLY"), None)
|
||||
if cutoff is None:
|
||||
return None
|
||||
|
||||
|
||||
@@ -129,6 +129,13 @@ def has_instval(opname: str, argval : Any):
|
||||
return check_instructions
|
||||
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
def has_no_lines(cfg: CFG, node: ControlFlowTemplate | None) -> bool:
|
||||
return node is None or all(i.starts_line is None for i in node.get_instructions())
|
||||
|
||||
|
||||
>>>>>>> Stashed changes
|
||||
def run_is(n: int):
|
||||
def check_run(cfg: CFG, node: ControlFlowTemplate | None) -> bool:
|
||||
return cfg.run == n
|
||||
|
||||
Reference in New Issue
Block a user