Commit 8b158e72 authored by Xavier Thompson's avatar Xavier Thompson

Add CypclassWrapper.py to regroup code generation process

parent ae6700cc
#
# Code generation for wrapping cypclass as a Python Extension Type
#
# Will be generated:
# - a PyTypeObject definition for each user defined cypclass
# - Python wrappers for cypclass methods
# - Python getters/setters for cypclass attributes
# - Specific 'tp slots' for handling cycplass objects from Python:
# . tp_new
# . tp_init
# . tp_dealloc
# ...
#
# Functions defined here will be called from ModuleNode.py
#
# Reasons for using a separate file:
# - avoid cluttering ModuleNode.py
# - regroup common logic
# - decouple the code generation process from that of 'cdef class'
#
# Code generation for cypclass will be similar to code generation for 'cdef class' in ModuleNode.py,
# but differences are significant enough that it is better to introduce some redundancy than try to
# handle both 'cdef class' and 'cypclass' in ModuleNode.py.
#
def generate_cypclass_typeobj_declarations(env, code, definition):
"""
Generate declarations of global pointers to the PyTypeObject for each cypclass
"""
for entry in env.cypclass_entries:
if definition or entry.defined_in_pxd:
code.putln("static PyTypeObject *%s = 0;" % (
entry.type.typeptr_cname))
cyp_scope = entry.type.scope
if cyp_scope:
# generate declarations for nested cycplasses
generate_cypclass_typeobj_declarations(cyp_scope, code, definition)
...@@ -19,6 +19,7 @@ from .PyrexTypes import CPtrType ...@@ -19,6 +19,7 @@ from .PyrexTypes import CPtrType
from . import Future from . import Future
from . import Annotate from . import Annotate
from . import Code from . import Code
from . import CypclassWrapper
from . import Naming from . import Naming
from . import Nodes from . import Nodes
from . import Options from . import Options
...@@ -615,7 +616,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -615,7 +616,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
modulecode.putln("") modulecode.putln("")
modulecode.putln("/* Module declarations from '%s' */" % module.qualified_name) modulecode.putln("/* Module declarations from '%s' */" % module.qualified_name)
self.generate_c_class_declarations(module, modulecode, defined_here) self.generate_c_class_declarations(module, modulecode, defined_here)
self.generate_cypclass_typeobj_declarations(module, modulecode, defined_here) CypclassWrapper.generate_cypclass_typeobj_declarations(module, modulecode, defined_here)
self.generate_cvariable_declarations(module, modulecode, defined_here) self.generate_cvariable_declarations(module, modulecode, defined_here)
self.generate_cfunction_declarations(module, modulecode, defined_here) self.generate_cfunction_declarations(module, modulecode, defined_here)
...@@ -1808,16 +1809,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1808,16 +1809,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("static PyTypeObject *%s = 0;" % ( code.putln("static PyTypeObject *%s = 0;" % (
entry.type.typeptr_cname)) entry.type.typeptr_cname))
def generate_cypclass_typeobj_declarations(self, env, code, definition):
for entry in env.cypclass_entries:
if definition or entry.defined_in_pxd:
code.putln("static PyTypeObject *%s = 0;" % (
entry.type.typeptr_cname))
cyp_scope = entry.type.scope
if cyp_scope:
# generate declarations for nested cycplasses
self.generate_cypclass_typeobj_declarations(cyp_scope, code, definition)
def generate_cvariable_declarations(self, env, code, definition): def generate_cvariable_declarations(self, env, code, definition):
if env.is_cython_builtin: if env.is_cython_builtin:
return return
......
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