Exemplo n.º 1
0
 def GenerateBase(self, ast, more_headers):
   """Extension module generation."""
   ast_manipulations.MoveExtendsBackIntoClassesInPlace(ast)
   self.init += ast.extra_init
   for s in gen.Headlines(
       ast.source,
       [
           'PYTHON', 'absl/memory/memory.h',
           'absl/types/optional.h'
       ] + more_headers +
       # Container templates calling PyObj* go last.
       [
           'clif/python/stltypes.h',
           'clif/python/slots.h'
       ],
       open_ns=self.wrap_namespace):
     yield s
   yield ''
   yield 'using namespace clif;'
   yield ''
   yield 'static const char* ThisModuleName = "%s";' % self.path
   for s in postconv.GenPostConvTable(self.typemap):
     yield s
   if astutils.HaveEnum(ast.decls):
     yield ''
     yield 'static PyObject *_Enum{}, *_IntEnum{};  // set below in Init()'
   self.catch_cpp_exceptions = ast.catch_exceptions
   for d in ast.decls:
     for s in self.WrapDecl(d):
       yield s
   assert not self.nested, 'decl stack not exhausted (in GenBase)'
   yield ''
   yield '// Initialize module'
   if self.methods:
     for s in gen.MethodDef(self.methods):
       yield s
   for s in self.GenTypesReady():  # extends self.init
     yield s
   for s in self.GenInitFunction(ast.source):  # consumes self.init
     yield s
   yield ''
   yield '}  // namespace %s' % self.wrap_namespace
   if self.types:
     # Assumed we always want a deterministic output. Since dict/set order
     # is not, do sorted() order traversal.
     #
     # Save sorted types for GenerateHeader.
     self.types = sorted(self.types, key=types.Order)
     for ns, ts in itertools.groupby(self.types, types.Namespace):
       for s in gen.TypeConverters(ns, ts, self.wrap_namespace,
                                   self.py3output):
         yield s
   if self.static_init:
     for s in gen.PyModInitFunction(
         init_name=self.static_init,
         ns=self.wrap_namespace,
         py3=self.py3output):
       yield s
Exemplo n.º 2
0
 def GenerateInit(self, source_filename, skip_initfunc=False):
   """Generate module initialization file."""
   assert not self.nested, 'decl stack not exhausted (in GenInit)'
   for s in gen.Headlines(source_filename, ['PYTHON'],
                          open_ns=self.wrap_namespace): yield s
   yield ''
   yield 'bool Ready();'
   yield 'PyObject* Init();'
   yield ''
   yield '}  // namespace %s' % self.wrap_namespace
   if not skip_initfunc:
     for s in gen.PyModInitFunction(modname=self.modname, py3=self.py3output,
                                    ns=self.wrap_namespace): yield s