예제 #1
0
 def generate_method_table(self, println):
     writer = cg.CppCodeWriter(println)
     writer.println('static')
     writer.println('PyMethodDef meth_%s[] = {' % cg.mangle(self.fullname))
     with writer.indent():
         fmt = '{ "%(name)s", (PyCFunction)%(func)s, METH_VARARGS, NULL },'
         for meth in self.methods:
             name = meth.name
             func = meth.c_name
             writer.println(fmt % locals())
         for enumkind in self.enums:
             for enum in enumkind.value_names:
                 name = enum
                 func = enumkind.c_name(enum)
                 writer.println(fmt % locals())
         for attr in self.attrs:
             # getter
             name = attr.getter_name
             func = attr.getter_c_name
             writer.println(fmt % locals())
             # setter
             name = attr.setter_name
             func = attr.setter_c_name
             writer.println(fmt % locals())
         writer.println('{ NULL },')
     writer.println('};')
     writer.println()
예제 #2
0
 def generate_submodule_table(self, println, extras=()):
     writer = cg.CppCodeWriter(println)
     writer.println('static')
     name = cg.mangle(self.fullname)
     writer.println('SubModuleEntry submodule_%(name)s[] = {' % locals())
     with writer.indent():
         for cls in self.classes:
             name = cls.name
             table = cg.mangle(cls.fullname)
             writer.println('{ "%(name)s", meth_%(table)s, NULL },' %
                            locals())
         for ns in self.namespaces:
             name = ns.localname
             table = cg.mangle(ns.fullname)
             fmt = '{ "%(name)s", meth_%(table)s, submodule_%(table)s },'
             writer.println(fmt % locals())
         for name, table in extras:
             writer.println('{ "%(name)s", %(table)s, NULL },' % locals())
         writer.println('{ NULL }')
     writer.println('};')
     writer.println('')
예제 #3
0
 def generate_cpp(self, println):
     self.compile_cpp(cg.CppCodeWriter(println))