From 6e4f792ebf8c17139c63dc7112aaa0ef7f02ca9a Mon Sep 17 00:00:00 2001 From: Xinlong Hu <118075581+XinlongCS@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:01:52 -0500 Subject: [PATCH] With.py 3.11 With 3.11 template edits which is similar to 3.12 and 3.13 --- .../templates/With.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pylingual/control_flow_reconstruction/templates/With.py b/pylingual/control_flow_reconstruction/templates/With.py index 26f2276..fa8eb67 100644 --- a/pylingual/control_flow_reconstruction/templates/With.py +++ b/pylingual/control_flow_reconstruction/templates/With.py @@ -2,12 +2,10 @@ from typing import override from ..cft import ControlFlowTemplate, EdgeKind, register_template from ..utils import T, N, exact_instructions, starting_instructions, to_indented_source, make_try_match, versions_from - -class WithCleanup3_12(ControlFlowTemplate): +class WithCleanup3_11(ControlFlowTemplate): template = T( start=N("reraise", "poptop", "exc").with_cond( - exact_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START", "POP_JUMP_IF_TRUE"), # 3.12 - exact_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START", "TO_BOOL", "POP_JUMP_IF_TRUE"), # 3.13 + starting_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START"), # 3.11 and later ), reraise=N(None, None, "exc").with_cond(exact_instructions("RERAISE")).with_in_deg(1), poptop=N("tail", None, "exc").with_cond(exact_instructions("POP_TOP")).with_in_deg(1), @@ -17,16 +15,17 @@ class WithCleanup3_12(ControlFlowTemplate): try_match = make_try_match({}, "start", "reraise", "poptop", "exc", "tail") - @override + @to_indented_source def to_indented_source(self, source): - return [] + """ + {tail} + """ - -@register_template(0, 10, *versions_from(3, 12)) +@register_template(0, 10, (3, 11), (3, 12), (3, 13)) class With3_12(ControlFlowTemplate): template = T( setup_with=~N("with_body", None), - with_body=N("normal_cleanup", None, "exc_cleanup").with_in_deg(1), + with_body=N("normal_cleanup.", None, "exc_cleanup").with_in_deg(1), exc_cleanup=N.tail().of_subtemplate(WithCleanup3_12).with_in_deg(1), normal_cleanup=~N.tail(), ) @@ -38,4 +37,5 @@ class With3_12(ControlFlowTemplate): """ {setup_with} {with_body} - """ + {exc_cleanup} + """ \ No newline at end of file