support type analysis in TempResultFromStatNode
authorStefan Behnel <scoder@users.berlios.de>
Sat, 8 May 2010 20:25:55 +0000 (22:25 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 8 May 2010 20:25:55 +0000 (22:25 +0200)
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/UtilNodes.py

index 61b0ec68eec09348c0f2620edcdbf7670d3cc78d..90ec66ae04bd0b881a2c11d90f7318c4f18b8988 100644 (file)
@@ -1035,6 +1035,11 @@ property NAME:
         node.analyse_declarations(self.env_stack[-1])
         return node
 
+    def visit_TempResultFromStatNode(self, node):
+        self.visitchildren(node)
+        node.analyse_declarations(self.env_stack[-1])
+        return node
+
     # Some nodes are no longer needed after declaration
     # analysis and can be dropped. The analysis was performed
     # on these nodes in a seperate recursive process from the
index 579f9e46438f24ccf8871f922c6a59887054b47c..cef526ef3c20721df799824ee170de8462ce36bf 100644 (file)
@@ -119,17 +119,24 @@ class ResultRefNode(AtomicExprNode):
     subexprs = []
     lhs_of_first_assignment = False
 
-    def __init__(self, expression):
-        self.pos = expression.pos
+    def __init__(self, expression=None, pos=None):
         self.expression = expression
-        if hasattr(expression, "type"):
-            self.type = expression.type
+        self.pos = None
+        if expression is not None:
+            self.pos = expression.pos
+            if hasattr(expression, "type"):
+                self.type = expression.type
+        if pos is not None:
+            self.pos = pos
+        assert self.pos is not None
 
     def analyse_types(self, env):
-        self.type = self.expression.type
+        if self.expression is not None:
+            self.type = self.expression.type
 
     def infer_type(self, env):
-        return self.expression.infer_type(env)
+        if self.expression is not None:
+            return self.expression.infer_type(env)
 
     def is_simple(self):
         return True
@@ -258,9 +265,6 @@ class TempResultFromStatNode(ExprNodes.ExprNode):
     # body.  Requires a ResultRefNode that it sets up to refer to its
     # own temp result.  The StatNode must assign a value to the result
     # node, which then becomes the result of this node.
-    #
-    # This can only be used in/after type analysis.
-    #
 
     subexprs = []
     child_attrs = ['body']
@@ -272,6 +276,12 @@ class TempResultFromStatNode(ExprNodes.ExprNode):
         self.type = result_ref.type
         self.is_temp = 1
 
+    def analyse_declarations(self, env):
+        self.body.analyse_declarations(env)
+    
+    def analyse_types(self, env):
+        self.body.analyse_expressions(env)
+
     def generate_result_code(self, code):
         self.result_ref.result_code = self.result()
         self.body.generate_execution_code(code)