From 8912c51fe275a7d8debe12f84f7e86ce4a240266 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 21 Aug 2015 13:43:29 +0200 Subject: only publicly export initialisors and finalisors if necessary --- src/duk-libdom-dictionary.c | 6 ++++++ src/duk-libdom-interface.c | 7 +++++++ src/duk-libdom.c | 39 ++++++++++++++++++++------------------- 3 files changed, 33 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/duk-libdom-dictionary.c b/src/duk-libdom-dictionary.c index 275855e..6aae0ca 100644 --- a/src/duk-libdom-dictionary.c +++ b/src/duk-libdom-dictionary.c @@ -367,6 +367,9 @@ output_dictionary_init_declaration(FILE* outf, { struct genbind_node *param_node; + if (dictionarye->refcount == 0) { + fprintf(outf, "static "); + } fprintf(outf, "void %s_%s___init(duk_context *ctx, %s_private_t *priv", DLPFX, dictionarye->class_name, dictionarye->class_name); @@ -446,6 +449,9 @@ output_dictionary_fini(FILE* outf, GENBIND_METHOD_TYPE_FINI); /* finaliser definition */ + if (dictionarye->refcount == 0) { + fprintf(outf, "static "); + } fprintf(outf, "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n", DLPFX, dictionarye->class_name, dictionarye->class_name); diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c index 7501bea..3ac7d83 100644 --- a/src/duk-libdom-interface.c +++ b/src/duk-libdom-interface.c @@ -432,6 +432,9 @@ output_interface_init_declaration(FILE* outf, { struct genbind_node *param_node; + if (interfacee->refcount == 0) { + fprintf(outf, "static "); + } fprintf(outf, "void %s_%s___init(duk_context *ctx, %s_private_t *priv", DLPFX, interfacee->class_name, interfacee->class_name); @@ -510,7 +513,11 @@ output_interface_fini(FILE* outf, NULL, GENBIND_METHOD_TYPE_FINI); + /* finaliser definition */ + if (interfacee->refcount == 0) { + fprintf(outf, "static "); + } fprintf(outf, "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n", DLPFX, interfacee->class_name, interfacee->class_name); diff --git a/src/duk-libdom.c b/src/duk-libdom.c index 45e7e79..02b41b3 100644 --- a/src/duk-libdom.c +++ b/src/duk-libdom.c @@ -331,26 +331,27 @@ output_prototype_header(struct ir *ir) fprintf(protof, "duk_ret_t %s_%s___proto(duk_context *ctx);\n", DLPFX, interfacee->class_name); - /** \todo if the interface has no references (no other - * interface inherits from it) there is no reason to export - * the initalisor/finaliser as no other class - * constructor/destructor should call them. Additionally the - * init/fini definition should be made static. + /* if the interface has no references (no other interface + * inherits from it) there is no reason to export the + * initalisor/finaliser as no other class + * constructor/destructor should call them. */ - - /* finaliser declaration */ - fprintf(protof, - "void %s_%s___fini(duk_context *ctx, %s_private_t *priv);\n", - DLPFX, interfacee->class_name, interfacee->class_name); - - /* find the initialisor method on the class (if any) */ - init_node = genbind_node_find_method(interfacee->class, - NULL, - GENBIND_METHOD_TYPE_INIT); - - /* initialisor definition */ - output_interface_init_declaration(protof, interfacee, init_node); - fprintf(protof, ";\n\n"); + if (interfacee->refcount > 0) { + /* finaliser declaration */ + fprintf(protof, + "void %s_%s___fini(duk_context *ctx, %s_private_t *priv);\n", + DLPFX, interfacee->class_name, interfacee->class_name); + + /* find the initialisor method on the class (if any) */ + init_node = genbind_node_find_method(interfacee->class, + NULL, + GENBIND_METHOD_TYPE_INIT); + + /* initialisor definition */ + output_interface_init_declaration(protof, interfacee, init_node); + fprintf(protof, ";\n\n"); + } + fprintf(protof, "\n"); } close_header(ir, protof, "prototype"); -- cgit v1.2.3