diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-12-24 08:49:50 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-12-24 08:49:50 -0500 |
commit | b17f27672208a07318f8aa62a1bd64b18e9961d1 (patch) | |
tree | 450d61783f4aff46a5f07c2b78ca3fcd27228aca /lab/parser.py | |
parent | ae91d45616dbc4dddcd66955b41ffb5fa420ddda (diff) | |
download | python-coveragepy-git-b17f27672208a07318f8aa62a1bd64b18e9961d1.tar.gz |
WIP: measure branches with ast instead of bytecode
--HG--
branch : ast-branch
Diffstat (limited to 'lab/parser.py')
-rw-r--r-- | lab/parser.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lab/parser.py b/lab/parser.py index 1a679e8c..9a064257 100644 --- a/lab/parser.py +++ b/lab/parser.py @@ -82,7 +82,7 @@ class ParserMain(object): if options.dis: print("Main code:") - self.disassemble(bp, histogram=options.histogram) + self.disassemble(bp, chunks=options.chunks, histogram=options.histogram) arcs = bp._all_arcs() if options.chunks: @@ -123,15 +123,20 @@ class ParserMain(object): m2 = 'C' if lineno in cp.raw_excluded: m3 = 'x' - a = arc_chars[lineno].ljust(arc_width) + + if arc_chars: + a = arc_chars[lineno].ljust(arc_width) + else: + a = "" + print("%4d %s%s%s%s%s %s" % (lineno, m0, m1, m2, m3, a, ltext)) - def disassemble(self, byte_parser, histogram=False): + def disassemble(self, byte_parser, chunks=False, histogram=False): """Disassemble code, for ad-hoc experimenting.""" for bp in byte_parser.child_parsers(): - chunks = bp._split_into_chunks() - chunkd = dict((chunk.byte, chunk) for chunk in chunks) + if chunks: + chunkd = dict((chunk.byte, chunk) for chunk in bp._split_into_chunks()) if bp.text: srclines = bp.text.splitlines() else: @@ -151,11 +156,11 @@ class ParserMain(object): elif disline.offset > 0: print("") line = disgen.format_dis_line(disline) - chunk = chunkd.get(disline.offset) - if chunk: - chunkstr = ":: %r" % chunk - else: - chunkstr = "" + chunkstr = "" + if chunks: + chunk = chunkd.get(disline.offset) + if chunk: + chunkstr = ":: %r" % chunk print("%-70s%s" % (line, chunkstr)) print("") |