summaryrefslogtreecommitdiff
path: root/rebuilder.py
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-01-21 17:41:41 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-01-21 17:41:41 +0100
commitece63ef432fc131bb3372df912c3dae7b1a8b7a9 (patch)
tree1237249876b02c9e1e9edc47701005d9bfd350fe /rebuilder.py
parent13c8cb6bf539e411f4c2913fe04648b4d947565c (diff)
downloadastroid-git-ece63ef432fc131bb3372df912c3dae7b1a8b7a9.tar.gz
fix some more infos
--HG-- branch : rebuild
Diffstat (limited to 'rebuilder.py')
-rw-r--r--rebuilder.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/rebuilder.py b/rebuilder.py
index f8fff89a..8db0cc34 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -34,11 +34,12 @@ def _check_children(node):
"""a helper function to check children - parent relations"""
for child in node.get_children():
if not hasattr(child, 'parent'):
- print " %s has child %s %x with no parent" % (node, child, id(child))
+ print " ERROR: %s has child %s %x with no parent" % (node, child, id(child))
elif not child.parent:
- print " %s has child %s %x with parent %r" % (node, child, id(child), child.parent)
+ print " ERROR: %s has child %s %x with parent %r" % (node, child, id(child), child.parent)
elif child.parent is not node:
- print " child %s %x has not parent %s %x" % (child, id(child), node, id(node))
+ print " ERROR: %s %x has child %s %x with wrong parent %s" % (node,
+ id(node), child, id(child), child.parent)
_check_children(child)
@@ -76,15 +77,20 @@ class RebuildVisitor(ASTVisitor):
def set_infos(self, newnode, oldnode):
"""set parent and line number infos"""
+ # some nodes are created by the TreeRebuilder without going through
+ # the visit method; hence we have to set infos explicitly
child = None
for child in newnode.get_children():
if child is not None:
child.parent = newnode
else:
print "newnode %s has None as child" % newnode
+ if hasattr(oldnode, 'lineno'):
+ newnode.lineno = oldnode.lineno
# newnode.set_line_info(child)
def walk(self, node):
+ """start the walk down the tree and do some work after it"""
newnode = self.visit(node, None)
_check_children(newnode)
for name, nodes in self._delayed.items():
@@ -307,5 +313,6 @@ class RebuildVisitor(ASTVisitor):
newnode.name = self.visit(excobj, node)
self.asscontext = None
newnode.body = [self.visit(child, node) for child in body]
+ self.set_infos(newnode, node)
return newnode