From be671f42562d946073a04555c8c5e5479142ce74 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 19 Jun 2008 13:34:49 -0700 Subject: [PATCH] Mark closure visitor --- Cython/Compiler/Nodes.py | 7 ++++--- Cython/Compiler/ParseTreeTransforms.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index faf16dc9..f363f17d 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1883,9 +1883,10 @@ class OverrideCheckNode(StatNode): # code.put_decref(self.func_temp, PyrexTypes.py_object_type) code.putln("}") +class ClassDefNode(StatNode, BlockNode): + pass - -class PyClassDefNode(StatNode, BlockNode): +class PyClassDefNode(ClassDefNode): # A Python class definition. # # name EncodedString Name of the class @@ -1957,7 +1958,7 @@ class PyClassDefNode(StatNode, BlockNode): self.dict.generate_disposal_code(code) -class CClassDefNode(StatNode, BlockNode): +class CClassDefNode(ClassDefNode): # An extension type definition. # # visibility 'private' or 'public' or 'extern' diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index ef4d9b83..d11dd5e7 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -185,3 +185,26 @@ class AnalyseExpressionsTransform(VisitorTransform): self.visitchildren(node) return node +class MarkClosureNode(VisitorTransform): + + needs_closure = False + + def visit_FuncDefNode(self, node): + self.needs_closure = False + self.visitchildren(node) + node.needs_closure = self.needs_closure + self.needs_closure = True + return node + + def visit_ClassDefNode(self, node): + self.visitchildren(node) + self.needs_closure = True + return node + + def visit_YieldNode(self, node): + self.needs_closure = True + + def visit_Node(self, node): + self.visitchildren(node) + return node + -- 2.26.2