From 47aeb5aa53e2797edda0a80bebec82659301b67a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 8 May 2010 22:25:55 +0200 Subject: [PATCH] support type analysis in TempResultFromStatNode --- Cython/Compiler/ParseTreeTransforms.py | 5 +++++ Cython/Compiler/UtilNodes.py | 28 +++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 61b0ec68..90ec66ae 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -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 diff --git a/Cython/Compiler/UtilNodes.py b/Cython/Compiler/UtilNodes.py index 579f9e46..cef526ef 100644 --- a/Cython/Compiler/UtilNodes.py +++ b/Cython/Compiler/UtilNodes.py @@ -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) -- 2.26.2