Gitweb links:
...log
http://git.netsurf-browser.org/nsgenbind.git/shortlog/4b723a410bc1a3355d4...
...commit
http://git.netsurf-browser.org/nsgenbind.git/commit/4b723a410bc1a3355d401...
...tree
http://git.netsurf-browser.org/nsgenbind.git/tree/4b723a410bc1a3355d401b9...
The branch, vince/interfacemap has been updated
via 4b723a410bc1a3355d401b95ac390f377b5d77b8 (commit)
via 1fcab4d37de137bbc346e6ed82d92ed97f2024cf (commit)
from 2976a0e461da9777b23851eb37e285cbf1b8d6b1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/nsgenbind.git/commit/?id=4b723a410bc1a3355...
commit 4b723a410bc1a3355d401b95ac390f377b5d77b8
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Clean up code generation functions
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 173d22f..a883f7c 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -34,6 +34,207 @@
" */"
/**
+ * Output code to create a private structure
+ *
+ */
+static int output_create_private(FILE* outf, char *class_name)
+{
+ fprintf(outf, "\t/* create private data and attach to instance */\n");
+ fprintf(outf, "\t%s_private_t *priv = calloc(1, sizeof(*priv));\n",
+ class_name);
+ fprintf(outf, "\tif (priv == NULL) return 0;\n");
+ fprintf(outf, "\tduk_push_pointer(ctx, priv);\n");
+ fprintf(outf, "\tduk_put_prop_string(ctx, 0, PRIVATE_MAGIC)\n\n");
+
+ return 0;
+}
+
+/**
+ * generate code that gets a private pointer
+ */
+static int output_safe_get_private(FILE* outf, char *class_name, int idx)
+{
+ fprintf(outf, "\t%s_private_t *priv;\n", class_name);
+ fprintf(outf, "\tduk_get_prop_string(ctx, %d, PRIVATE_MAGIC);\n",idx);
+ fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
+ fprintf(outf, "\tduk_pop(ctx);\n");
+ fprintf(outf, "\tif (priv == NULL) return 0;\n\n");
+ return 0;
+}
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *interface_name)
+{
+ char *proto_name;
+ int pnamelen;
+
+ /* duplicate the interface name in upper case */
+ pnamelen = strlen(interface_name) + 1; /* allow for null byte */
+ proto_name = malloc(pnamelen);
+ for ( ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen] = toupper(interface_name[pnamelen]);
+ }
+ fprintf(outf, "\t/* get prototype */\n");
+ fprintf(outf, "\tduk_get_global_string(ctx, PROTO_MAGIC);\n");
+ fprintf(outf, "\tduk_get_prop_string(ctx, -1, PROTO_NAME(%s));\n",
+ proto_name);
+ fprintf(outf, "\tduk_replace(ctx, -2);\n");
+
+ free(proto_name);
+
+ return 0;
+}
+
+/**
+ * generate code that sets a destructor in a prototype
+ */
+static int output_set_destructor(FILE* outf, char *class_name, int idx)
+{
+ fprintf(outf, "\t/* Set the destructor */\n");
+ fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
+ fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___destructor, 1);\n",
+ DLPFX, class_name);
+ fprintf(outf, "\tduk_set_finalizer(ctx, -2);\n");
+ fprintf(outf, "\tduk_pop(ctx);\n\n");
+
+ return 0;
+}
+
+/**
+ * generate code that sets a constructor in a prototype
+ */
+static int
+output_set_constructor(FILE* outf, char *class_name, int idx, int argc)
+{
+ fprintf(outf, "\t/* Set the constructor */\n");
+ fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
+ fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___constructor,
%d);\n",
+ DLPFX, class_name, 1 + argc);
+ fprintf(outf, "\tduk_put_prop_string(ctx, -2, INIT_MAGIC);\n");
+ fprintf(outf, "\tduk_pop(ctx);\n\n");
+
+ return 0;
+}
+
+static int
+output_dump_stack(FILE* outf)
+{
+ if (options->dbglog) {
+ /* dump stack */
+ fprintf(outf, "\tduk_push_context_dump(ctx);\n");
+ fprintf(outf, "\tLOG(\"Stack: %%s\", duk_to_string(ctx,
-1));\n");
+ fprintf(outf, "\tduk_pop(ctx);\n");
+ }
+ return 0;
+}
+
+/**
+ * generate code that adds a method in a prototype
+ */
+static int
+output_add_method(FILE* outf, char *class_name, char *method, int argc)
+{
+ fprintf(outf, "\t/* Add a method */\n");
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, %s);\n", method);
+ fprintf(outf, "\tduk_push_c_function(ctx, %s_%s_%s, ",
+ DLPFX, class_name, method);
+ if (argc == -1) {
+ fprintf(outf, "DUK_VARARGS);\n");
+ } else {
+ fprintf(outf, "%d);\n", argc);
+ }
+ output_dump_stack(outf);
+ fprintf(outf, "\tduk_def_prop(ctx, -3,\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_VALUE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+
+ return 0;
+}
+
+/**
+ * Generate source to populate a read/write property on a prototype
+ */
+static int
+output_populate_rw_property(FILE* outf, const char *class_name, const char *property)
+{
+ fprintf(outf, "\t/* Add read/write property */\n");
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
+ fprintf(outf,
+ "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
+ DLPFX, class_name, property);
+ fprintf(outf,
+ "\tduk_push_c_function(ctx, %s_%s_%s_setter, 1);\n",
+ DLPFX, class_name, property);
+ fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_SETTER |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+
+ return 0;
+}
+
+/**
+ * Generate source to populate a readonly property on a prototype
+ */
+static int
+output_populate_ro_property(FILE* outf, const char *class_name, const char *property)
+{
+ fprintf(outf, "\t/* Add readonly property */\n");
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
+ fprintf(outf,
+ "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
+ DLPFX, class_name, property);
+ fprintf(outf,
+ "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+
+ return 0;
+}
+
+/**
+ * Generate source to add a constant int value on a prototype
+ */
+static int
+output_prototype_constant_int(FILE *outf, const char *constant_name, int value)
+{
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
constant_name);
+ fprintf(outf, "\tduk_push_int(ctx, %d);\n", value);
+ fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |
DUK_DEFPROP_HAVE_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_ENUMERABLE |
DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+ return 0;
+}
+
+/**
+ * generate code that gets a private pointer for a method
+ */
+static int
+output_get_method_private(FILE* outf, char *class_name)
+{
+ fprintf(outf, "\t/* Get private data for method */\n");
+ fprintf(outf, "\t%s_private_t *priv = NULL;\n", class_name);
+ fprintf(outf, "\tduk_push_this(ctx);\n");
+ fprintf(outf, "\tduk_get_prop_string(ctx, -1, PRIVATE_MAGIC);\n");
+ fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
+ fprintf(outf, "\tduk_pop_2(ctx);\n");
+ fprintf(outf, "\tif (priv == NULL) return 0; /* can do? No can do.
*/\n\n");
+ return 0;
+}
+
+/**
* Generate a C class name for the interface.
*
* The IDL interface names are camelcase and not similar to libdom naming so it
@@ -119,35 +320,6 @@ output_cdata(FILE* outf,
}
/**
- * Output code to create a private structure
- *
- */
-static int output_duckky_create_private(FILE* outf, char *class_name)
-{
- fprintf(outf, "\t/* create private data and attach to instance */\n");
- fprintf(outf, "\t%s_private_t *priv = calloc(1, sizeof(*priv));\n",
- class_name);
- fprintf(outf, "\tif (priv == NULL) return 0;\n");
- fprintf(outf, "\tduk_push_pointer(ctx, priv);\n");
- fprintf(outf, "\tduk_put_prop_string(ctx, 0, PRIVATE_MAGIC)\n\n");
-
- return 0;
-}
-
-/**
- * generate code that gets a private pointer
- */
-static int output_ducky_safe_get_private(FILE* outf, char *class_name, int idx)
-{
- fprintf(outf,
- "\t%s_private_t *priv = dukky_get_private(ctx, %d);\n",
- class_name, idx);
- fprintf(outf, "\tif (priv == NULL) return 0;\n\n");
- return 0;
-}
-
-
-/**
* generate the interface constructor
*/
static int
@@ -161,7 +333,7 @@ output_interface_constructor(FILE* outf, struct interface_map_entry
*interfacee)
DLPFX, interfacee->class_name);
fprintf(outf,"{\n");
- output_duckky_create_private(outf, interfacee->class_name);
+ output_create_private(outf, interfacee->class_name);
/* generate call to initialisor */
fprintf(outf,
@@ -195,7 +367,7 @@ output_interface_destructor(FILE* outf, struct interface_map_entry
*interfacee)
DLPFX, interfacee->class_name);
fprintf(outf,"{\n");
- output_ducky_safe_get_private(outf, interfacee->class_name, 0);
+ output_safe_get_private(outf, interfacee->class_name, 0);
/* generate call to finaliser */
fprintf(outf,
@@ -419,89 +591,6 @@ output_interface_fini(FILE* outf,
return 0;
}
-/**
- * generate code that gets a prototype by name
- */
-static int output_get_prototype(FILE* outf, const char *interface_name)
-{
- char *proto_name;
- int pnamelen;
-
- /* duplicate the interface name in upper case */
- pnamelen = strlen(interface_name) + 1; /* allow for null byte */
- proto_name = malloc(pnamelen);
- for ( ; pnamelen >= 0; pnamelen--) {
- proto_name[pnamelen] = toupper(interface_name[pnamelen]);
- }
- fprintf(outf, "\t/* get prototype */\n");
- fprintf(outf, "\tduk_get_global_string(ctx, PROTO_MAGIC);\n");
- fprintf(outf, "\tduk_get_prop_string(ctx, -1, PROTO_NAME(%s));\n",
- proto_name);
- fprintf(outf, "\tduk_replace(ctx, -2);\n");
-
- free(proto_name);
-
- return 0;
-}
-
-/**
- * generate code that sets a destructor in a prototype
- */
-static int output_set_destructor(FILE* outf, char *class_name, int idx)
-{
- fprintf(outf, "\t/* Set the destructor */\n");
- fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
- fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___destructor, 1);\n",
- DLPFX, class_name);
- fprintf(outf, "\tduk_set_finalizer(ctx, -2);\n");
- fprintf(outf, "\tduk_pop(ctx);\n\n");
-
- return 0;
-}
-
-/**
- * generate code that sets a constructor in a prototype
- */
-static int
-output_set_constructor(FILE* outf, char *class_name, int idx, int argc)
-{
- fprintf(outf, "\t/* Set the constructor */\n");
- fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
- fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___constructor,
%d);\n",
- DLPFX, class_name, 1 + argc);
- fprintf(outf, "\tduk_put_prop_string(ctx, -2, INIT_MAGIC);\n");
- fprintf(outf, "\tduk_pop(ctx);\n\n");
-
- return 0;
-}
-
-/**
- * generate code that adds a method in a prototype
- */
-static int
-output_add_method(FILE* outf, char *class_name, char *method, int argc)
-{
- fprintf(outf, "\t/* Add a method */\n");
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, %s);\n", method);
- fprintf(outf, "\tduk_push_c_function(ctx, %s_%s_%s, ",
- DLPFX, class_name, method);
- if (argc == -1) {
- fprintf(outf, "DUK_VARARGS);\n");
-
- } else {
- fprintf(outf, "%d);\n", argc);
- }
- fprintf(outf, "\tDUKKY_DUMP_STACK(ctx);\n");
- fprintf(outf, "\tduk_def_prop(ctx, -3,\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_VALUE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
-
- return 0;
-}
/**
* count the number of arguments to an operation
@@ -554,7 +643,6 @@ output_prototype_method(FILE* outf,
output_add_method(outf, interfacee->class_name, op_name, op_argc);
return 0;
-
}
/**
@@ -600,47 +688,8 @@ output_prototype_methods(FILE *outf, struct interface_map_entry
*interfacee)
}
return 0;
-
}
-static int
-output_populate_rw_property(FILE* outf, const char *class_name, const char *property)
-{
- fprintf(outf, "\t/* Add read/write property */\n");
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
- fprintf(outf,
- "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
- DLPFX, class_name, property);
- fprintf(outf,
- "\tduk_push_c_function(ctx, %s_%s_%s_setter, 1);\n",
- DLPFX, class_name, property);
- fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_SETTER |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
-
- return 0;
-}
-
-static int
-output_populate_ro_property(FILE* outf, const char *class_name, const char *property)
-{
- fprintf(outf, "\t/* Add readonly property */\n");
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
- fprintf(outf,
- "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
- DLPFX, class_name, property);
- fprintf(outf,
- "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
-
- return 0;
-}
static int
output_prototype_attribute(FILE *outf,
@@ -651,11 +700,10 @@ output_prototype_attribute(FILE *outf,
return output_populate_ro_property(outf,
interfacee->class_name,
attributee->name);
- } else {
- return output_populate_rw_property(outf,
- interfacee->class_name,
- attributee->name);
}
+ return output_populate_rw_property(outf,
+ interfacee->class_name,
+ attributee->name);
}
/**
@@ -665,14 +713,17 @@ static int
output_prototype_attributes(FILE *outf, struct interface_map_entry *interfacee)
{
int attrc;
+ int res = 0;
for (attrc = 0; attrc < interfacee->attributec; attrc++) {
- output_prototype_attribute(outf,
- interfacee,
- interfacee->attributev + attrc);
+ res = output_prototype_attribute(outf,interfacee,
+ interfacee->attributev + attrc);
+ if (res != 0) {
+ break;
+ }
}
- return 0;
+ return res;
}
/**
@@ -693,14 +744,8 @@ output_prototype_constant(FILE *outf,
NULL,
WEBIDL_NODE_TYPE_LITERAL_INT));
+ output_prototype_constant_int(outf, constante->name, *value);
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
constante->name);
- fprintf(outf, "\tduk_push_int(ctx, %d);\n", *value);
- fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |
DUK_DEFPROP_HAVE_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_ENUMERABLE |
DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
return 0;
}
@@ -711,12 +756,17 @@ static int
output_prototype_constants(FILE *outf, struct interface_map_entry *interfacee)
{
int attrc;
+ int res = 0;
for (attrc = 0; attrc < interfacee->constantc; attrc++) {
- output_prototype_constant(outf, interfacee->constantv + attrc);
+ res = output_prototype_constant(outf,
+ interfacee->constantv + attrc);
+ if (res != 0) {
+ break;
+ }
}
- return 0;
+ return res;
}
/**
@@ -766,21 +816,6 @@ output_interface_prototype(FILE* outf,
return 0;
}
-/**
- * generate code that gets a private pointer for a method
- */
-static int
-output_get_method_private(FILE* outf, char *class_name)
-{
- fprintf(outf, "\t/* Get private data for method */\n");
- fprintf(outf, "\t%s_private_t *priv = NULL;\n", class_name);
- fprintf(outf, "\tduk_push_this(ctx);\n");
- fprintf(outf, "\tduk_get_prop_string(ctx, -1, PRIVATE_MAGIC);\n");
- fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
- fprintf(outf, "\tduk_pop_2(ctx);\n");
- fprintf(outf, "\tif (priv == NULL) return 0; /* can do? No can do.
*/\n\n");
- return 0;
-}
/**
* generate a single class method for an interface operation
commitdiff
http://git.netsurf-browser.org/nsgenbind.git/commit/?id=1fcab4d37de137bbc...
commit 1fcab4d37de137bbc346e6ed82d92ed97f2024cf
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Generate prototype header and include it from each class source
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index e277eec..173d22f 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -309,20 +309,12 @@ output_interface_inherit_init(FILE* outf,
}
static int
-output_interface_init(FILE* outf,
- struct interface_map_entry *interfacee,
- struct interface_map_entry *inherite)
+output_interface_init_declaration(FILE* outf,
+ struct interface_map_entry *interfacee,
+ struct genbind_node *init_node)
{
- struct genbind_node *init_node;
struct genbind_node *param_node;
- int res;
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
- /* initialisor definition */
fprintf(outf,
"void %s_%s___init(duk_context *ctx, %s_private_t *priv",
DLPFX, interfacee->class_name, interfacee->class_name);
@@ -345,7 +337,28 @@ output_interface_init(FILE* outf,
param_node, GENBIND_NODE_TYPE_METHOD);
}
- fprintf(outf,")\n{\n");
+ fprintf(outf,")");
+
+ return 0;
+}
+
+static int
+output_interface_init(FILE* outf,
+ struct interface_map_entry *interfacee,
+ struct interface_map_entry *inherite)
+{
+ struct genbind_node *init_node;
+ int res;
+
+ /* 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(outf, interfacee, init_node);
+
+ fprintf(outf,"\n{\n");
/* if this interface inherits ensure we call its initialisor */
res = output_interface_inherit_init(outf, interfacee, inherite);
@@ -915,12 +928,22 @@ output_interface_attributes(FILE* outf,
return 0;
}
-static int output_private_include(FILE* outf)
+/**
+ * generate preface block for nsgenbind
+ */
+static int output_tool_preface(FILE* outf)
{
char *fpath;
+
+ fprintf(outf, "\n%s\n\n", NSGENBIND_PREAMBLE);
+
fpath = genb_fpath("private.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
- fprintf(outf, "\n#include \"%s\"\n", fpath);
+ fpath = genb_fpath("prototype.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
return 0;
}
@@ -963,8 +986,7 @@ static int output_interface(struct genbind_node *genbind,
output_cdata(ifacef, binding_node, GENBIND_NODE_TYPE_PREFACE);
/* tool preface */
- fprintf(ifacef, "\n%s\n", NSGENBIND_PREAMBLE);
- output_private_include(ifacef);
+ output_tool_preface(ifacef);
/* class preface */
output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PREFACE);
@@ -1021,7 +1043,9 @@ op_error:
return res;
}
-/** generate private header */
+/**
+ * generate private header
+ */
static int
output_private_header(struct interface_map *interface_map)
{
@@ -1072,12 +1096,56 @@ output_private_header(struct interface_map *interface_map)
}
-
fclose(privf);
return 0;
}
+/**
+ * generate protottype header
+ */
+static int
+output_prototype_header(struct interface_map *interface_map)
+{
+ int idx;
+ FILE *protof;
+
+ /* open output file */
+ protof = genb_fopen("prototype.h", "w");
+ if (protof == NULL) {
+ return -1;
+ }
+
+ for (idx = 0; idx < interface_map->entryc; idx++) {
+ struct interface_map_entry *interfacee;
+ struct genbind_node *init_node;
+
+ interfacee = interface_map->entries + idx;
+
+ /* prototype declaration */
+ fprintf(protof, "duk_ret_t %s_%s___proto(duk_context
*ctx);\n",
+ DLPFX, interfacee->class_name);
+
+ /* 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");
+ }
+
+ fclose(protof);
+
+ return 0;
+}
+
int duk_libdom_output(struct genbind_node *genbind,
struct webidl_node *webidl,
struct interface_map *interface_map)
@@ -1101,9 +1169,11 @@ int duk_libdom_output(struct genbind_node *genbind,
goto output_err;
}
-
/* generate prototype header */
- /** \todo implement header */
+ res = output_prototype_header(interface_map);
+ if (res != 0) {
+ goto output_err;
+ }
/* generate makefile fragment */
/** \todo implement makefile generation */
-----------------------------------------------------------------------
Summary of changes:
src/duk-libdom.c | 517 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 311 insertions(+), 206 deletions(-)
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index e277eec..a883f7c 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -34,6 +34,207 @@
" */"
/**
+ * Output code to create a private structure
+ *
+ */
+static int output_create_private(FILE* outf, char *class_name)
+{
+ fprintf(outf, "\t/* create private data and attach to instance */\n");
+ fprintf(outf, "\t%s_private_t *priv = calloc(1, sizeof(*priv));\n",
+ class_name);
+ fprintf(outf, "\tif (priv == NULL) return 0;\n");
+ fprintf(outf, "\tduk_push_pointer(ctx, priv);\n");
+ fprintf(outf, "\tduk_put_prop_string(ctx, 0, PRIVATE_MAGIC)\n\n");
+
+ return 0;
+}
+
+/**
+ * generate code that gets a private pointer
+ */
+static int output_safe_get_private(FILE* outf, char *class_name, int idx)
+{
+ fprintf(outf, "\t%s_private_t *priv;\n", class_name);
+ fprintf(outf, "\tduk_get_prop_string(ctx, %d, PRIVATE_MAGIC);\n",idx);
+ fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
+ fprintf(outf, "\tduk_pop(ctx);\n");
+ fprintf(outf, "\tif (priv == NULL) return 0;\n\n");
+ return 0;
+}
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *interface_name)
+{
+ char *proto_name;
+ int pnamelen;
+
+ /* duplicate the interface name in upper case */
+ pnamelen = strlen(interface_name) + 1; /* allow for null byte */
+ proto_name = malloc(pnamelen);
+ for ( ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen] = toupper(interface_name[pnamelen]);
+ }
+ fprintf(outf, "\t/* get prototype */\n");
+ fprintf(outf, "\tduk_get_global_string(ctx, PROTO_MAGIC);\n");
+ fprintf(outf, "\tduk_get_prop_string(ctx, -1, PROTO_NAME(%s));\n",
+ proto_name);
+ fprintf(outf, "\tduk_replace(ctx, -2);\n");
+
+ free(proto_name);
+
+ return 0;
+}
+
+/**
+ * generate code that sets a destructor in a prototype
+ */
+static int output_set_destructor(FILE* outf, char *class_name, int idx)
+{
+ fprintf(outf, "\t/* Set the destructor */\n");
+ fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
+ fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___destructor, 1);\n",
+ DLPFX, class_name);
+ fprintf(outf, "\tduk_set_finalizer(ctx, -2);\n");
+ fprintf(outf, "\tduk_pop(ctx);\n\n");
+
+ return 0;
+}
+
+/**
+ * generate code that sets a constructor in a prototype
+ */
+static int
+output_set_constructor(FILE* outf, char *class_name, int idx, int argc)
+{
+ fprintf(outf, "\t/* Set the constructor */\n");
+ fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
+ fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___constructor,
%d);\n",
+ DLPFX, class_name, 1 + argc);
+ fprintf(outf, "\tduk_put_prop_string(ctx, -2, INIT_MAGIC);\n");
+ fprintf(outf, "\tduk_pop(ctx);\n\n");
+
+ return 0;
+}
+
+static int
+output_dump_stack(FILE* outf)
+{
+ if (options->dbglog) {
+ /* dump stack */
+ fprintf(outf, "\tduk_push_context_dump(ctx);\n");
+ fprintf(outf, "\tLOG(\"Stack: %%s\", duk_to_string(ctx,
-1));\n");
+ fprintf(outf, "\tduk_pop(ctx);\n");
+ }
+ return 0;
+}
+
+/**
+ * generate code that adds a method in a prototype
+ */
+static int
+output_add_method(FILE* outf, char *class_name, char *method, int argc)
+{
+ fprintf(outf, "\t/* Add a method */\n");
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, %s);\n", method);
+ fprintf(outf, "\tduk_push_c_function(ctx, %s_%s_%s, ",
+ DLPFX, class_name, method);
+ if (argc == -1) {
+ fprintf(outf, "DUK_VARARGS);\n");
+ } else {
+ fprintf(outf, "%d);\n", argc);
+ }
+ output_dump_stack(outf);
+ fprintf(outf, "\tduk_def_prop(ctx, -3,\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_VALUE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+
+ return 0;
+}
+
+/**
+ * Generate source to populate a read/write property on a prototype
+ */
+static int
+output_populate_rw_property(FILE* outf, const char *class_name, const char *property)
+{
+ fprintf(outf, "\t/* Add read/write property */\n");
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
+ fprintf(outf,
+ "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
+ DLPFX, class_name, property);
+ fprintf(outf,
+ "\tduk_push_c_function(ctx, %s_%s_%s_setter, 1);\n",
+ DLPFX, class_name, property);
+ fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_SETTER |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+
+ return 0;
+}
+
+/**
+ * Generate source to populate a readonly property on a prototype
+ */
+static int
+output_populate_ro_property(FILE* outf, const char *class_name, const char *property)
+{
+ fprintf(outf, "\t/* Add readonly property */\n");
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
+ fprintf(outf,
+ "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
+ DLPFX, class_name, property);
+ fprintf(outf,
+ "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+
+ return 0;
+}
+
+/**
+ * Generate source to add a constant int value on a prototype
+ */
+static int
+output_prototype_constant_int(FILE *outf, const char *constant_name, int value)
+{
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
constant_name);
+ fprintf(outf, "\tduk_push_int(ctx, %d);\n", value);
+ fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |
DUK_DEFPROP_HAVE_ENUMERABLE |\n");
+ fprintf(outf, "\t DUK_DEFPROP_ENUMERABLE |
DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
+ fprintf(outf, "\tduk_pop(ctx)\n\n");
+ return 0;
+}
+
+/**
+ * generate code that gets a private pointer for a method
+ */
+static int
+output_get_method_private(FILE* outf, char *class_name)
+{
+ fprintf(outf, "\t/* Get private data for method */\n");
+ fprintf(outf, "\t%s_private_t *priv = NULL;\n", class_name);
+ fprintf(outf, "\tduk_push_this(ctx);\n");
+ fprintf(outf, "\tduk_get_prop_string(ctx, -1, PRIVATE_MAGIC);\n");
+ fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
+ fprintf(outf, "\tduk_pop_2(ctx);\n");
+ fprintf(outf, "\tif (priv == NULL) return 0; /* can do? No can do.
*/\n\n");
+ return 0;
+}
+
+/**
* Generate a C class name for the interface.
*
* The IDL interface names are camelcase and not similar to libdom naming so it
@@ -119,35 +320,6 @@ output_cdata(FILE* outf,
}
/**
- * Output code to create a private structure
- *
- */
-static int output_duckky_create_private(FILE* outf, char *class_name)
-{
- fprintf(outf, "\t/* create private data and attach to instance */\n");
- fprintf(outf, "\t%s_private_t *priv = calloc(1, sizeof(*priv));\n",
- class_name);
- fprintf(outf, "\tif (priv == NULL) return 0;\n");
- fprintf(outf, "\tduk_push_pointer(ctx, priv);\n");
- fprintf(outf, "\tduk_put_prop_string(ctx, 0, PRIVATE_MAGIC)\n\n");
-
- return 0;
-}
-
-/**
- * generate code that gets a private pointer
- */
-static int output_ducky_safe_get_private(FILE* outf, char *class_name, int idx)
-{
- fprintf(outf,
- "\t%s_private_t *priv = dukky_get_private(ctx, %d);\n",
- class_name, idx);
- fprintf(outf, "\tif (priv == NULL) return 0;\n\n");
- return 0;
-}
-
-
-/**
* generate the interface constructor
*/
static int
@@ -161,7 +333,7 @@ output_interface_constructor(FILE* outf, struct interface_map_entry
*interfacee)
DLPFX, interfacee->class_name);
fprintf(outf,"{\n");
- output_duckky_create_private(outf, interfacee->class_name);
+ output_create_private(outf, interfacee->class_name);
/* generate call to initialisor */
fprintf(outf,
@@ -195,7 +367,7 @@ output_interface_destructor(FILE* outf, struct interface_map_entry
*interfacee)
DLPFX, interfacee->class_name);
fprintf(outf,"{\n");
- output_ducky_safe_get_private(outf, interfacee->class_name, 0);
+ output_safe_get_private(outf, interfacee->class_name, 0);
/* generate call to finaliser */
fprintf(outf,
@@ -309,20 +481,12 @@ output_interface_inherit_init(FILE* outf,
}
static int
-output_interface_init(FILE* outf,
- struct interface_map_entry *interfacee,
- struct interface_map_entry *inherite)
+output_interface_init_declaration(FILE* outf,
+ struct interface_map_entry *interfacee,
+ struct genbind_node *init_node)
{
- struct genbind_node *init_node;
struct genbind_node *param_node;
- int res;
-
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
- /* initialisor definition */
fprintf(outf,
"void %s_%s___init(duk_context *ctx, %s_private_t *priv",
DLPFX, interfacee->class_name, interfacee->class_name);
@@ -345,7 +509,28 @@ output_interface_init(FILE* outf,
param_node, GENBIND_NODE_TYPE_METHOD);
}
- fprintf(outf,")\n{\n");
+ fprintf(outf,")");
+
+ return 0;
+}
+
+static int
+output_interface_init(FILE* outf,
+ struct interface_map_entry *interfacee,
+ struct interface_map_entry *inherite)
+{
+ struct genbind_node *init_node;
+ int res;
+
+ /* 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(outf, interfacee, init_node);
+
+ fprintf(outf,"\n{\n");
/* if this interface inherits ensure we call its initialisor */
res = output_interface_inherit_init(outf, interfacee, inherite);
@@ -406,89 +591,6 @@ output_interface_fini(FILE* outf,
return 0;
}
-/**
- * generate code that gets a prototype by name
- */
-static int output_get_prototype(FILE* outf, const char *interface_name)
-{
- char *proto_name;
- int pnamelen;
-
- /* duplicate the interface name in upper case */
- pnamelen = strlen(interface_name) + 1; /* allow for null byte */
- proto_name = malloc(pnamelen);
- for ( ; pnamelen >= 0; pnamelen--) {
- proto_name[pnamelen] = toupper(interface_name[pnamelen]);
- }
- fprintf(outf, "\t/* get prototype */\n");
- fprintf(outf, "\tduk_get_global_string(ctx, PROTO_MAGIC);\n");
- fprintf(outf, "\tduk_get_prop_string(ctx, -1, PROTO_NAME(%s));\n",
- proto_name);
- fprintf(outf, "\tduk_replace(ctx, -2);\n");
-
- free(proto_name);
-
- return 0;
-}
-
-/**
- * generate code that sets a destructor in a prototype
- */
-static int output_set_destructor(FILE* outf, char *class_name, int idx)
-{
- fprintf(outf, "\t/* Set the destructor */\n");
- fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
- fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___destructor, 1);\n",
- DLPFX, class_name);
- fprintf(outf, "\tduk_set_finalizer(ctx, -2);\n");
- fprintf(outf, "\tduk_pop(ctx);\n\n");
-
- return 0;
-}
-
-/**
- * generate code that sets a constructor in a prototype
- */
-static int
-output_set_constructor(FILE* outf, char *class_name, int idx, int argc)
-{
- fprintf(outf, "\t/* Set the constructor */\n");
- fprintf(outf, "\tduk_dup(ctx, %d);\n", idx);
- fprintf(outf, "\tduk_push_c_function(ctx, %s_%s___constructor,
%d);\n",
- DLPFX, class_name, 1 + argc);
- fprintf(outf, "\tduk_put_prop_string(ctx, -2, INIT_MAGIC);\n");
- fprintf(outf, "\tduk_pop(ctx);\n\n");
-
- return 0;
-}
-
-/**
- * generate code that adds a method in a prototype
- */
-static int
-output_add_method(FILE* outf, char *class_name, char *method, int argc)
-{
- fprintf(outf, "\t/* Add a method */\n");
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, %s);\n", method);
- fprintf(outf, "\tduk_push_c_function(ctx, %s_%s_%s, ",
- DLPFX, class_name, method);
- if (argc == -1) {
- fprintf(outf, "DUK_VARARGS);\n");
-
- } else {
- fprintf(outf, "%d);\n", argc);
- }
- fprintf(outf, "\tDUKKY_DUMP_STACK(ctx);\n");
- fprintf(outf, "\tduk_def_prop(ctx, -3,\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_VALUE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
-
- return 0;
-}
/**
* count the number of arguments to an operation
@@ -541,7 +643,6 @@ output_prototype_method(FILE* outf,
output_add_method(outf, interfacee->class_name, op_name, op_argc);
return 0;
-
}
/**
@@ -587,47 +688,8 @@ output_prototype_methods(FILE *outf, struct interface_map_entry
*interfacee)
}
return 0;
-
}
-static int
-output_populate_rw_property(FILE* outf, const char *class_name, const char *property)
-{
- fprintf(outf, "\t/* Add read/write property */\n");
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
- fprintf(outf,
- "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
- DLPFX, class_name, property);
- fprintf(outf,
- "\tduk_push_c_function(ctx, %s_%s_%s_setter, 1);\n",
- DLPFX, class_name, property);
- fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_SETTER |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
-
- return 0;
-}
-
-static int
-output_populate_ro_property(FILE* outf, const char *class_name, const char *property)
-{
- fprintf(outf, "\t/* Add readonly property */\n");
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
property);
- fprintf(outf,
- "\tduk_push_c_function(ctx, %s_%s_%s_getter, 0);\n",
- DLPFX, class_name, property);
- fprintf(outf,
- "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_ENUMERABLE |
DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
-
- return 0;
-}
static int
output_prototype_attribute(FILE *outf,
@@ -638,11 +700,10 @@ output_prototype_attribute(FILE *outf,
return output_populate_ro_property(outf,
interfacee->class_name,
attributee->name);
- } else {
- return output_populate_rw_property(outf,
- interfacee->class_name,
- attributee->name);
}
+ return output_populate_rw_property(outf,
+ interfacee->class_name,
+ attributee->name);
}
/**
@@ -652,14 +713,17 @@ static int
output_prototype_attributes(FILE *outf, struct interface_map_entry *interfacee)
{
int attrc;
+ int res = 0;
for (attrc = 0; attrc < interfacee->attributec; attrc++) {
- output_prototype_attribute(outf,
- interfacee,
- interfacee->attributev + attrc);
+ res = output_prototype_attribute(outf,interfacee,
+ interfacee->attributev + attrc);
+ if (res != 0) {
+ break;
+ }
}
- return 0;
+ return res;
}
/**
@@ -680,14 +744,8 @@ output_prototype_constant(FILE *outf,
NULL,
WEBIDL_NODE_TYPE_LITERAL_INT));
+ output_prototype_constant_int(outf, constante->name, *value);
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- fprintf(outf, "\tduk_push_string(ctx, \"%s\");\n",
constante->name);
- fprintf(outf, "\tduk_push_int(ctx, %d);\n", *value);
- fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE |\n");
- fprintf(outf, "\t DUK_DEFPROP_HAVE_WRITABLE |
DUK_DEFPROP_HAVE_ENUMERABLE |\n");
- fprintf(outf, "\t DUK_DEFPROP_ENUMERABLE |
DUK_DEFPROP_HAVE_CONFIGURABLE);\n");
- fprintf(outf, "\tduk_pop(ctx)\n\n");
return 0;
}
@@ -698,12 +756,17 @@ static int
output_prototype_constants(FILE *outf, struct interface_map_entry *interfacee)
{
int attrc;
+ int res = 0;
for (attrc = 0; attrc < interfacee->constantc; attrc++) {
- output_prototype_constant(outf, interfacee->constantv + attrc);
+ res = output_prototype_constant(outf,
+ interfacee->constantv + attrc);
+ if (res != 0) {
+ break;
+ }
}
- return 0;
+ return res;
}
/**
@@ -753,21 +816,6 @@ output_interface_prototype(FILE* outf,
return 0;
}
-/**
- * generate code that gets a private pointer for a method
- */
-static int
-output_get_method_private(FILE* outf, char *class_name)
-{
- fprintf(outf, "\t/* Get private data for method */\n");
- fprintf(outf, "\t%s_private_t *priv = NULL;\n", class_name);
- fprintf(outf, "\tduk_push_this(ctx);\n");
- fprintf(outf, "\tduk_get_prop_string(ctx, -1, PRIVATE_MAGIC);\n");
- fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
- fprintf(outf, "\tduk_pop_2(ctx);\n");
- fprintf(outf, "\tif (priv == NULL) return 0; /* can do? No can do.
*/\n\n");
- return 0;
-}
/**
* generate a single class method for an interface operation
@@ -915,12 +963,22 @@ output_interface_attributes(FILE* outf,
return 0;
}
-static int output_private_include(FILE* outf)
+/**
+ * generate preface block for nsgenbind
+ */
+static int output_tool_preface(FILE* outf)
{
char *fpath;
+
+ fprintf(outf, "\n%s\n\n", NSGENBIND_PREAMBLE);
+
fpath = genb_fpath("private.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
- fprintf(outf, "\n#include \"%s\"\n", fpath);
+ fpath = genb_fpath("prototype.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
return 0;
}
@@ -963,8 +1021,7 @@ static int output_interface(struct genbind_node *genbind,
output_cdata(ifacef, binding_node, GENBIND_NODE_TYPE_PREFACE);
/* tool preface */
- fprintf(ifacef, "\n%s\n", NSGENBIND_PREAMBLE);
- output_private_include(ifacef);
+ output_tool_preface(ifacef);
/* class preface */
output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PREFACE);
@@ -1021,7 +1078,9 @@ op_error:
return res;
}
-/** generate private header */
+/**
+ * generate private header
+ */
static int
output_private_header(struct interface_map *interface_map)
{
@@ -1072,12 +1131,56 @@ output_private_header(struct interface_map *interface_map)
}
-
fclose(privf);
return 0;
}
+/**
+ * generate protottype header
+ */
+static int
+output_prototype_header(struct interface_map *interface_map)
+{
+ int idx;
+ FILE *protof;
+
+ /* open output file */
+ protof = genb_fopen("prototype.h", "w");
+ if (protof == NULL) {
+ return -1;
+ }
+
+ for (idx = 0; idx < interface_map->entryc; idx++) {
+ struct interface_map_entry *interfacee;
+ struct genbind_node *init_node;
+
+ interfacee = interface_map->entries + idx;
+
+ /* prototype declaration */
+ fprintf(protof, "duk_ret_t %s_%s___proto(duk_context
*ctx);\n",
+ DLPFX, interfacee->class_name);
+
+ /* 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");
+ }
+
+ fclose(protof);
+
+ return 0;
+}
+
int duk_libdom_output(struct genbind_node *genbind,
struct webidl_node *webidl,
struct interface_map *interface_map)
@@ -1101,9 +1204,11 @@ int duk_libdom_output(struct genbind_node *genbind,
goto output_err;
}
-
/* generate prototype header */
- /** \todo implement header */
+ res = output_prototype_header(interface_map);
+ if (res != 0) {
+ goto output_err;
+ }
/* generate makefile fragment */
/** \todo implement makefile generation */
--
NetSurf Generator for JavaScript bindings