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))
def GenerateFrom(ast): """Traverse ast and generate output files.""" inc_headers = list(ast.usertype_includes) api_header = _GetHeaders(ast) modname = FLAGS.modname or StripExt(os.path.basename(ast.source)).replace( '-', '_') m = pyext.Module(modname, ast.typemaps, for_py3=FLAGS.py3output, indent=FLAGS.indent) inc_headers.append(os.path.basename(FLAGS.header_out)) # Order of generators is important. if api_header: with open(FLAGS.ccdeps_out, 'w') as cout: gen.WriteTo(cout, m.GenerateBase(ast, api_header, inc_headers)) with open(FLAGS.ccinit_out, 'w') as iout: gen.WriteTo(iout, m.GenerateInit(ast.source)) with open(FLAGS.header_out, 'w') as hout: gen.WriteTo(hout, m.GenerateHeader(ast.source, api_header, ast.macros))