bgenGeneratorGroup.py: changed placement of some blank lines in output
bgenObjectDefinition.py: support chaining of object definitions macsupport.py: support functions returning pointers to existing windows/dialogs bgen.py: tighten rules for recognizing simple symbol definitions
This commit is contained in:
parent
cc0d879069
commit
80ffd6683c
@ -13,6 +13,7 @@ class GeneratorGroup:
|
|||||||
def generate(self):
|
def generate(self):
|
||||||
for g in self.generators:
|
for g in self.generators:
|
||||||
g.generate()
|
g.generate()
|
||||||
|
Output()
|
||||||
Output("static PyMethodDef %s_methods[] = {", self.prefix)
|
Output("static PyMethodDef %s_methods[] = {", self.prefix)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
for g in self.generators:
|
for g in self.generators:
|
||||||
@ -20,7 +21,6 @@ class GeneratorGroup:
|
|||||||
Output("{NULL, NULL, 0}")
|
Output("{NULL, NULL, 0}")
|
||||||
DedentLevel()
|
DedentLevel()
|
||||||
Output("};")
|
Output("};")
|
||||||
Output()
|
|
||||||
|
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
|
@ -21,6 +21,7 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
self.typename = name + '_Type'
|
self.typename = name + '_Type'
|
||||||
self.argref = "" # set to "*" if arg to <type>_New should be pointer
|
self.argref = "" # set to "*" if arg to <type>_New should be pointer
|
||||||
self.static = "static " # set to "" to make <type>_New and <type>_Convert public
|
self.static = "static " # set to "" to make <type>_New and <type>_Convert public
|
||||||
|
self.basechain = "NULL" # set to &<basetype>_chain to chain methods
|
||||||
|
|
||||||
def add(self, g):
|
def add(self, g):
|
||||||
g.setselftype(self.objecttype, self.itselftype)
|
g.setselftype(self.objecttype, self.itselftype)
|
||||||
@ -38,18 +39,15 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
sf = self.static and "staticforward "
|
sf = self.static and "staticforward "
|
||||||
Output("%sPyTypeObject %s;", sf, self.typename)
|
Output("%sPyTypeObject %s;", sf, self.typename)
|
||||||
Output()
|
Output()
|
||||||
|
|
||||||
Output("#define %s_Check(x) ((x)->ob_type == &%s)",
|
Output("#define %s_Check(x) ((x)->ob_type == &%s)",
|
||||||
self.prefix, self.typename)
|
self.prefix, self.typename)
|
||||||
Output()
|
Output()
|
||||||
|
|
||||||
Output("typedef struct %s {", self.objecttype)
|
Output("typedef struct %s {", self.objecttype)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
Output("PyObject_HEAD")
|
Output("PyObject_HEAD")
|
||||||
self.outputStructMembers()
|
self.outputStructMembers()
|
||||||
DedentLevel()
|
DedentLevel()
|
||||||
Output("} %s;", self.objecttype)
|
Output("} %s;", self.objecttype)
|
||||||
Output()
|
|
||||||
|
|
||||||
self.outputNew()
|
self.outputNew()
|
||||||
|
|
||||||
@ -59,6 +57,10 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
|
|
||||||
GeneratorGroup.generate(self)
|
GeneratorGroup.generate(self)
|
||||||
|
|
||||||
|
Output()
|
||||||
|
Output("%sPyMethodChain %s_chain = { %s_methods, %s };",
|
||||||
|
self.static, self.prefix, self.prefix, self.basechain)
|
||||||
|
|
||||||
self.outputGetattr()
|
self.outputGetattr()
|
||||||
|
|
||||||
self.outputSetattr()
|
self.outputSetattr()
|
||||||
@ -71,6 +73,7 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
Output("%s ob_itself;", self.itselftype)
|
Output("%s ob_itself;", self.itselftype)
|
||||||
|
|
||||||
def outputNew(self):
|
def outputNew(self):
|
||||||
|
Output()
|
||||||
Output("%sPyObject *%s_New(itself)", self.static, self.prefix)
|
Output("%sPyObject *%s_New(itself)", self.static, self.prefix)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
Output("const %s %sitself;", self.itselftype, self.argref)
|
Output("const %s %sitself;", self.itselftype, self.argref)
|
||||||
@ -83,7 +86,6 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
self.outputInitStructMembers()
|
self.outputInitStructMembers()
|
||||||
Output("return (PyObject *)it;")
|
Output("return (PyObject *)it;")
|
||||||
OutRbrace()
|
OutRbrace()
|
||||||
Output()
|
|
||||||
|
|
||||||
def outputInitStructMembers(self):
|
def outputInitStructMembers(self):
|
||||||
Output("it->ob_itself = %sitself;", self.argref)
|
Output("it->ob_itself = %sitself;", self.argref)
|
||||||
@ -112,6 +114,7 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
"Override this method to apply additional conversions"
|
"Override this method to apply additional conversions"
|
||||||
|
|
||||||
def outputDealloc(self):
|
def outputDealloc(self):
|
||||||
|
Output()
|
||||||
Output("static void %s_dealloc(self)", self.prefix)
|
Output("static void %s_dealloc(self)", self.prefix)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
Output("%s *self;", self.objecttype)
|
Output("%s *self;", self.objecttype)
|
||||||
@ -120,7 +123,6 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
self.outputCleanupStructMembers()
|
self.outputCleanupStructMembers()
|
||||||
Output("PyMem_DEL(self);")
|
Output("PyMem_DEL(self);")
|
||||||
OutRbrace()
|
OutRbrace()
|
||||||
Output()
|
|
||||||
|
|
||||||
def outputCleanupStructMembers(self):
|
def outputCleanupStructMembers(self):
|
||||||
self.outputFreeIt("self->ob_itself")
|
self.outputFreeIt("self->ob_itself")
|
||||||
@ -129,6 +131,7 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
Output("/* Cleanup of %s goes here */", name)
|
Output("/* Cleanup of %s goes here */", name)
|
||||||
|
|
||||||
def outputGetattr(self):
|
def outputGetattr(self):
|
||||||
|
Output()
|
||||||
Output("static PyObject *%s_getattr(self, name)", self.prefix)
|
Output("static PyObject *%s_getattr(self, name)", self.prefix)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
Output("%s *self;", self.objecttype)
|
Output("%s *self;", self.objecttype)
|
||||||
@ -137,20 +140,21 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
OutLbrace()
|
OutLbrace()
|
||||||
self.outputGetattrBody()
|
self.outputGetattrBody()
|
||||||
OutRbrace()
|
OutRbrace()
|
||||||
Output()
|
|
||||||
|
|
||||||
def outputGetattrBody(self):
|
def outputGetattrBody(self):
|
||||||
self.outputGetattrHook()
|
self.outputGetattrHook()
|
||||||
Output("return Py_FindMethod(%s_methods, (PyObject *)self, name);", self.prefix)
|
Output("return Py_FindMethodInChain(&%s_chain, (PyObject *)self, name);",
|
||||||
|
self.prefix)
|
||||||
|
|
||||||
def outputGetattrHook(self):
|
def outputGetattrHook(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def outputSetattr(self):
|
def outputSetattr(self):
|
||||||
Output("#define %s_setattr NULL", self.prefix)
|
|
||||||
Output()
|
Output()
|
||||||
|
Output("#define %s_setattr NULL", self.prefix)
|
||||||
|
|
||||||
def outputTypeObject(self):
|
def outputTypeObject(self):
|
||||||
|
Output()
|
||||||
Output("%sPyTypeObject %s = {", self.static, self.typename)
|
Output("%sPyTypeObject %s = {", self.static, self.typename)
|
||||||
IndentLevel()
|
IndentLevel()
|
||||||
Output("PyObject_HEAD_INIT(&PyType_Type)")
|
Output("PyObject_HEAD_INIT(&PyType_Type)")
|
||||||
@ -168,7 +172,10 @@ class ObjectDefinition(GeneratorGroup):
|
|||||||
|
|
||||||
|
|
||||||
class GlobalObjectDefinition(ObjectDefinition):
|
class GlobalObjectDefinition(ObjectDefinition):
|
||||||
"Same as ObjectDefinition but exports its New and Create methods"
|
"""Like ObjectDefinition but exports some parts.
|
||||||
|
|
||||||
|
XXX Should also somehow generate a .h file for them.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, name, prefix = None, itselftype = None):
|
def __init__(self, name, prefix = None, itselftype = None):
|
||||||
ObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
|
ObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
|
||||||
|
@ -37,6 +37,8 @@ ControlHandle = OpaqueByValueType("ControlHandle", "CtlObj")
|
|||||||
# Windows and Dialogs
|
# Windows and Dialogs
|
||||||
WindowPtr = OpaqueByValueType("WindowPtr", "WinObj")
|
WindowPtr = OpaqueByValueType("WindowPtr", "WinObj")
|
||||||
DialogPtr = OpaqueByValueType("DialogPtr", "DlgObj")
|
DialogPtr = OpaqueByValueType("DialogPtr", "DlgObj")
|
||||||
|
ExistingWindowPtr = OpaqueByValueType("WindowPtr", "WinObj_WhichWindow", "BUG")
|
||||||
|
ExistingDialogPtr = OpaqueByValueType("DialogPtr", "WinObj_WhichWindow", "BUG")
|
||||||
|
|
||||||
# NULL pointer passed in as optional storage -- not present in Python version
|
# NULL pointer passed in as optional storage -- not present in Python version
|
||||||
NullStorage = FakeType("(void *)0")
|
NullStorage = FakeType("(void *)0")
|
||||||
@ -98,6 +100,8 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
|
|||||||
|
|
||||||
extern PyObject *CtlObj_New(ControlHandle);
|
extern PyObject *CtlObj_New(ControlHandle);
|
||||||
extern int CtlObj_Convert(PyObject *, ControlHandle *);
|
extern int CtlObj_Convert(PyObject *, ControlHandle *);
|
||||||
|
|
||||||
|
extern PyObject *WinObj_WhichWindow(WindowPtr);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Stuff added just before the module's init function
|
# Stuff added just before the module's init function
|
||||||
|
@ -94,7 +94,7 @@ class Scanner:
|
|||||||
self.whole_pat = "\(<type>[a-zA-Z0-9_]+\)[ \t\n]+" + \
|
self.whole_pat = "\(<type>[a-zA-Z0-9_]+\)[ \t\n]+" + \
|
||||||
"\(<name>[a-zA-Z0-9_]+\)[ \t\n]*(\(<args>[^()]*\))"
|
"\(<name>[a-zA-Z0-9_]+\)[ \t\n]*(\(<args>[^()]*\))"
|
||||||
self.sym_pat = "^[ \t]*\(<name>[a-zA-Z0-9_]+\)[ \t]*=" + \
|
self.sym_pat = "^[ \t]*\(<name>[a-zA-Z0-9_]+\)[ \t]*=" + \
|
||||||
"[ \t]*\(<defn>[-0-9'\"][^\t\n,]*\),?"
|
"[ \t]*\(<defn>[-0-9'\"][^\t\n,}]*\),?"
|
||||||
self.asplit_pat = "^\(<type>.*[^a-zA-Z0-9_]\)\(<name>[a-zA-Z0-9_]+\)$"
|
self.asplit_pat = "^\(<type>.*[^a-zA-Z0-9_]\)\(<name>[a-zA-Z0-9_]+\)$"
|
||||||
|
|
||||||
def compilepatterns(self):
|
def compilepatterns(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user