from sets import Set as set
import copy
+class SkipDeclarations:
+ """
+ Variable and function declarations can often have a deep tree structure,
+ and yet most transformations don't need to descend to this depth.
+
+ Declaration nodes are removed after AnalyseDeclarationsTransform, so there
+ is no need to use this for transformations after that point.
+ """
+ def visit_CTypeDefNode(self, node):
+ return node
+
+ def visit_CVarDefNode(self, node):
+ return node
+
+ def visit_CDeclaratorNode(self, node):
+ return node
+
+ def visit_CBaseTypeNode(self, node):
+ return node
+
+ def visit_CEnumDefNode(self, node):
+ return node
+
+ def visit_CStructOrUnionDefNode(self, node):
+ return node
+
+
class NormalizeTree(CythonTransform):
"""
This transform fixes up a few things after parsing
else:
return []
+ def visit_CDeclaratorNode(self, node):
+ return node
+
class PostParseError(CompileError): pass
raise PostParseError(node.pos, ERR_BUF_LOCALONLY)
return node
-class PxdPostParse(CythonTransform):
+class PxdPostParse(CythonTransform, SkipDeclarations):
"""
Basic interpretation/validity checking that should only be
done on pxd trees.
return None
else:
return node
-
-class InterpretCompilerDirectives(CythonTransform):
+
+class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
"""
After parsing, options can be stored in a number of places:
- #cython-comments at the top of the file (stored in ModuleNode)
else:
return self.visit_Node(node)
-class WithTransform(CythonTransform):
+class WithTransform(CythonTransform, SkipDeclarations):
# EXCINFO is manually set to a variable that contains
# the exc_info() tuple that can be generated by the enclosing except
excinfo_temp.ref(node.pos))
return TempsBlockNode(node.pos, temps=[excinfo_temp], body=result)
+
+ def visit_ExprNode(self, node):
+ # With statements are never inside expressions.
+ return node
+
-class DecoratorTransform(CythonTransform):
+class DecoratorTransform(CythonTransform, SkipDeclarations):
def visit_DefNode(self, func_node):
if not func_node.decorators:
# analysis and can be dropped. The analysis was performed
# on these nodes in a seperate recursive process from the
# enclosing function or module, so we can simply drop them.
+ def visit_CDeclaratorNode(self, node):
+ return node
+
+ def visit_CTypeDefNode(self, node):
+ return node
+
+ def visit_CBaseTypeNode(self, node):
+ return None
+
+ def visit_CEnumDefNode(self, node):
+ return None
+
+ def visit_CStructOrUnionDefNode(self, node):
+ return None
+
def visit_CVarDefNode(self, node):
if node.need_properties:
# cdef public attributes may need type testing on