from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
from Optimize import FlattenBuiltinTypeCreation, ConstantFolding, FinalOptimizePhase
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
# are generated at code generation time.
return node
if pxd:
- _check_c_declarations = None
+ _check_c_declarations = check_c_declarations_pxd
_specific_post_parse = PxdPostParse(self)
else:
_check_c_declarations = check_c_declarations
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):
module_node.scope.check_c_classes()
module_node.scope.check_c_functions()
type.vtabstruct_cname = self.mangle(Naming.vtabstruct_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):
# Performs post-analysis checking and finishing up of extension types
# being implemented in this module. This is called only for the main
# If the type or any of its base types have Python-valued
# C attributes, then it needs to participate in GC.
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())
def declare_var(self, name, type, pos,
if self.defined:
error(pos,
"C attributes cannot be added in implementation part of"
- " extension type")
+ " extension type defined in a pxd")
if get_special_method_signature(name):
error(pos,
"The name '%s' is reserved for a special method."