summaryrefslogtreecommitdiff
path: root/src/duk-libdom.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-08-05 22:27:25 +0100
committerVincent Sanders <vince@kyllikki.org>2015-08-05 22:27:25 +0100
commit619dbd53bc4624e3a4e9bb291e61ed358272d009 (patch)
treeccfcb01347558b484590847833a8d5660a750977 /src/duk-libdom.c
parent5af5647471a44f489f14a415f10b7b8e34344581 (diff)
downloadnsgenbind-619dbd53bc4624e3a4e9bb291e61ed358272d009.tar.gz
nsgenbind-619dbd53bc4624e3a4e9bb291e61ed358272d009.tar.bz2
change method and property generators default block generation
If the binding implementation of a method or property is empty then generate a default implementation (currently simply a return statement) otherwise the binding implementation must be complete including a return statement.
Diffstat (limited to 'src/duk-libdom.c')
-rw-r--r--src/duk-libdom.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 6966f02..31ec0a1 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -343,7 +343,12 @@ static char *gen_class_name(struct interface_map_entry *interfacee)
/**
* output character data of node of given type.
*
- * used for pre/pro/epi/post sections
+ * used for any cdata including pre/pro/epi/post sections
+ *
+ * \param outf The file handle to write output.
+ * \param node The node to search.
+ * \param nodetype the type of child node to search for.
+ * \return The number of nodes written or 0 for none.
*/
static int
output_cdata(FILE* outf,
@@ -351,14 +356,17 @@ output_cdata(FILE* outf,
enum genbind_node_type nodetype)
{
char *cdata;
+ int res = 0;
+
cdata = genbind_node_gettext(
genbind_node_find_type(
genbind_node_getnode(node),
NULL, nodetype));
if (cdata != NULL) {
fprintf(outf, "%s", cdata);
+ res = 1;
}
- return 0;
+ return res;
}
static FILE *open_header(struct interface_map *interface_map, const char *name)
@@ -919,6 +927,9 @@ output_interface_operation(FILE* outf,
if (operatione->name != NULL) {
/* normal method definition */
+
+ int cdatac; /* cdata blocks output */
+
fprintf(outf,
"static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
DLPFX, interfacee->class_name, operatione->name);
@@ -926,9 +937,14 @@ output_interface_operation(FILE* outf,
output_get_method_private(outf, interfacee->class_name);
- output_cdata(outf, operatione->method, GENBIND_NODE_TYPE_CDATA);
+ cdatac = output_cdata(outf,
+ operatione->method,
+ GENBIND_NODE_TYPE_CDATA);
- fprintf(outf,"\treturn 0;\n");
+ if (cdatac == 0) {
+ /* no implementation so generate default */
+ fprintf(outf,"\treturn 0;\n");
+ }
fprintf(outf, "}\n\n");
} else {
@@ -969,6 +985,8 @@ output_interface_attribute(FILE* outf,
struct interface_map_entry *interfacee,
struct interface_map_attribute_entry *atributee)
{
+ int cdatac;
+
/* getter definition */
fprintf(outf,
"static duk_ret_t %s_%s_%s_getter(duk_context *ctx)\n",
@@ -977,9 +995,12 @@ output_interface_attribute(FILE* outf,
output_get_method_private(outf, interfacee->class_name);
- output_cdata(outf, atributee->getter, GENBIND_NODE_TYPE_CDATA);
+ cdatac = output_cdata(outf, atributee->getter, GENBIND_NODE_TYPE_CDATA);
- fprintf(outf,"\treturn 0;\n");
+ if (cdatac == 0) {
+ /* no implementation so generate default */
+ fprintf(outf,"\treturn 0;\n");
+ }
fprintf(outf, "}\n\n");
@@ -996,9 +1017,13 @@ output_interface_attribute(FILE* outf,
output_get_method_private(outf, interfacee->class_name);
- output_cdata(outf, atributee->setter, GENBIND_NODE_TYPE_CDATA);
+ cdatac = output_cdata(outf, atributee->setter, GENBIND_NODE_TYPE_CDATA);
+
+ if (cdatac == 0) {
+ /* no implementation so generate default */
+ fprintf(outf,"\treturn 0;\n");
+ }
- fprintf(outf,"\treturn 0;\n");
fprintf(outf, "}\n\n");