]> granicus.if.org Git - python/commitdiff
Add utility to set filename attribute on all nodes
authorJeremy Hylton <jeremy@alum.mit.edu>
Mon, 17 Sep 2001 18:02:21 +0000 (18:02 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Mon, 17 Sep 2001 18:02:21 +0000 (18:02 +0000)
Lib/compiler/misc.py
Tools/compiler/compiler/misc.py

index 9cbd73ff23547a1e7e110be10f14d0cdcb1bee4c..b4bbe78050c261b60ef44f51f10bba3422a8b3e4 100644 (file)
@@ -64,3 +64,12 @@ def mangle(name, klass):
         klass = klass[:MANGLE_LEN-tlen]
 
     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())
+        
index 9cbd73ff23547a1e7e110be10f14d0cdcb1bee4c..b4bbe78050c261b60ef44f51f10bba3422a8b3e4 100644 (file)
@@ -64,3 +64,12 @@ def mangle(name, klass):
         klass = klass[:MANGLE_LEN-tlen]
 
     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())
+