Beispiel #1
0
def _GenHeader(messages):
    for ns, ts in itertools.groupby(messages, types.Namespace):
        yield ''
        if ns == '::':
            ns = 'clif'
            yield gen.OpenNs(ns)
        else:
            yield gen.OpenNs(ns)
            yield 'using namespace ::clif;'
        yield ''
        for t in ts:
            for s in t.GenHeader():
                yield s
        yield ''
        yield gen.CloseNs(ns)
Beispiel #2
0
 def GenerateHeader(self, source_filename, api_header_filename, macros,
                    more_headers=None):
   """Generate header file with type conversion declarations."""
   if more_headers is None:
     more_headers = []
   for s in gen.Headlines(source_filename, [
       'absl/types/optional.h', api_header_filename,
       'clif/python/postconv.h'
   ] + more_headers, ['memory']):
     yield s
   if self.types:
     for ns, ts in itertools.groupby(self.types, types.Namespace):
       yield ''
       yield gen.OpenNs(ns)
       if ns and ns != 'clif':
         yield 'using namespace ::clif;'
       yield ''
       for t in ts:
         for s in t.GenHeader():
           yield s
       yield ''
       yield gen.CloseNs(ns)
     yield ''
     yield ('// CLIF init_module if (PyObject* m = PyImport_ImportModule('
            '"%s")) Py_DECREF(m);' % self.path)
     yield '// CLIF init_module else goto err;'
   else:
     yield '// This module defines no types.'
   for m in macros:
     yield ''
     yield '// CLIF macro %s %s' % (
         m.name, m.definition.decode('utf-8').replace('\n', r'\n'))
Beispiel #3
0
 def GenerateHeader(self, source_filename, api_header_filename, macros,
                    is_extended_from_python, more_headers=None):
   """Generate header file with type conversion declarations."""
   if more_headers is None:
     more_headers = []
   for s in gen.Headlines(source_filename, [
       'absl/types/optional.h', api_header_filename,
       'clif/python/postconv.h'
   ] + more_headers, ['memory']):
     yield s
   if self.types:
     for ns, ts in itertools.groupby(self.types, types.Namespace):
       yield ''
       yield gen.OpenNs(ns)
       if ns and ns != 'clif':
         yield 'using namespace ::clif;'
       yield ''
       for t in ts:
         for s in t.GenHeader():
           yield s
       yield ''
       yield gen.CloseNs(ns)
     yield ''
     import_path = self.path
     if is_extended_from_python:
       flds = import_path.split('.')
       if not flds[-1].startswith('_'):
         raise ValueError(
             'OPTION is_extended_from_python is applicable only to private'
             ' extensions (i.e. the unqualified name of the extension must'
             ' start with an underscore). Fully-qualified extension name: %s'
             % self.path)
       flds[-1] = flds[-1][1:]
       import_path = '.'.join(flds)
     yield ('// CLIF init_module if (PyObject* m = PyImport_ImportModule('
            '"%s")) Py_DECREF(m);' % import_path)
     yield '// CLIF init_module else goto err;'
   else:
     yield '// This module defines no types.'
   for m in macros:
     yield ''
     yield '// CLIF macro %s %s' % (
         m.name, m.definition.decode('utf-8').replace('\n', r'\n'))