From 505946d747d9ae6e4d5e1d134eae4aba971a33e5 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 10 Jan 2020 10:26:40 -0500 Subject: [PATCH] Add "testtrue" reduction rule... only for 3.7 for now. --- test/stdlib/runtests.sh | 7 +++++-- uncompyle6/parsers/parse3.py | 6 +++++- uncompyle6/parsers/parse37base.py | 4 ++++ uncompyle6/parsers/reducecheck/__init__.py | 1 + uncompyle6/scanners/scanner37base.py | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/stdlib/runtests.sh b/test/stdlib/runtests.sh index ad3610ef..36526205 100755 --- a/test/stdlib/runtests.sh +++ b/test/stdlib/runtests.sh @@ -21,6 +21,7 @@ function displaytime { printf '%d seconds\n' $S } +# Python version setup FULLVERSION=$(pyenv local) PYVERSION=${FULLVERSION%.*} MINOR=${FULLVERSION##?.?.} @@ -196,7 +197,9 @@ case $PYVERSION in 3.3) SKIP_TESTS=( + [test_ast.py]=1 # Investigate: syntax error [test_atexit.py]=1 # + [test_cmd_line.py]=1 # too long? ) if (( batch )) ; then # Fails in crontab environment? @@ -496,7 +499,7 @@ srcdir=$(dirname $me) cd $srcdir fulldir=$(pwd) -# Python version setup +# pyenv version cleaning for dir in .. ../.. ; do (cd $dir && [[ -r .python-version ]] && rm -v .python-version ) done @@ -583,7 +586,7 @@ typeset -i ALL_FILES_ENDTIME=$(date +%s) (( time_diff = ALL_FILES_ENDTIME - ALL_FILES_STARTTIME)) -printf "Ran $i unit-test files in " +printf "Ran $i unit-test files, $allerrs errors; Elapsed time: " displaytime $time_diff echo "Skipped $skipped test for known failures." cd $fulldir/../.. && pyenv local $FULLVERSION diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 900f84bc..2210dd2f 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -29,7 +29,7 @@ that a later phase can turn into a sequence of ASCII text. import re from uncompyle6.scanners.tok import Token from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func -from uncompyle6.parsers.reducecheck import except_handler_else +from uncompyle6.parsers.reducecheck import except_handler_else, testtrue from uncompyle6.parsers.treenode import SyntaxTree from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from xdis import PYTHON3 @@ -317,6 +317,7 @@ class Python3Parser(PythonParser): ret_cond ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM ret_expr_or_cond or ::= expr JUMP_IF_TRUE_OR_POP expr COME_FROM + or ::= expr jmp_true expr and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM # compare_chained1 is used exclusively in chained_compare @@ -1464,6 +1465,7 @@ class Python3Parser(PythonParser): self.check_reduce["ifstmt"] = "AST" self.check_reduce["annotate_tuple"] = "noAST" self.check_reduce["except_handler_else"] = "tokens" + self.check_reduce["testtrue"] = "tokens" if not PYTHON3: self.check_reduce["kwarg"] = "noAST" if self.version < 3.6: @@ -1504,6 +1506,8 @@ class Python3Parser(PythonParser): last -= 1 jump_forward_else = ast[2] return tokens[first].off2int() <= jump_forward_else[0].attr < tokens[last].off2int() + elif lhs == "testtrue": + return testtrue(self, lhs, n, rule, ast, tokens, first, last) elif lhs == "while1stmt": # If there is a fall through to the COME_FROM_LOOP, then this is diff --git a/uncompyle6/parsers/parse37base.py b/uncompyle6/parsers/parse37base.py index e250135f..915fd22d 100644 --- a/uncompyle6/parsers/parse37base.py +++ b/uncompyle6/parsers/parse37base.py @@ -14,6 +14,7 @@ from uncompyle6.parsers.reducecheck import ( ifstmt, ifstmts_jump, or_check, + testtrue, while1stmt, while1elsestmt, ) @@ -1001,6 +1002,7 @@ class Python37BaseParser(PythonParser): self.check_reduce["ifstmtl"] = "AST" self.check_reduce["import_from37"] = "AST" self.check_reduce["or"] = "AST" + self.check_reduce["testtrue"] = "tokens" return def custom_classfunc_rule(self, opname, token, customize, next_token): @@ -1112,6 +1114,8 @@ class Python37BaseParser(PythonParser): return or_check(self, lhs, n, rule, ast, tokens, first, last) elif lhs == "while1elsestmt": return while1elsestmt(self, lhs, n, rule, ast, tokens, first, last) + elif lhs == "testtrue": + return testtrue(self, lhs, n, rule, ast, tokens, first, last) elif lhs == "while1stmt": return while1stmt(self, lhs, n, rule, ast, tokens, first, last) diff --git a/uncompyle6/parsers/reducecheck/__init__.py b/uncompyle6/parsers/reducecheck/__init__.py index e5f50202..edd374e1 100644 --- a/uncompyle6/parsers/reducecheck/__init__.py +++ b/uncompyle6/parsers/reducecheck/__init__.py @@ -5,6 +5,7 @@ from uncompyle6.parsers.reducecheck.iflaststmt import * from uncompyle6.parsers.reducecheck.ifstmt import * from uncompyle6.parsers.reducecheck.ifstmts_jump import * from uncompyle6.parsers.reducecheck.or_check import * +from uncompyle6.parsers.reducecheck.testtrue import * from uncompyle6.parsers.reducecheck.tryelsestmt import * from uncompyle6.parsers.reducecheck.while1elsestmt import * from uncompyle6.parsers.reducecheck.while1stmt import * diff --git a/uncompyle6/scanners/scanner37base.py b/uncompyle6/scanners/scanner37base.py index b8c9775e..89240bc1 100644 --- a/uncompyle6/scanners/scanner37base.py +++ b/uncompyle6/scanners/scanner37base.py @@ -520,6 +520,7 @@ class Scanner37Base(Scanner): offset = inst.offset op = inst.opcode + # FIXME: this code is going to get removed. # Determine structures and fix jumps in Python versions # since 2.3 self.detect_control_flow(offset, targets, i)