|
1 |
| -# Copyright (c) 2015-2023 by Rocky Bernstein |
| 1 | +# Copyright (c) 2015-2024 by Rocky Bernstein |
2 | 2 | # Copyright (c) 2005 by Dan Pascu <[email protected]>
|
3 | 3 | # Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
|
4 | 4 | #
|
|
36 | 36 | from __future__ import print_function
|
37 | 37 |
|
38 | 38 | from copy import copy
|
| 39 | +from sys import intern |
39 | 40 |
|
40 |
| -from xdis import code2num, iscode, op_has_argument, instruction_size |
| 41 | +from xdis import code2num, instruction_size, iscode, op_has_argument |
41 | 42 | from xdis.bytecode import _get_const_info
|
42 |
| -from uncompyle6.scanner import Scanner, Token |
43 | 43 |
|
44 |
| -from sys import intern |
| 44 | +from uncompyle6.scanner import Scanner, Token |
45 | 45 |
|
46 | 46 |
|
47 | 47 | class Scanner2(Scanner):
|
@@ -206,7 +206,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
206 | 206 | bytecode = self.build_instructions(co)
|
207 | 207 |
|
208 | 208 | if show_asm in ("both", "before"):
|
209 |
| - print("\n# ---- before tokenization:") |
| 209 | + print("\n# ---- disassembly:") |
210 | 210 | bytecode.disassemble_bytes(
|
211 | 211 | co.co_code,
|
212 | 212 | varnames=co.co_varnames,
|
@@ -235,7 +235,6 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
235 | 235 | # 'LOAD_ASSERT' is used in assert statements.
|
236 | 236 | self.load_asserts = set()
|
237 | 237 | for i in self.op_range(0, codelen):
|
238 |
| - |
239 | 238 | # We need to detect the difference between:
|
240 | 239 | # raise AssertionError
|
241 | 240 | # and
|
@@ -327,9 +326,14 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
327 | 326 | "BUILD_SET",
|
328 | 327 | ):
|
329 | 328 | t = Token(
|
330 |
| - op_name, oparg, pattr, offset, |
| 329 | + op_name, |
| 330 | + oparg, |
| 331 | + pattr, |
| 332 | + offset, |
331 | 333 | self.linestarts.get(offset, None),
|
332 |
| - op, has_arg, self.opc |
| 334 | + op, |
| 335 | + has_arg, |
| 336 | + self.opc, |
333 | 337 | )
|
334 | 338 | collection_type = op_name.split("_")[1]
|
335 | 339 | next_tokens = self.bound_collection_from_tokens(
|
@@ -490,7 +494,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
490 | 494 | pass
|
491 | 495 |
|
492 | 496 | if show_asm in ("both", "after"):
|
493 |
| - print("\n# ---- after tokenization:") |
| 497 | + print("\n# ---- tokenization:") |
494 | 498 | for t in new_tokens:
|
495 | 499 | print(t.format(line_prefix=""))
|
496 | 500 | print()
|
@@ -540,14 +544,17 @@ def build_statement_indices(self):
|
540 | 544 | for s in stmt_list:
|
541 | 545 | if code[s] == self.opc.JUMP_ABSOLUTE and s not in pass_stmts:
|
542 | 546 | target = self.get_target(s)
|
543 |
| - if target > s or (self.lines and self.lines[last_stmt].l_no == self.lines[s].l_no): |
| 547 | + if target > s or ( |
| 548 | + self.lines and self.lines[last_stmt].l_no == self.lines[s].l_no |
| 549 | + ): |
544 | 550 | stmts.remove(s)
|
545 | 551 | continue
|
546 | 552 | j = self.prev[s]
|
547 | 553 | while code[j] == self.opc.JUMP_ABSOLUTE:
|
548 | 554 | j = self.prev[j]
|
549 | 555 | if (
|
550 |
| - self.version >= (2, 3) and self.opname_for_offset(j) == "LIST_APPEND" |
| 556 | + self.version >= (2, 3) |
| 557 | + and self.opname_for_offset(j) == "LIST_APPEND" |
551 | 558 | ): # list comprehension
|
552 | 559 | stmts.remove(s)
|
553 | 560 | continue
|
@@ -924,7 +931,6 @@ def detect_control_flow(self, offset, op, extended_arg):
|
924 | 931 |
|
925 | 932 | # Is it an "and" inside an "if" or "while" block
|
926 | 933 | if op == self.opc.PJIF:
|
927 |
| - |
928 | 934 | # Search for other POP_JUMP_IF_...'s targeting the
|
929 | 935 | # same target, of the current POP_JUMP_... instruction,
|
930 | 936 | # starting from current offset, and filter everything inside inner 'or'
|
@@ -1116,7 +1122,6 @@ def detect_control_flow(self, offset, op, extended_arg):
|
1116 | 1122 |
|
1117 | 1123 | # Is this a loop and not an "if" statement?
|
1118 | 1124 | if (if_end < pre_rtarget) and (pre[if_end] in self.setup_loop_targets):
|
1119 |
| - |
1120 | 1125 | if if_end > start:
|
1121 | 1126 | return
|
1122 | 1127 | else:
|
|
0 commit comments