You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Add "testtrue" reduction rule...
only for 3.7 for now.
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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 *
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user