def output_free_funs(header, intro, cfg): header.write('\n\n\n/* ==== free functions ==== */\n\n') import sig s = sig.cpp_signature(cfg) funcs = [(s.get(f), f) for f in intro.exported_freefunctions()] funcs.sort() for sig, fun in funcs: header.write(output_callable(fun, cfg) + '\n\n')
def output_callable(callable, cfg): s = sig.cpp_signature(cfg) csig = s.get(callable) if isinstance(callable, introspect.freefun_i): csig = 'inline ' + csig subst_dict, templ = cpp_callable_body(callable, cfg) subst_dict['signature']=csig return Template(templ).substitute(subst_dict)
def output_callable(callable, cfg): s = sig.cpp_signature(cfg) csig = s.get(callable) if isinstance(callable, introspect.freefun_i): csig = 'inline ' + csig subst_dict, templ = cpp_callable_body(callable, cfg) subst_dict['signature'] = csig return Template(templ).substitute(subst_dict)
def output_class(cls, header, intro, cfg): substd = { 'c_handle' : gencommon.c_handle_from_cls(cls,cfg), 'cpp_name' : gencommon.cls_from_cls(cls,cfg) } gencommon.update_dict(substd, cfg, 'c_handle_inc', 'c_handle_dec') decl_string = gencommon.decl_string_generic(cls) cls_body = get_class_body(decl_string in cfg['ref_counted']) cls_muster = Template(cls_body).safe_substitute(substd) body = [] import sig s = sig.cpp_signature(cfg) methods = [(s.get(m), m) for m in cls.methods()] methods.sort() for sig, m in methods: body.append(cpp_indent(output_callable(m, cfg), 4)) substd = { 'body' : "\n".join(body) } cls_def = Template(cls_muster).substitute(substd) header.write(cls_def)
def output_class(cls, header, intro, cfg): substd = { 'c_handle': gencommon.c_handle_from_cls(cls, cfg), 'cpp_name': gencommon.cls_from_cls(cls, cfg) } gencommon.update_dict(substd, cfg, 'c_handle_inc', 'c_handle_dec') decl_string = gencommon.decl_string_generic(cls) cls_body = get_class_body(decl_string in cfg['ref_counted']) cls_muster = Template(cls_body).safe_substitute(substd) body = [] import sig s = sig.cpp_signature(cfg) methods = [(s.get(m), m) for m in cls.methods()] methods.sort() for sig, m in methods: body.append(cpp_indent(output_callable(m, cfg), 4)) substd = {'body': "\n".join(body)} cls_def = Template(cls_muster).substitute(substd) header.write(cls_def)