From e26c7407a07a3b440664fe77c2f6d62a747ce3fc Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 23 Jun 2019 20:00:00 -0400 Subject: [PATCH] Small changes to document some of the complexity. --- uncompyle6/parsers/parse26.py | 1 + uncompyle6/parsers/parse27.py | 2 ++ uncompyle6/parsers/parse3.py | 1 + uncompyle6/semantics/consts.py | 10 ++++++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/uncompyle6/parsers/parse26.py b/uncompyle6/parsers/parse26.py index 9d431dff..969471e2 100644 --- a/uncompyle6/parsers/parse26.py +++ b/uncompyle6/parsers/parse26.py @@ -175,6 +175,7 @@ class Python26Parser(Python2Parser): iflaststmt ::= testexpr_then c_stmts_opt JUMP_ABSOLUTE come_froms POP_TOP iflaststmt ::= testexpr c_stmts_opt JUMP_ABSOLUTE come_froms POP_TOP + # "if"/"else" statement that ends in a RETURN ifelsestmtr ::= testexpr_then return_if_stmts returns testexpr_then ::= testtrue_then diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index ff67efb1..9bc8bf51 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -180,6 +180,8 @@ class Python27Parser(Python2Parser): ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel ifelsestmtl ::= testexpr c_stmts_opt CONTINUE else_suitel + + # "if"/"else" statement that ends in a RETURN ifelsestmtr ::= testexpr return_if_stmts COME_FROM returns # Common with 2.6 diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 0b8778a7..34a04bf7 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -177,6 +177,7 @@ class Python3Parser(PythonParser): ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec ifelsestmtc ::= testexpr c_stmts_opt jump_absolute_else else_suitec + # "if"/"else" statement that ends in a RETURN ifelsestmtr ::= testexpr return_if_stmts returns ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index c9b9cdd2..cae5c952 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -350,11 +350,17 @@ TABLE_DIRECT = { 'testtrue': ( 'not %p', (0, PRECEDENCE['unary_not']) ), + # Generally the args here are 0: (some sort of) "testexpr", + # 1: (some sort of) "cstmts_opt", + # 2 or 3: "else_suite" + # But unfortunately there are irregularities, For example, 2.6- uses "testexpr_then" + # and sometimes "cstmts" instead of "cstmts_opt" happens. + # Down the line we might isolate these into version-specific rules. 'ifelsestmt': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ), 'ifelsestmtc': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ), 'ifelsestmtl': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ), 'ifelsestmtr': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 2 ), - 'ifelsestmtr2': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM + 'ifelsestmtr2': ( '%|if %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM in position 2 # "elif" forms are not generated by the parser but are created through tree @@ -364,7 +370,7 @@ TABLE_DIRECT = { 'elifstmt': ( '%|elif %c:\n%+%c%-', 0, 1 ), 'elifelsestmt': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 3 ), 'elifelsestmtr': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 2 ), - 'elifelsestmtr2': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM + 'elifelsestmtr2': ( '%|elif %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 3 ), # has COME_FROM in position 2 'whileTruestmt': ( '%|while True:\n%+%c%-\n\n', 1 ), 'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ),