# HG changeset patch # User paulb@jeremy # Date 1161392016 -7200 # Node ID 83eac7448e9d71ef8982027d477d9603458b1999 # Parent c5c392d882dd107c2a0e2c3ec97479376509dfdc Changed module naming. diff -r c5c392d882dd -r 83eac7448e9d simplify.py --- a/simplify.py Sat Oct 21 02:52:41 2006 +0200 +++ b/simplify.py Sat Oct 21 02:53:36 2006 +0200 @@ -40,6 +40,7 @@ from simplified import * import compiler.ast +import os class Simplifier(Visitor): @@ -82,8 +83,8 @@ self.visitor = self - def process(self, node): - result = self.dispatch(node) + def process(self, node, name): + result = self.dispatch(node, name) result.simplifier = self return result @@ -106,14 +107,15 @@ # Relatively trivial transformations. - def visitModule(self, module): + def visitModule(self, module, name=None): """ Process the given 'module', producing a Module object which contains the - resulting program nodes. + resulting program nodes. If the optional 'name' is provided, the 'name' + attribute is set on the Module object using a value other than None. """ - result = Module(module, 1, name="module") + result = Module(module, 1, name=name) module_code = self.dispatch(module.node) # NOTE: Constant initialisation necessary for annotation but perhaps @@ -1199,15 +1201,21 @@ def simplify(filename, builtins=0): """ - Simplify the module stored in the file with the given 'filename'. If the - optional 'builtins' parameter is set to a true value (the default being a - false value), then the module is considered as the builtins module. + Simplify the module stored in the file with the given 'filename'. + + If the optional 'builtins' parameter is set to a true value (the default + being a false value), then the module is considered as the builtins module. """ simplifier = Simplifier(builtins) module = compiler.parseFile(filename) - simplified = simplifier.process(module) compiler.misc.set_filename(filename, module) + if builtins: + name = "__builtins__" + else: + path, ext = os.path.splitext(filename) + path, name = os.path.split(path) + simplified = simplifier.process(module, name) return simplified # vim: tabstop=4 expandtab shiftwidth=4