From 1e2b89613455b925db89186d8806c6175d152205 Mon Sep 17 00:00:00 2001 From: Mysterie Date: Thu, 20 Sep 2012 12:31:22 +0200 Subject: [PATCH] Update from master branch uncompyle2 --- uncompyle2/Parser.py | 2 ++ uncompyle2/Scanner25.py | 7 ++++++- uncompyle2/Scanner26.py | 7 ++++++- uncompyle2/Scanner27.py | 6 +++++- uncompyle2/Walker.py | 3 ++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/uncompyle2/Parser.py b/uncompyle2/Parser.py index 89fc675a..cbbd7dbc 100755 --- a/uncompyle2/Parser.py +++ b/uncompyle2/Parser.py @@ -514,6 +514,8 @@ class Parser(GenericASTBuilder): while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM while1stmt ::= SETUP_LOOP return_stmts COME_FROM + while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM + whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK diff --git a/uncompyle2/Scanner25.py b/uncompyle2/Scanner25.py index 8e74051a..66af8299 100755 --- a/uncompyle2/Scanner25.py +++ b/uncompyle2/Scanner25.py @@ -168,6 +168,7 @@ class Scanner: oparg = self.get_argument(offset) + extended_arg extended_arg = 0 if op == dis.EXTENDED_ARG: + raise 'TODO' extended_arg = oparg * 65536L continue if op in dis.hasconst: @@ -746,6 +747,10 @@ class Scanner: (line_no, next_line_byte) = self.lines[pos] jump_back = self.last_instr(start, end, JA, next_line_byte, False) + if jump_back and jump_back != self.prev[end] and code[jump_back+3] in (JA, JF): + if code[self.prev[end]] == RETURN_VALUE or \ + (code[self.prev[end]] == POP_BLOCK and code[self.prev[self.prev[end]]] == RETURN_VALUE): + jump_back = None if not jump_back: # loop suite ends in return. wtf right? jump_back = self.last_instr(start, end, RETURN_VALUE) if not jump_back: @@ -785,7 +790,7 @@ class Scanner: test_target = self.get_target(test) if test_target > (jump_back+3): jump_back = test_target - + self.not_continue.add(jump_back) self.loops.append(target) self.structs.append({'type': loop_type + '-loop', 'start': target, diff --git a/uncompyle2/Scanner26.py b/uncompyle2/Scanner26.py index 9c3f6ea8..49088be4 100755 --- a/uncompyle2/Scanner26.py +++ b/uncompyle2/Scanner26.py @@ -168,6 +168,7 @@ class Scanner: oparg = self.get_argument(offset) + extended_arg extended_arg = 0 if op == dis.EXTENDED_ARG: + raise 'TODO' extended_arg = oparg * 65536L continue if op in dis.hasconst: @@ -740,6 +741,10 @@ class Scanner: (line_no, next_line_byte) = self.lines[pos] jump_back = self.last_instr(start, end, JA, next_line_byte, False) + if jump_back and jump_back != self.prev[end] and code[jump_back+3] in (JA, JF): + if code[self.prev[end]] == RETURN_VALUE or \ + (code[self.prev[end]] == POP_BLOCK and code[self.prev[self.prev[end]]] == RETURN_VALUE): + jump_back = None if not jump_back: # loop suite ends in return. wtf right? jump_back = self.last_instr(start, end, RETURN_VALUE) if not jump_back: @@ -779,7 +784,7 @@ class Scanner: test_target = self.get_target(test) if test_target > (jump_back+3): jump_back = test_target - + self.not_continue.add(jump_back) self.loops.append(target) self.structs.append({'type': loop_type + '-loop', 'start': target, diff --git a/uncompyle2/Scanner27.py b/uncompyle2/Scanner27.py index 965f731b..4561c156 100755 --- a/uncompyle2/Scanner27.py +++ b/uncompyle2/Scanner27.py @@ -538,6 +538,10 @@ class Scanner: (line_no, next_line_byte) = self.lines[pos] jump_back = self.last_instr(start, end, JA, next_line_byte, False) + if jump_back and jump_back != self.prev[end] and code[jump_back+3] in (JA, JF): + if code[self.prev[end]] == RETURN_VALUE or \ + (code[self.prev[end]] == POP_BLOCK and code[self.prev[self.prev[end]]] == RETURN_VALUE): + jump_back = None if not jump_back: # loop suite ends in return. wtf right? jump_back = self.last_instr(start, end, RETURN_VALUE) + 1 if not jump_back: @@ -576,7 +580,7 @@ class Scanner: test_target = self.get_target(test) if test_target > (jump_back+3): jump_back = test_target - + self.not_continue.add(jump_back) self.loops.append(target) self.structs.append({'type': loop_type + '-loop', 'start': target, diff --git a/uncompyle2/Walker.py b/uncompyle2/Walker.py index 98ec3d9a..03ba9353 100755 --- a/uncompyle2/Walker.py +++ b/uncompyle2/Walker.py @@ -258,6 +258,7 @@ TABLE_DIRECT = { 'whilestmt': ( '%|while %c:\n%+%c%-\n\n', 1, 2 ), 'while1stmt': ( '%|while 1:\n%+%c%-\n\n', 1 ), + 'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 3 ), 'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ), 'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ), 'forstmt': ( '%|for %c in %c:\n%+%c%-\n\n', 3, 1, 4 ), @@ -1360,7 +1361,7 @@ class Walker(GenericASTTraversal, object): #else: # print ast[-1][-1] - for g in find_globals(ast, {}).keys(): + for g in find_globals(ast, set()): self.print_(indent, 'global ', g) self.gen_source(ast, code._customize)