diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-09-01 20:47:37 +0000 |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-09-01 20:47:37 +0000 |
commit | 92f397209055a0ae7599e5a7ea202f19fae8fd7b (patch) | |
tree | b9d2a72d6e90c065cc7fa7ff6351fa7dd39424ff /Lib/compiler/pycodegen.py | |
parent | 3620857d60e000300d5fa475fa9404bc535b536f (diff) | |
download | cpython-git-92f397209055a0ae7599e5a7ea202f19fae8fd7b.tar.gz |
patch by Neil Schemenauer to improve (fix?) line number generation
Diffstat (limited to 'Lib/compiler/pycodegen.py')
-rw-r--r-- | Lib/compiler/pycodegen.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index a4c9e5b18f..2a1b3081c6 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -70,6 +70,7 @@ class CodeGenerator: self.loops = misc.Stack() self.curStack = 0 self.maxStack = 0 + self.last_lineno = None self._setupGraphDelegation() def _setupGraphDelegation(self): @@ -107,7 +108,8 @@ class CodeGenerator: self.emit(prefix + '_GLOBAL', name) def set_lineno(self, node): - """Emit SET_LINENO if node has lineno attribute + """Emit SET_LINENO if node has lineno attribute and it is + different than the last lineno emitted. Returns true if SET_LINENO was emitted. @@ -117,8 +119,9 @@ class CodeGenerator: then, this method works around missing line numbers. """ lineno = getattr(node, 'lineno', None) - if lineno is not None: + if lineno is not None and lineno != self.last_lineno: self.emit('SET_LINENO', lineno) + self.last_lineno = lineno return 1 return 0 @@ -414,6 +417,7 @@ class CodeGenerator: pass def visitName(self, node): + self.set_lineno(node) self.loadName(node.name) def visitPass(self, node): |