From 8cdaac93abc76d109f88f2e02d006f0cfb87a88a Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 13 Apr 2017 21:27:22 -0400 Subject: [PATCH] Add if1else. Fixes #101 --- test/bytecode_3.1/03_if_true_else.pyc | Bin 0 -> 174 bytes test/simple_source/bug27+/03_if_true_else.py | 1 + uncompyle6/parser.py | 6 +++++- uncompyle6/parsers/parse3.py | 1 - uncompyle6/semantics/consts.py | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/bytecode_3.1/03_if_true_else.pyc create mode 100644 test/simple_source/bug27+/03_if_true_else.py diff --git a/test/bytecode_3.1/03_if_true_else.pyc b/test/bytecode_3.1/03_if_true_else.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5085777c7c71da6620e4dac8117ba1534dfd4c9d GIT binary patch literal 174 zcmeb0;pK`|{t%JOfCLzUYzH7N76B3|ObkUl3@Ho@dCUx{j0}t^j10jV%s`1ukTSmz z4JIH}$^s-pib_*UIe?7#__WNN)cAM}Ae#X}l&S-{#hJMUK)K@l(xT*4{iM=#BXezi l1LOG2wD=OB{`l0K;#9qYO0YRLx%nxjIjMFai;6*J0RScCAkP2* literal 0 HcmV?d00001 diff --git a/test/simple_source/bug27+/03_if_true_else.py b/test/simple_source/bug27+/03_if_true_else.py new file mode 100644 index 00000000..bfdcae3c --- /dev/null +++ b/test/simple_source/bug27+/03_if_true_else.py @@ -0,0 +1 @@ +1 if 1 else __file__ diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 5169d550..9ab80c95 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -508,8 +508,12 @@ class PythonParser(GenericASTBuilder): expr ::= conditional conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM conditional ::= expr jmp_false expr JUMP_ABSOLUTE expr + expr ::= conditionalnot - conditionalnot ::= expr jmp_true expr _jump expr COME_FROM + conditionalnot ::= expr jmp_true expr _jump expr COME_FROM + + expr ::= conditionalTrue + conditionalTrue ::= expr JUMP_FORWARD expr COME_FROM ret_expr ::= expr ret_expr ::= ret_and diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index b011f064..1c530bc2 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -409,7 +409,6 @@ class Python3Parser(PythonParser): conditional ::= expr jmp_false expr jf_else expr COME_FROM conditionalnot ::= expr jmp_true expr jf_else expr COME_FROM - expr ::= LOAD_CLASSNAME # Python 3.4+ diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index ee233ae3..6570522b 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -170,6 +170,7 @@ TABLE_DIRECT = { 'or': ( '%c or %c', 0, 2 ), 'ret_or': ( '%c or %c', 0, 2 ), 'conditional': ( '%p if %p else %p', (2, 27), (0, 27), (4, 27)), + 'conditionalTrue': ( '%p if 1 else %p', (0, 27), (2, 27)), 'ret_cond': ( '%p if %p else %p', (2, 27), (0, 27), (-1, 27)), 'conditionalnot': ( '%p if not %p else %p', (2, 27), (0, 22), (4, 27)), 'ret_cond_not': ( '%p if not %p else %p', (2, 27), (0, 22), (-1, 27)),