Constraining IfElse and expanding TryExcept

This commit is contained in:
Xinlong Hu
2025-07-09 11:36:30 -05:00
parent 41c5d4ffe0
commit a0feb5a008
2 changed files with 6 additions and 6 deletions
@@ -7,7 +7,7 @@ class IfElse(ControlFlowTemplate):
template = T(
if_header=~N("if_body", "else_body").with_cond(without_top_level_instructions("WITH_EXCEPT_START", "CHECK_EXC_MATCH", "FOR_ITER")),
if_body=~N("tail.").with_in_deg(1),
else_body=~N("tail.").with_in_deg(1),
else_body=~N("tail.").with_cond(without_top_level_instructions("RERAISE", "END_FINALLY")).with_in_deg(1),
tail=N.tail(),
)
@@ -219,7 +219,7 @@ class TryFinally3_11(ControlFlowTemplate):
try_header=N("try_body"),
try_body=N("finally_body", None, "fail_body"),
finally_body=~N("tail.").with_in_deg(1).with_cond(no_back_edges),
fail_body=N(E.exc("reraise")).with_cond(ending_instructions("POP_TOP", "RERAISE")),
fail_body=N(E.exc("reraise")).with_cond(ending_instructions("POP_TOP", "RERAISE"), ending_instructions("DELETE_SUBSCR", "RERAISE")),
reraise=reraise,
tail=N.tail(),
)
@@ -315,7 +315,7 @@ class Try3_9(ControlFlowTemplate):
try_header=~N("try_body"),
try_body=N("try_footer.", None, "except_body"),
try_footer=~N("tail."),
except_body=~N("tail.").of_subtemplate(Except3_9),
except_body=~N("tail.").with_in_deg(1).of_subtemplate(Except3_9),
tail=N.tail(),
)
@@ -457,7 +457,7 @@ class TryFinally3_9(ControlFlowTemplate):
try_header=N("try_body"),
try_body=N("finally_body", None, "fail_body"),
finally_body=~N("tail.").with_in_deg(1).with_cond(no_back_edges),
fail_body=N("tail.").with_cond(ending_instructions("POP_TOP", "RERAISE")),
fail_body=N("tail.").with_cond(ending_instructions("POP_TOP", "RERAISE"), ending_instructions("DELETE_SUBSCR", "RERAISE")),
tail=N.tail(),
)
template2 = T(
@@ -687,14 +687,14 @@ class TryFinally3_6(ControlFlowTemplate):
try_header=N("try_body"),
try_body=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")),
fail_body=N("tail.").with_cond(with_instructions("POP_TOP", "END_FINALLY"), with_instructions("DELETE_SUBSCR", "END_FINALLY")),
tail=N.tail(),
)
template2 = T(
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")),
fail_body=N("tail.").with_cond(with_instructions("POP_TOP", "END_FINALLY"), with_instructions("DELETE_SUBSCR", "END_FINALLY")),
tail=N.tail(),
)