Commit 14d0d75e authored by Robert Bradshaw's avatar Robert Bradshaw

#286, make sure cdef classes fully defined in pxd

parent 25a506e3
...@@ -85,7 +85,7 @@ class Context(object): ...@@ -85,7 +85,7 @@ class Context(object):
from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
from Optimize import FlattenBuiltinTypeCreation, ConstantFolding, FinalOptimizePhase from Optimize import FlattenBuiltinTypeCreation, ConstantFolding, FinalOptimizePhase
from Buffer import IntroduceBufferAuxiliaryVars from Buffer import IntroduceBufferAuxiliaryVars
from ModuleNode import check_c_declarations from ModuleNode import check_c_declarations, check_c_declarations_pxd
# Temporary hack that can be used to ensure that all result_code's # Temporary hack that can be used to ensure that all result_code's
# are generated at code generation time. # are generated at code generation time.
...@@ -97,7 +97,7 @@ class Context(object): ...@@ -97,7 +97,7 @@ class Context(object):
return node return node
if pxd: if pxd:
_check_c_declarations = None _check_c_declarations = check_c_declarations_pxd
_specific_post_parse = PxdPostParse(self) _specific_post_parse = PxdPostParse(self)
else: else:
_check_c_declarations = check_c_declarations _check_c_declarations = check_c_declarations
......
...@@ -27,6 +27,10 @@ from Cython.Utils import open_new_file, replace_suffix, UtilityCode ...@@ -27,6 +27,10 @@ from Cython.Utils import open_new_file, replace_suffix, UtilityCode
from StringEncoding import escape_byte_string, EncodedString from StringEncoding import escape_byte_string, EncodedString
def check_c_declarations_pxd(module_node):
module_node.scope.check_c_classes_pxd()
return module_node
def check_c_declarations(module_node): def check_c_declarations(module_node):
module_node.scope.check_c_classes() module_node.scope.check_c_classes()
module_node.scope.check_c_functions() module_node.scope.check_c_functions()
......
...@@ -1114,6 +1114,22 @@ class ModuleScope(Scope): ...@@ -1114,6 +1114,22 @@ class ModuleScope(Scope):
type.vtabstruct_cname = self.mangle(Naming.vtabstruct_prefix, entry.name) type.vtabstruct_cname = self.mangle(Naming.vtabstruct_prefix, entry.name)
type.vtabptr_cname = self.mangle(Naming.vtabptr_prefix, entry.name) type.vtabptr_cname = self.mangle(Naming.vtabptr_prefix, entry.name)
def check_c_classes_pxd(self):
# Performs post-analysis checking and finishing up of extension types
# being implemented in this module. This is called only for the .pxd.
#
# Checks all extension types declared in this scope to
# make sure that:
#
# * The extension type is fully declared
#
# Also allocates a name for the vtable if needed.
#
for entry in self.c_class_entries:
# Check defined
if not entry.type.scope:
error(entry.pos, "C class '%s' is declared but not defined" % entry.name)
def check_c_classes(self): def check_c_classes(self):
# Performs post-analysis checking and finishing up of extension types # Performs post-analysis checking and finishing up of extension types
# being implemented in this module. This is called only for the main # being implemented in this module. This is called only for the main
...@@ -1389,7 +1405,8 @@ class CClassScope(ClassScope): ...@@ -1389,7 +1405,8 @@ class CClassScope(ClassScope):
# If the type or any of its base types have Python-valued # If the type or any of its base types have Python-valued
# C attributes, then it needs to participate in GC. # C attributes, then it needs to participate in GC.
return self.has_pyobject_attrs or \ return self.has_pyobject_attrs or \
(self.parent_type.base_type and \ (self.parent_type.base_type and
self.parent_type.base_type.scope is not None and
self.parent_type.base_type.scope.needs_gc()) self.parent_type.base_type.scope.needs_gc())
def declare_var(self, name, type, pos, def declare_var(self, name, type, pos,
...@@ -1399,7 +1416,7 @@ class CClassScope(ClassScope): ...@@ -1399,7 +1416,7 @@ class CClassScope(ClassScope):
if self.defined: if self.defined:
error(pos, error(pos,
"C attributes cannot be added in implementation part of" "C attributes cannot be added in implementation part of"
" extension type") " extension type defined in a pxd")
if get_special_method_signature(name): if get_special_method_signature(name):
error(pos, error(pos,
"The name '%s' is reserved for a special method." "The name '%s' is reserved for a special method."
......
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