From: Stefan Behnel Date: Sun, 4 Oct 2009 07:38:57 +0000 (+0200) Subject: merge X-Git-Tag: 0.12.alpha0~182^2~12 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=19f7caa7d7908351270383c321c1085d7485abb5;p=cython.git merge --- 19f7caa7d7908351270383c321c1085d7485abb5 diff --cc Cython/Compiler/ExprNodes.py index b1b26e02,b590ad79..0eb76619 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@@ -3503,10 -3501,9 +3503,12 @@@ class DictNode(ExprNode) # obj_conversion_errors [PyrexError] used internally subexprs = ['key_value_pairs'] + is_temp = 1 + type = dict_type + type = dict_type + obj_conversion_errors = [] + def calculate_constant_result(self): self.constant_result = dict([ item.constant_result for item in self.key_value_pairs]) diff --cc Cython/Compiler/Visitor.py index cfc79f96,636d9d05..86354dd6 --- a/Cython/Compiler/Visitor.py +++ b/Cython/Compiler/Visitor.py @@@ -272,22 -275,37 +275,53 @@@ class CythonTransform(VisitorTransform) self.visitchildren(node) return node + class ScopeTrackingTransform(CythonTransform): + # Keeps track of type of scopes + scope_type = None # can be either of 'module', 'function', 'cclass', 'pyclass' + scope_node = None + + def visit_ModuleNode(self, node): + self.scope_type = 'module' + self.scope_node = node + self.visitchildren(node) + return node + + def visit_scope(self, node, scope_type): + prev = self.scope_type, self.scope_node + self.scope_type = scope_type + self.scope_node = node + self.visitchildren(node) + self.scope_type, self.scope_node = prev + return node + + def visit_CClassDefNode(self, node): + return self.visit_scope(node, 'cclass') + + def visit_PyClassDefNode(self, node): + return self.visit_scope(node, 'pyclass') + + def visit_FuncDefNode(self, node): + return self.visit_scope(node, 'function') + + def visit_CStructOrUnionDefNode(self, node): + return self.visit_scope(node, 'struct') + +class RecursiveNodeReplacer(VisitorTransform): + """ + Recursively replace all occurrences of a node in a subtree by + another node. + """ + def __init__(self, orig_node, new_node): + super(RecursiveNodeReplacer, self).__init__() + self.orig_node, self.new_node = orig_node, new_node + + def visit_Node(self, node): + self.visitchildren(node) + if node is self.orig_node: + return self.new_node + else: + return node +