From 406df297df9d54fb8273b076c16c3e323c2428f6 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 7 May 2016 23:29:23 -0400 Subject: [PATCH] Python 3 build class parsing --- test/bytecode_3.5/07_classparam.pyc | Bin 0 -> 370 bytes test/simple_source/def/07_classparam.py | 6 ++++++ uncompyle6/parsers/parse3.py | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/bytecode_3.5/07_classparam.pyc create mode 100644 test/simple_source/def/07_classparam.py diff --git a/test/bytecode_3.5/07_classparam.pyc b/test/bytecode_3.5/07_classparam.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b511f7f683fa3ec6ab76f260e6aeb25fc85ada66 GIT binary patch literal 370 zcmYLEu};G<5IrYNi9#!NVvg7%RV|2t1)(m8jim!pmy;D66v>W*ogkI9{0uXH!swNW zUtr>#(AM%jpYQqIJD*Lb+2!Zr@e2UHDGqB)*^0tl5eV806o6*1VZiQ11R{oaD#svM zKrw<{1iKhEL?y5;#y=#4g88iGT8g%7lq^GOzZfMe3O6H=5E_$DkTa4;KDm39b^B1n zK1B>Y5PgQIjp$U!Cx|Z{R|E3__JrE>@O$nmO>XE+XG^&h@@aW-jiutwHQaK&Xtp+{ z*GX`X2qvt*zvXSELEUSQ_CuBu;nSO8 L+S}3IX~zBl-Ahty literal 0 HcmV?d00001 diff --git a/test/simple_source/def/07_classparam.py b/test/simple_source/def/07_classparam.py new file mode 100644 index 00000000..6d3fcfe6 --- /dev/null +++ b/test/simple_source/def/07_classparam.py @@ -0,0 +1,6 @@ +# Tests Python 3: +# build_class ::= LOAD_BUILD_CLASS mkfunc expr call_function CALL_FUNCTION_3 + +from collections import namedtuple +class Event(namedtuple('Event', 'time, priority, action, argument')): + pass diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index c0f58b58..646a5d2b 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -393,9 +393,14 @@ class Python3Parser(PythonParser): def custom_build_class_rule(self, opname, i, token, tokens, customize): """ + # Should the first rule be somehow folded into the 2nd one? build_class ::= LOAD_BUILD_CLASS mkfunc LOAD_CLASSNAME {expr}^n CALL_FUNCTION_n+2 LOAD_CONST CALL_FUNCTION_n + build_class ::= LOAD_BUILD_CLASS mkfunc + expr + call_function + CALL_FUNCTION_3 """ # FIXME: I bet this can be simplified # look for next MAKE_FUNCTION @@ -405,14 +410,14 @@ class Python3Parser(PythonParser): pass assert i < len(tokens), "build_class needs to find MAKE_FUNCTION" assert tokens[i+1].type == 'LOAD_CONST', \ - "build_class expecing CONST after MAKE_FUNCTION" + "build_class expecting CONST after MAKE_FUNCTION" for i in range(i, len(tokens)): if tokens[i].type == 'CALL_FUNCTION': call_fn_tok = tokens[i] break assert call_fn_tok, "build_class custom rule needs to find CALL_FUNCTION" - # customize CALL_FUNCTION + # customize build_class rule call_function = self.call_fn_name(call_fn_tok) args_pos = call_fn_tok.attr & 0xff args_kw = (call_fn_tok.attr >> 8) & 0xff @@ -420,6 +425,11 @@ class Python3Parser(PythonParser): "%s" % (('expr ' * (args_pos - 1) + ('kwarg ' * args_kw)), call_function)) self.add_unique_rule(rule, opname, token.attr, customize) + + # Can the above build_class rule be folded into this rule? + rule = ("build_class ::= LOAD_BUILD_CLASS mkfunc expr call_function " + "CALL_FUNCTION_" + str(args_pos+1)) + self.add_unique_rule(rule, opname, token.attr, customize) return def custom_classfunc_rule(self, opname, token, customize):