Pulled transforms from ModuleNode to Main
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 19 Jun 2008 19:43:33 +0000 (12:43 -0700)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 19 Jun 2008 19:43:33 +0000 (12:43 -0700)
Cython/Compiler/Main.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/ParseTreeTransforms.py

index 25e5c91ff568aa0728aadeea873549e84ec2cab3..8ae57153a8504c3329374b302ff30ada12614dfa 100644 (file)
@@ -343,16 +343,22 @@ def create_generate_code(context, options):
     def generate_code(module_node):
         scope = module_node.scope
         result = create_default_resultobj(module_node.compilation_source, options)
-        module_node.process_implementation(scope, options, result)
+        module_node.process_implementation(options, result)
         return result
     return generate_code
 
 def create_default_pipeline(context, options):
     from ParseTreeTransforms import WithTransform, PostParse
+    from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
+    from ModuleNode import check_c_classes
+    
     return [
         create_parse(context),
         PostParse(),
         WithTransform(),
+        AnalyseDeclarationsTransform(),
+        check_c_classes,
+        AnalyseExpressionsTransform(),
         create_generate_code(context, options)
     ]
 
index 7061515ff045291042d175b90cf9138d502649fe..b2237f7baf8fd828be85c1b02f0fc6ff9c6908ad 100644 (file)
@@ -25,6 +25,10 @@ from PyrexTypes import py_object_type
 from Cython.Utils import open_new_file, replace_suffix
 
 
+def check_c_classes(module_node):
+    module_node.scope.check_c_classes()
+    return module_node
+
 class ModuleNode(Nodes.Node, Nodes.BlockNode):
     #  doc       string or None
     #  body      StatListNode
@@ -47,14 +51,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             env.doc = self.doc
         self.body.analyse_declarations(env)
     
-    def process_implementation(self, env, options, result):
-        # Currently, scope is also set by the parse step in Main.py; they will be the same
-        assert self.scope is env
-        self.scope = env
-        from ParseTreeTransforms import AnalyseDeclarationsTransform, AnalyseExpressionsTransform
-        AnalyseDeclarationsTransform(env).visit_ModuleNode(self) # self.analyse_declarations(env)
-        env.check_c_classes()
-        AnalyseExpressionsTransform().visit_ModuleNode(self) # self.body.analyse_expressions(env)
+    def process_implementation(self, options, result):
+        env = self.scope
         env.return_type = PyrexTypes.c_void_type
         self.referenced_modules = []
         self.find_referenced_modules(env, self.referenced_modules, {})
index ef4d9b8328ac6420bbaa1896f5ba88c10273b538..dbb30d246eee8cdbeb80a91072b44a4502fdbe28 100644 (file)
@@ -145,15 +145,15 @@ class WithTransform(VisitorTransform):
 
 class AnalyseDeclarationsTransform(VisitorTransform):
 
-    def __init__(self, env):
-        VisitorTransform.__init__(self)
-        self.env_stack = [env]
+    def __call__(self, root):
+        self.env_stack = [root.scope]
+        return super(AnalyseDeclarationsTransform, self).__call__(root)        
     
     def visit_ModuleNode(self, node):
         node.analyse_declarations(self.env_stack[-1])
         self.visitchildren(node)
         return node
-        
+
     def visit_FuncDefNode(self, node):
         lenv = node.create_local_scope(self.env_stack[-1])
         node.body.analyse_control_flow(lenv) # this will be totally refactored