summaryrefslogtreecommitdiff
path: root/coverage/parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-04-18 09:31:59 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-04-18 09:31:59 -0400
commitdf2d7500786e991d9def8a2ec3d4fbdf6f37af3a (patch)
tree00e3e8c728eb82ab3aa53e67f21dcff7462cc9c3 /coverage/parser.py
parent416d324374b09c516e129f0a13fd8f15206f2c78 (diff)
downloadpython-coveragepy-git-df2d7500786e991d9def8a2ec3d4fbdf6f37af3a.tar.gz
Put all chunk/arc logic in one place.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r--coverage/parser.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/coverage/parser.py b/coverage/parser.py
index 91b685ce..cb0fc1fc 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -430,9 +430,10 @@ class ByteParser(object):
Returns a list of `Chunk` objects.
"""
- # The list of chunks so far, and the one we're working on.
- chunks = []
- chunk = None
+ # The list of chunks so far, and the one we're working on. We always
+ # start with an entrance to the code object.
+ chunk = Chunk(0, -1, True)
+ chunks = [chunk]
# A dict mapping byte offsets of line starts to the line numbers.
bytes_lines_map = dict(self._bytes_lines())
@@ -460,7 +461,7 @@ class ByteParser(object):
# Walk the byte codes building chunks.
for bc in bytecodes:
- # Maybe have to start a new chunk
+ # Maybe have to start a new chunk.
start_new_chunk = False
first_chunk = False
if bc.offset in bytes_lines_map:
@@ -483,7 +484,7 @@ class ByteParser(object):
chunk = Chunk(bc.offset, chunk_lineno, first_chunk)
chunks.append(chunk)
- # Look at the opcode
+ # Look at the opcode.
if bc.jump_to >= 0 and bc.op not in OPS_NO_JUMP:
if ignore_branch:
# Someone earlier wanted us to ignore this branch.
@@ -573,9 +574,6 @@ class ByteParser(object):
# A map from byte offsets to chunks jumped into.
byte_chunks = dict((c.byte, c) for c in chunks)
- # There's always an entrance at the first chunk.
- yield (-1, byte_chunks[0].line)
-
# Traverse from the first chunk in each line, and yield arcs where
# the trace function will be invoked.
for chunk in chunks:
@@ -586,7 +584,7 @@ class ByteParser(object):
chunks_to_consider = [chunk]
while chunks_to_consider:
# Get the chunk we're considering, and make sure we don't
- # consider it again
+ # consider it again.
this_chunk = chunks_to_consider.pop()
chunks_considered.add(this_chunk)