1.1 --- a/simplify.py Sat Oct 21 02:52:41 2006 +0200
1.2 +++ b/simplify.py Sat Oct 21 02:53:36 2006 +0200
1.3 @@ -40,6 +40,7 @@
1.4
1.5 from simplified import *
1.6 import compiler.ast
1.7 +import os
1.8
1.9 class Simplifier(Visitor):
1.10
1.11 @@ -82,8 +83,8 @@
1.12
1.13 self.visitor = self
1.14
1.15 - def process(self, node):
1.16 - result = self.dispatch(node)
1.17 + def process(self, node, name):
1.18 + result = self.dispatch(node, name)
1.19 result.simplifier = self
1.20 return result
1.21
1.22 @@ -106,14 +107,15 @@
1.23
1.24 # Relatively trivial transformations.
1.25
1.26 - def visitModule(self, module):
1.27 + def visitModule(self, module, name=None):
1.28
1.29 """
1.30 Process the given 'module', producing a Module object which contains the
1.31 - resulting program nodes.
1.32 + resulting program nodes. If the optional 'name' is provided, the 'name'
1.33 + attribute is set on the Module object using a value other than None.
1.34 """
1.35
1.36 - result = Module(module, 1, name="module")
1.37 + result = Module(module, 1, name=name)
1.38 module_code = self.dispatch(module.node)
1.39
1.40 # NOTE: Constant initialisation necessary for annotation but perhaps
1.41 @@ -1199,15 +1201,21 @@
1.42 def simplify(filename, builtins=0):
1.43
1.44 """
1.45 - Simplify the module stored in the file with the given 'filename'. If the
1.46 - optional 'builtins' parameter is set to a true value (the default being a
1.47 - false value), then the module is considered as the builtins module.
1.48 + Simplify the module stored in the file with the given 'filename'.
1.49 +
1.50 + If the optional 'builtins' parameter is set to a true value (the default
1.51 + being a false value), then the module is considered as the builtins module.
1.52 """
1.53
1.54 simplifier = Simplifier(builtins)
1.55 module = compiler.parseFile(filename)
1.56 - simplified = simplifier.process(module)
1.57 compiler.misc.set_filename(filename, module)
1.58 + if builtins:
1.59 + name = "__builtins__"
1.60 + else:
1.61 + path, ext = os.path.splitext(filename)
1.62 + path, name = os.path.split(path)
1.63 + simplified = simplifier.process(module, name)
1.64 return simplified
1.65
1.66 # vim: tabstop=4 expandtab shiftwidth=4