Skip to content

Commit bec88e4

Browse files
committed
Name phases "disassembly" and "tokenization"
1 parent b88af23 commit bec88e4

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

uncompyle6/scanners/scanner2.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015-2023 by Rocky Bernstein
1+
# Copyright (c) 2015-2024 by Rocky Bernstein
22
# Copyright (c) 2005 by Dan Pascu <[email protected]>
33
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
44
#
@@ -36,12 +36,12 @@
3636
from __future__ import print_function
3737

3838
from copy import copy
39+
from sys import intern
3940

40-
from xdis import code2num, iscode, op_has_argument, instruction_size
41+
from xdis import code2num, instruction_size, iscode, op_has_argument
4142
from xdis.bytecode import _get_const_info
42-
from uncompyle6.scanner import Scanner, Token
4343

44-
from sys import intern
44+
from uncompyle6.scanner import Scanner, Token
4545

4646

4747
class Scanner2(Scanner):
@@ -206,7 +206,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
206206
bytecode = self.build_instructions(co)
207207

208208
if show_asm in ("both", "before"):
209-
print("\n# ---- before tokenization:")
209+
print("\n# ---- disassembly:")
210210
bytecode.disassemble_bytes(
211211
co.co_code,
212212
varnames=co.co_varnames,
@@ -235,7 +235,6 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
235235
# 'LOAD_ASSERT' is used in assert statements.
236236
self.load_asserts = set()
237237
for i in self.op_range(0, codelen):
238-
239238
# We need to detect the difference between:
240239
# raise AssertionError
241240
# and
@@ -327,9 +326,14 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
327326
"BUILD_SET",
328327
):
329328
t = Token(
330-
op_name, oparg, pattr, offset,
329+
op_name,
330+
oparg,
331+
pattr,
332+
offset,
331333
self.linestarts.get(offset, None),
332-
op, has_arg, self.opc
334+
op,
335+
has_arg,
336+
self.opc,
333337
)
334338
collection_type = op_name.split("_")[1]
335339
next_tokens = self.bound_collection_from_tokens(
@@ -490,7 +494,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
490494
pass
491495

492496
if show_asm in ("both", "after"):
493-
print("\n# ---- after tokenization:")
497+
print("\n# ---- tokenization:")
494498
for t in new_tokens:
495499
print(t.format(line_prefix=""))
496500
print()
@@ -540,14 +544,17 @@ def build_statement_indices(self):
540544
for s in stmt_list:
541545
if code[s] == self.opc.JUMP_ABSOLUTE and s not in pass_stmts:
542546
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+
):
544550
stmts.remove(s)
545551
continue
546552
j = self.prev[s]
547553
while code[j] == self.opc.JUMP_ABSOLUTE:
548554
j = self.prev[j]
549555
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"
551558
): # list comprehension
552559
stmts.remove(s)
553560
continue
@@ -924,7 +931,6 @@ def detect_control_flow(self, offset, op, extended_arg):
924931

925932
# Is it an "and" inside an "if" or "while" block
926933
if op == self.opc.PJIF:
927-
928934
# Search for other POP_JUMP_IF_...'s targeting the
929935
# same target, of the current POP_JUMP_... instruction,
930936
# starting from current offset, and filter everything inside inner 'or'
@@ -1116,7 +1122,6 @@ def detect_control_flow(self, offset, op, extended_arg):
11161122

11171123
# Is this a loop and not an "if" statement?
11181124
if (if_end < pre_rtarget) and (pre[if_end] in self.setup_loop_targets):
1119-
11201125
if if_end > start:
11211126
return
11221127
else:

uncompyle6/scanners/scanner26.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015-2017, 2021-2022 by Rocky Bernstein
1+
# Copyright (c) 2015-2017, 2021-2022, 2024 by Rocky Bernstein
22
# Copyright (c) 2005 by Dan Pascu <[email protected]>
33
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
44
#
@@ -80,7 +80,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
8080

8181
# show_asm = 'after'
8282
if show_asm in ("both", "before"):
83-
print("\n# ---- before tokenization:")
83+
print("\n# ---- disassembly:")
8484
for instr in bytecode.get_instructions(co):
8585
print(instr.disassemble(self.opc))
8686

@@ -346,7 +346,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
346346
pass
347347

348348
if show_asm in ("both", "after"):
349-
print("\n# ---- after tokenization:")
349+
print("\n# ---- tokenization:")
350350
for t in tokens:
351351
print(t.format(line_prefix=""))
352352
print()

uncompyle6/scanners/scanner3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def ingest(
418418

419419
# show_asm = 'both'
420420
if show_asm in ("both", "before"):
421-
print("\n# ---- before tokenization:")
421+
print("\n# ---- disassembly:")
422422
bytecode.disassemble_bytes(
423423
co.co_code,
424424
varnames=co.co_varnames,
@@ -788,7 +788,7 @@ def ingest(
788788
pass
789789

790790
if show_asm in ("both", "after"):
791-
print("\n# ---- after tokenization:")
791+
print("\n# ---- tokenization:")
792792
for t in new_tokens:
793793
print(t.format(line_prefix=""))
794794
print()

0 commit comments

Comments
 (0)