From a0feb5a008a9277a4ebbc875084a5a0e8909ad3a Mon Sep 17 00:00:00 2001 From: Xinlong Hu <118075581+XinlongCS@users.noreply.github.com> Date: Wed, 9 Jul 2025 11:36:30 -0500 Subject: [PATCH] Constraining IfElse and expanding TryExcept --- .../templates/Conditional.py | 2 +- .../control_flow_reconstruction/templates/Exception.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pylingual/control_flow_reconstruction/templates/Conditional.py b/pylingual/control_flow_reconstruction/templates/Conditional.py index 7bdb50f..f40713d 100644 --- a/pylingual/control_flow_reconstruction/templates/Conditional.py +++ b/pylingual/control_flow_reconstruction/templates/Conditional.py @@ -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(), ) diff --git a/pylingual/control_flow_reconstruction/templates/Exception.py b/pylingual/control_flow_reconstruction/templates/Exception.py index 227e8ce..f907d7c 100644 --- a/pylingual/control_flow_reconstruction/templates/Exception.py +++ b/pylingual/control_flow_reconstruction/templates/Exception.py @@ -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(), )