Пример #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
Пример #2
0
 def GenerateBase(self, ast, api_header, more_headers):
     """Extension module generation."""
     self.init += ast.extra_init
     for s in (gen.Headlines(
             ast.source,
         ['PYTHON', 'clif/python/ptr_util.h', 'clif/python/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 'using namespace clif;'
     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
     yield ''
     for d in ast.decls:
         for s in (self.WrapDecl(d)):
             yield s
     assert not self.nested, 'decl stack not exhausted'
     yield ''
     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(api_header)  # 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
Пример #3
0
def GenerateFrom(messages, proto_filename, clif_hdr, proto_hdr):
    """Traverse ast and generate output files."""
    with open(FLAGS.header_out, 'w') as hout:
        gen.WriteTo(
            hout,
            gen.Headlines(proto_filename,
                          [proto_hdr, 'clif/python/postconv.h']))
        gen.WriteTo(hout, _GenHeader(messages))

    with open(FLAGS.ccdeps_out, 'w') as cout:
        gen.WriteTo(
            cout,
            gen.Headlines(
                proto_filename,
                ['clif/python/runtime.h', 'clif/python/types.h', clif_hdr]))
        for ns, ts in itertools.groupby(messages, types.Namespace):
            if ns == '::':
                ns = 'clif'
            gen.WriteTo(cout, gen.TypeConverters(ns, ts))