summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-11-01 10:59:34 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2015-11-01 10:59:34 (GMT)
commitcb53cae2230eedbba7807ea4c60f469fea08ccb7 (patch)
tree82a579d2371adaf74a208eeee3d681cbc8002f15
parent70a95724ab5c4629a9c37cfdc5db750684f48b05 (diff)
downloadnsgenbind-cb53cae2230eedbba7807ea4c60f469fea08ccb7.tar.gz
nsgenbind-cb53cae2230eedbba7807ea4c60f469fea08ccb7.tar.bz2
split heuristic code generation out from interface logic
-rw-r--r--src/Makefile3
-rw-r--r--src/duk-libdom-generated.c210
-rw-r--r--src/duk-libdom-interface.c191
-rw-r--r--src/duk-libdom.h11
4 files changed, 230 insertions, 185 deletions
diff --git a/src/Makefile b/src/Makefile
index 3ecfbe1..15095de 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,7 +2,8 @@ CFLAGS := $(CFLAGS) -I$(BUILDDIR) -Isrc/ -g -DYYENABLE_NLS=0
# Sources in this directory
DIR_SOURCES := nsgenbind.c utils.c webidl-ast.c nsgenbind-ast.c ir.c \
- duk-libdom.c duk-libdom-interface.c duk-libdom-dictionary.c duk-libdom-common.c
+ duk-libdom.c duk-libdom-interface.c duk-libdom-dictionary.c \
+ duk-libdom-common.c duk-libdom-generated.c
# jsapi-libdom.c jsapi-libdom-function.c jsapi-libdom-property.c jsapi-libdom-init.c jsapi-libdom-new.c jsapi-libdom-infmap.c jsapi-libdom-jsclass.c
diff --git a/src/duk-libdom-generated.c b/src/duk-libdom-generated.c
new file mode 100644
index 0000000..dd294ca
--- a/dev/null
+++ b/src/duk-libdom-generated.c
@@ -0,0 +1,210 @@
+/* duktape and libdom binding generation implementation
+ *
+ * This file is part of nsgenbind.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
+ */
+
+/**
+ * \file
+ * functions that automatically generate binding contents based on heuristics
+ * with explicit knowledge about libdom and how IDL data types map to it.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include "options.h"
+#include "utils.h"
+#include "nsgenbind-ast.h"
+#include "webidl-ast.h"
+#include "ir.h"
+#include "duk-libdom.h"
+
+/* exported function documented in duk-libdom.h */
+int
+output_generated_attribute_getter(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_attribute_entry *atributee)
+{
+ switch (atributee->base_type) {
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\tdom_string *str;\n"
+ "\n");
+ fprintf(outf,
+ "\texc = dom_%s_get_%s((struct dom_%s *)((node_private_t*)priv)->node, &str);\n",
+ interfacee->class_name,
+ atributee->property_name,
+ interfacee->class_name);
+ fprintf(outf,
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n"
+ "\tduk_push_lstring(ctx,\n"
+ "\t\tdom_string_data(str),\n"
+ "\t\tdom_string_length(str));\n"
+ "\tdom_string_unref(str);\n"
+ "\n"
+ "\treturn 1;\n");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ if (atributee->type_modifier == WEBIDL_TYPE_MODIFIER_UNSIGNED) {
+ fprintf(outf, "\tdom_ulong l;\n");
+ } else {
+ fprintf(outf, "\tdom_long l;\n");
+ }
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\n");
+ fprintf(outf,
+ "\texc = dom_%s_get_%s((struct dom_%s *)((node_private_t*)priv)->node, &l);\n",
+ interfacee->class_name,
+ atributee->property_name,
+ interfacee->class_name);
+ fprintf(outf,
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n"
+ "\tduk_push_number(ctx, (duk_double_t)l);\n"
+ "\n"
+ "\treturn 1;\n");
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\tbool b;\n"
+ "\n");
+ fprintf(outf,
+ "\texc = dom_%s_get_%s((struct dom_%s *)((node_private_t*)priv)->node, &b);\n",
+ interfacee->class_name,
+ atributee->property_name,
+ interfacee->class_name);
+ fprintf(outf,
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n"
+ "\tduk_push_boolean(ctx, b);\n"
+ "\n"
+ "\treturn 1;\n");
+ break;
+
+ default:
+ return -1;
+
+ }
+
+ WARN(WARNING_GENERATED,
+ "Generated: getter %s::%s();",
+ interfacee->name, atributee->name);
+
+ return 0;
+}
+
+/* exported function documented in duk-libdom.h */
+int
+output_generated_attribute_setter(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_attribute_entry *atributee)
+{
+ switch (atributee->base_type) {
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\tdom_string *str;\n"
+ "\tduk_size_t slen;\n"
+ "\tconst char *s;\n"
+ "\ts = duk_safe_to_lstring(ctx, 0, &slen);\n"
+ "\n"
+ "\texc = dom_string_create((const uint8_t *)s, slen, &str);\n"
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n");
+ fprintf(outf,
+ "\texc = dom_%s_set_%s((struct dom_%s *)((node_private_t*)priv)->node, str);\n",
+ interfacee->class_name,
+ atributee->property_name,
+ interfacee->class_name);
+ fprintf(outf,
+ "\tdom_string_unref(str);\n"
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n"
+ "\treturn 0;\n");
+ break;
+
+ case WEBIDL_TYPE_LONG:
+ if (atributee->type_modifier == WEBIDL_TYPE_MODIFIER_UNSIGNED) {
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\tdom_ulong l;\n"
+ "\n"
+ "\tl = duk_get_uint(ctx, 0);\n"
+ "\n");
+ } else {
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\tdom_long l;\n"
+ "\n"
+ "\tl = duk_get_int(ctx, 0);\n"
+ "\n");
+ }
+ fprintf(outf,
+ "\texc = dom_%s_set_%s((struct dom_%s *)((node_private_t*)priv)->node, l);\n",
+ interfacee->class_name,
+ atributee->property_name,
+ interfacee->class_name);
+ fprintf(outf,
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n"
+ "\treturn 0;\n");
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "\tdom_exception exc;\n"
+ "\tbool b;\n"
+ "\n"
+ "\tb = duk_get_boolean(ctx, 0);\n"
+ "\n");
+ fprintf(outf,
+ "\texc = dom_%s_set_%s((struct dom_%s *)((node_private_t*)priv)->node, b);\n",
+ interfacee->class_name,
+ atributee->property_name,
+ interfacee->class_name);
+ fprintf(outf,
+ "\tif (exc != DOM_NO_ERR) {\n"
+ "\t\treturn 0;\n"
+ "\t}\n"
+ "\n"
+ "\treturn 0;\n");
+ break;
+
+ default:
+ return -1;
+
+ }
+
+ WARN(WARNING_GENERATED,
+ "Generated: getter %s::%s();",
+ interfacee->name, atributee->name);
+
+ return 0;
+}
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c
index 553a213..d7214e3 100644
--- a/src/duk-libdom-interface.c
+++ b/src/duk-libdom-interface.c
@@ -1161,6 +1161,11 @@ output_interface_operation(FILE* outf,
WARN(WARNING_UNIMPLEMENTED,
"Unimplemented: method %s::%s();",
interfacee->name, operatione->name);
+
+ if (options->dbglog) {
+ fprintf(outf, "\tLOG(\"Unimplemented\");\n" );
+ }
+
fprintf(outf,"\treturn 0;\n");
}
@@ -1192,93 +1197,6 @@ output_interface_operations(FILE* outf, struct ir_entry *ife)
}
-/**
- * Generate class property getter for a single attribute
- */
-static int
-output_generated_attribute_getter(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_attribute_entry *atributee)
-{
- switch (atributee->base_type) {
- case WEBIDL_TYPE_STRING:
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\tdom_string *str;\n"
- "\n");
- fprintf(outf,
- "\texc = dom_%s_get_%s((struct dom_%s *)((node_private_t*)priv)->node, &str);\n",
- interfacee->class_name,
- atributee->property_name,
- interfacee->class_name);
- fprintf(outf,
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n"
- "\tduk_push_lstring(ctx,\n"
- "\t\tdom_string_data(str),\n"
- "\t\tdom_string_length(str));\n"
- "\tdom_string_unref(str);\n"
- "\n"
- "\treturn 1;\n");
- break;
-
- case WEBIDL_TYPE_LONG:
- if (atributee->type_modifier == WEBIDL_TYPE_MODIFIER_UNSIGNED) {
- fprintf(outf, "\tdom_ulong l;\n");
- } else {
- fprintf(outf, "\tdom_long l;\n");
- }
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\n");
- fprintf(outf,
- "\texc = dom_%s_get_%s((struct dom_%s *)((node_private_t*)priv)->node, &l);\n",
- interfacee->class_name,
- atributee->property_name,
- interfacee->class_name);
- fprintf(outf,
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n"
- "\tduk_push_number(ctx, (duk_double_t)l);\n"
- "\n"
- "\treturn 1;\n");
- break;
-
- case WEBIDL_TYPE_BOOL:
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\tbool b;\n"
- "\n");
- fprintf(outf,
- "\texc = dom_%s_get_%s((struct dom_%s *)((node_private_t*)priv)->node, &b);\n",
- interfacee->class_name,
- atributee->property_name,
- interfacee->class_name);
- fprintf(outf,
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n"
- "\tduk_push_boolean(ctx, b);\n"
- "\n"
- "\treturn 1;\n");
- break;
-
- default:
- return -1;
-
- }
-
- WARN(WARNING_GENERATED,
- "Generated: getter %s::%s();",
- interfacee->name, atributee->name);
-
- return 0;
-}
/**
* Output class property getter for a single attribute
@@ -1312,6 +1230,8 @@ output_attribute_getter(FILE* outf,
}
}
+ /* no implementation so generate default and warnings if required */
+
WARN(WARNING_UNIMPLEMENTED,
"Unimplemented: getter %s::%s(%s);",
interfacee->name,
@@ -1323,7 +1243,6 @@ output_attribute_getter(FILE* outf,
fprintf(outf, "\tLOG(\"Unimplemented\");\n" );
}
- /* no implementation so generate default */
fprintf(outf,
"\treturn 0;\n"
"}\n\n");
@@ -1331,102 +1250,6 @@ output_attribute_getter(FILE* outf,
return 0;
}
-/**
- * Generate class property setter for a single attribute
- */
-static int
-output_generated_attribute_setter(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_attribute_entry *atributee)
-{
- switch (atributee->base_type) {
- case WEBIDL_TYPE_STRING:
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\tdom_string *str;\n"
- "\tduk_size_t slen;\n"
- "\tconst char *s;\n"
- "\ts = duk_safe_to_lstring(ctx, 0, &slen);\n"
- "\n"
- "\texc = dom_string_create((const uint8_t *)s, slen, &str);\n"
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n");
- fprintf(outf,
- "\texc = dom_%s_set_%s((struct dom_%s *)((node_private_t*)priv)->node, str);\n",
- interfacee->class_name,
- atributee->property_name,
- interfacee->class_name);
- fprintf(outf,
- "\tdom_string_unref(str);\n"
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n"
- "\treturn 0;\n");
- break;
-
- case WEBIDL_TYPE_LONG:
- if (atributee->type_modifier == WEBIDL_TYPE_MODIFIER_UNSIGNED) {
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\tdom_ulong l;\n"
- "\n"
- "\tl = duk_get_uint(ctx, 0);\n"
- "\n");
- } else {
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\tdom_long l;\n"
- "\n"
- "\tl = duk_get_int(ctx, 0);\n"
- "\n");
- }
- fprintf(outf,
- "\texc = dom_%s_set_%s((struct dom_%s *)((node_private_t*)priv)->node, l);\n",
- interfacee->class_name,
- atributee->property_name,
- interfacee->class_name);
- fprintf(outf,
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n"
- "\treturn 0;\n");
- break;
-
- case WEBIDL_TYPE_BOOL:
- fprintf(outf,
- "\tdom_exception exc;\n"
- "\tbool b;\n"
- "\n"
- "\tb = duk_get_boolean(ctx, 0);\n"
- "\n");
- fprintf(outf,
- "\texc = dom_%s_set_%s((struct dom_%s *)((node_private_t*)priv)->node, b);\n",
- interfacee->class_name,
- atributee->property_name,
- interfacee->class_name);
- fprintf(outf,
- "\tif (exc != DOM_NO_ERR) {\n"
- "\t\treturn 0;\n"
- "\t}\n"
- "\n"
- "\treturn 0;\n");
- break;
-
- default:
- return -1;
-
- }
-
- WARN(WARNING_GENERATED,
- "Generated: getter %s::%s();",
- interfacee->name, atributee->name);
-
- return 0;
-}
/**
* Generate class property setter for a putforwards attribute
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index 73b7233..51d4327 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -111,4 +111,15 @@ int output_ctype(FILE *outf, struct genbind_node *node, bool identifier);
*/
char *gen_idl2c_name(const char *idlname);
+/**
+ * Generate class property setter for a single attribute.
+ */
+int output_generated_attribute_setter(FILE* outf, struct ir_entry *interfacee, struct ir_attribute_entry *atributee);
+
+/**
+ * Generate class property getter for a single attribute.
+ */
+int output_generated_attribute_getter(FILE* outf, struct ir_entry *interfacee, struct ir_attribute_entry *atributee);
+
+
#endif