Commit ebea5bf9 authored by Stefan Behnel's avatar Stefan Behnel

let PostParse transform inherit from ScopeTrackingTransform to avoid code duplication

parent 5932f48a
from Cython.Compiler.Visitor import VisitorTransform, TreeVisitor from Cython.Compiler.Visitor import VisitorTransform, TreeVisitor
from Cython.Compiler.Visitor import CythonTransform, EnvTransform from Cython.Compiler.Visitor import CythonTransform, EnvTransform, ScopeTrackingTransform
from Cython.Compiler.ModuleNode import ModuleNode from Cython.Compiler.ModuleNode import ModuleNode
from Cython.Compiler.Nodes import * from Cython.Compiler.Nodes import *
from Cython.Compiler.ExprNodes import * from Cython.Compiler.ExprNodes import *
...@@ -130,7 +130,7 @@ class PostParseError(CompileError): pass ...@@ -130,7 +130,7 @@ class PostParseError(CompileError): pass
ERR_CDEF_INCLASS = 'Cannot assign default value to fields in cdef classes, structs or unions' ERR_CDEF_INCLASS = 'Cannot assign default value to fields in cdef classes, structs or unions'
ERR_BUF_DEFAULTS = 'Invalid buffer defaults specification (see docs)' ERR_BUF_DEFAULTS = 'Invalid buffer defaults specification (see docs)'
ERR_INVALID_SPECIALATTR_TYPE = 'Special attributes must not have a type declared' ERR_INVALID_SPECIALATTR_TYPE = 'Special attributes must not have a type declared'
class PostParse(CythonTransform): class PostParse(ScopeTrackingTransform):
""" """
Basic interpretation of the parse tree, as well as validity Basic interpretation of the parse tree, as well as validity
checking that can be done on a very basic level on the parse checking that can be done on a very basic level on the parse
...@@ -175,28 +175,8 @@ class PostParse(CythonTransform): ...@@ -175,28 +175,8 @@ class PostParse(CythonTransform):
} }
def visit_ModuleNode(self, node): def visit_ModuleNode(self, node):
self.scope_type = 'module'
self.scope_node = node
self.lambda_counter = 1 self.lambda_counter = 1
self.visitchildren(node) return super(PostParse, self).visit_ModuleNode(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_ClassDefNode(self, node):
return self.visit_scope(node, 'class')
def visit_FuncDefNode(self, node):
return self.visit_scope(node, 'function')
def visit_CStructOrUnionDefNode(self, node):
return self.visit_scope(node, 'struct')
def visit_LambdaNode(self, node): def visit_LambdaNode(self, node):
# unpack a lambda expression into the corresponding DefNode # unpack a lambda expression into the corresponding DefNode
...@@ -239,7 +219,7 @@ class PostParse(CythonTransform): ...@@ -239,7 +219,7 @@ class PostParse(CythonTransform):
declbase = declbase.base declbase = declbase.base
if isinstance(declbase, CNameDeclaratorNode): if isinstance(declbase, CNameDeclaratorNode):
if declbase.default is not None: if declbase.default is not None:
if self.scope_type in ('class', 'struct'): if self.scope_type in ('cclass', 'pyclass', 'struct'):
if isinstance(self.scope_node, CClassDefNode): if isinstance(self.scope_node, CClassDefNode):
handler = self.specialattribute_handlers.get(decl.name) handler = self.specialattribute_handlers.get(decl.name)
if handler: if handler:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment