Add "testtrue" reduction rule...

only for 3.7 for now.
This commit is contained in:
rocky
2020-01-10 10:26:40 -05:00
parent 07f16fa040
commit 505946d747
5 changed files with 16 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ function displaytime {
printf '%d seconds\n' $S printf '%d seconds\n' $S
} }
# Python version setup
FULLVERSION=$(pyenv local) FULLVERSION=$(pyenv local)
PYVERSION=${FULLVERSION%.*} PYVERSION=${FULLVERSION%.*}
MINOR=${FULLVERSION##?.?.} MINOR=${FULLVERSION##?.?.}
@@ -196,7 +197,9 @@ case $PYVERSION in
3.3) 3.3)
SKIP_TESTS=( SKIP_TESTS=(
[test_ast.py]=1 # Investigate: syntax error
[test_atexit.py]=1 # [test_atexit.py]=1 #
[test_cmd_line.py]=1 # too long?
) )
if (( batch )) ; then if (( batch )) ; then
# Fails in crontab environment? # Fails in crontab environment?
@@ -496,7 +499,7 @@ srcdir=$(dirname $me)
cd $srcdir cd $srcdir
fulldir=$(pwd) fulldir=$(pwd)
# Python version setup # pyenv version cleaning
for dir in .. ../.. ; do for dir in .. ../.. ; do
(cd $dir && [[ -r .python-version ]] && rm -v .python-version ) (cd $dir && [[ -r .python-version ]] && rm -v .python-version )
done done
@@ -583,7 +586,7 @@ typeset -i ALL_FILES_ENDTIME=$(date +%s)
(( time_diff = ALL_FILES_ENDTIME - ALL_FILES_STARTTIME)) (( 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 displaytime $time_diff
echo "Skipped $skipped test for known failures." echo "Skipped $skipped test for known failures."
cd $fulldir/../.. && pyenv local $FULLVERSION cd $fulldir/../.. && pyenv local $FULLVERSION

View File

@@ -29,7 +29,7 @@ that a later phase can turn into a sequence of ASCII text.
import re import re
from uncompyle6.scanners.tok import Token from uncompyle6.scanners.tok import Token
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func 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 uncompyle6.parsers.treenode import SyntaxTree
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from xdis import PYTHON3 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 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 JUMP_IF_TRUE_OR_POP expr COME_FROM
or ::= expr jmp_true expr
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM
# compare_chained1 is used exclusively in chained_compare # compare_chained1 is used exclusively in chained_compare
@@ -1464,6 +1465,7 @@ class Python3Parser(PythonParser):
self.check_reduce["ifstmt"] = "AST" self.check_reduce["ifstmt"] = "AST"
self.check_reduce["annotate_tuple"] = "noAST" self.check_reduce["annotate_tuple"] = "noAST"
self.check_reduce["except_handler_else"] = "tokens" self.check_reduce["except_handler_else"] = "tokens"
self.check_reduce["testtrue"] = "tokens"
if not PYTHON3: if not PYTHON3:
self.check_reduce["kwarg"] = "noAST" self.check_reduce["kwarg"] = "noAST"
if self.version < 3.6: if self.version < 3.6:
@@ -1504,6 +1506,8 @@ class Python3Parser(PythonParser):
last -= 1 last -= 1
jump_forward_else = ast[2] jump_forward_else = ast[2]
return tokens[first].off2int() <= jump_forward_else[0].attr < tokens[last].off2int() 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": elif lhs == "while1stmt":
# If there is a fall through to the COME_FROM_LOOP, then this is # If there is a fall through to the COME_FROM_LOOP, then this is

View File

@@ -14,6 +14,7 @@ from uncompyle6.parsers.reducecheck import (
ifstmt, ifstmt,
ifstmts_jump, ifstmts_jump,
or_check, or_check,
testtrue,
while1stmt, while1stmt,
while1elsestmt, while1elsestmt,
) )
@@ -1001,6 +1002,7 @@ class Python37BaseParser(PythonParser):
self.check_reduce["ifstmtl"] = "AST" self.check_reduce["ifstmtl"] = "AST"
self.check_reduce["import_from37"] = "AST" self.check_reduce["import_from37"] = "AST"
self.check_reduce["or"] = "AST" self.check_reduce["or"] = "AST"
self.check_reduce["testtrue"] = "tokens"
return return
def custom_classfunc_rule(self, opname, token, customize, next_token): 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) return or_check(self, lhs, n, rule, ast, tokens, first, last)
elif lhs == "while1elsestmt": elif lhs == "while1elsestmt":
return while1elsestmt(self, lhs, n, rule, ast, tokens, first, last) 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": elif lhs == "while1stmt":
return while1stmt(self, lhs, n, rule, ast, tokens, first, last) return while1stmt(self, lhs, n, rule, ast, tokens, first, last)

View File

@@ -5,6 +5,7 @@ from uncompyle6.parsers.reducecheck.iflaststmt import *
from uncompyle6.parsers.reducecheck.ifstmt import * from uncompyle6.parsers.reducecheck.ifstmt import *
from uncompyle6.parsers.reducecheck.ifstmts_jump import * from uncompyle6.parsers.reducecheck.ifstmts_jump import *
from uncompyle6.parsers.reducecheck.or_check import * from uncompyle6.parsers.reducecheck.or_check import *
from uncompyle6.parsers.reducecheck.testtrue import *
from uncompyle6.parsers.reducecheck.tryelsestmt import * from uncompyle6.parsers.reducecheck.tryelsestmt import *
from uncompyle6.parsers.reducecheck.while1elsestmt import * from uncompyle6.parsers.reducecheck.while1elsestmt import *
from uncompyle6.parsers.reducecheck.while1stmt import * from uncompyle6.parsers.reducecheck.while1stmt import *

View File

@@ -520,6 +520,7 @@ class Scanner37Base(Scanner):
offset = inst.offset offset = inst.offset
op = inst.opcode op = inst.opcode
# FIXME: this code is going to get removed.
# Determine structures and fix jumps in Python versions # Determine structures and fix jumps in Python versions
# since 2.3 # since 2.3
self.detect_control_flow(offset, targets, i) self.detect_control_flow(offset, targets, i)