Add utility to set filename attribute on all nodes

This commit is contained in:
Jeremy Hylton 2001-09-17 18:02:21 +00:00
parent b329b7134c
commit 09392b77a4
2 changed files with 18 additions and 0 deletions

View File

@ -64,3 +64,12 @@ def mangle(name, klass):
klass = klass[:MANGLE_LEN-tlen] klass = klass[:MANGLE_LEN-tlen]
return "_%s%s" % (klass, name) return "_%s%s" % (klass, name)
def set_filename(filename, tree):
"""Set the filename attribute to filename on every node in tree"""
worklist = [tree]
while worklist:
node = worklist.pop(0)
node.filename = filename
worklist.extend(node.getChildNodes())

View File

@ -64,3 +64,12 @@ def mangle(name, klass):
klass = klass[:MANGLE_LEN-tlen] klass = klass[:MANGLE_LEN-tlen]
return "_%s%s" % (klass, name) return "_%s%s" % (klass, name)
def set_filename(filename, tree):
"""Set the filename attribute to filename on every node in tree"""
worklist = [tree]
while worklist:
node = worklist.pop(0)
node.filename = filename
worklist.extend(node.getChildNodes())