toolchains: branch master updated. a47ec59181b5d5f7588f75517cb5c2b95ff22e08
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/toolchains.git/shortlog/a47ec59181b5d5f758...
...commit http://git.netsurf-browser.org/toolchains.git/commit/a47ec59181b5d5f7588f...
...tree http://git.netsurf-browser.org/toolchains.git/tree/a47ec59181b5d5f7588f75...
The branch, master has been updated
via a47ec59181b5d5f7588f75517cb5c2b95ff22e08 (commit)
via a71589395ea15a9652d0a8785af5f6d18d9b79a8 (commit)
from e88575dbac2075d574d65bcc91f0e345ee2110d2 (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/toolchains.git/commit/?id=a47ec59181b5d5f7...
commit a47ec59181b5d5f7588f75517cb5c2b95ff22e08
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Update openurl.library download location
diff --git a/ppc-amigaos/Makefile b/ppc-amigaos/Makefile
index 18a39cb..e59f911 100644
--- a/ppc-amigaos/Makefile
+++ b/ppc-amigaos/Makefile
@@ -22,9 +22,9 @@ UPSTREAM_MPC_URI := http://www.multiprecision.org/mpc/download/$(UPSTREAM_MPC_TA
UPSTREAM_NDK_TARBALL := SDK_53.29.lha
UPSTREAM_NDK_URI := "http://hyperion-entertainment.biz/index.php/downloads?view=download&forma..."
-UPSTREAM_OPENURL_VERSION := 7.8
-UPSTREAM_OPENURL_TARBALL := openurl
-UPSTREAM_OPENURL_URI := http://svn.code.sf.net/p/openurllib/code/releases/$(UPSTREAM_OPENURL_VERS...
+UPSTREAM_OPENURL_VERSION := 7.16
+UPSTREAM_OPENURL_TARBALL := openurl-$(UPSTREAM_OPENURL_VERSION)
+UPSTREAM_OPENURL_URI := https://github.com/jens-maus/libopenurl/archive/$(UPSTREAM_OPENURL_VERSIO...
# need to force the auto* version in use
GCC_AUTOCONF := autoconf2.64
@@ -89,7 +89,9 @@ $(BUILDSTEPS)/ndk.d: $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL) $(SOURCESDIR)/$(UPSTR
cp -r $(BUILDDIR)/ndk/tmp/clib2 $(PREFIX)/$(TARGET_NAME)/SDK/clib2
cp -r $(BUILDDIR)/ndk/tmp/Local/common/include/* $(PREFIX)/$(TARGET_NAME)/SDK/newlib/include/
cp -r $(BUILDDIR)/ndk/tmp/Local/newlib/lib/* $(PREFIX)/$(TARGET_NAME)/SDK/newlib/lib/
- cp -r $(SOURCESDIR)/$(UPSTREAM_OPENURL_TARBALL)/include/* $(PREFIX)/$(TARGET_NAME)/SDK/include/include_h/
+ mkdir -p $(BUILDDIR)/openurl
+ cd $(BUILDDIR)/openurl && tar xaf $(SOURCESDIR)/$(UPSTREAM_OPENURL_TARBALL)
+ cp -r $(BUILDDIR)/openurl/libopenurl-$(UPSTREAM_OPENURL_VERSION)/include/* $(PREFIX)/$(TARGET_NAME)/SDK/include/include_h/
touch $@
###
@@ -157,7 +159,7 @@ $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL):
wget -q -O $@ $(UPSTREAM_NDK_URI)
$(SOURCESDIR)/$(UPSTREAM_OPENURL_TARBALL):
- svn export $(UPSTREAM_OPENURL_URI) $@
+ wget -q -O $@ $(UPSTREAM_OPENURL_URI)
###
# Rule to create buildsteps dir
commitdiff http://git.netsurf-browser.org/toolchains.git/commit/?id=a71589395ea15a96...
commit a71589395ea15a9652d0a8785af5f6d18d9b79a8
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Update to SDK 53.29
diff --git a/ppc-amigaos/Makefile b/ppc-amigaos/Makefile
index e7ab849..18a39cb 100644
--- a/ppc-amigaos/Makefile
+++ b/ppc-amigaos/Makefile
@@ -19,8 +19,8 @@ UPSTREAM_MPC_VERSION := 0.8.2
UPSTREAM_MPC_TARBALL := mpc-$(UPSTREAM_MPC_VERSION).tar.gz
UPSTREAM_MPC_URI := http://www.multiprecision.org/mpc/download/$(UPSTREAM_MPC_TARBALL)
-UPSTREAM_NDK_TARBALL := SDK_53.24.lha
-UPSTREAM_NDK_URI := "http://hyperion-entertainment.biz/index.php?option=com_registration&view=..."
+UPSTREAM_NDK_TARBALL := SDK_53.29.lha
+UPSTREAM_NDK_URI := "http://hyperion-entertainment.biz/index.php/downloads?view=download&forma..."
UPSTREAM_OPENURL_VERSION := 7.8
UPSTREAM_OPENURL_TARBALL := openurl
@@ -80,9 +80,9 @@ $(BUILDSTEPS)/ndk.d: $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL) $(SOURCESDIR)/$(UPSTR
mkdir -p $(BUILDDIR)/ndk/tmp/
lha xw=$(BUILDDIR)/ndk $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL)
lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/base.lha
- lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/newlib-53.28.lha
- lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/clib2-1.205.lha
- lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/pthread.lha
+ lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/newlib-53.30.lha
+ lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/clib2-1.206.lha
+ lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/pthreads-53.11.lha
mkdir -p $(PREFIX)/$(TARGET_NAME)/SDK
cp -r $(BUILDDIR)/ndk/tmp/Include $(PREFIX)/$(TARGET_NAME)/SDK/include
cp -r $(BUILDDIR)/ndk/tmp/newlib $(PREFIX)/$(TARGET_NAME)/SDK/newlib
-----------------------------------------------------------------------
Summary of changes:
ppc-amigaos/Makefile | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/ppc-amigaos/Makefile b/ppc-amigaos/Makefile
index e7ab849..e59f911 100644
--- a/ppc-amigaos/Makefile
+++ b/ppc-amigaos/Makefile
@@ -19,12 +19,12 @@ UPSTREAM_MPC_VERSION := 0.8.2
UPSTREAM_MPC_TARBALL := mpc-$(UPSTREAM_MPC_VERSION).tar.gz
UPSTREAM_MPC_URI := http://www.multiprecision.org/mpc/download/$(UPSTREAM_MPC_TARBALL)
-UPSTREAM_NDK_TARBALL := SDK_53.24.lha
-UPSTREAM_NDK_URI := "http://hyperion-entertainment.biz/index.php?option=com_registration&view=..."
+UPSTREAM_NDK_TARBALL := SDK_53.29.lha
+UPSTREAM_NDK_URI := "http://hyperion-entertainment.biz/index.php/downloads?view=download&forma..."
-UPSTREAM_OPENURL_VERSION := 7.8
-UPSTREAM_OPENURL_TARBALL := openurl
-UPSTREAM_OPENURL_URI := http://svn.code.sf.net/p/openurllib/code/releases/$(UPSTREAM_OPENURL_VERS...
+UPSTREAM_OPENURL_VERSION := 7.16
+UPSTREAM_OPENURL_TARBALL := openurl-$(UPSTREAM_OPENURL_VERSION)
+UPSTREAM_OPENURL_URI := https://github.com/jens-maus/libopenurl/archive/$(UPSTREAM_OPENURL_VERSIO...
# need to force the auto* version in use
GCC_AUTOCONF := autoconf2.64
@@ -80,16 +80,18 @@ $(BUILDSTEPS)/ndk.d: $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL) $(SOURCESDIR)/$(UPSTR
mkdir -p $(BUILDDIR)/ndk/tmp/
lha xw=$(BUILDDIR)/ndk $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL)
lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/base.lha
- lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/newlib-53.28.lha
- lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/clib2-1.205.lha
- lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/pthread.lha
+ lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/newlib-53.30.lha
+ lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/clib2-1.206.lha
+ lha xw=$(BUILDDIR)/ndk/tmp $(BUILDDIR)/ndk/SDK_Install/pthreads-53.11.lha
mkdir -p $(PREFIX)/$(TARGET_NAME)/SDK
cp -r $(BUILDDIR)/ndk/tmp/Include $(PREFIX)/$(TARGET_NAME)/SDK/include
cp -r $(BUILDDIR)/ndk/tmp/newlib $(PREFIX)/$(TARGET_NAME)/SDK/newlib
cp -r $(BUILDDIR)/ndk/tmp/clib2 $(PREFIX)/$(TARGET_NAME)/SDK/clib2
cp -r $(BUILDDIR)/ndk/tmp/Local/common/include/* $(PREFIX)/$(TARGET_NAME)/SDK/newlib/include/
cp -r $(BUILDDIR)/ndk/tmp/Local/newlib/lib/* $(PREFIX)/$(TARGET_NAME)/SDK/newlib/lib/
- cp -r $(SOURCESDIR)/$(UPSTREAM_OPENURL_TARBALL)/include/* $(PREFIX)/$(TARGET_NAME)/SDK/include/include_h/
+ mkdir -p $(BUILDDIR)/openurl
+ cd $(BUILDDIR)/openurl && tar xaf $(SOURCESDIR)/$(UPSTREAM_OPENURL_TARBALL)
+ cp -r $(BUILDDIR)/openurl/libopenurl-$(UPSTREAM_OPENURL_VERSION)/include/* $(PREFIX)/$(TARGET_NAME)/SDK/include/include_h/
touch $@
###
@@ -157,7 +159,7 @@ $(SOURCESDIR)/$(UPSTREAM_NDK_TARBALL):
wget -q -O $@ $(UPSTREAM_NDK_URI)
$(SOURCESDIR)/$(UPSTREAM_OPENURL_TARBALL):
- svn export $(UPSTREAM_OPENURL_URI) $@
+ wget -q -O $@ $(UPSTREAM_OPENURL_URI)
###
# Rule to create buildsteps dir
--
Cross-compilation toolchains and environments
8 years
nsgenbind: branch master updated. release/0.1.2-58-g8395629
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenbind.git/shortlog/83956295f66576becbf...
...commit http://git.netsurf-browser.org/nsgenbind.git/commit/83956295f66576becbf5d...
...tree http://git.netsurf-browser.org/nsgenbind.git/tree/83956295f66576becbf5de8...
The branch, master has been updated
via 83956295f66576becbf5de8cef915cd0d54f409b (commit)
via d6f41574a18866ebfbb8b61f9afcd0a0de2d40cf (commit)
from 8912c51fe275a7d8debe12f84f7e86ce4a240266 (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=83956295f66576bec...
commit 83956295f66576becbf5de8cef915cd0d54f409b
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Change dictionary generation to produce C accessors.
This generates routines which correctly handle reading a member from a
dictionary and returning it as the correct c type. Currently the types
"any", "user" and "sequence" remain unhandled.
diff --git a/src/duk-libdom-dictionary.c b/src/duk-libdom-dictionary.c
index 6aae0ca..69ce8aa 100644
--- a/src/duk-libdom-dictionary.c
+++ b/src/duk-libdom-dictionary.c
@@ -27,464 +27,290 @@
#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
-/**
- * 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, %s_magic_string_private);\n\n",
- DLPFX);
-
- 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, %s_magic_string_private);\n",
- idx, DLPFX);
- 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 the dictionary constructor
+ * get default value as a string
*/
static int
-output_dictionary_constructor(FILE* outf, struct ir_entry *dictionarye)
+get_member_default_str(struct ir_entry *dictionarye,
+ struct ir_operation_argument_entry *membere,
+ enum webidl_type member_type,
+ char **defl_out)
{
- int init_argc;
-
- /* constructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
- DLPFX, dictionarye->class_name);
- fprintf(outf,"{\n");
-
- output_create_private(outf, dictionarye->class_name);
-
- /* generate call to initialisor */
- fprintf(outf,
- "\t%s_%s___init(ctx, priv",
- DLPFX, dictionarye->class_name);
- for (init_argc = 1;
- init_argc <= dictionarye->class_init_argc;
- init_argc++) {
- fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
- }
- fprintf(outf, ");\n");
-
-
- fprintf(outf, "\tduk_set_top(ctx, 1);\n");
- fprintf(outf, "\treturn 1;\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a duktape prototype name
- */
-static char *get_prototype_name(const char *dictionary_name)
-{
- char *proto_name;
- int pnamelen;
- int pfxlen;
-
- /* duplicate the dictionary name in upper case */
- pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
- pnamelen = strlen(dictionary_name) + 1;
-
- proto_name = malloc(pnamelen + pfxlen);
- snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, dictionary_name);
- for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
- proto_name[pnamelen + pfxlen] = toupper(dictionary_name[pnamelen]);
+ struct webidl_node *lit_node;
+ enum webidl_node_type lit_type;
+ int *lit_int;
+ float *lit_flt;
+
+ lit_node = webidl_node_getnode(
+ webidl_node_find_type(
+ webidl_node_getnode(membere->node),
+ NULL,
+ WEBIDL_NODE_TYPE_OPTIONAL));
+ if (lit_node == NULL) {
+ *defl_out = NULL;
+ return 0;
}
- return proto_name;
-}
-
-
-/**
- * generate code that gets a prototype by name
- */
-static int output_get_prototype(FILE* outf, const char *dictionary_name)
-{
- char *proto_name;
-
- proto_name = get_prototype_name(dictionary_name);
-
- fprintf(outf,
- "\t/* get prototype */\n");
- fprintf(outf,
- "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
- DLPFX);
- fprintf(outf,
- "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
- MAGICPFX);
- fprintf(outf, "\tduk_pop(ctx);\n\n");
- return 0;
-}
-
-/**
- * generate the dictionary prototype creator
- */
-static int
-output_dictionary_prototype(FILE* outf,
- struct ir *ir,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
-{
- struct genbind_node *proto_node;
+ lit_type = webidl_node_gettype(lit_node);
- /* find the prototype method on the class */
- proto_node = genbind_node_find_method(dictionarye->class,
- NULL,
- GENBIND_METHOD_TYPE_PROTOTYPE);
+ switch (lit_type) {
- /* prototype definition */
- fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
- DLPFX, dictionarye->class_name);
- fprintf(outf,"{\n");
-
- /* Output any binding data first */
- if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
- fprintf(outf,"\n");
- }
-
- /* generate prototype chaining if dictionary has a parent */
- if (inherite != NULL) {
- fprintf(outf,
- "\t/* Set this prototype's prototype (left-parent) */\n");
- output_get_prototype(outf, inherite->name);
- fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
+ case WEBIDL_NODE_TYPE_LITERAL_BOOL:
+ if (member_type != WEBIDL_TYPE_BOOL) {
+ fprintf(stderr,
+ "Dictionary %s:%s literal boolean type mismatch\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
+ }
+ lit_int = webidl_node_getint(lit_node);
+ if (*lit_int == 0) {
+ *defl_out = strdup("false");
+ } else {
+ *defl_out = strdup("true");
+ }
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_NULL:
+ *defl_out = strdup("NULL");
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_STRING:
+ *defl_out = strdup(webidl_node_gettext(lit_node));
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_INT:
+ lit_int = webidl_node_getint(lit_node);
+ *defl_out = malloc(128);
+ sprintf(*defl_out, "%d", *lit_int);
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
+ lit_flt = webidl_node_getfloat(lit_node);
+ *defl_out = malloc(128);
+ sprintf(*defl_out, "%f", *lit_flt);
+ break;
+
+ default:
+ *defl_out = NULL;
+ break;
}
- /* dictionary members*/
-
-
- /* generate setting of destructor */
- output_set_destructor(outf, dictionarye->class_name, 0);
-
- /* generate setting of constructor */
- output_set_constructor(outf,
- dictionarye->class_name,
- 0,
- dictionarye->class_init_argc);
-
- fprintf(outf,"\treturn 1; /* The prototype object */\n");
-
- fprintf(outf, "}\n\n");
-
return 0;
}
/**
- * generate the dictionary destructor
+ * generate a single class method for an interface operation
*/
static int
-output_dictionary_destructor(FILE* outf, struct ir_entry *dictionarye)
+output_member_acessor(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_operation_argument_entry *membere)
{
- /* destructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
- DLPFX, dictionarye->class_name);
- fprintf(outf,"{\n");
-
- output_safe_get_private(outf, dictionarye->class_name, 0);
-
- /* generate call to finaliser */
- fprintf(outf,
- "\t%s_%s___fini(ctx, priv);\n",
- DLPFX, dictionarye->class_name);
-
- fprintf(outf,"\tfree(priv);\n");
- fprintf(outf,"\treturn 0;\n");
-
- fprintf(outf, "}\n\n");
+ struct webidl_node *type_node;
+ enum webidl_type *argument_type;
+ char *defl; /* default for member */
+ int res;
- return 0;
-}
+ type_node = webidl_node_find_type(
+ webidl_node_getnode(membere->node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
-/**
- * generate an initialisor call to parent dictionary
- */
-static int
-output_dictionary_inherit_init(FILE* outf,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
-{
- struct genbind_node *init_node;
- struct genbind_node *inh_init_node;
- struct genbind_node *param_node;
- struct genbind_node *inh_param_node;
-
- /* only need to call parent initialisor if there is one */
- if (inherite == NULL) {
- return 0;
+ if (type_node == NULL) {
+ fprintf(stderr, "%s:%s has no type\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
}
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(dictionarye->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
-
- inh_init_node = genbind_node_find_method(inherite->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
-
-
- fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
- DLPFX, inherite->class_name);
-
- /* for each parameter in the parent find a matching named
- * parameter to pass and cast if necessary
- */
-
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (inh_param_node != NULL) {
- char *param_name;
- param_name = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_IDENT));
-
- param_node = genbind_node_find_type_ident(
- genbind_node_getnode(init_node),
+ argument_type = (enum webidl_type *)webidl_node_getint(
+ webidl_node_find_type(
+ webidl_node_getnode(type_node),
NULL,
- GENBIND_NODE_TYPE_PARAMETER,
- param_name);
- if (param_node == NULL) {
- fprintf(stderr, "class \"%s\" (dictionary %s) parent class \"%s\" (dictionary %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
- dictionarye->class_name,
- dictionarye->name,
- inherite->class_name,
- inherite->name,
- param_name);
- return -1;
- } else {
- char *param_type;
- char *inh_param_type;
-
- fprintf(outf, ", ");
-
- /* cast the parameter if required */
- param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- inh_param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- if (strcmp(param_type, inh_param_type) != 0) {
- fprintf(outf, "(%s)", inh_param_type);
- }
-
- /* output the parameter identifier */
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
- }
+ WEBIDL_NODE_TYPE_TYPE_BASE));
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- inh_param_node, GENBIND_NODE_TYPE_METHOD);
+ if (argument_type == NULL) {
+ fprintf(stderr,
+ "%s:%s has no type base\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
}
- fprintf(outf, ");\n");
-
- return 0;
-}
-
-static int
-output_dictionary_init_declaration(FILE* outf,
- struct ir_entry *dictionarye,
- struct genbind_node *init_node)
-{
- 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);
-
- /* count the number of arguments on the initializer */
- dictionarye->class_init_argc = 0;
-
- /* output the paramters on the method (if any) */
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (param_node != NULL) {
- dictionarye->class_init_argc++;
- fprintf(outf, ", ");
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
-
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- param_node, GENBIND_NODE_TYPE_PARAMETER);
+ /* get default text */
+ res = get_member_default_str(dictionarye, membere, *argument_type, &defl);
+ if (res != 0) {
+ return res;
}
- fprintf(outf,")");
+ switch (*argument_type) {
- return 0;
-}
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "const char *\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
+ "{\n",
+ DLPFX, dictionarye->class_name, membere->name);
+
+ if (defl == NULL) {
+ fprintf(outf,
+ "\tconst char *ret = NULL; /* No default */\n");
+ } else {
+ fprintf(outf,
+ "\tconst char *ret = \"%s\"; /* Default value of %s */\n",
+ defl, membere->name);
+ }
-static int
-output_dictionary_init(FILE* outf,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
-{
- struct genbind_node *init_node;
- int res;
+ fprintf(outf,
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a string */\n"
+ "\t\tret = duk_require_string(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n",
+ membere->name);
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "duk_bool_t\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
+ "{\n",
+ DLPFX, dictionarye->class_name, membere->name);
+
+ if (defl == NULL) {
+ fprintf(outf,
+ "\tduk_bool_t ret = false; /* No default */\n");
+ } else {
+ fprintf(outf,
+ "\tduk_bool_t ret = %s; /* Default value of %s */\n",
+ defl, membere->name);
+ }
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(dictionarye->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
+ fprintf(outf,
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a boolean */\n"
+ "\t\tret = duk_require_boolean(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n",
+ membere->name);
+
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ case WEBIDL_TYPE_LONG:
+ case WEBIDL_TYPE_LONGLONG:
+ fprintf(outf,
+ "duk_int_t\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
+ "{\n",
+ DLPFX, dictionarye->class_name, membere->name);
- /* initialisor definition */
- output_dictionary_init_declaration(outf, dictionarye, init_node);
+ if (defl == NULL) {
+ fprintf(outf, "\tduk_int_t ret = 0; /* No default */\n");
+ } else {
+ fprintf(outf,
+ "\tduk_int_t ret = %s; /* Default value of %s */\n",
+ defl, membere->name);
+ }
- fprintf(outf,"\n{\n");
+ fprintf(outf,
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a int */\n"
+ "\t\tret = duk_require_int(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n",
+ membere->name);
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ fprintf(outf,
+ "duk_double_t\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n",
+ DLPFX, dictionarye->class_name, membere->name);
- /* if this dictionary inherits ensure we call its initialisor */
- res = output_dictionary_inherit_init(outf, dictionarye, inherite);
- if (res != 0) {
- return res;
- }
+ fprintf(outf,
+ "{\n"
+ "\tduk_double_t ret = %s; /* Default value of %s */\n"
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n",
+ defl, membere->name, membere->name);
- /* generate log statement */
- if (options->dbglog) {
fprintf(outf,
- "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a number */\n"
+ "\t\tret = duk_require_number(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n");
+ break;
+
+ default:
+ WARN(WARNING_UNIMPLEMENTED,
+ "Dictionary %s:%s unhandled type (%d)\n",
+ dictionarye->name,
+ membere->name,
+ *argument_type);
+ fprintf(outf,
+ "/* Dictionary %s:%s unhandled type (%d) */\n\n",
+ dictionarye->name,
+ membere->name,
+ *argument_type);
}
- /* output the initaliser code from the binding */
- output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
-
- fprintf(outf, "}\n\n");
+ if (defl != NULL) {
+ free(defl);
+ }
return 0;
-
}
static int
-output_dictionary_fini(FILE* outf,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
+output_member_acessors(FILE* outf, struct ir_entry *dictionarye)
{
- struct genbind_node *fini_node;
-
- /* find the finaliser method on the class (if any) */
- fini_node = genbind_node_find_method(dictionarye->class,
- NULL,
- 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);
- fprintf(outf,"{\n");
-
- /* generate log statement */
- if (options->dbglog) {
- fprintf(outf,
- "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
- }
-
- /* output the finialisor code from the binding */
- output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
+ int memberc;
+ int res = 0;
- /* if this dictionary inherits ensure we call its finaliser */
- if (inherite != NULL) {
- fprintf(outf,
- "\t%s_%s___fini(ctx, &priv->parent);\n",
- DLPFX, inherite->class_name);
+ for (memberc = 0;
+ memberc < dictionarye->u.dictionary.memberc;
+ memberc++) {
+ res = output_member_acessor(
+ outf,
+ dictionarye,
+ dictionarye->u.dictionary.memberv + memberc);
+ if (res != 0) {
+ break;
+ }
}
- fprintf(outf, "}\n\n");
- return 0;
+ return res;
}
-/**
- * generate a source file to implement a dictionary using duk and libdom.
- */
+/* exported function documented in duk-libdom.h */
int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
{
FILE *ifacef;
- struct ir_entry *inherite;
int res = 0;
/* open output file */
@@ -493,9 +319,6 @@ int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
return -1;
}
- /* find parent dictionary entry */
- inherite = ir_inherit_entry(ir, dictionarye);
-
/* tool preface */
output_tool_preface(ifacef);
@@ -520,34 +343,8 @@ int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
fprintf(ifacef, "\n");
- /* initialisor */
- res = output_dictionary_init(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- res = output_dictionary_fini(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* constructor */
- res = output_dictionary_constructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* destructor */
- res = output_dictionary_destructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
- /** todo property handlers */
-
- /* prototype */
- res = output_dictionary_prototype(ifacef, ir, dictionarye, inherite);
+ res = output_member_acessors(ifacef, dictionarye);
if (res != 0) {
goto op_error;
}
@@ -575,3 +372,102 @@ op_error:
return res;
}
+
+/**
+ * generate a single class method declaration for an interface operation
+ */
+static int
+output_member_declaration(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_operation_argument_entry *membere)
+{
+ struct webidl_node *type_node;
+ enum webidl_type *argument_type;
+
+ type_node = webidl_node_find_type(
+ webidl_node_getnode(membere->node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ if (type_node == NULL) {
+ fprintf(stderr, "%s:%s has no type\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
+ }
+
+ argument_type = (enum webidl_type *)webidl_node_getint(
+ webidl_node_find_type(
+ webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE));
+
+ if (argument_type == NULL) {
+ fprintf(stderr,
+ "%s:%s has no type base\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
+ }
+
+
+ switch (*argument_type) {
+
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "const char *%s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "duk_bool_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ case WEBIDL_TYPE_LONG:
+ case WEBIDL_TYPE_LONGLONG:
+ fprintf(outf,
+ "duk_int_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ fprintf(outf,
+ "duk_double_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ default:
+ fprintf(outf,
+ "/* Dictionary %s:%s unhandled type (%d) */\n",
+ dictionarye->name,
+ membere->name,
+ *argument_type);
+ }
+
+ return 0;
+}
+
+/* exported function documented in duk-libdom.h */
+int output_dictionary_declaration(FILE* outf, struct ir_entry *dictionarye)
+{
+ int memberc;
+ int res = 0;
+
+ for (memberc = 0;
+ memberc < dictionarye->u.dictionary.memberc;
+ memberc++) {
+ res = output_member_declaration(
+ outf,
+ dictionarye,
+ dictionarye->u.dictionary.memberv + memberc);
+ if (res != 0) {
+ break;
+ }
+ }
+
+ return res;
+}
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c
index 3ac7d83..aa44d38 100644
--- a/src/duk-libdom-interface.c
+++ b/src/duk-libdom-interface.c
@@ -792,7 +792,7 @@ output_interface_elipsis_operation(FILE* outf,
* operation with elipsis should go
*/
WARN(WARNING_UNIMPLEMENTED,
- "Elipsis parameetrs not checked: method %s::%s();",
+ "Elipsis parameters not checked: method %s::%s();",
interfacee->name, operatione->name);
output_get_method_private(outf, interfacee->class_name);
@@ -1339,3 +1339,46 @@ op_error:
return res;
}
+/* exported function documented in duk-libdom.h */
+int output_interface_declaration(FILE* outf, struct ir_entry *interfacee)
+{
+ struct genbind_node *init_node;
+
+ /* do not generate prototype declarations for interfaces marked no
+ * output
+ */
+ if (interfacee->u.interface.noobject) {
+ return 0;
+ }
+
+ /* prototype declaration */
+ fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
+ DLPFX, interfacee->class_name);
+
+ /* 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.
+ */
+ if (interfacee->refcount < 1) {
+ fprintf(outf, "\n");
+
+ return 0;
+ }
+
+ /* finaliser declaration */
+ fprintf(outf,
+ "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(outf, interfacee, init_node);
+
+ fprintf(outf, ";\n\n");
+
+ return 0;
+}
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 02b41b3..f72bc96 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -132,14 +132,14 @@ static FILE *open_header(struct ir *ir, const char *name)
return NULL;
}
+ /* tool preface */
+ output_tool_preface(hdrf);
+
/* binding preface */
output_cdata(hdrf,
ir->binding_node,
GENBIND_NODE_TYPE_PREFACE);
- /* tool preface */
- output_tool_preface(hdrf);
-
/* header guard */
fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
fprintf(hdrf, "#define %s_%s_h\n\n", DLPFX, name);
@@ -172,43 +172,6 @@ static int close_header(struct ir *ir,
}
-
-
-static int
-output_interface_init_declaration(FILE* outf,
- struct ir_entry *interfacee,
- struct genbind_node *init_node)
-{
- struct genbind_node *param_node;
-
- fprintf(outf,
- "void %s_%s___init(duk_context *ctx, %s_private_t *priv",
- DLPFX, interfacee->class_name, interfacee->class_name);
-
- /* count the number of arguments on the initializer */
- interfacee->class_init_argc = 0;
-
- /* output the paramters on the method (if any) */
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (param_node != NULL) {
- interfacee->class_init_argc++;
- fprintf(outf, ", ");
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
-
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- param_node, GENBIND_NODE_TYPE_PARAMETER);
- }
-
- fprintf(outf,")");
-
- return 0;
-}
-
-
/**
* generate private header
*/
@@ -314,44 +277,19 @@ output_prototype_header(struct ir *ir)
protof = open_header(ir, "prototype");
for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
- struct genbind_node *init_node;
-
- interfacee = ir->entries + idx;
+ struct ir_entry *entry;
- /* do not generate prototype declarations for interfaces marked
- * no output
- */
- if ((interfacee->type == IR_ENTRY_TYPE_INTERFACE) &&
- (interfacee->u.interface.noobject)) {
- continue;
- }
+ entry = ir->entries + idx;
- /* prototype declaration */
- fprintf(protof, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
- DLPFX, interfacee->class_name);
+ switch (entry->type) {
+ case IR_ENTRY_TYPE_INTERFACE:
+ output_interface_declaration(protof, entry);
+ break;
- /* 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.
- */
- 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");
+ case IR_ENTRY_TYPE_DICTIONARY:
+ output_dictionary_declaration(protof, entry);
+ break;
}
- fprintf(protof, "\n");
}
close_header(ir, protof, "prototype");
@@ -612,6 +550,10 @@ output_binding_src(struct ir *ir)
interfacee = ir->entries + idx;
+ if (interfacee->type == IR_ENTRY_TYPE_DICTIONARY) {
+ continue;
+ }
+
/* do not generate prototype calls for interfaces marked
* no output
*/
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index 84fc497..79b440e 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -20,11 +20,21 @@ int duk_libdom_output(struct ir *ir);
int output_interface(struct ir *ir, struct ir_entry *interfacee);
/**
+ * generate a declaration to implement a dictionary using duk and libdom.
+ */
+int output_interface_declaration(FILE* outf, struct ir_entry *interfacee);
+
+/**
* generate a source file to implement a dictionary using duk and libdom.
*/
int output_dictionary(struct ir *ir, struct ir_entry *dictionarye);
/**
+ * generate a declaration to implement a dictionary using duk and libdom.
+ */
+int output_dictionary_declaration(FILE* outf, struct ir_entry *dictionarye);
+
+/**
* generate preface block for nsgenbind
*/
int output_tool_preface(FILE* outf);
diff --git a/src/webidl-ast.c b/src/webidl-ast.c
index dc78e1f..e9dda2d 100644
--- a/src/webidl-ast.c
+++ b/src/webidl-ast.c
@@ -34,6 +34,7 @@ struct webidl_node {
void *value;
struct webidl_node *node; /* node has a list of nodes */
char *text; /* node data is text */
+ float *flt;
int number; /* node data is an integer */
} r;
};
@@ -299,6 +300,22 @@ webidl_node_getint(struct webidl_node *node)
}
/* exported interface defined in webidl-ast.h */
+float *
+webidl_node_getfloat(struct webidl_node *node)
+{
+ if (node != NULL) {
+ switch(node->type) {
+ case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
+ return node->r.flt;
+
+ default:
+ break;
+ }
+ }
+ return NULL;
+}
+
+/* exported interface defined in webidl-ast.h */
enum webidl_node_type webidl_node_gettype(struct webidl_node *node)
{
return node->type;
@@ -398,7 +415,7 @@ static const char *webidl_node_type_to_str(enum webidl_node_type type)
return "Literal (bool)";
case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
- return "Literal (string)";
+ return "Literal (float)";
case WEBIDL_NODE_TYPE_LITERAL_STRING:
return "Literal (string)";
diff --git a/src/webidl-ast.h b/src/webidl-ast.h
index 0872965..9ae2ebb 100644
--- a/src/webidl-ast.h
+++ b/src/webidl-ast.h
@@ -105,6 +105,8 @@ struct webidl_node *webidl_node_add(struct webidl_node *node, struct webidl_node
char *webidl_node_gettext(struct webidl_node *node);
struct webidl_node *webidl_node_getnode(struct webidl_node *node);
int *webidl_node_getint(struct webidl_node *node);
+float *webidl_node_getfloat(struct webidl_node *node);
+
enum webidl_node_type webidl_node_gettype(struct webidl_node *node);
/* node searches */
commitdiff http://git.netsurf-browser.org/nsgenbind.git/commit/?id=d6f41574a18866ebf...
commit d6f41574a18866ebfbb8b61f9afcd0a0de2d40cf
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add dictionary members to ir
diff --git a/src/ir.c b/src/ir.c
index 3a2a1c8..b3631f4 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -189,7 +189,6 @@ argument_map_new(struct webidl_node *arg_list_node,
cure->node = argument;
-
cure->optionalc = webidl_node_enumerate_type(
webidl_node_getnode(argument),
WEBIDL_NODE_TYPE_OPTIONAL);
@@ -547,6 +546,86 @@ constant_map_new(struct webidl_node *interface,
return 0;
}
+
+static int
+member_map_new(struct webidl_node *dictionary,
+ int *memberc_out,
+ struct ir_operation_argument_entry **memberv_out)
+{
+ struct webidl_node *list_node;
+ struct webidl_node *member_node; /* member node */
+ struct ir_operation_argument_entry *cure; /* current entry */
+ struct ir_operation_argument_entry *memberv;
+ int memberc;
+
+ /* enumerate members */
+ memberc = enumerate_interface_type(dictionary,
+ WEBIDL_NODE_TYPE_ARGUMENT);
+
+ if (memberc < 1) {
+ *memberc_out = 0;
+ *memberv_out = NULL; /* no members so empty map */
+ return 0;
+ }
+
+ memberv = calloc(memberc, sizeof(struct ir_operation_argument_entry));
+ if (memberv == NULL) {
+ return -1;
+ };
+ cure = memberv;
+
+ /* iterate each list node within the dictionary */
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(dictionary),
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
+
+ while (list_node != NULL) {
+ /* iterate through members on list */
+ member_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ NULL,
+ WEBIDL_NODE_TYPE_ARGUMENT);
+
+ while (member_node != NULL) {
+ cure->node = member_node;
+
+ cure->name = webidl_node_gettext(
+ webidl_node_find_type(
+ webidl_node_getnode(member_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT));
+
+ cure->optionalc = webidl_node_enumerate_type(
+ webidl_node_getnode(member_node),
+ WEBIDL_NODE_TYPE_OPTIONAL);
+
+ cure->elipsisc = webidl_node_enumerate_type(
+ webidl_node_getnode(member_node),
+ WEBIDL_NODE_TYPE_ELLIPSIS);
+
+ cure++;
+
+ /* move to next member */
+ member_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ member_node,
+ WEBIDL_NODE_TYPE_ARGUMENT);
+ }
+
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(dictionary),
+ list_node,
+ WEBIDL_NODE_TYPE_LIST);
+ }
+
+ *memberc_out = memberc;
+ *memberv_out = memberv; /* resulting members map */
+
+ return 0;
+
+}
+
static int
entry_map_new(struct genbind_node *genbind,
struct webidl_node *interface,
@@ -692,8 +771,10 @@ entry_map_new(struct genbind_node *genbind,
/* identify this is an interface entry */
cure->type = IR_ENTRY_TYPE_DICTIONARY;
-
-
+ /* enumerate and map the dictionary members */
+ member_map_new(node,
+ &cure->u.dictionary.memberc,
+ &cure->u.dictionary.memberv);
/* move to next interface */
node = webidl_node_find_type(interface,
@@ -753,6 +834,36 @@ int ir_new(struct genbind_node *genbind,
return 0;
}
+static int ir_dump_dictionary(FILE *dumpf, struct ir_entry *ecur)
+{
+ if (ecur->u.dictionary.memberc > 0) {
+ int argc;
+
+ fprintf(dumpf, "\t%d members\n", ecur->u.dictionary.memberc);
+
+ for (argc = 0; argc < ecur->u.dictionary.memberc; argc++) {
+ struct ir_operation_argument_entry *arge;
+
+ arge = ecur->u.dictionary.memberv + argc;
+
+ fprintf(dumpf, "\t\t%s\n", arge->name);
+
+ if (arge->optionalc != 0) {
+ fprintf(dumpf,
+ "\t\t\toptional:%d\n",
+ arge->optionalc);
+ }
+
+ if (arge->elipsisc != 0) {
+ fprintf(dumpf,
+ "\t\t\telipsis:%d\n",
+ arge->elipsisc);
+ }
+ }
+ }
+ return 0;
+}
+
static int ir_dump_interface(FILE *dumpf, struct ir_entry *ecur)
{
if (ecur->u.interface.operationc > 0) {
@@ -886,8 +997,15 @@ int ir_dump(struct ir *ir)
fprintf(dumpf, "\tclass:%p\n", ecur->class);
}
- if (ecur->type == IR_ENTRY_TYPE_INTERFACE) {
+ switch (ecur->type) {
+ case IR_ENTRY_TYPE_INTERFACE:
ir_dump_interface(dumpf, ecur);
+ break;
+
+ case IR_ENTRY_TYPE_DICTIONARY:
+ ir_dump_dictionary(dumpf, ecur);
+ break;
+
}
ecur++;
}
diff --git a/src/ir.h b/src/ir.h
index cf431f6..1092fab 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -24,7 +24,9 @@ struct ir_operation_argument_entry {
struct webidl_node *node;
};
-/** map entry for each overload of an operation */
+/**
+ * map entry for each overload of an operation.
+ */
struct ir_operation_overload_entry {
struct webidl_node *type; /**< The return type of this overload */
@@ -49,6 +51,7 @@ struct ir_operation_entry {
struct ir_attribute_entry {
const char *name; /** attribute name */
struct webidl_node *node; /**< AST attribute node */
+
enum webidl_type_modifier modifier;
struct genbind_node *getter; /**< getter from binding */
struct genbind_node *setter; /**< getter from binding */
@@ -81,8 +84,12 @@ struct ir_interface_entry {
struct ir_constant_entry *constantv;
};
-/** map entry for a dictionary */
+/**
+ * map entry for a dictionary
+ */
struct ir_dictionary_entry {
+ int memberc; /**< the number of members */
+ struct ir_operation_argument_entry *memberv;
};
enum ir_entry_type {
-----------------------------------------------------------------------
Summary of changes:
src/duk-libdom-dictionary.c | 766 +++++++++++++++++++------------------------
src/duk-libdom-interface.c | 45 ++-
src/duk-libdom.c | 90 +----
src/duk-libdom.h | 10 +
src/ir.c | 126 ++++++-
src/ir.h | 11 +-
src/webidl-ast.c | 19 +-
src/webidl-ast.h | 2 +
8 files changed, 552 insertions(+), 517 deletions(-)
diff --git a/src/duk-libdom-dictionary.c b/src/duk-libdom-dictionary.c
index 6aae0ca..69ce8aa 100644
--- a/src/duk-libdom-dictionary.c
+++ b/src/duk-libdom-dictionary.c
@@ -27,464 +27,290 @@
#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
-/**
- * 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, %s_magic_string_private);\n\n",
- DLPFX);
-
- 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, %s_magic_string_private);\n",
- idx, DLPFX);
- 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 the dictionary constructor
+ * get default value as a string
*/
static int
-output_dictionary_constructor(FILE* outf, struct ir_entry *dictionarye)
+get_member_default_str(struct ir_entry *dictionarye,
+ struct ir_operation_argument_entry *membere,
+ enum webidl_type member_type,
+ char **defl_out)
{
- int init_argc;
-
- /* constructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
- DLPFX, dictionarye->class_name);
- fprintf(outf,"{\n");
-
- output_create_private(outf, dictionarye->class_name);
-
- /* generate call to initialisor */
- fprintf(outf,
- "\t%s_%s___init(ctx, priv",
- DLPFX, dictionarye->class_name);
- for (init_argc = 1;
- init_argc <= dictionarye->class_init_argc;
- init_argc++) {
- fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
- }
- fprintf(outf, ");\n");
-
-
- fprintf(outf, "\tduk_set_top(ctx, 1);\n");
- fprintf(outf, "\treturn 1;\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a duktape prototype name
- */
-static char *get_prototype_name(const char *dictionary_name)
-{
- char *proto_name;
- int pnamelen;
- int pfxlen;
-
- /* duplicate the dictionary name in upper case */
- pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
- pnamelen = strlen(dictionary_name) + 1;
-
- proto_name = malloc(pnamelen + pfxlen);
- snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, dictionary_name);
- for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
- proto_name[pnamelen + pfxlen] = toupper(dictionary_name[pnamelen]);
+ struct webidl_node *lit_node;
+ enum webidl_node_type lit_type;
+ int *lit_int;
+ float *lit_flt;
+
+ lit_node = webidl_node_getnode(
+ webidl_node_find_type(
+ webidl_node_getnode(membere->node),
+ NULL,
+ WEBIDL_NODE_TYPE_OPTIONAL));
+ if (lit_node == NULL) {
+ *defl_out = NULL;
+ return 0;
}
- return proto_name;
-}
-
-
-/**
- * generate code that gets a prototype by name
- */
-static int output_get_prototype(FILE* outf, const char *dictionary_name)
-{
- char *proto_name;
-
- proto_name = get_prototype_name(dictionary_name);
-
- fprintf(outf,
- "\t/* get prototype */\n");
- fprintf(outf,
- "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
- DLPFX);
- fprintf(outf,
- "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
- MAGICPFX);
- fprintf(outf, "\tduk_pop(ctx);\n\n");
- return 0;
-}
-
-/**
- * generate the dictionary prototype creator
- */
-static int
-output_dictionary_prototype(FILE* outf,
- struct ir *ir,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
-{
- struct genbind_node *proto_node;
+ lit_type = webidl_node_gettype(lit_node);
- /* find the prototype method on the class */
- proto_node = genbind_node_find_method(dictionarye->class,
- NULL,
- GENBIND_METHOD_TYPE_PROTOTYPE);
+ switch (lit_type) {
- /* prototype definition */
- fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
- DLPFX, dictionarye->class_name);
- fprintf(outf,"{\n");
-
- /* Output any binding data first */
- if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
- fprintf(outf,"\n");
- }
-
- /* generate prototype chaining if dictionary has a parent */
- if (inherite != NULL) {
- fprintf(outf,
- "\t/* Set this prototype's prototype (left-parent) */\n");
- output_get_prototype(outf, inherite->name);
- fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
+ case WEBIDL_NODE_TYPE_LITERAL_BOOL:
+ if (member_type != WEBIDL_TYPE_BOOL) {
+ fprintf(stderr,
+ "Dictionary %s:%s literal boolean type mismatch\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
+ }
+ lit_int = webidl_node_getint(lit_node);
+ if (*lit_int == 0) {
+ *defl_out = strdup("false");
+ } else {
+ *defl_out = strdup("true");
+ }
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_NULL:
+ *defl_out = strdup("NULL");
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_STRING:
+ *defl_out = strdup(webidl_node_gettext(lit_node));
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_INT:
+ lit_int = webidl_node_getint(lit_node);
+ *defl_out = malloc(128);
+ sprintf(*defl_out, "%d", *lit_int);
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
+ lit_flt = webidl_node_getfloat(lit_node);
+ *defl_out = malloc(128);
+ sprintf(*defl_out, "%f", *lit_flt);
+ break;
+
+ default:
+ *defl_out = NULL;
+ break;
}
- /* dictionary members*/
-
-
- /* generate setting of destructor */
- output_set_destructor(outf, dictionarye->class_name, 0);
-
- /* generate setting of constructor */
- output_set_constructor(outf,
- dictionarye->class_name,
- 0,
- dictionarye->class_init_argc);
-
- fprintf(outf,"\treturn 1; /* The prototype object */\n");
-
- fprintf(outf, "}\n\n");
-
return 0;
}
/**
- * generate the dictionary destructor
+ * generate a single class method for an interface operation
*/
static int
-output_dictionary_destructor(FILE* outf, struct ir_entry *dictionarye)
+output_member_acessor(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_operation_argument_entry *membere)
{
- /* destructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
- DLPFX, dictionarye->class_name);
- fprintf(outf,"{\n");
-
- output_safe_get_private(outf, dictionarye->class_name, 0);
-
- /* generate call to finaliser */
- fprintf(outf,
- "\t%s_%s___fini(ctx, priv);\n",
- DLPFX, dictionarye->class_name);
-
- fprintf(outf,"\tfree(priv);\n");
- fprintf(outf,"\treturn 0;\n");
-
- fprintf(outf, "}\n\n");
+ struct webidl_node *type_node;
+ enum webidl_type *argument_type;
+ char *defl; /* default for member */
+ int res;
- return 0;
-}
+ type_node = webidl_node_find_type(
+ webidl_node_getnode(membere->node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
-/**
- * generate an initialisor call to parent dictionary
- */
-static int
-output_dictionary_inherit_init(FILE* outf,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
-{
- struct genbind_node *init_node;
- struct genbind_node *inh_init_node;
- struct genbind_node *param_node;
- struct genbind_node *inh_param_node;
-
- /* only need to call parent initialisor if there is one */
- if (inherite == NULL) {
- return 0;
+ if (type_node == NULL) {
+ fprintf(stderr, "%s:%s has no type\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
}
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(dictionarye->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
-
- inh_init_node = genbind_node_find_method(inherite->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
-
-
- fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
- DLPFX, inherite->class_name);
-
- /* for each parameter in the parent find a matching named
- * parameter to pass and cast if necessary
- */
-
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (inh_param_node != NULL) {
- char *param_name;
- param_name = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_IDENT));
-
- param_node = genbind_node_find_type_ident(
- genbind_node_getnode(init_node),
+ argument_type = (enum webidl_type *)webidl_node_getint(
+ webidl_node_find_type(
+ webidl_node_getnode(type_node),
NULL,
- GENBIND_NODE_TYPE_PARAMETER,
- param_name);
- if (param_node == NULL) {
- fprintf(stderr, "class \"%s\" (dictionary %s) parent class \"%s\" (dictionary %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
- dictionarye->class_name,
- dictionarye->name,
- inherite->class_name,
- inherite->name,
- param_name);
- return -1;
- } else {
- char *param_type;
- char *inh_param_type;
-
- fprintf(outf, ", ");
-
- /* cast the parameter if required */
- param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- inh_param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- if (strcmp(param_type, inh_param_type) != 0) {
- fprintf(outf, "(%s)", inh_param_type);
- }
-
- /* output the parameter identifier */
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
- }
+ WEBIDL_NODE_TYPE_TYPE_BASE));
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- inh_param_node, GENBIND_NODE_TYPE_METHOD);
+ if (argument_type == NULL) {
+ fprintf(stderr,
+ "%s:%s has no type base\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
}
- fprintf(outf, ");\n");
-
- return 0;
-}
-
-static int
-output_dictionary_init_declaration(FILE* outf,
- struct ir_entry *dictionarye,
- struct genbind_node *init_node)
-{
- 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);
-
- /* count the number of arguments on the initializer */
- dictionarye->class_init_argc = 0;
-
- /* output the paramters on the method (if any) */
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (param_node != NULL) {
- dictionarye->class_init_argc++;
- fprintf(outf, ", ");
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
-
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- param_node, GENBIND_NODE_TYPE_PARAMETER);
+ /* get default text */
+ res = get_member_default_str(dictionarye, membere, *argument_type, &defl);
+ if (res != 0) {
+ return res;
}
- fprintf(outf,")");
+ switch (*argument_type) {
- return 0;
-}
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "const char *\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
+ "{\n",
+ DLPFX, dictionarye->class_name, membere->name);
+
+ if (defl == NULL) {
+ fprintf(outf,
+ "\tconst char *ret = NULL; /* No default */\n");
+ } else {
+ fprintf(outf,
+ "\tconst char *ret = \"%s\"; /* Default value of %s */\n",
+ defl, membere->name);
+ }
-static int
-output_dictionary_init(FILE* outf,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
-{
- struct genbind_node *init_node;
- int res;
+ fprintf(outf,
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a string */\n"
+ "\t\tret = duk_require_string(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n",
+ membere->name);
+
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "duk_bool_t\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
+ "{\n",
+ DLPFX, dictionarye->class_name, membere->name);
+
+ if (defl == NULL) {
+ fprintf(outf,
+ "\tduk_bool_t ret = false; /* No default */\n");
+ } else {
+ fprintf(outf,
+ "\tduk_bool_t ret = %s; /* Default value of %s */\n",
+ defl, membere->name);
+ }
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(dictionarye->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
+ fprintf(outf,
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a boolean */\n"
+ "\t\tret = duk_require_boolean(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n",
+ membere->name);
+
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ case WEBIDL_TYPE_LONG:
+ case WEBIDL_TYPE_LONGLONG:
+ fprintf(outf,
+ "duk_int_t\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n"
+ "{\n",
+ DLPFX, dictionarye->class_name, membere->name);
- /* initialisor definition */
- output_dictionary_init_declaration(outf, dictionarye, init_node);
+ if (defl == NULL) {
+ fprintf(outf, "\tduk_int_t ret = 0; /* No default */\n");
+ } else {
+ fprintf(outf,
+ "\tduk_int_t ret = %s; /* Default value of %s */\n",
+ defl, membere->name);
+ }
- fprintf(outf,"\n{\n");
+ fprintf(outf,
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n"
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a int */\n"
+ "\t\tret = duk_require_int(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n",
+ membere->name);
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ fprintf(outf,
+ "duk_double_t\n"
+ "%s_%s_get_%s(duk_context *ctx, duk_idx_t idx)\n",
+ DLPFX, dictionarye->class_name, membere->name);
- /* if this dictionary inherits ensure we call its initialisor */
- res = output_dictionary_inherit_init(outf, dictionarye, inherite);
- if (res != 0) {
- return res;
- }
+ fprintf(outf,
+ "{\n"
+ "\tduk_double_t ret = %s; /* Default value of %s */\n"
+ "\t/* ... obj@idx ... */\n"
+ "\tduk_get_prop_string(ctx, idx, \"%s\");\n",
+ defl, membere->name, membere->name);
- /* generate log statement */
- if (options->dbglog) {
fprintf(outf,
- "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
+ "\t/* ... obj@idx ... value/undefined */\n"
+ "\tif (!duk_is_undefined(ctx, -1)) {\n"
+ "\t\t/* Note, this throws a duk_error if it's not a number */\n"
+ "\t\tret = duk_require_number(ctx, -1);\n"
+ "\t}\n"
+ "\tduk_pop(ctx);\n"
+ "\treturn ret;\n"
+ "}\n\n");
+ break;
+
+ default:
+ WARN(WARNING_UNIMPLEMENTED,
+ "Dictionary %s:%s unhandled type (%d)\n",
+ dictionarye->name,
+ membere->name,
+ *argument_type);
+ fprintf(outf,
+ "/* Dictionary %s:%s unhandled type (%d) */\n\n",
+ dictionarye->name,
+ membere->name,
+ *argument_type);
}
- /* output the initaliser code from the binding */
- output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
-
- fprintf(outf, "}\n\n");
+ if (defl != NULL) {
+ free(defl);
+ }
return 0;
-
}
static int
-output_dictionary_fini(FILE* outf,
- struct ir_entry *dictionarye,
- struct ir_entry *inherite)
+output_member_acessors(FILE* outf, struct ir_entry *dictionarye)
{
- struct genbind_node *fini_node;
-
- /* find the finaliser method on the class (if any) */
- fini_node = genbind_node_find_method(dictionarye->class,
- NULL,
- 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);
- fprintf(outf,"{\n");
-
- /* generate log statement */
- if (options->dbglog) {
- fprintf(outf,
- "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
- }
-
- /* output the finialisor code from the binding */
- output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
+ int memberc;
+ int res = 0;
- /* if this dictionary inherits ensure we call its finaliser */
- if (inherite != NULL) {
- fprintf(outf,
- "\t%s_%s___fini(ctx, &priv->parent);\n",
- DLPFX, inherite->class_name);
+ for (memberc = 0;
+ memberc < dictionarye->u.dictionary.memberc;
+ memberc++) {
+ res = output_member_acessor(
+ outf,
+ dictionarye,
+ dictionarye->u.dictionary.memberv + memberc);
+ if (res != 0) {
+ break;
+ }
}
- fprintf(outf, "}\n\n");
- return 0;
+ return res;
}
-/**
- * generate a source file to implement a dictionary using duk and libdom.
- */
+/* exported function documented in duk-libdom.h */
int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
{
FILE *ifacef;
- struct ir_entry *inherite;
int res = 0;
/* open output file */
@@ -493,9 +319,6 @@ int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
return -1;
}
- /* find parent dictionary entry */
- inherite = ir_inherit_entry(ir, dictionarye);
-
/* tool preface */
output_tool_preface(ifacef);
@@ -520,34 +343,8 @@ int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
fprintf(ifacef, "\n");
- /* initialisor */
- res = output_dictionary_init(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- res = output_dictionary_fini(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* constructor */
- res = output_dictionary_constructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* destructor */
- res = output_dictionary_destructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
- /** todo property handlers */
-
- /* prototype */
- res = output_dictionary_prototype(ifacef, ir, dictionarye, inherite);
+ res = output_member_acessors(ifacef, dictionarye);
if (res != 0) {
goto op_error;
}
@@ -575,3 +372,102 @@ op_error:
return res;
}
+
+/**
+ * generate a single class method declaration for an interface operation
+ */
+static int
+output_member_declaration(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_operation_argument_entry *membere)
+{
+ struct webidl_node *type_node;
+ enum webidl_type *argument_type;
+
+ type_node = webidl_node_find_type(
+ webidl_node_getnode(membere->node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ if (type_node == NULL) {
+ fprintf(stderr, "%s:%s has no type\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
+ }
+
+ argument_type = (enum webidl_type *)webidl_node_getint(
+ webidl_node_find_type(
+ webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE));
+
+ if (argument_type == NULL) {
+ fprintf(stderr,
+ "%s:%s has no type base\n",
+ dictionarye->name,
+ membere->name);
+ return -1;
+ }
+
+
+ switch (*argument_type) {
+
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "const char *%s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "duk_bool_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ case WEBIDL_TYPE_SHORT:
+ case WEBIDL_TYPE_LONG:
+ case WEBIDL_TYPE_LONGLONG:
+ fprintf(outf,
+ "duk_int_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ fprintf(outf,
+ "duk_double_t %s_%s_get_%s(duk_context *ctx, duk_idx_t idx);\n",
+ DLPFX, dictionarye->class_name, membere->name);
+ break;
+
+ default:
+ fprintf(outf,
+ "/* Dictionary %s:%s unhandled type (%d) */\n",
+ dictionarye->name,
+ membere->name,
+ *argument_type);
+ }
+
+ return 0;
+}
+
+/* exported function documented in duk-libdom.h */
+int output_dictionary_declaration(FILE* outf, struct ir_entry *dictionarye)
+{
+ int memberc;
+ int res = 0;
+
+ for (memberc = 0;
+ memberc < dictionarye->u.dictionary.memberc;
+ memberc++) {
+ res = output_member_declaration(
+ outf,
+ dictionarye,
+ dictionarye->u.dictionary.memberv + memberc);
+ if (res != 0) {
+ break;
+ }
+ }
+
+ return res;
+}
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c
index 3ac7d83..aa44d38 100644
--- a/src/duk-libdom-interface.c
+++ b/src/duk-libdom-interface.c
@@ -792,7 +792,7 @@ output_interface_elipsis_operation(FILE* outf,
* operation with elipsis should go
*/
WARN(WARNING_UNIMPLEMENTED,
- "Elipsis parameetrs not checked: method %s::%s();",
+ "Elipsis parameters not checked: method %s::%s();",
interfacee->name, operatione->name);
output_get_method_private(outf, interfacee->class_name);
@@ -1339,3 +1339,46 @@ op_error:
return res;
}
+/* exported function documented in duk-libdom.h */
+int output_interface_declaration(FILE* outf, struct ir_entry *interfacee)
+{
+ struct genbind_node *init_node;
+
+ /* do not generate prototype declarations for interfaces marked no
+ * output
+ */
+ if (interfacee->u.interface.noobject) {
+ return 0;
+ }
+
+ /* prototype declaration */
+ fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
+ DLPFX, interfacee->class_name);
+
+ /* 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.
+ */
+ if (interfacee->refcount < 1) {
+ fprintf(outf, "\n");
+
+ return 0;
+ }
+
+ /* finaliser declaration */
+ fprintf(outf,
+ "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(outf, interfacee, init_node);
+
+ fprintf(outf, ";\n\n");
+
+ return 0;
+}
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 02b41b3..f72bc96 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -132,14 +132,14 @@ static FILE *open_header(struct ir *ir, const char *name)
return NULL;
}
+ /* tool preface */
+ output_tool_preface(hdrf);
+
/* binding preface */
output_cdata(hdrf,
ir->binding_node,
GENBIND_NODE_TYPE_PREFACE);
- /* tool preface */
- output_tool_preface(hdrf);
-
/* header guard */
fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
fprintf(hdrf, "#define %s_%s_h\n\n", DLPFX, name);
@@ -172,43 +172,6 @@ static int close_header(struct ir *ir,
}
-
-
-static int
-output_interface_init_declaration(FILE* outf,
- struct ir_entry *interfacee,
- struct genbind_node *init_node)
-{
- struct genbind_node *param_node;
-
- fprintf(outf,
- "void %s_%s___init(duk_context *ctx, %s_private_t *priv",
- DLPFX, interfacee->class_name, interfacee->class_name);
-
- /* count the number of arguments on the initializer */
- interfacee->class_init_argc = 0;
-
- /* output the paramters on the method (if any) */
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (param_node != NULL) {
- interfacee->class_init_argc++;
- fprintf(outf, ", ");
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
-
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- param_node, GENBIND_NODE_TYPE_PARAMETER);
- }
-
- fprintf(outf,")");
-
- return 0;
-}
-
-
/**
* generate private header
*/
@@ -314,44 +277,19 @@ output_prototype_header(struct ir *ir)
protof = open_header(ir, "prototype");
for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
- struct genbind_node *init_node;
-
- interfacee = ir->entries + idx;
+ struct ir_entry *entry;
- /* do not generate prototype declarations for interfaces marked
- * no output
- */
- if ((interfacee->type == IR_ENTRY_TYPE_INTERFACE) &&
- (interfacee->u.interface.noobject)) {
- continue;
- }
+ entry = ir->entries + idx;
- /* prototype declaration */
- fprintf(protof, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
- DLPFX, interfacee->class_name);
+ switch (entry->type) {
+ case IR_ENTRY_TYPE_INTERFACE:
+ output_interface_declaration(protof, entry);
+ break;
- /* 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.
- */
- 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");
+ case IR_ENTRY_TYPE_DICTIONARY:
+ output_dictionary_declaration(protof, entry);
+ break;
}
- fprintf(protof, "\n");
}
close_header(ir, protof, "prototype");
@@ -612,6 +550,10 @@ output_binding_src(struct ir *ir)
interfacee = ir->entries + idx;
+ if (interfacee->type == IR_ENTRY_TYPE_DICTIONARY) {
+ continue;
+ }
+
/* do not generate prototype calls for interfaces marked
* no output
*/
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index 84fc497..79b440e 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -20,11 +20,21 @@ int duk_libdom_output(struct ir *ir);
int output_interface(struct ir *ir, struct ir_entry *interfacee);
/**
+ * generate a declaration to implement a dictionary using duk and libdom.
+ */
+int output_interface_declaration(FILE* outf, struct ir_entry *interfacee);
+
+/**
* generate a source file to implement a dictionary using duk and libdom.
*/
int output_dictionary(struct ir *ir, struct ir_entry *dictionarye);
/**
+ * generate a declaration to implement a dictionary using duk and libdom.
+ */
+int output_dictionary_declaration(FILE* outf, struct ir_entry *dictionarye);
+
+/**
* generate preface block for nsgenbind
*/
int output_tool_preface(FILE* outf);
diff --git a/src/ir.c b/src/ir.c
index 3a2a1c8..b3631f4 100644
--- a/src/ir.c
+++ b/src/ir.c
@@ -189,7 +189,6 @@ argument_map_new(struct webidl_node *arg_list_node,
cure->node = argument;
-
cure->optionalc = webidl_node_enumerate_type(
webidl_node_getnode(argument),
WEBIDL_NODE_TYPE_OPTIONAL);
@@ -547,6 +546,86 @@ constant_map_new(struct webidl_node *interface,
return 0;
}
+
+static int
+member_map_new(struct webidl_node *dictionary,
+ int *memberc_out,
+ struct ir_operation_argument_entry **memberv_out)
+{
+ struct webidl_node *list_node;
+ struct webidl_node *member_node; /* member node */
+ struct ir_operation_argument_entry *cure; /* current entry */
+ struct ir_operation_argument_entry *memberv;
+ int memberc;
+
+ /* enumerate members */
+ memberc = enumerate_interface_type(dictionary,
+ WEBIDL_NODE_TYPE_ARGUMENT);
+
+ if (memberc < 1) {
+ *memberc_out = 0;
+ *memberv_out = NULL; /* no members so empty map */
+ return 0;
+ }
+
+ memberv = calloc(memberc, sizeof(struct ir_operation_argument_entry));
+ if (memberv == NULL) {
+ return -1;
+ };
+ cure = memberv;
+
+ /* iterate each list node within the dictionary */
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(dictionary),
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
+
+ while (list_node != NULL) {
+ /* iterate through members on list */
+ member_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ NULL,
+ WEBIDL_NODE_TYPE_ARGUMENT);
+
+ while (member_node != NULL) {
+ cure->node = member_node;
+
+ cure->name = webidl_node_gettext(
+ webidl_node_find_type(
+ webidl_node_getnode(member_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT));
+
+ cure->optionalc = webidl_node_enumerate_type(
+ webidl_node_getnode(member_node),
+ WEBIDL_NODE_TYPE_OPTIONAL);
+
+ cure->elipsisc = webidl_node_enumerate_type(
+ webidl_node_getnode(member_node),
+ WEBIDL_NODE_TYPE_ELLIPSIS);
+
+ cure++;
+
+ /* move to next member */
+ member_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ member_node,
+ WEBIDL_NODE_TYPE_ARGUMENT);
+ }
+
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(dictionary),
+ list_node,
+ WEBIDL_NODE_TYPE_LIST);
+ }
+
+ *memberc_out = memberc;
+ *memberv_out = memberv; /* resulting members map */
+
+ return 0;
+
+}
+
static int
entry_map_new(struct genbind_node *genbind,
struct webidl_node *interface,
@@ -692,8 +771,10 @@ entry_map_new(struct genbind_node *genbind,
/* identify this is an interface entry */
cure->type = IR_ENTRY_TYPE_DICTIONARY;
-
-
+ /* enumerate and map the dictionary members */
+ member_map_new(node,
+ &cure->u.dictionary.memberc,
+ &cure->u.dictionary.memberv);
/* move to next interface */
node = webidl_node_find_type(interface,
@@ -753,6 +834,36 @@ int ir_new(struct genbind_node *genbind,
return 0;
}
+static int ir_dump_dictionary(FILE *dumpf, struct ir_entry *ecur)
+{
+ if (ecur->u.dictionary.memberc > 0) {
+ int argc;
+
+ fprintf(dumpf, "\t%d members\n", ecur->u.dictionary.memberc);
+
+ for (argc = 0; argc < ecur->u.dictionary.memberc; argc++) {
+ struct ir_operation_argument_entry *arge;
+
+ arge = ecur->u.dictionary.memberv + argc;
+
+ fprintf(dumpf, "\t\t%s\n", arge->name);
+
+ if (arge->optionalc != 0) {
+ fprintf(dumpf,
+ "\t\t\toptional:%d\n",
+ arge->optionalc);
+ }
+
+ if (arge->elipsisc != 0) {
+ fprintf(dumpf,
+ "\t\t\telipsis:%d\n",
+ arge->elipsisc);
+ }
+ }
+ }
+ return 0;
+}
+
static int ir_dump_interface(FILE *dumpf, struct ir_entry *ecur)
{
if (ecur->u.interface.operationc > 0) {
@@ -886,8 +997,15 @@ int ir_dump(struct ir *ir)
fprintf(dumpf, "\tclass:%p\n", ecur->class);
}
- if (ecur->type == IR_ENTRY_TYPE_INTERFACE) {
+ switch (ecur->type) {
+ case IR_ENTRY_TYPE_INTERFACE:
ir_dump_interface(dumpf, ecur);
+ break;
+
+ case IR_ENTRY_TYPE_DICTIONARY:
+ ir_dump_dictionary(dumpf, ecur);
+ break;
+
}
ecur++;
}
diff --git a/src/ir.h b/src/ir.h
index cf431f6..1092fab 100644
--- a/src/ir.h
+++ b/src/ir.h
@@ -24,7 +24,9 @@ struct ir_operation_argument_entry {
struct webidl_node *node;
};
-/** map entry for each overload of an operation */
+/**
+ * map entry for each overload of an operation.
+ */
struct ir_operation_overload_entry {
struct webidl_node *type; /**< The return type of this overload */
@@ -49,6 +51,7 @@ struct ir_operation_entry {
struct ir_attribute_entry {
const char *name; /** attribute name */
struct webidl_node *node; /**< AST attribute node */
+
enum webidl_type_modifier modifier;
struct genbind_node *getter; /**< getter from binding */
struct genbind_node *setter; /**< getter from binding */
@@ -81,8 +84,12 @@ struct ir_interface_entry {
struct ir_constant_entry *constantv;
};
-/** map entry for a dictionary */
+/**
+ * map entry for a dictionary
+ */
struct ir_dictionary_entry {
+ int memberc; /**< the number of members */
+ struct ir_operation_argument_entry *memberv;
};
enum ir_entry_type {
diff --git a/src/webidl-ast.c b/src/webidl-ast.c
index dc78e1f..e9dda2d 100644
--- a/src/webidl-ast.c
+++ b/src/webidl-ast.c
@@ -34,6 +34,7 @@ struct webidl_node {
void *value;
struct webidl_node *node; /* node has a list of nodes */
char *text; /* node data is text */
+ float *flt;
int number; /* node data is an integer */
} r;
};
@@ -299,6 +300,22 @@ webidl_node_getint(struct webidl_node *node)
}
/* exported interface defined in webidl-ast.h */
+float *
+webidl_node_getfloat(struct webidl_node *node)
+{
+ if (node != NULL) {
+ switch(node->type) {
+ case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
+ return node->r.flt;
+
+ default:
+ break;
+ }
+ }
+ return NULL;
+}
+
+/* exported interface defined in webidl-ast.h */
enum webidl_node_type webidl_node_gettype(struct webidl_node *node)
{
return node->type;
@@ -398,7 +415,7 @@ static const char *webidl_node_type_to_str(enum webidl_node_type type)
return "Literal (bool)";
case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
- return "Literal (string)";
+ return "Literal (float)";
case WEBIDL_NODE_TYPE_LITERAL_STRING:
return "Literal (string)";
diff --git a/src/webidl-ast.h b/src/webidl-ast.h
index 0872965..9ae2ebb 100644
--- a/src/webidl-ast.h
+++ b/src/webidl-ast.h
@@ -105,6 +105,8 @@ struct webidl_node *webidl_node_add(struct webidl_node *node, struct webidl_node
char *webidl_node_gettext(struct webidl_node *node);
struct webidl_node *webidl_node_getnode(struct webidl_node *node);
int *webidl_node_getint(struct webidl_node *node);
+float *webidl_node_getfloat(struct webidl_node *node);
+
enum webidl_node_type webidl_node_gettype(struct webidl_node *node);
/* node searches */
--
NetSurf Generator for JavaScript bindings
8 years
netsurf: branch master updated. release/3.3-316-g2576664
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/257666499deef1e6ff03c...
...commit http://git.netsurf-browser.org/netsurf.git/commit/257666499deef1e6ff03c91...
...tree http://git.netsurf-browser.org/netsurf.git/tree/257666499deef1e6ff03c9167...
The branch, master has been updated
via 257666499deef1e6ff03c9167c282a5aead8fc6f (commit)
from 914ba332e2853baa30809eda11a878ab686253f6 (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/netsurf.git/commit/?id=257666499deef1e6ff0...
commit 257666499deef1e6ff03c9167c282a5aead8fc6f
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Reorder percentage calculation.
Fixed point representation couldn't store 0.65 exactly, so avoid doing
the divide by 100 first.
I will look at moving this into libcss's fixed point header and doing
it in a way that avoids arithmetic overflow, but for now this fixes
el reg layout.
diff --git a/render/layout.c b/render/layout.c
index 4539867..a54d324 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -67,8 +67,8 @@
#define AUTO INT_MIN
-/* Fixed point value percentage of an integer, to an integer */
-#define FPCT_OF_INT_TOINT(a, b) FIXTOINT(FMUL(FDIV(a, F_100), INTTOFIX(b)))
+/* Fixed point percentage (a) of an integer (b), to an integer */
+#define FPCT_OF_INT_TOINT(a, b) (FIXTOINT(FDIV((a * b), F_100)))
static bool layout_block_context(struct box *block, int viewport_height,
-----------------------------------------------------------------------
Summary of changes:
render/layout.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/render/layout.c b/render/layout.c
index 4539867..a54d324 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -67,8 +67,8 @@
#define AUTO INT_MIN
-/* Fixed point value percentage of an integer, to an integer */
-#define FPCT_OF_INT_TOINT(a, b) FIXTOINT(FMUL(FDIV(a, F_100), INTTOFIX(b)))
+/* Fixed point percentage (a) of an integer (b), to an integer */
+#define FPCT_OF_INT_TOINT(a, b) (FIXTOINT(FDIV((a * b), F_100)))
static bool layout_block_context(struct box *block, int viewport_height,
--
NetSurf Browser
8 years, 1 month
netsurf: branch master updated. release/3.3-315-g914ba33
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/914ba332e2853baa30809...
...commit http://git.netsurf-browser.org/netsurf.git/commit/914ba332e2853baa30809ed...
...tree http://git.netsurf-browser.org/netsurf.git/tree/914ba332e2853baa30809eda1...
The branch, master has been updated
via 914ba332e2853baa30809eda11a878ab686253f6 (commit)
from 4bbf2ac58af4a660d108ec51867a7cf8e674cc39 (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/netsurf.git/commit/?id=914ba332e2853baa308...
commit 914ba332e2853baa30809eda11a878ab686253f6
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Use the correct decoded surrogate values for calculating kerning widths
diff --git a/amiga/font.c b/amiga/font.c
index 5f661c4..c9a6d86 100644
--- a/amiga/font.c
+++ b/amiga/font.c
@@ -676,6 +676,7 @@ static inline int32 ami_font_width_glyph(struct OutlineFont *ofont,
struct GlyphWidthEntry *gwnode;
bool skip_c2 = false;
uint32 long_char_1 = 0;
+ uint32 long_char_2;
#ifndef __amigaos4__
struct BulletBase *BulletBase = ofont->BulletBase;
#endif
@@ -712,9 +713,10 @@ static inline int32 ami_font_width_glyph(struct OutlineFont *ofont,
kern = 0;
if(!skip_c2) {
+ long_char_2 = amiga_nsfont_decode_surrogate(char2);
if(ESetInfo(AMI_OFONT_ENGINE,
- OT_GlyphCode, *char1,
- OT_GlyphCode2, *char2,
+ OT_GlyphCode, long_char_1,
+ OT_GlyphCode2, long_char_2,
TAG_END) == OTERR_Success)
{
EObtainInfo(AMI_OFONT_ENGINE,
-----------------------------------------------------------------------
Summary of changes:
amiga/font.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/amiga/font.c b/amiga/font.c
index 5f661c4..c9a6d86 100644
--- a/amiga/font.c
+++ b/amiga/font.c
@@ -676,6 +676,7 @@ static inline int32 ami_font_width_glyph(struct OutlineFont *ofont,
struct GlyphWidthEntry *gwnode;
bool skip_c2 = false;
uint32 long_char_1 = 0;
+ uint32 long_char_2;
#ifndef __amigaos4__
struct BulletBase *BulletBase = ofont->BulletBase;
#endif
@@ -712,9 +713,10 @@ static inline int32 ami_font_width_glyph(struct OutlineFont *ofont,
kern = 0;
if(!skip_c2) {
+ long_char_2 = amiga_nsfont_decode_surrogate(char2);
if(ESetInfo(AMI_OFONT_ENGINE,
- OT_GlyphCode, *char1,
- OT_GlyphCode2, *char2,
+ OT_GlyphCode, long_char_1,
+ OT_GlyphCode2, long_char_2,
TAG_END) == OTERR_Success)
{
EObtainInfo(AMI_OFONT_ENGINE,
--
NetSurf Browser
8 years, 1 month
netsurf: branch master updated. release/3.3-314-g4bbf2ac
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/4bbf2ac58af4a660d108e...
...commit http://git.netsurf-browser.org/netsurf.git/commit/4bbf2ac58af4a660d108ec5...
...tree http://git.netsurf-browser.org/netsurf.git/tree/4bbf2ac58af4a660d108ec518...
The branch, master has been updated
via 4bbf2ac58af4a660d108ec51867a7cf8e674cc39 (commit)
from cba6bdb481545e404e0769b051090b16046a99f5 (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/netsurf.git/commit/?id=4bbf2ac58af4a660d10...
commit 4bbf2ac58af4a660d108ec51867a7cf8e674cc39
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Avoid accessing NULL pointer
diff --git a/amiga/gui.c b/amiga/gui.c
index f386b62..07fded3 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -346,13 +346,14 @@ bool ami_locate_resource(char *fullpath, const char *file)
/* Check NetSurf user data area first */
- strcpy(fullpath, current_user_dir);
- found = ami_gui_check_resource(fullpath, file);
- if(found) return true;
+ if(current_user_dir != NULL) {
+ strcpy(fullpath, current_user_dir);
+ found = ami_gui_check_resource(fullpath, file);
+ if(found) return true;
+ }
/* Check current theme directory */
- if(nsoption_charp(theme))
- {
+ if(nsoption_charp(theme)) {
strcpy(fullpath, nsoption_charp(theme));
found = ami_gui_check_resource(fullpath, file);
if(found) return true;
@@ -362,28 +363,23 @@ bool ami_locate_resource(char *fullpath, const char *file)
locale = OpenLocale(NULL);
- for(i=0;i<10;i++)
- {
+ for(i=0;i<10;i++) {
strcpy(fullpath,"PROGDIR:Resources/");
- if(locale->loc_PrefLanguages[i])
- {
+ if(locale->loc_PrefLanguages[i]) {
ami_gui_map_filename(&remapped, "PROGDIR:Resources",
locale->loc_PrefLanguages[i], "LangNames");
netsurf_mkpath(&fullpath, &fullpath_len, 2, fullpath, remapped);
found = ami_gui_check_resource(fullpath, file);
- }
- else
- {
+ } else {
continue;
}
if(found) break;
}
- if(!found)
- {
+ if(!found) {
/* If not found yet, check in PROGDIR:Resources/en,
* might not be in user's preferred languages */
@@ -393,8 +389,7 @@ bool ami_locate_resource(char *fullpath, const char *file)
CloseLocale(locale);
- if(!found)
- {
+ if(!found) {
/* Lastly check directly in PROGDIR:Resources */
strcpy(fullpath, "PROGDIR:Resources/");
-----------------------------------------------------------------------
Summary of changes:
amiga/gui.c | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/amiga/gui.c b/amiga/gui.c
index f386b62..07fded3 100644
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -346,13 +346,14 @@ bool ami_locate_resource(char *fullpath, const char *file)
/* Check NetSurf user data area first */
- strcpy(fullpath, current_user_dir);
- found = ami_gui_check_resource(fullpath, file);
- if(found) return true;
+ if(current_user_dir != NULL) {
+ strcpy(fullpath, current_user_dir);
+ found = ami_gui_check_resource(fullpath, file);
+ if(found) return true;
+ }
/* Check current theme directory */
- if(nsoption_charp(theme))
- {
+ if(nsoption_charp(theme)) {
strcpy(fullpath, nsoption_charp(theme));
found = ami_gui_check_resource(fullpath, file);
if(found) return true;
@@ -362,28 +363,23 @@ bool ami_locate_resource(char *fullpath, const char *file)
locale = OpenLocale(NULL);
- for(i=0;i<10;i++)
- {
+ for(i=0;i<10;i++) {
strcpy(fullpath,"PROGDIR:Resources/");
- if(locale->loc_PrefLanguages[i])
- {
+ if(locale->loc_PrefLanguages[i]) {
ami_gui_map_filename(&remapped, "PROGDIR:Resources",
locale->loc_PrefLanguages[i], "LangNames");
netsurf_mkpath(&fullpath, &fullpath_len, 2, fullpath, remapped);
found = ami_gui_check_resource(fullpath, file);
- }
- else
- {
+ } else {
continue;
}
if(found) break;
}
- if(!found)
- {
+ if(!found) {
/* If not found yet, check in PROGDIR:Resources/en,
* might not be in user's preferred languages */
@@ -393,8 +389,7 @@ bool ami_locate_resource(char *fullpath, const char *file)
CloseLocale(locale);
- if(!found)
- {
+ if(!found) {
/* Lastly check directly in PROGDIR:Resources */
strcpy(fullpath, "PROGDIR:Resources/");
--
NetSurf Browser
8 years, 1 month
libsvgtiny: branch master updated. release/0.1.3-3-ga32dcf6
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/a32dcf6d6f66935a8b...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/a32dcf6d6f66935a8b82...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/a32dcf6d6f66935a8b82ea...
The branch, master has been updated
via a32dcf6d6f66935a8b82ea1f8f04e783fcf51fd6 (commit)
from 35db3a3d047cd55b2104294fbe4d39f5b72a7e14 (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/libsvgtiny.git/commit/?id=a32dcf6d6f66935a...
commit a32dcf6d6f66935a8b82ea1f8f04e783fcf51fd6
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Fix reallocation of path buffer length to cope with differng path lengths
diff --git a/src/svgtiny.c b/src/svgtiny.c
index 6215b04..e42077a 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -473,18 +473,21 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
int n;
/* Ensure there is sufficient space for path elements */
- if ((palloc - i) < 7) {
- float *tp;
- palloc = (palloc * 2) + (palloc / 2);
- tp = realloc(p, sizeof p[0] * palloc);
- if (tp == NULL) {
- free(p);
- free(path_d);
- svgtiny_cleanup_state_local(&state);
- return svgtiny_OUT_OF_MEMORY;
- }
- p = tp;
- }
+#define ALLOC_PATH_ELEMENTS(NUM_ELEMENTS) \
+ do { \
+ if ((palloc - i) < NUM_ELEMENTS) { \
+ float *tp; \
+ palloc = (palloc * 2) + (palloc / 2); \
+ tp = realloc(p, sizeof p[0] * palloc); \
+ if (tp == NULL) { \
+ free(p); \
+ free(path_d); \
+ svgtiny_cleanup_state_local(&state); \
+ return svgtiny_OUT_OF_MEMORY; \
+ } \
+ p = tp; \
+ } \
+ } while(0)
/* moveto (M, m), lineto (L, l) (2 arguments) */
@@ -495,6 +498,7 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
else
plot_command = svgtiny_PATH_LINE;
do {
+ ALLOC_PATH_ELEMENTS(3);
p[i++] = plot_command;
if ('a' <= *command) {
x += last_x;
@@ -515,6 +519,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
/* closepath (Z, z) (no arguments) */
} else if (sscanf(s, " %1[Zz] %n", command, &n) == 1) {
/*LOG(("closepath"));*/
+ ALLOC_PATH_ELEMENTS(1);
+
p[i++] = svgtiny_PATH_CLOSE;
s += n;
last_cubic_x = last_quad_x = last_x = subpath_first_x;
@@ -524,6 +530,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
} else if (sscanf(s, " %1[Hh] %f %n", command, &x, &n) == 2) {
/*LOG(("horizontal lineto"));*/
do {
+ ALLOC_PATH_ELEMENTS(3);
+
p[i++] = svgtiny_PATH_LINE;
if (*command == 'h')
x += last_x;
@@ -537,6 +545,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
} else if (sscanf(s, " %1[Vv] %f %n", command, &y, &n) == 2) {
/*LOG(("vertical lineto"));*/
do {
+ ALLOC_PATH_ELEMENTS(3);
+
p[i++] = svgtiny_PATH_LINE;
if (*command == 'v')
y += last_y;
@@ -551,6 +561,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x1, &y1, &x2, &y2, &x, &y, &n) == 7) {
/*LOG(("curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
if (*command == 'c') {
x1 += last_x;
@@ -575,6 +587,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x2, &y2, &x, &y, &n) == 5) {
/*LOG(("shorthand/smooth curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
x1 = last_x + (last_x - last_cubic_x);
y1 = last_y + (last_y - last_cubic_y);
@@ -599,6 +613,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x1, &y1, &x, &y, &n) == 5) {
/*LOG(("quadratic Bezier curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
last_quad_x = x1;
last_quad_y = y1;
@@ -624,6 +640,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x, &y, &n) == 3) {
/*LOG(("shorthand/smooth quadratic Bezier curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
x1 = last_x + (last_x - last_quad_x);
y1 = last_y + (last_y - last_quad_y);
@@ -650,6 +668,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&rx, &ry, &rotation, &large_arc, &sweep,
&x, &y, &n) == 8) {
do {
+ ALLOC_PATH_ELEMENTS(3);
+
p[i++] = svgtiny_PATH_LINE;
if (*command == 'a') {
x += last_x;
@@ -681,15 +701,15 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
/* resize path element array to not be over allocated */
if (palloc != i) {
- float *tp;
-
- /* try the resize, if it fails just continue to use the old
- * allocation
- */
- tp = realloc(p, sizeof p[0] * i);
- if (tp != NULL) {
- p = tp;
- }
+ float *tp;
+
+ /* try the resize, if it fails just continue to use the old
+ * allocation
+ */
+ tp = realloc(p, sizeof p[0] * i);
+ if (tp != NULL) {
+ p = tp;
+ }
}
err = svgtiny_add_path(p, i, &state);
-----------------------------------------------------------------------
Summary of changes:
src/svgtiny.c | 62 ++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 21 deletions(-)
diff --git a/src/svgtiny.c b/src/svgtiny.c
index 6215b04..e42077a 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -473,18 +473,21 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
int n;
/* Ensure there is sufficient space for path elements */
- if ((palloc - i) < 7) {
- float *tp;
- palloc = (palloc * 2) + (palloc / 2);
- tp = realloc(p, sizeof p[0] * palloc);
- if (tp == NULL) {
- free(p);
- free(path_d);
- svgtiny_cleanup_state_local(&state);
- return svgtiny_OUT_OF_MEMORY;
- }
- p = tp;
- }
+#define ALLOC_PATH_ELEMENTS(NUM_ELEMENTS) \
+ do { \
+ if ((palloc - i) < NUM_ELEMENTS) { \
+ float *tp; \
+ palloc = (palloc * 2) + (palloc / 2); \
+ tp = realloc(p, sizeof p[0] * palloc); \
+ if (tp == NULL) { \
+ free(p); \
+ free(path_d); \
+ svgtiny_cleanup_state_local(&state); \
+ return svgtiny_OUT_OF_MEMORY; \
+ } \
+ p = tp; \
+ } \
+ } while(0)
/* moveto (M, m), lineto (L, l) (2 arguments) */
@@ -495,6 +498,7 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
else
plot_command = svgtiny_PATH_LINE;
do {
+ ALLOC_PATH_ELEMENTS(3);
p[i++] = plot_command;
if ('a' <= *command) {
x += last_x;
@@ -515,6 +519,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
/* closepath (Z, z) (no arguments) */
} else if (sscanf(s, " %1[Zz] %n", command, &n) == 1) {
/*LOG(("closepath"));*/
+ ALLOC_PATH_ELEMENTS(1);
+
p[i++] = svgtiny_PATH_CLOSE;
s += n;
last_cubic_x = last_quad_x = last_x = subpath_first_x;
@@ -524,6 +530,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
} else if (sscanf(s, " %1[Hh] %f %n", command, &x, &n) == 2) {
/*LOG(("horizontal lineto"));*/
do {
+ ALLOC_PATH_ELEMENTS(3);
+
p[i++] = svgtiny_PATH_LINE;
if (*command == 'h')
x += last_x;
@@ -537,6 +545,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
} else if (sscanf(s, " %1[Vv] %f %n", command, &y, &n) == 2) {
/*LOG(("vertical lineto"));*/
do {
+ ALLOC_PATH_ELEMENTS(3);
+
p[i++] = svgtiny_PATH_LINE;
if (*command == 'v')
y += last_y;
@@ -551,6 +561,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x1, &y1, &x2, &y2, &x, &y, &n) == 7) {
/*LOG(("curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
if (*command == 'c') {
x1 += last_x;
@@ -575,6 +587,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x2, &y2, &x, &y, &n) == 5) {
/*LOG(("shorthand/smooth curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
x1 = last_x + (last_x - last_cubic_x);
y1 = last_y + (last_y - last_cubic_y);
@@ -599,6 +613,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x1, &y1, &x, &y, &n) == 5) {
/*LOG(("quadratic Bezier curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
last_quad_x = x1;
last_quad_y = y1;
@@ -624,6 +640,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&x, &y, &n) == 3) {
/*LOG(("shorthand/smooth quadratic Bezier curveto"));*/
do {
+ ALLOC_PATH_ELEMENTS(7);
+
p[i++] = svgtiny_PATH_BEZIER;
x1 = last_x + (last_x - last_quad_x);
y1 = last_y + (last_y - last_quad_y);
@@ -650,6 +668,8 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
&rx, &ry, &rotation, &large_arc, &sweep,
&x, &y, &n) == 8) {
do {
+ ALLOC_PATH_ELEMENTS(3);
+
p[i++] = svgtiny_PATH_LINE;
if (*command == 'a') {
x += last_x;
@@ -681,15 +701,15 @@ svgtiny_code svgtiny_parse_path(dom_element *path,
/* resize path element array to not be over allocated */
if (palloc != i) {
- float *tp;
-
- /* try the resize, if it fails just continue to use the old
- * allocation
- */
- tp = realloc(p, sizeof p[0] * i);
- if (tp != NULL) {
- p = tp;
- }
+ float *tp;
+
+ /* try the resize, if it fails just continue to use the old
+ * allocation
+ */
+ tp = realloc(p, sizeof p[0] * i);
+ if (tp != NULL) {
+ p = tp;
+ }
}
err = svgtiny_add_path(p, i, &state);
--
NetSurf SVG decoder
8 years, 1 month
libcss: branch tlsa/shared-styles updated. release/0.5.0-15-g5a41694
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libcss.git/shortlog/5a41694af51d820a3f697f...
...commit http://git.netsurf-browser.org/libcss.git/commit/5a41694af51d820a3f697f3b...
...tree http://git.netsurf-browser.org/libcss.git/tree/5a41694af51d820a3f697f3bbc...
The branch, tlsa/shared-styles has been updated
discards c78be88ddd451c3badeacf8a5e76e86a6161b847 (commit)
discards 4834c6938e13d866fb152f8a39fb33a2314b71a6 (commit)
discards c9dc8446814b5df918d30fdff3cbbd273962f7e8 (commit)
discards 4067e18cbfc8627cb26a868a442988abe77f0f6e (commit)
discards f44edbb40c3d421482c976561a34d248eb13f16e (commit)
via 5a41694af51d820a3f697f3bbcaefa0dc5091c26 (commit)
via e6f16ffdd6fd204edb1735b1b9d0f7c305136428 (commit)
via ae9ec4464807db7ba96ea49435d8bf45a5eaf51e (commit)
via 91046993f7586edb101e537369ab64928fbdca7f (commit)
via bfaf7d371e3f58487a0a6b1efbbac9935747df54 (commit)
via c754efd5b1ce267cdd1da43c2e4fa924c0bb8334 (commit)
via b1684e3588d95b93f3268895c5a0a7c156cd018e (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (c78be88ddd451c3badeacf8a5e76e86a6161b847)
\
N -- N -- N (5a41694af51d820a3f697f3bbcaefa0dc5091c26)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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/libcss.git/commit/?id=5a41694af51d820a3f69...
commit 5a41694af51d820a3f697f3bbcaefa0dc5091c26
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Composition: Avoid extension block checks irrelevent to property group.
diff --git a/src/select/computed.c b/src/select/computed.c
index 182a7e7..107c884 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -296,20 +296,24 @@ css_error css_computed_style_compose(const css_computed_style *parent,
/* Iterate through the properties */
for (i = 0; i < CSS_N_PROPERTIES; i++) {
- /* Skip any in extension blocks if the block does not exist */
- if (prop_dispatch[i].group == GROUP_UNCOMMON &&
- parent->i.uncommon == NULL &&
- child->i.uncommon == NULL)
- continue;
-
- if (prop_dispatch[i].group == GROUP_PAGE &&
- parent->page == NULL && child->page == NULL)
- continue;
-
- if (prop_dispatch[i].group == GROUP_AURAL &&
- parent->i.aural == NULL &&
- child->i.aural == NULL)
- continue;
+ /* Skip any in extension blocks if the block does not exist */
+ switch(prop_dispatch[i].group) {
+ case GROUP_NORMAL:
+ break;
+ case GROUP_UNCOMMON:
+ if (parent->i.uncommon == NULL &&
+ child->i.uncommon == NULL)
+ continue;
+ break;
+ case GROUP_PAGE:
+ if (parent->page == NULL && child->page == NULL)
+ continue;
+ break;
+ case GROUP_AURAL:
+ if (parent->i.aural == NULL && child->i.aural == NULL)
+ continue;
+ break;
+ }
/* Compose the property */
error = prop_dispatch[i].compose(parent, child, *result);
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=e6f16ffdd6fd204edb17...
commit e6f16ffdd6fd204edb1735b1b9d0f7c305136428
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Change arena hash from FNV-1 to 32-bit MurmurHash2.
diff --git a/src/select/arena.c b/src/select/arena.c
index 8f5a319..1b0ea57 100644
--- a/src/select/arena.c
+++ b/src/select/arena.c
@@ -9,6 +9,7 @@
#include <string.h>
#include "select/arena.h"
+#include "select/arena_hash.h"
#include "select/computed.h"
#define TU_SIZE 3037
@@ -18,23 +19,6 @@ struct css_computed_uncommon *table_u[TU_SIZE];
struct css_computed_style *table_s[TS_SIZE];
-/**
- * FNV-1 hash
- */
-static inline uint32_t css__arena_hash(const uint8_t *data, size_t len)
-{
- lwc_hash h = 0x811c9dc5;
-
- while (len > 0) {
- h *= 0x01000193;
- h ^= *data++;
- len--;
- }
-
- return h;
-}
-
-
static inline uint32_t css__arena_hash_uncommon(struct css_computed_uncommon *u)
{
return css__arena_hash((const uint8_t *) &u->i, sizeof(u->i));
diff --git a/src/select/arena_hash.h b/src/select/arena_hash.h
new file mode 100644
index 0000000..58abcd4
--- /dev/null
+++ b/src/select/arena_hash.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#ifndef css_select_arena_hash_h_
+#define css_select_arena_hash_h_
+
+#include <stdint.h>
+
+/**
+ * Currently 32-bit MurmurHash2.
+ *
+ * Created by Austin Appleby, and placed in the public domain.
+ * https://sites.google.com/site/murmurhash/
+ *
+ * Refactored and adapted a little for libcss.
+ */
+static inline uint32_t css__arena_hash(const uint8_t *data, size_t len)
+{
+ /* Hashing constants */
+ const uint32_t m = 0x5bd1e995;
+ const int r = 24;
+
+ /* Start with length */
+ uint32_t h = len;
+
+ /* Hash four bytes at a time */
+ while (len >= 4) {
+ /* If we could ensure 4-byte alignment of the input, this
+ * could be faster. */
+ uint32_t k =
+ (((uint32_t) data[0]) ) |
+ (((uint32_t) data[1]) << 8) |
+ (((uint32_t) data[2]) << 16) |
+ (((uint32_t) data[3]) << 24);
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+ h *= m;
+ h ^= k;
+ data += 4;
+ len -= 4;
+ }
+
+ /* Hash any left over bytes */
+ switch (len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0];
+ h *= m;
+ }
+
+ /* Finalise */
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}
+
+#endif
+
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=ae9ec4464807db7ba96e...
commit ae9ec4464807db7ba96ea49435d8bf45a5eaf51e
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
After composing styles, intern the result in the style sharing arena.
Note this changes the API.
Selection tests updated.
diff --git a/include/libcss/computed.h b/include/libcss/computed.h
index 233265c..f8f3391 100644
--- a/include/libcss/computed.h
+++ b/include/libcss/computed.h
@@ -83,12 +83,12 @@ css_error css_computed_style_initialise(css_computed_style *style,
struct css_select_handler *handler, void *pw);
css_error css_computed_style_compose(const css_computed_style *parent,
- const css_computed_style *child,
+ css_computed_style *child,
css_error (*compute_font_size)(void *pw,
const struct css_hint *parent,
struct css_hint *size),
void *pw,
- css_computed_style *result);
+ css_computed_style **result);
/******************************************************************************
* Property accessors below here *
diff --git a/src/select/computed.c b/src/select/computed.c
index 817da31..182a7e7 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -7,6 +7,7 @@
#include <string.h>
+#include "select/arena.h"
#include "select/computed.h"
#include "select/dispatch.h"
#include "select/propget.h"
@@ -92,6 +93,13 @@ css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon)
if (uncommon == NULL)
return CSS_BADPARM;
+ if (uncommon->count > 1) {
+ uncommon->count--;
+ return CSS_OK;
+
+ } else if (uncommon->count == 1) {
+ css__arena_remove_uncommon_style(uncommon);
+ }
if (uncommon != NULL) {
if (uncommon->counter_increment != NULL) {
@@ -176,6 +184,13 @@ css_error css_computed_style_destroy(css_computed_style *style)
css__computed_uncommon_destroy(style->i.uncommon);
+ if (style->count > 1) {
+ style->count--;
+ return CSS_OK;
+
+ } else if (style->count == 1) {
+ css__arena_remove_style(style);
+ }
if (style->page != NULL) {
free(style->page);
@@ -270,11 +285,11 @@ css_error css_computed_style_initialise(css_computed_style *style,
* \note \a child and \a result may point at the same object
*/
css_error css_computed_style_compose(const css_computed_style *parent,
- const css_computed_style *child,
+ css_computed_style *child,
css_error (*compute_font_size)(void *pw,
const css_hint *parent, css_hint *size),
void *pw,
- css_computed_style *result)
+ css_computed_style **result)
{
css_error error = CSS_OK;
size_t i;
@@ -297,13 +312,19 @@ css_error css_computed_style_compose(const css_computed_style *parent,
continue;
/* Compose the property */
- error = prop_dispatch[i].compose(parent, child, result);
+ error = prop_dispatch[i].compose(parent, child, *result);
if (error != CSS_OK)
break;
}
/* Finally, compute absolute values for everything */
- return css__compute_absolute_values(parent, result, compute_font_size, pw);
+ error = css__compute_absolute_values(parent, *result,
+ compute_font_size, pw);
+ if (error != CSS_OK) {
+ return error;
+ }
+
+ return css__arena_intern_style(result);
}
/******************************************************************************
diff --git a/test/select-common.c b/test/select-common.c
index f1762a6..42cdb76 100644
--- a/test/select-common.c
+++ b/test/select-common.c
@@ -773,7 +773,7 @@ static void run_test_select_tree(css_select_ctx *select,
node->parent->sr->styles[ctx->pseudo_element],
sr->styles[ctx->pseudo_element],
compute_font_size, NULL,
- sr->styles[ctx->pseudo_element]) == CSS_OK);
+ &(sr->styles[ctx->pseudo_element])) == CSS_OK);
}
node->sr = sr;
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=91046993f7586edb101e...
commit 91046993f7586edb101e537369ab64928fbdca7f
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add arena module for interning computed styles.
Builds, but currently unused.
diff --git a/src/select/Makefile b/src/select/Makefile
index eb89c1f..e937191 100644
--- a/src/select/Makefile
+++ b/src/select/Makefile
@@ -1,4 +1,4 @@
# Sources
-DIR_SOURCES := computed.c dispatch.c hash.c select.c font_face.c
+DIR_SOURCES := arena.c computed.c dispatch.c hash.c select.c font_face.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/select/arena.c b/src/select/arena.c
new file mode 100644
index 0000000..8f5a319
--- /dev/null
+++ b/src/select/arena.c
@@ -0,0 +1,377 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#include <string.h>
+
+#include "select/arena.h"
+#include "select/computed.h"
+
+#define TU_SIZE 3037
+#define TS_SIZE 5101
+
+struct css_computed_uncommon *table_u[TU_SIZE];
+struct css_computed_style *table_s[TS_SIZE];
+
+
+/**
+ * FNV-1 hash
+ */
+static inline uint32_t css__arena_hash(const uint8_t *data, size_t len)
+{
+ lwc_hash h = 0x811c9dc5;
+
+ while (len > 0) {
+ h *= 0x01000193;
+ h ^= *data++;
+ len--;
+ }
+
+ return h;
+}
+
+
+static inline uint32_t css__arena_hash_uncommon(struct css_computed_uncommon *u)
+{
+ return css__arena_hash((const uint8_t *) &u->i, sizeof(u->i));
+}
+
+
+static inline uint32_t css__arena_hash_style(struct css_computed_style *s)
+{
+ return css__arena_hash((const uint8_t *) &s->i, sizeof(s->i));
+}
+
+
+static inline bool arena__compare_computed_page(
+ const struct css_computed_page *a,
+ const struct css_computed_page *b)
+{
+ if (a == NULL && b == NULL) {
+ return true;
+
+ } else if (a == NULL || b == NULL) {
+ return false;
+ }
+
+ return memcmp(a, b, sizeof(struct css_computed_page)) == 0;
+}
+
+
+static inline bool arena__compare_computed_content_item(
+ const struct css_computed_content_item *a,
+ const struct css_computed_content_item *b)
+{
+ if (a == NULL && b == NULL) {
+ return true;
+
+ } else if (a == NULL || b == NULL) {
+ return false;
+ }
+
+ if (a->type != b->type) {
+ return false;
+ }
+
+ return memcmp(a, b, sizeof(struct css_computed_content_item)) == 0;
+}
+
+
+static inline bool arena__compare_css_computed_counter(
+ const struct css_computed_counter *a,
+ const struct css_computed_counter *b)
+{
+ bool match;
+
+ if (a == NULL && b == NULL) {
+ return true;
+
+ } else if (a == NULL || b == NULL) {
+ return false;
+ }
+
+ if (a->value == b->value &&
+ lwc_string_isequal(a->name, b->name,
+ &match) == lwc_error_ok &&
+ match == true) {
+ return true;
+ }
+
+ return false;
+}
+
+static inline bool arena__compare_string_list(
+ lwc_string **a,
+ lwc_string **b)
+{
+ if (a == NULL && b == NULL) {
+ return true;
+
+ } else if (a == NULL || b == NULL) {
+ return false;
+ }
+
+ while (*a != NULL && *b != NULL) {
+ bool match;
+
+ if (lwc_string_isequal(*a, *b, &match) != lwc_error_ok ||
+ match == false) {
+ return false;
+ }
+
+ a++;
+ b++;
+ }
+
+ if (*a != *b) {
+ return false;
+ }
+
+ return true;
+}
+
+
+static inline bool css__arena_uncommon_is_equal(
+ struct css_computed_uncommon *a,
+ struct css_computed_uncommon *b)
+{
+ if (memcmp(&a->i, &b->i, sizeof(struct css_computed_uncommon_i)) != 0) {
+ return false;
+ }
+
+ if (!arena__compare_css_computed_counter(
+ a->counter_increment,
+ b->counter_increment)) {
+ return false;
+ }
+
+ if (!arena__compare_css_computed_counter(
+ a->counter_reset,
+ b->counter_reset)) {
+ return false;
+ }
+
+ if (!arena__compare_computed_content_item(
+ a->content,
+ b->content)) {
+ return false;
+ }
+
+ if (!arena__compare_string_list(
+ a->cursor,
+ b->cursor)) {
+ return false;
+ }
+
+ return true;
+}
+
+
+static inline bool css__arena_style_is_equal(
+ struct css_computed_style *a,
+ struct css_computed_style *b)
+{
+ if (memcmp(&a->i, &b->i, sizeof(struct css_computed_style_i)) != 0) {
+ return false;
+ }
+
+ if (!arena__compare_string_list(
+ a->font_family,
+ b->font_family)) {
+ return false;
+ }
+
+ if (!arena__compare_string_list(
+ a->quotes,
+ b->quotes)) {
+ return false;
+ }
+
+ if (!arena__compare_computed_page(
+ a->page,
+ b->page)) {
+ return false;
+ }
+
+ return true;
+}
+
+
+static void css__arena_intern_uncommon(
+ struct css_computed_uncommon **uncommon)
+{
+ struct css_computed_uncommon *u = *uncommon;
+ uint32_t hash, index;
+
+ /* Need to intern the uncommon block */
+ hash = css__arena_hash_uncommon(u);
+ index = hash % TU_SIZE;
+ u->bin = index;
+
+ if (table_u[index] == NULL) {
+ /* Can just insert */
+ table_u[index] = u;
+ u->count = 1;
+ } else {
+ /* Check for existing */
+ struct css_computed_uncommon *l = table_u[index];
+ struct css_computed_uncommon *existing = NULL;
+
+ do {
+ if (css__arena_uncommon_is_equal(l, u)) {
+ existing = l;
+ break;
+ }
+ l = l->next;
+ } while (l != NULL);
+
+ if (existing != NULL) {
+ css__computed_uncommon_destroy(u);
+ existing->count++;
+ *uncommon = existing;
+ } else {
+ /* Add to list */
+ u->next = table_u[index];
+ table_u[index] = u;
+ u->count = 1;
+ }
+ }
+}
+
+
+/* Internally exported function, documented in src/select/arena.h */
+css_error css__arena_intern_style(struct css_computed_style **style)
+{
+ struct css_computed_style *s = *style;
+ uint32_t hash, index;
+
+ if (s->count != 0) {
+ return CSS_BADPARM;
+ }
+
+ if (s->i.uncommon != NULL) {
+ if (s->i.uncommon->count != 0) {
+ return CSS_BADPARM;
+ }
+ css__arena_intern_uncommon(&s->i.uncommon);
+ }
+
+ /* Need to intern the style block */
+ hash = css__arena_hash_style(s);
+ index = hash % TS_SIZE;
+ s->bin = index;
+
+ if (table_s[index] == NULL) {
+ /* Can just insert */
+ table_s[index] = s;
+ s->count = 1;
+ } else {
+ /* Check for existing */
+ struct css_computed_style *l = table_s[index];
+ struct css_computed_style *existing = NULL;
+
+ do {
+ if (css__arena_style_is_equal(l, s)) {
+ existing = l;
+ break;
+ }
+ l = l->next;
+ } while (l != NULL);
+
+ if (existing != NULL) {
+ s->i.uncommon = NULL;
+ css_computed_style_destroy(s);
+ existing->count++;
+ *style = existing;
+ } else {
+ /* Add to list */
+ s->next = table_s[index];
+ table_s[index] = s;
+ s->count = 1;
+ }
+ }
+
+ return CSS_OK;
+}
+
+
+/* Internally exported function, documented in src/select/arena.h */
+enum css_error css__arena_remove_style(struct css_computed_style *style)
+{
+ uint32_t index = style->bin;
+
+ if (table_s[index] == NULL) {
+ return CSS_BADPARM;
+
+ } else {
+ /* Check for existing */
+ struct css_computed_style *l = table_s[index];
+ struct css_computed_style *existing = NULL;
+ struct css_computed_style *prev = NULL;
+
+ do {
+ if (css__arena_style_is_equal(l, style)) {
+ existing = l;
+ break;
+ }
+ prev = l;
+ l = l->next;
+ } while (l != NULL);
+
+ if (existing != NULL) {
+ if (prev != NULL) {
+ prev->next = existing->next;
+ } else {
+ table_s[index] = existing->next;
+ }
+ } else {
+ return CSS_BADPARM;
+ }
+ }
+
+ return CSS_OK;
+}
+
+
+/* Internally exported function, documented in src/select/arena.h */
+enum css_error css__arena_remove_uncommon_style(
+ struct css_computed_uncommon *uncommon)
+{
+ uint32_t index = uncommon->bin;
+
+ if (table_u[index] == NULL) {
+ return CSS_BADPARM;
+
+ } else {
+ /* Check for existing */
+ struct css_computed_uncommon *l = table_u[index];
+ struct css_computed_uncommon *existing = NULL;
+ struct css_computed_uncommon *prev = NULL;
+
+ do {
+ if (css__arena_uncommon_is_equal(l, uncommon)) {
+ existing = l;
+ break;
+ }
+ prev = l;
+ l = l->next;
+ } while (l != NULL);
+
+ if (existing != NULL) {
+ if (prev != NULL) {
+ prev->next = existing->next;
+ } else {
+ table_u[index] = existing->next;
+ }
+ } else {
+ return CSS_BADPARM;
+ }
+ }
+
+ return CSS_OK;
+}
+
diff --git a/src/select/arena.h b/src/select/arena.h
new file mode 100644
index 0000000..af06050
--- /dev/null
+++ b/src/select/arena.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Copyright 2015 Michael Drake <tlsa(a)netsurf-browser.org>
+ */
+
+#ifndef css_select_arena_h_
+#define css_select_arena_h_
+
+struct css_computed_style;
+struct css_computed_uncommon;
+
+/*
+ * Add computed style to the style sharing arena, or exchange for existing
+ *
+ * This takes a computed style. Note that the original computed style
+ * may be freed by this call and all future usage should be via the
+ * updated computed style parameter.
+ *
+ * \params style The style to intern; possibly freed and updated
+ * \return CSS_OK on success or appropriate error otherwise.
+ */
+enum css_error css__arena_intern_style(struct css_computed_style **style);
+
+/*
+ * Remove a computed style from the style sharing arena
+ *
+ * \params style The style to remove from the style sharing arena
+ * \return CSS_OK on success or appropriate error otherwise.
+ */
+enum css_error css__arena_remove_style(struct css_computed_style *style);
+
+/*
+ * Remove a computed style's uncommon block from the style sharing arena
+ *
+ * \params uncommon The uncommon style to remove from the style sharing arena
+ * \return CSS_OK on success or appropriate error otherwise.
+ */
+enum css_error css__arena_remove_uncommon_style(
+ struct css_computed_uncommon *uncommon);
+
+#endif
+
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=bfaf7d371e3f58487a0a...
commit bfaf7d371e3f58487a0a6b1efbbac9935747df54
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Ensure computed content items are initialised to zero.
This allows comparing them with memcmp.
diff --git a/src/select/properties/content.c b/src/select/properties/content.c
index a9dd211..472a66a 100644
--- a/src/select/properties/content.c
+++ b/src/select/properties/content.c
@@ -49,6 +49,7 @@ css_error css__cascade_content(uint32_t opv, css_style *style,
}
content = temp;
+ memset(content + n_contents, 0, sizeof(css_computed_content_item));
switch (v & 0xff) {
case CONTENT_COUNTER:
commitdiff http://git.netsurf-browser.org/libcss.git/commit/?id=c754efd5b1ce267cdd1d...
commit c754efd5b1ce267cdd1da43c2e4fa924c0bb8334
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Move trivially compared parts of computed styles to sub-structures.
diff --git a/src/select/computed.c b/src/select/computed.c
index dc632f9..817da31 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -75,59 +75,61 @@ css_error css_computed_style_create(css_computed_style **result)
if (s == NULL)
return CSS_NOMEM;
+ s->bin = UINT32_MAX;
*result = s;
return CSS_OK;
}
/**
- * Destroy a computed style
+ * Destroy an uncommon computed style section
*
* \param style Style to destroy
* \return CSS_OK on success, appropriate error otherwise
*/
-css_error css_computed_style_destroy(css_computed_style *style)
+css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon)
{
- if (style == NULL)
+ if (uncommon == NULL)
return CSS_BADPARM;
- if (style->uncommon != NULL) {
- if (style->uncommon->counter_increment != NULL) {
+
+ if (uncommon != NULL) {
+ if (uncommon->counter_increment != NULL) {
css_computed_counter *c;
- for (c = style->uncommon->counter_increment;
+ for (c = uncommon->counter_increment;
c->name != NULL; c++) {
lwc_string_unref(c->name);
}
- free(style->uncommon->counter_increment);
+ free(uncommon->counter_increment);
}
- if (style->uncommon->counter_reset != NULL) {
+ if (uncommon->counter_reset != NULL) {
css_computed_counter *c;
- for (c = style->uncommon->counter_reset;
+ for (c = uncommon->counter_reset;
c->name != NULL; c++) {
lwc_string_unref(c->name);
}
- free(style->uncommon->counter_reset);
+ free(uncommon->counter_reset);
}
- if (style->uncommon->cursor != NULL) {
+ if (uncommon->cursor != NULL) {
lwc_string **s;
- for (s = style->uncommon->cursor; *s != NULL; s++) {
+ for (s = uncommon->cursor; *s != NULL; s++) {
lwc_string_unref(*s);
}
- free(style->uncommon->cursor);
+ free(uncommon->cursor);
}
- if (style->uncommon->content != NULL) {
+ if (uncommon->content != NULL) {
css_computed_content_item *c;
- for (c = style->uncommon->content;
+ for (c = uncommon->content;
c->type != CSS_COMPUTED_CONTENT_NONE;
c++) {
switch (c->type) {
@@ -152,18 +154,35 @@ css_error css_computed_style_destroy(css_computed_style *style)
}
}
- free(style->uncommon->content);
+ free(uncommon->content);
}
- free(style->uncommon);
+ free(uncommon);
}
+ return CSS_OK;
+}
+
+/**
+ * Destroy a computed style
+ *
+ * \param style Style to destroy
+ * \return CSS_OK on success, appropriate error otherwise
+ */
+css_error css_computed_style_destroy(css_computed_style *style)
+{
+ if (style == NULL)
+ return CSS_BADPARM;
+
+ css__computed_uncommon_destroy(style->i.uncommon);
+
+
if (style->page != NULL) {
free(style->page);
}
- if (style->aural != NULL) {
- free(style->aural);
+ if (style->i.aural != NULL) {
+ free(style->i.aural);
}
if (style->font_family != NULL) {
@@ -186,11 +205,11 @@ css_error css_computed_style_destroy(css_computed_style *style)
free(style->quotes);
}
- if (style->list_style_image != NULL)
- lwc_string_unref(style->list_style_image);
+ if (style->i.list_style_image != NULL)
+ lwc_string_unref(style->i.list_style_image);
- if (style->background_image != NULL)
- lwc_string_unref(style->background_image);
+ if (style->i.background_image != NULL)
+ lwc_string_unref(style->i.background_image);
free(style);
@@ -264,8 +283,8 @@ css_error css_computed_style_compose(const css_computed_style *parent,
for (i = 0; i < CSS_N_PROPERTIES; i++) {
/* Skip any in extension blocks if the block does not exist */
if (prop_dispatch[i].group == GROUP_UNCOMMON &&
- parent->uncommon == NULL &&
- child->uncommon == NULL)
+ parent->i.uncommon == NULL &&
+ child->i.uncommon == NULL)
continue;
if (prop_dispatch[i].group == GROUP_PAGE &&
@@ -273,7 +292,8 @@ css_error css_computed_style_compose(const css_computed_style *parent,
continue;
if (prop_dispatch[i].group == GROUP_AURAL &&
- parent->aural == NULL && child->aural == NULL)
+ parent->i.aural == NULL &&
+ child->i.aural == NULL)
continue;
/* Compose the property */
@@ -444,7 +464,7 @@ uint8_t css_computed_top(const css_computed_style *style,
*unit = CSS_UNIT_PX;
} else if (top == CSS_TOP_AUTO) {
/* Top is auto => -bottom */
- *length = -style->bottom;
+ *length = -style->i.bottom;
*unit = (css_unit) (bottom >> 2);
}
@@ -474,7 +494,7 @@ uint8_t css_computed_right(const css_computed_style *style,
*unit = CSS_UNIT_PX;
} else if (right == CSS_RIGHT_AUTO) {
/* Right is auto => -left */
- *length = -style->left;
+ *length = -style->i.left;
*unit = (css_unit) (left >> 2);
} else {
/** \todo Consider containing block's direction
@@ -508,7 +528,7 @@ uint8_t css_computed_bottom(const css_computed_style *style,
} else if (bottom == CSS_BOTTOM_AUTO ||
(top & 0x3) != CSS_TOP_AUTO) {
/* Bottom is auto or top is not auto => -top */
- *length = -style->top;
+ *length = -style->i.top;
*unit = (css_unit) (top >> 2);
}
@@ -538,7 +558,7 @@ uint8_t css_computed_left(const css_computed_style *style,
*unit = CSS_UNIT_PX;
} else if (left == CSS_LEFT_AUTO) {
/* Left is auto => -right */
- *length = -style->right;
+ *length = -style->i.right;
*unit = (css_unit) (right >> 2);
} else {
/** \todo Consider containing block's direction
@@ -1144,7 +1164,7 @@ css_error css__compute_absolute_values(const css_computed_style *parent,
return error;
/* Uncommon properties */
- if (style->uncommon != NULL) {
+ if (style->i.uncommon != NULL) {
/* Fix up border-spacing */
error = compute_absolute_length_pair(style,
&ex_size.data.length,
diff --git a/src/select/computed.h b/src/select/computed.h
index 0ca01d9..f965993 100644
--- a/src/select/computed.h
+++ b/src/select/computed.h
@@ -13,7 +13,7 @@
-typedef struct css_computed_uncommon {
+struct css_computed_uncommon_i {
/*
* border_spacing 1 + 2(4) 2(4)
* break_before 4 0
@@ -99,13 +99,20 @@ typedef struct css_computed_uncommon {
css_color column_rule_color;
css_fixed column_rule_width;
css_fixed column_width;
+};
+
+typedef struct css_computed_uncommon {
+ struct css_computed_uncommon_i i;
css_computed_counter *counter_increment;
css_computed_counter *counter_reset;
- lwc_string **cursor;
-
css_computed_content_item *content;
+
+ lwc_string **cursor;
+ struct css_computed_uncommon *next;
+ uint32_t count;
+ uint32_t bin;
} css_computed_uncommon;
typedef struct css_computed_page {
@@ -122,7 +129,7 @@ typedef struct css_computed_page {
int32_t orphans;
} css_computed_page;
-struct css_computed_style {
+struct css_computed_style_i {
/*
* background_attachment 2
* background_repeat 3
@@ -302,15 +309,24 @@ struct css_computed_style {
int32_t z_index;
+ css_computed_uncommon *uncommon;/**< Uncommon properties */
+ void *aural; /**< Aural properties */
+};
+
+struct css_computed_style {
+ struct css_computed_style_i i;
+
lwc_string **font_family;
lwc_string **quotes;
-
- css_computed_uncommon *uncommon;/**< Uncommon properties */
- void *aural; /**< Aural properties */
css_computed_page *page; /**< Page properties */
+ struct css_computed_style *next;
+ uint32_t count;
+ uint32_t bin;
};
+css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon);
+
css_error css__compute_absolute_values(const css_computed_style *parent,
css_computed_style *style,
css_error (*compute_font_size)(void *pw,
diff --git a/src/select/properties/border_spacing.c b/src/select/properties/border_spacing.c
index 1b32747..db7b1f2 100644
--- a/src/select/properties/border_spacing.c
+++ b/src/select/properties/border_spacing.c
@@ -71,10 +71,10 @@ css_error css__compose_border_spacing(const css_computed_style *parent,
uint8_t type = get_border_spacing(child, &hlength, &hunit,
&vlength, &vunit);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_BORDER_SPACING_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_BORDER_SPACING_INHERIT) {
type = get_border_spacing(parent,
&hlength, &hunit, &vlength, &vunit);
diff --git a/src/select/properties/clip.c b/src/select/properties/clip.c
index d98c7eb..cc39d99 100644
--- a/src/select/properties/clip.c
+++ b/src/select/properties/clip.c
@@ -102,10 +102,10 @@ css_error css__compose_clip(const css_computed_style *parent,
false, false, false, false };
uint8_t type = get_clip(child, &rect);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_CLIP_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_CLIP_INHERIT) {
type = get_clip(parent, &rect);
}
diff --git a/src/select/properties/column_count.c b/src/select/properties/column_count.c
index 92fdec2..4ded377 100644
--- a/src/select/properties/column_count.c
+++ b/src/select/properties/column_count.c
@@ -59,10 +59,10 @@ css_error css__compose_column_count(const css_computed_style *parent,
int32_t count = 0;
uint8_t type = get_column_count(child, &count);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COLUMN_COUNT_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COLUMN_COUNT_INHERIT) {
type = get_column_count(parent, &count);
}
diff --git a/src/select/properties/column_gap.c b/src/select/properties/column_gap.c
index 641f529..f544f44 100644
--- a/src/select/properties/column_gap.c
+++ b/src/select/properties/column_gap.c
@@ -41,10 +41,10 @@ css_error css__compose_column_gap(const css_computed_style *parent,
css_unit unit = CSS_UNIT_EM;
uint8_t type = get_column_gap(child, &length, &unit);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COLUMN_GAP_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COLUMN_GAP_INHERIT) {
type = get_column_gap(parent, &length, &unit);
}
diff --git a/src/select/properties/column_width.c b/src/select/properties/column_width.c
index 45eb7fc..b6550ab 100644
--- a/src/select/properties/column_width.c
+++ b/src/select/properties/column_width.c
@@ -41,10 +41,10 @@ css_error css__compose_column_width(const css_computed_style *parent,
css_unit unit = CSS_UNIT_EM;
uint8_t type = get_column_width(child, &length, &unit);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COLUMN_WIDTH_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COLUMN_WIDTH_INHERIT) {
type = get_column_width(parent, &length, &unit);
}
diff --git a/src/select/properties/content.c b/src/select/properties/content.c
index c79dd0d..a9dd211 100644
--- a/src/select/properties/content.c
+++ b/src/select/properties/content.c
@@ -206,13 +206,13 @@ css_error css__compose_content(const css_computed_style *parent,
const css_computed_content_item *items = NULL;
uint8_t type = get_content(child, &items);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_CONTENT_INHERIT ||
- (child->uncommon != NULL && result != child)) {
+ (child->i.uncommon != NULL && result != child)) {
size_t n_items = 0;
css_computed_content_item *copy = NULL;
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_CONTENT_INHERIT) {
type = get_content(parent, &items);
}
diff --git a/src/select/properties/counter_increment.c b/src/select/properties/counter_increment.c
index 429e558..644607b 100644
--- a/src/select/properties/counter_increment.c
+++ b/src/select/properties/counter_increment.c
@@ -56,13 +56,13 @@ css_error css__compose_counter_increment(const css_computed_style *parent,
const css_computed_counter *items = NULL;
uint8_t type = get_counter_increment(child, &items);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COUNTER_INCREMENT_INHERIT ||
- (child->uncommon != NULL && result != child)) {
+ (child->i.uncommon != NULL && result != child)) {
size_t n_items = 0;
css_computed_counter *copy = NULL;
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COUNTER_INCREMENT_INHERIT) {
type = get_counter_increment(parent, &items);
}
diff --git a/src/select/properties/counter_reset.c b/src/select/properties/counter_reset.c
index ddf54aa..05559f5 100644
--- a/src/select/properties/counter_reset.c
+++ b/src/select/properties/counter_reset.c
@@ -55,13 +55,13 @@ css_error css__compose_counter_reset(const css_computed_style *parent,
const css_computed_counter *items = NULL;
uint8_t type = get_counter_reset(child, &items);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COUNTER_RESET_INHERIT ||
- (child->uncommon != NULL && result != child)) {
+ (child->i.uncommon != NULL && result != child)) {
size_t n_items = 0;
css_computed_counter *copy = NULL;
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_COUNTER_RESET_INHERIT) {
type = get_counter_reset(parent, &items);
}
diff --git a/src/select/properties/cursor.c b/src/select/properties/cursor.c
index a77d21b..1ca497f 100644
--- a/src/select/properties/cursor.c
+++ b/src/select/properties/cursor.c
@@ -172,13 +172,13 @@ css_error css__compose_cursor(const css_computed_style *parent,
lwc_string **urls = NULL;
uint8_t type = get_cursor(child, &urls);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_CURSOR_INHERIT ||
- (child->uncommon != NULL && result != child)) {
+ (child->i.uncommon != NULL && result != child)) {
size_t n_urls = 0;
lwc_string **copy = NULL;
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_CURSOR_INHERIT) {
type = get_cursor(parent, &urls);
}
diff --git a/src/select/properties/letter_spacing.c b/src/select/properties/letter_spacing.c
index 322efef..cc00100 100644
--- a/src/select/properties/letter_spacing.c
+++ b/src/select/properties/letter_spacing.c
@@ -41,10 +41,10 @@ css_error css__compose_letter_spacing(const css_computed_style *parent,
css_unit unit = CSS_UNIT_PX;
uint8_t type = get_letter_spacing(child, &length, &unit);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_LETTER_SPACING_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_LETTER_SPACING_INHERIT) {
type = get_letter_spacing(parent, &length, &unit);
}
diff --git a/src/select/properties/outline_color.c b/src/select/properties/outline_color.c
index 36aafd7..2613839 100644
--- a/src/select/properties/outline_color.c
+++ b/src/select/properties/outline_color.c
@@ -65,10 +65,10 @@ css_error css__compose_outline_color(const css_computed_style *parent,
css_color color = 0;
uint8_t type = get_outline_color(child, &color);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_OUTLINE_COLOR_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_OUTLINE_COLOR_INHERIT) {
type = get_outline_color(parent, &color);
}
diff --git a/src/select/properties/outline_width.c b/src/select/properties/outline_width.c
index 5380179..547c42a 100644
--- a/src/select/properties/outline_width.c
+++ b/src/select/properties/outline_width.c
@@ -41,10 +41,10 @@ css_error css__compose_outline_width(const css_computed_style *parent,
css_unit unit = CSS_UNIT_PX;
uint8_t type = get_outline_width(child, &length, &unit);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_OUTLINE_WIDTH_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_OUTLINE_WIDTH_INHERIT) {
type = get_outline_width(parent, &length, &unit);
}
diff --git a/src/select/properties/word_spacing.c b/src/select/properties/word_spacing.c
index dd4e1d7..24eda89 100644
--- a/src/select/properties/word_spacing.c
+++ b/src/select/properties/word_spacing.c
@@ -41,10 +41,10 @@ css_error css__compose_word_spacing(const css_computed_style *parent,
css_unit unit = CSS_UNIT_PX;
uint8_t type = get_word_spacing(child, &length, &unit);
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_WORD_SPACING_INHERIT ||
- (child->uncommon != NULL && result != child)) {
- if ((child->uncommon == NULL && parent->uncommon != NULL) ||
+ (child->i.uncommon != NULL && result != child)) {
+ if ((child->i.uncommon == NULL && parent->i.uncommon != NULL) ||
type == CSS_WORD_SPACING_INHERIT) {
type = get_word_spacing(parent, &length, &unit);
}
diff --git a/src/select/propget.h b/src/select/propget.h
index 2a263aa..5552e39 100644
--- a/src/select/propget.h
+++ b/src/select/propget.h
@@ -21,15 +21,15 @@ static inline uint8_t get_letter_spacing(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[LETTER_SPACING_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[LETTER_SPACING_INDEX];
bits &= LETTER_SPACING_MASK;
bits >>= LETTER_SPACING_SHIFT;
/* 6bits: uuuutt : unit | type */
if ((bits & 3) == CSS_LETTER_SPACING_SET) {
- *length = style->uncommon->letter_spacing;
+ *length = style->i.uncommon->i.letter_spacing;
*unit = bits >> 2;
}
@@ -49,15 +49,15 @@ static inline uint8_t get_letter_spacing(
static inline uint8_t get_outline_color(
const css_computed_style *style, css_color *color)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[OUTLINE_COLOR_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[OUTLINE_COLOR_INDEX];
bits &= OUTLINE_COLOR_MASK;
bits >>= OUTLINE_COLOR_SHIFT;
/* 2bits: tt : type */
if ((bits & 3) == CSS_OUTLINE_COLOR_COLOR) {
- *color = style->uncommon->outline_color;
+ *color = style->i.uncommon->i.outline_color;
}
return (bits & 3);
@@ -77,15 +77,15 @@ static inline uint8_t get_outline_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[OUTLINE_WIDTH_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[OUTLINE_WIDTH_INDEX];
bits &= OUTLINE_WIDTH_MASK;
bits >>= OUTLINE_WIDTH_SHIFT;
/* 7bits: uuuuttt : unit | type */
if ((bits & 7) == CSS_OUTLINE_WIDTH_WIDTH) {
- *length = style->uncommon->outline_width;
+ *length = style->i.uncommon->i.outline_width;
*unit = bits >> 3;
}
@@ -110,24 +110,24 @@ static inline uint8_t get_border_spacing(
css_fixed *hlength, css_unit *hunit,
css_fixed *vlength, css_unit *vunit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[BORDER_SPACING_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[BORDER_SPACING_INDEX];
bits &= BORDER_SPACING_MASK;
bits >>= BORDER_SPACING_SHIFT;
/* 1 bit: type */
if (bits == CSS_BORDER_SPACING_SET) {
uint8_t bits1 =
- style->uncommon->bits[BORDER_SPACING_INDEX1];
+ style->i.uncommon->i.bits[BORDER_SPACING_INDEX1];
bits1 &= BORDER_SPACING_MASK1;
bits1 >>= BORDER_SPACING_SHIFT1;
/* 8bits: hhhhvvvv : hunit | vunit */
- *hlength = style->uncommon->border_spacing[0];
+ *hlength = style->i.uncommon->i.border_spacing[0];
*hunit = bits1 >> 4;
- *vlength = style->uncommon->border_spacing[1];
+ *vlength = style->i.uncommon->i.border_spacing[1];
*vunit = bits1 & 0xf;
}
@@ -152,8 +152,8 @@ static inline uint8_t get_border_spacing(
static inline uint8_t get_break_after(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[BREAK_AFTER_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[BREAK_AFTER_INDEX];
bits &= BREAK_AFTER_MASK;
bits >>= BREAK_AFTER_SHIFT;
@@ -174,8 +174,8 @@ static inline uint8_t get_break_after(
static inline uint8_t get_break_before(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[BREAK_BEFORE_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[BREAK_BEFORE_INDEX];
bits &= BREAK_BEFORE_MASK;
bits >>= BREAK_BEFORE_SHIFT;
@@ -196,8 +196,8 @@ static inline uint8_t get_break_before(
static inline uint8_t get_break_inside(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[BREAK_INSIDE_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[BREAK_INSIDE_INDEX];
bits &= BREAK_INSIDE_MASK;
bits >>= BREAK_INSIDE_SHIFT;
@@ -219,15 +219,15 @@ static inline uint8_t get_word_spacing(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[WORD_SPACING_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[WORD_SPACING_INDEX];
bits &= WORD_SPACING_MASK;
bits >>= WORD_SPACING_SHIFT;
/* 6bits: uuuutt : unit | type */
if ((bits & 3) == CSS_WORD_SPACING_SET) {
- *length = style->uncommon->word_spacing;
+ *length = style->i.uncommon->i.word_spacing;
*unit = bits >> 2;
}
@@ -247,8 +247,8 @@ static inline uint8_t get_word_spacing(
static inline uint8_t get_writing_mode(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[WRITING_MODE_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[WRITING_MODE_INDEX];
bits &= WRITING_MODE_MASK;
bits >>= WRITING_MODE_SHIFT;
@@ -270,13 +270,13 @@ static inline uint8_t get_counter_increment(
const css_computed_style *style,
const css_computed_counter **counters)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COUNTER_INCREMENT_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COUNTER_INCREMENT_INDEX];
bits &= COUNTER_INCREMENT_MASK;
bits >>= COUNTER_INCREMENT_SHIFT;
/* 1bit: type */
- *counters = style->uncommon->counter_increment;
+ *counters = style->i.uncommon->counter_increment;
return bits;
}
@@ -295,13 +295,13 @@ static inline uint8_t get_counter_reset(
const css_computed_style *style,
const css_computed_counter **counters)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COUNTER_RESET_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COUNTER_RESET_INDEX];
bits &= COUNTER_RESET_MASK;
bits >>= COUNTER_RESET_SHIFT;
/* 1bit: type */
- *counters = style->uncommon->counter_reset;
+ *counters = style->i.uncommon->counter_reset;
return bits;
}
@@ -320,13 +320,13 @@ static inline uint8_t get_cursor(
const css_computed_style *style,
lwc_string ***urls)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[CURSOR_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[CURSOR_INDEX];
bits &= CURSOR_MASK;
bits >>= CURSOR_SHIFT;
/* 5bits: type */
- *urls = style->uncommon->cursor;
+ *urls = style->i.uncommon->cursor;
return bits;
}
@@ -351,8 +351,8 @@ static inline uint8_t get_clip(
const css_computed_style *style,
css_computed_clip_rect *rect)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[CLIP_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[CLIP_INDEX];
bits &= CLIP_MASK;
bits >>= CLIP_SHIFT;
@@ -368,33 +368,33 @@ static inline uint8_t get_clip(
if (rect->top_auto == false ||
rect->right_auto == false) {
/* 8bits: ttttrrrr : top | right */
- bits1 = style->uncommon->bits[CLIP_INDEX1];
+ bits1 = style->i.uncommon->i.bits[CLIP_INDEX1];
bits1 &= CLIP_MASK1;
bits1 >>= CLIP_SHIFT1;
} else {
bits1 = 0;
}
- rect->top = style->uncommon->clip[0];
+ rect->top = style->i.uncommon->i.clip[0];
rect->tunit = bits1 >> 4;
- rect->right = style->uncommon->clip[1];
+ rect->right = style->i.uncommon->i.clip[1];
rect->runit = bits1 & 0xf;
if (rect->bottom_auto == false ||
rect->left_auto == false) {
/* 8bits: bbbbllll : bottom | left */
- bits1 = style->uncommon->bits[CLIP_INDEX2];
+ bits1 = style->i.uncommon->i.bits[CLIP_INDEX2];
bits1 &= CLIP_MASK2;
bits1 >>= CLIP_SHIFT2;
} else {
bits1 = 0;
}
- rect->bottom = style->uncommon->clip[2];
+ rect->bottom = style->i.uncommon->i.clip[2];
rect->bunit = bits1 >> 4;
- rect->left = style->uncommon->clip[3];
+ rect->left = style->i.uncommon->i.clip[3];
rect->lunit = bits1 & 0xf;
}
@@ -420,13 +420,13 @@ static inline uint8_t get_clip(
static inline uint8_t get_column_count(
const css_computed_style *style, int32_t *count)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_COUNT_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_COUNT_INDEX];
bits &= COLUMN_COUNT_MASK;
bits >>= COLUMN_COUNT_SHIFT;
/* 2bits: tt : type */
- *count = style->uncommon->column_count;
+ *count = style->i.uncommon->i.column_count;
return bits;
}
@@ -444,8 +444,8 @@ static inline uint8_t get_column_count(
static inline uint8_t get_column_fill(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_FILL_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_FILL_INDEX];
bits &= COLUMN_FILL_MASK;
bits >>= COLUMN_FILL_SHIFT;
@@ -467,14 +467,14 @@ static inline uint8_t get_column_gap(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_GAP_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_GAP_INDEX];
bits &= COLUMN_GAP_MASK;
bits >>= COLUMN_GAP_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_COLUMN_GAP_SET) {
- *length = style->uncommon->column_gap;
+ *length = style->i.uncommon->i.column_gap;
*unit = bits >> 2;
}
@@ -495,13 +495,13 @@ static inline uint8_t get_column_rule_color(
const css_computed_style *style,
css_color *color)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_RULE_COLOR_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_RULE_COLOR_INDEX];
bits &= COLUMN_RULE_COLOR_MASK;
bits >>= COLUMN_RULE_COLOR_SHIFT;
/* 2bits: type */
- *color = style->uncommon->column_rule_color;
+ *color = style->i.uncommon->i.column_rule_color;
return bits;
}
@@ -520,8 +520,8 @@ static inline uint8_t get_column_rule_color(
static inline uint8_t get_column_rule_style(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_RULE_STYLE_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_RULE_STYLE_INDEX];
bits &= COLUMN_RULE_STYLE_MASK;
bits >>= COLUMN_RULE_STYLE_SHIFT;
@@ -543,14 +543,14 @@ static inline uint8_t get_column_rule_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_RULE_WIDTH_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_RULE_WIDTH_INDEX];
bits &= COLUMN_RULE_WIDTH_MASK;
bits >>= COLUMN_RULE_WIDTH_SHIFT;
/* 7bits: uuuuttt : units | type */
if ((bits & 0x7) == CSS_COLUMN_RULE_WIDTH_WIDTH) {
- *length = style->uncommon->column_rule_width;
+ *length = style->i.uncommon->i.column_rule_width;
*unit = bits >> 3;
}
@@ -570,8 +570,8 @@ static inline uint8_t get_column_rule_width(
static inline uint8_t get_column_span(
const css_computed_style *style)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_SPAN_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_SPAN_INDEX];
bits &= COLUMN_SPAN_MASK;
bits >>= COLUMN_SPAN_SHIFT;
@@ -593,14 +593,14 @@ static inline uint8_t get_column_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[COLUMN_WIDTH_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[COLUMN_WIDTH_INDEX];
bits &= COLUMN_WIDTH_MASK;
bits >>= COLUMN_WIDTH_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_COLUMN_WIDTH_SET) {
- *length = style->uncommon->column_width;
+ *length = style->i.uncommon->i.column_width;
*unit = bits >> 2;
}
@@ -621,13 +621,13 @@ static inline uint8_t get_content(
const css_computed_style *style,
const css_computed_content_item **content)
{
- if (style->uncommon != NULL) {
- uint8_t bits = style->uncommon->bits[CONTENT_INDEX];
+ if (style->i.uncommon != NULL) {
+ uint8_t bits = style->i.uncommon->i.bits[CONTENT_INDEX];
bits &= CONTENT_MASK;
bits >>= CONTENT_SHIFT;
/* 2bits: type */
- *content = style->uncommon->content;
+ *content = style->i.uncommon->content;
return bits;
}
@@ -646,13 +646,13 @@ static inline uint8_t get_vertical_align(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[VERTICAL_ALIGN_INDEX];
+ uint8_t bits = style->i.bits[VERTICAL_ALIGN_INDEX];
bits &= VERTICAL_ALIGN_MASK;
bits >>= VERTICAL_ALIGN_SHIFT;
/* 8bits: uuuutttt : units | type */
if ((bits & 0xf) == CSS_VERTICAL_ALIGN_SET) {
- *length = style->vertical_align;
+ *length = style->i.vertical_align;
*unit = bits >> 4;
}
@@ -669,13 +669,13 @@ static inline uint8_t get_font_size(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[FONT_SIZE_INDEX];
+ uint8_t bits = style->i.bits[FONT_SIZE_INDEX];
bits &= FONT_SIZE_MASK;
bits >>= FONT_SIZE_SHIFT;
/* 8bits: uuuutttt : units | type */
if ((bits & 0xf) == CSS_FONT_SIZE_DIMENSION) {
- *length = style->font_size;
+ *length = style->i.font_size;
*unit = bits >> 4;
}
@@ -692,13 +692,13 @@ static inline uint8_t get_border_top_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[BORDER_TOP_WIDTH_INDEX];
+ uint8_t bits = style->i.bits[BORDER_TOP_WIDTH_INDEX];
bits &= BORDER_TOP_WIDTH_MASK;
bits >>= BORDER_TOP_WIDTH_SHIFT;
/* 7bits: uuuuttt : units | type */
if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) {
- *length = style->border_width[0];
+ *length = style->i.border_width[0];
*unit = bits >> 3;
}
@@ -715,13 +715,13 @@ static inline uint8_t get_border_right_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[BORDER_RIGHT_WIDTH_INDEX];
+ uint8_t bits = style->i.bits[BORDER_RIGHT_WIDTH_INDEX];
bits &= BORDER_RIGHT_WIDTH_MASK;
bits >>= BORDER_RIGHT_WIDTH_SHIFT;
/* 7bits: uuuuttt : units | type */
if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) {
- *length = style->border_width[1];
+ *length = style->i.border_width[1];
*unit = bits >> 3;
}
@@ -738,13 +738,13 @@ static inline uint8_t get_border_bottom_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[BORDER_BOTTOM_WIDTH_INDEX];
+ uint8_t bits = style->i.bits[BORDER_BOTTOM_WIDTH_INDEX];
bits &= BORDER_BOTTOM_WIDTH_MASK;
bits >>= BORDER_BOTTOM_WIDTH_SHIFT;
/* 7bits: uuuuttt : units | type */
if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) {
- *length = style->border_width[2];
+ *length = style->i.border_width[2];
*unit = bits >> 3;
}
@@ -761,13 +761,13 @@ static inline uint8_t get_border_left_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[BORDER_LEFT_WIDTH_INDEX];
+ uint8_t bits = style->i.bits[BORDER_LEFT_WIDTH_INDEX];
bits &= BORDER_LEFT_WIDTH_MASK;
bits >>= BORDER_LEFT_WIDTH_SHIFT;
/* 7bits: uuuuttt : units | type */
if ((bits & 0x7) == CSS_BORDER_WIDTH_WIDTH) {
- *length = style->border_width[3];
+ *length = style->i.border_width[3];
*unit = bits >> 3;
}
@@ -784,12 +784,12 @@ static inline uint8_t get_background_image(
const css_computed_style *style,
lwc_string **url)
{
- uint8_t bits = style->bits[BACKGROUND_IMAGE_INDEX];
+ uint8_t bits = style->i.bits[BACKGROUND_IMAGE_INDEX];
bits &= BACKGROUND_IMAGE_MASK;
bits >>= BACKGROUND_IMAGE_SHIFT;
/* 1bit: type */
- *url = style->background_image;
+ *url = style->i.background_image;
return bits;
}
@@ -804,12 +804,12 @@ static inline uint8_t get_color(
const css_computed_style *style,
css_color *color)
{
- uint8_t bits = style->bits[COLOR_INDEX];
+ uint8_t bits = style->i.bits[COLOR_INDEX];
bits &= COLOR_MASK;
bits >>= COLOR_SHIFT;
/* 1bit: type */
- *color = style->color;
+ *color = style->i.color;
return bits;
}
@@ -824,12 +824,12 @@ static inline uint8_t get_list_style_image(
const css_computed_style *style,
lwc_string **url)
{
- uint8_t bits = style->bits[LIST_STYLE_IMAGE_INDEX];
+ uint8_t bits = style->i.bits[LIST_STYLE_IMAGE_INDEX];
bits &= LIST_STYLE_IMAGE_MASK;
bits >>= LIST_STYLE_IMAGE_SHIFT;
/* 1bit: type */
- *url = style->list_style_image;
+ *url = style->i.list_style_image;
return bits;
}
@@ -844,7 +844,7 @@ static inline uint8_t get_quotes(
const css_computed_style *style,
lwc_string ***quotes)
{
- uint8_t bits = style->bits[QUOTES_INDEX];
+ uint8_t bits = style->i.bits[QUOTES_INDEX];
bits &= QUOTES_MASK;
bits >>= QUOTES_SHIFT;
@@ -864,13 +864,13 @@ static inline uint8_t get_top(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[TOP_INDEX];
+ uint8_t bits = style->i.bits[TOP_INDEX];
bits &= TOP_MASK;
bits >>= TOP_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_TOP_SET) {
- *length = style->top;
+ *length = style->i.top;
*unit = bits >> 2;
}
@@ -879,7 +879,7 @@ static inline uint8_t get_top(
static inline uint8_t get_top_bits(
const css_computed_style *style)
{
- uint8_t bits = style->bits[TOP_INDEX];
+ uint8_t bits = style->i.bits[TOP_INDEX];
bits &= TOP_MASK;
bits >>= TOP_SHIFT;
@@ -897,13 +897,13 @@ static inline uint8_t get_right(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[RIGHT_INDEX];
+ uint8_t bits = style->i.bits[RIGHT_INDEX];
bits &= RIGHT_MASK;
bits >>= RIGHT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_RIGHT_SET) {
- *length = style->right;
+ *length = style->i.right;
*unit = bits >> 2;
}
@@ -912,7 +912,7 @@ static inline uint8_t get_right(
static inline uint8_t get_right_bits(
const css_computed_style *style)
{
- uint8_t bits = style->bits[RIGHT_INDEX];
+ uint8_t bits = style->i.bits[RIGHT_INDEX];
bits &= RIGHT_MASK;
bits >>= RIGHT_SHIFT;
@@ -930,13 +930,13 @@ static inline uint8_t get_bottom(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[BOTTOM_INDEX];
+ uint8_t bits = style->i.bits[BOTTOM_INDEX];
bits &= BOTTOM_MASK;
bits >>= BOTTOM_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_BOTTOM_SET) {
- *length = style->bottom;
+ *length = style->i.bottom;
*unit = bits >> 2;
}
@@ -945,7 +945,7 @@ static inline uint8_t get_bottom(
static inline uint8_t get_bottom_bits(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BOTTOM_INDEX];
+ uint8_t bits = style->i.bits[BOTTOM_INDEX];
bits &= BOTTOM_MASK;
bits >>= BOTTOM_SHIFT;
@@ -963,13 +963,13 @@ static inline uint8_t get_left(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[LEFT_INDEX];
+ uint8_t bits = style->i.bits[LEFT_INDEX];
bits &= LEFT_MASK;
bits >>= LEFT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_LEFT_SET) {
- *length = style->left;
+ *length = style->i.left;
*unit = bits >> 2;
}
@@ -978,7 +978,7 @@ static inline uint8_t get_left(
static inline uint8_t get_left_bits(
const css_computed_style *style)
{
- uint8_t bits = style->bits[LEFT_INDEX];
+ uint8_t bits = style->i.bits[LEFT_INDEX];
bits &= LEFT_MASK;
bits >>= LEFT_SHIFT;
@@ -996,12 +996,12 @@ static inline uint8_t get_border_top_color(
const css_computed_style *style,
css_color *color)
{
- uint8_t bits = style->bits[BORDER_TOP_COLOR_INDEX];
+ uint8_t bits = style->i.bits[BORDER_TOP_COLOR_INDEX];
bits &= BORDER_TOP_COLOR_MASK;
bits >>= BORDER_TOP_COLOR_SHIFT;
/* 2bits: type */
- *color = style->border_color[0];
+ *color = style->i.border_color[0];
return bits;
}
@@ -1016,12 +1016,12 @@ static inline uint8_t get_border_right_color(
const css_computed_style *style,
css_color *color)
{
- uint8_t bits = style->bits[BORDER_RIGHT_COLOR_INDEX];
+ uint8_t bits = style->i.bits[BORDER_RIGHT_COLOR_INDEX];
bits &= BORDER_RIGHT_COLOR_MASK;
bits >>= BORDER_RIGHT_COLOR_SHIFT;
/* 2bits: type */
- *color = style->border_color[1];
+ *color = style->i.border_color[1];
return bits;
}
@@ -1036,12 +1036,12 @@ static inline uint8_t get_border_bottom_color(
const css_computed_style *style,
css_color *color)
{
- uint8_t bits = style->bits[BORDER_BOTTOM_COLOR_INDEX];
+ uint8_t bits = style->i.bits[BORDER_BOTTOM_COLOR_INDEX];
bits &= BORDER_BOTTOM_COLOR_MASK;
bits >>= BORDER_BOTTOM_COLOR_SHIFT;
/* 2bits: type */
- *color = style->border_color[2];
+ *color = style->i.border_color[2];
return bits;
}
@@ -1056,12 +1056,12 @@ static inline uint8_t get_border_left_color(
const css_computed_style *style,
css_color *color)
{
- uint8_t bits = style->bits[BORDER_LEFT_COLOR_INDEX];
+ uint8_t bits = style->i.bits[BORDER_LEFT_COLOR_INDEX];
bits &= BORDER_LEFT_COLOR_MASK;
bits >>= BORDER_LEFT_COLOR_SHIFT;
/* 2bits: type */
- *color = style->border_color[3];
+ *color = style->i.border_color[3];
return bits;
}
@@ -1076,13 +1076,13 @@ static inline uint8_t get_height(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[HEIGHT_INDEX];
+ uint8_t bits = style->i.bits[HEIGHT_INDEX];
bits &= HEIGHT_MASK;
bits >>= HEIGHT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_HEIGHT_SET) {
- *length = style->height;
+ *length = style->i.height;
*unit = bits >> 2;
}
@@ -1099,14 +1099,14 @@ static inline uint8_t get_line_height(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[LINE_HEIGHT_INDEX];
+ uint8_t bits = style->i.bits[LINE_HEIGHT_INDEX];
bits &= LINE_HEIGHT_MASK;
bits >>= LINE_HEIGHT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_LINE_HEIGHT_NUMBER ||
(bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) {
- *length = style->line_height;
+ *length = style->i.line_height;
}
if ((bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) {
@@ -1126,12 +1126,12 @@ static inline uint8_t get_background_color(
const css_computed_style *style,
css_color *color)
{
- uint8_t bits = style->bits[BACKGROUND_COLOR_INDEX];
+ uint8_t bits = style->i.bits[BACKGROUND_COLOR_INDEX];
bits &= BACKGROUND_COLOR_MASK;
bits >>= BACKGROUND_COLOR_SHIFT;
/* 2bits: type */
- *color = style->background_color;
+ *color = style->i.background_color;
return bits;
}
@@ -1146,12 +1146,12 @@ static inline uint8_t get_z_index(
const css_computed_style *style,
int32_t *z_index)
{
- uint8_t bits = style->bits[Z_INDEX_INDEX];
+ uint8_t bits = style->i.bits[Z_INDEX_INDEX];
bits &= Z_INDEX_MASK;
bits >>= Z_INDEX_SHIFT;
/* 2bits: type */
- *z_index = style->z_index;
+ *z_index = style->i.z_index;
return bits;
}
@@ -1166,13 +1166,13 @@ static inline uint8_t get_margin_top(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MARGIN_TOP_INDEX];
+ uint8_t bits = style->i.bits[MARGIN_TOP_INDEX];
bits &= MARGIN_TOP_MASK;
bits >>= MARGIN_TOP_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_MARGIN_SET) {
- *length = style->margin[0];
+ *length = style->i.margin[0];
*unit = bits >> 2;
}
@@ -1189,13 +1189,13 @@ static inline uint8_t get_margin_right(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MARGIN_RIGHT_INDEX];
+ uint8_t bits = style->i.bits[MARGIN_RIGHT_INDEX];
bits &= MARGIN_RIGHT_MASK;
bits >>= MARGIN_RIGHT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_MARGIN_SET) {
- *length = style->margin[1];
+ *length = style->i.margin[1];
*unit = bits >> 2;
}
@@ -1212,13 +1212,13 @@ static inline uint8_t get_margin_bottom(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MARGIN_BOTTOM_INDEX];
+ uint8_t bits = style->i.bits[MARGIN_BOTTOM_INDEX];
bits &= MARGIN_BOTTOM_MASK;
bits >>= MARGIN_BOTTOM_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_MARGIN_SET) {
- *length = style->margin[2];
+ *length = style->i.margin[2];
*unit = bits >> 2;
}
@@ -1235,13 +1235,13 @@ static inline uint8_t get_margin_left(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MARGIN_LEFT_INDEX];
+ uint8_t bits = style->i.bits[MARGIN_LEFT_INDEX];
bits &= MARGIN_LEFT_MASK;
bits >>= MARGIN_LEFT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_MARGIN_SET) {
- *length = style->margin[3];
+ *length = style->i.margin[3];
*unit = bits >> 2;
}
@@ -1257,7 +1257,7 @@ static inline uint8_t get_margin_left(
static inline uint8_t get_background_attachment(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BACKGROUND_ATTACHMENT_INDEX];
+ uint8_t bits = style->i.bits[BACKGROUND_ATTACHMENT_INDEX];
bits &= BACKGROUND_ATTACHMENT_MASK;
bits >>= BACKGROUND_ATTACHMENT_SHIFT;
@@ -1274,7 +1274,7 @@ static inline uint8_t get_background_attachment(
static inline uint8_t get_border_collapse(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BORDER_COLLAPSE_INDEX];
+ uint8_t bits = style->i.bits[BORDER_COLLAPSE_INDEX];
bits &= BORDER_COLLAPSE_MASK;
bits >>= BORDER_COLLAPSE_SHIFT;
@@ -1291,7 +1291,7 @@ static inline uint8_t get_border_collapse(
static inline uint8_t get_caption_side(
const css_computed_style *style)
{
- uint8_t bits = style->bits[CAPTION_SIDE_INDEX];
+ uint8_t bits = style->i.bits[CAPTION_SIDE_INDEX];
bits &= CAPTION_SIDE_MASK;
bits >>= CAPTION_SIDE_SHIFT;
@@ -1308,7 +1308,7 @@ static inline uint8_t get_caption_side(
static inline uint8_t get_direction(
const css_computed_style *style)
{
- uint8_t bits = style->bits[DIRECTION_INDEX];
+ uint8_t bits = style->i.bits[DIRECTION_INDEX];
bits &= DIRECTION_MASK;
bits >>= DIRECTION_SHIFT;
@@ -1326,13 +1326,13 @@ static inline uint8_t get_max_height(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MAX_HEIGHT_INDEX];
+ uint8_t bits = style->i.bits[MAX_HEIGHT_INDEX];
bits &= MAX_HEIGHT_MASK;
bits >>= MAX_HEIGHT_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_MAX_HEIGHT_SET) {
- *length = style->max_height;
+ *length = style->i.max_height;
*unit = bits >> 2;
}
@@ -1349,13 +1349,13 @@ static inline uint8_t get_max_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MAX_WIDTH_INDEX];
+ uint8_t bits = style->i.bits[MAX_WIDTH_INDEX];
bits &= MAX_WIDTH_MASK;
bits >>= MAX_WIDTH_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_MAX_WIDTH_SET) {
- *length = style->max_width;
+ *length = style->i.max_width;
*unit = bits >> 2;
}
@@ -1372,13 +1372,13 @@ static inline uint8_t get_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[WIDTH_INDEX];
+ uint8_t bits = style->i.bits[WIDTH_INDEX];
bits &= WIDTH_MASK;
bits >>= WIDTH_SHIFT;
/* 6bits: uuuutt : units | type */
if ((bits & 0x3) == CSS_WIDTH_SET) {
- *length = style->width;
+ *length = style->i.width;
*unit = bits >> 2;
}
@@ -1394,7 +1394,7 @@ static inline uint8_t get_width(
static inline uint8_t get_empty_cells(
const css_computed_style *style)
{
- uint8_t bits = style->bits[EMPTY_CELLS_INDEX];
+ uint8_t bits = style->i.bits[EMPTY_CELLS_INDEX];
bits &= EMPTY_CELLS_MASK;
bits >>= EMPTY_CELLS_SHIFT;
@@ -1411,7 +1411,7 @@ static inline uint8_t get_empty_cells(
static inline uint8_t get_float(
const css_computed_style *style)
{
- uint8_t bits = style->bits[FLOAT_INDEX];
+ uint8_t bits = style->i.bits[FLOAT_INDEX];
bits &= FLOAT_MASK;
bits >>= FLOAT_SHIFT;
@@ -1428,7 +1428,7 @@ static inline uint8_t get_float(
static inline uint8_t get_font_style(
const css_computed_style *style)
{
- uint8_t bits = style->bits[FONT_STYLE_INDEX];
+ uint8_t bits = style->i.bits[FONT_STYLE_INDEX];
bits &= FONT_STYLE_MASK;
bits >>= FONT_STYLE_SHIFT;
@@ -1446,13 +1446,13 @@ static inline uint8_t get_min_height(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MIN_HEIGHT_INDEX];
+ uint8_t bits = style->i.bits[MIN_HEIGHT_INDEX];
bits &= MIN_HEIGHT_MASK;
bits >>= MIN_HEIGHT_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_MIN_HEIGHT_SET) {
- *length = style->min_height;
+ *length = style->i.min_height;
*unit = bits >> 1;
}
@@ -1469,13 +1469,13 @@ static inline uint8_t get_min_width(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[MIN_WIDTH_INDEX];
+ uint8_t bits = style->i.bits[MIN_WIDTH_INDEX];
bits &= MIN_WIDTH_MASK;
bits >>= MIN_WIDTH_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_MIN_WIDTH_SET) {
- *length = style->min_width;
+ *length = style->i.min_width;
*unit = bits >> 1;
}
@@ -1491,7 +1491,7 @@ static inline uint8_t get_min_width(
static inline uint8_t get_background_repeat(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BACKGROUND_REPEAT_INDEX];
+ uint8_t bits = style->i.bits[BACKGROUND_REPEAT_INDEX];
bits &= BACKGROUND_REPEAT_MASK;
bits >>= BACKGROUND_REPEAT_SHIFT;
@@ -1508,7 +1508,7 @@ static inline uint8_t get_background_repeat(
static inline uint8_t get_clear(
const css_computed_style *style)
{
- uint8_t bits = style->bits[CLEAR_INDEX];
+ uint8_t bits = style->i.bits[CLEAR_INDEX];
bits &= CLEAR_MASK;
bits >>= CLEAR_SHIFT;
@@ -1526,13 +1526,13 @@ static inline uint8_t get_padding_top(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[PADDING_TOP_INDEX];
+ uint8_t bits = style->i.bits[PADDING_TOP_INDEX];
bits &= PADDING_TOP_MASK;
bits >>= PADDING_TOP_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_PADDING_SET) {
- *length = style->padding[0];
+ *length = style->i.padding[0];
*unit = bits >> 1;
}
@@ -1549,13 +1549,13 @@ static inline uint8_t get_padding_right(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[PADDING_RIGHT_INDEX];
+ uint8_t bits = style->i.bits[PADDING_RIGHT_INDEX];
bits &= PADDING_RIGHT_MASK;
bits >>= PADDING_RIGHT_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_PADDING_SET) {
- *length = style->padding[1];
+ *length = style->i.padding[1];
*unit = bits >> 1;
}
@@ -1572,13 +1572,13 @@ static inline uint8_t get_padding_bottom(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[PADDING_BOTTOM_INDEX];
+ uint8_t bits = style->i.bits[PADDING_BOTTOM_INDEX];
bits &= PADDING_BOTTOM_MASK;
bits >>= PADDING_BOTTOM_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_PADDING_SET) {
- *length = style->padding[2];
+ *length = style->i.padding[2];
*unit = bits >> 1;
}
@@ -1595,13 +1595,13 @@ static inline uint8_t get_padding_left(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[PADDING_LEFT_INDEX];
+ uint8_t bits = style->i.bits[PADDING_LEFT_INDEX];
bits &= PADDING_LEFT_MASK;
bits >>= PADDING_LEFT_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_PADDING_SET) {
- *length = style->padding[3];
+ *length = style->i.padding[3];
*unit = bits >> 1;
}
@@ -1617,7 +1617,7 @@ static inline uint8_t get_padding_left(
static inline uint8_t get_overflow_x(
const css_computed_style *style)
{
- uint8_t bits = style->bits[OVERFLOW_X_INDEX];
+ uint8_t bits = style->i.bits[OVERFLOW_X_INDEX];
bits &= OVERFLOW_X_MASK;
bits >>= OVERFLOW_X_SHIFT;
@@ -1634,7 +1634,7 @@ static inline uint8_t get_overflow_x(
static inline uint8_t get_overflow_y(
const css_computed_style *style)
{
- uint8_t bits = style->bits[OVERFLOW_Y_INDEX];
+ uint8_t bits = style->i.bits[OVERFLOW_Y_INDEX];
bits &= OVERFLOW_Y_MASK;
bits >>= OVERFLOW_Y_SHIFT;
@@ -1651,7 +1651,7 @@ static inline uint8_t get_overflow_y(
static inline uint8_t get_position(
const css_computed_style *style)
{
- uint8_t bits = style->bits[POSITION_INDEX];
+ uint8_t bits = style->i.bits[POSITION_INDEX];
bits &= POSITION_MASK;
bits >>= POSITION_SHIFT;
@@ -1669,13 +1669,13 @@ static inline uint8_t get_opacity(
const css_computed_style *style,
css_fixed *opacity)
{
- uint8_t bits = style->bits[OPACITY_INDEX];
+ uint8_t bits = style->i.bits[OPACITY_INDEX];
bits &= OPACITY_MASK;
bits >>= OPACITY_SHIFT;
/* 1bit: t : type */
if ((bits & 0x1) == CSS_OPACITY_SET) {
- *opacity = style->opacity;
+ *opacity = style->i.opacity;
}
return (bits & 0x1);
@@ -1690,7 +1690,7 @@ static inline uint8_t get_opacity(
static inline uint8_t get_text_transform(
const css_computed_style *style)
{
- uint8_t bits = style->bits[TEXT_TRANSFORM_INDEX];
+ uint8_t bits = style->i.bits[TEXT_TRANSFORM_INDEX];
bits &= TEXT_TRANSFORM_MASK;
bits >>= TEXT_TRANSFORM_SHIFT;
@@ -1708,13 +1708,13 @@ static inline uint8_t get_text_indent(
const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
- uint8_t bits = style->bits[TEXT_INDENT_INDEX];
+ uint8_t bits = style->i.bits[TEXT_INDENT_INDEX];
bits &= TEXT_INDENT_MASK;
bits >>= TEXT_INDENT_SHIFT;
/* 5bits: uuuut : units | type */
if ((bits & 0x1) == CSS_TEXT_INDENT_SET) {
- *length = style->text_indent;
+ *length = style->i.text_indent;
*unit = bits >> 1;
}
@@ -1730,7 +1730,7 @@ static inline uint8_t get_text_indent(
static inline uint8_t get_white_space(
const css_computed_style *style)
{
- uint8_t bits = style->bits[WHITE_SPACE_INDEX];
+ uint8_t bits = style->i.bits[WHITE_SPACE_INDEX];
bits &= WHITE_SPACE_MASK;
bits >>= WHITE_SPACE_SHIFT;
@@ -1752,21 +1752,21 @@ static inline uint8_t get_background_position(
css_fixed *hlength, css_unit *hunit,
css_fixed *vlength, css_unit *vunit)
{
- uint8_t bits = style->bits[BACKGROUND_POSITION_INDEX];
+ uint8_t bits = style->i.bits[BACKGROUND_POSITION_INDEX];
bits &= BACKGROUND_POSITION_MASK;
bits >>= BACKGROUND_POSITION_SHIFT;
/* 1bit: type */
if (bits == CSS_BACKGROUND_POSITION_SET) {
- uint8_t bits1 = style->bits[BACKGROUND_POSITION_INDEX1];
+ uint8_t bits1 = style->i.bits[BACKGROUND_POSITION_INDEX1];
bits1 &= BACKGROUND_POSITION_MASK1;
bits1 >>= BACKGROUND_POSITION_SHIFT1;
/* 8bits: hhhhvvvv : hunit | vunit */
- *hlength = style->background_position[0];
+ *hlength = style->i.background_position[0];
*hunit = bits1 >> 4;
- *vlength = style->background_position[1];
+ *vlength = style->i.background_position[1];
*vunit = bits1 & 0xf;
}
@@ -1785,7 +1785,7 @@ static inline uint8_t get_background_position(
static inline uint8_t get_display(
const css_computed_style *style)
{
- uint8_t bits = style->bits[DISPLAY_INDEX];
+ uint8_t bits = style->i.bits[DISPLAY_INDEX];
bits &= DISPLAY_MASK;
bits >>= DISPLAY_SHIFT;
@@ -1802,7 +1802,7 @@ static inline uint8_t get_display(
static inline uint8_t get_font_variant(
const css_computed_style *style)
{
- uint8_t bits = style->bits[FONT_VARIANT_INDEX];
+ uint8_t bits = style->i.bits[FONT_VARIANT_INDEX];
bits &= FONT_VARIANT_MASK;
bits >>= FONT_VARIANT_SHIFT;
@@ -1819,7 +1819,7 @@ static inline uint8_t get_font_variant(
static inline uint8_t get_text_decoration(
const css_computed_style *style)
{
- uint8_t bits = style->bits[TEXT_DECORATION_INDEX];
+ uint8_t bits = style->i.bits[TEXT_DECORATION_INDEX];
bits &= TEXT_DECORATION_MASK;
bits >>= TEXT_DECORATION_SHIFT;
@@ -1837,7 +1837,7 @@ static inline uint8_t get_font_family(
const css_computed_style *style,
lwc_string ***names)
{
- uint8_t bits = style->bits[FONT_FAMILY_INDEX];
+ uint8_t bits = style->i.bits[FONT_FAMILY_INDEX];
bits &= FONT_FAMILY_MASK;
bits >>= FONT_FAMILY_SHIFT;
@@ -1856,7 +1856,7 @@ static inline uint8_t get_font_family(
static inline uint8_t get_border_top_style(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BORDER_TOP_STYLE_INDEX];
+ uint8_t bits = style->i.bits[BORDER_TOP_STYLE_INDEX];
bits &= BORDER_TOP_STYLE_MASK;
bits >>= BORDER_TOP_STYLE_SHIFT;
@@ -1873,7 +1873,7 @@ static inline uint8_t get_border_top_style(
static inline uint8_t get_border_right_style(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BORDER_RIGHT_STYLE_INDEX];
+ uint8_t bits = style->i.bits[BORDER_RIGHT_STYLE_INDEX];
bits &= BORDER_RIGHT_STYLE_MASK;
bits >>= BORDER_RIGHT_STYLE_SHIFT;
@@ -1890,7 +1890,7 @@ static inline uint8_t get_border_right_style(
static inline uint8_t get_border_bottom_style(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BORDER_BOTTOM_STYLE_INDEX];
+ uint8_t bits = style->i.bits[BORDER_BOTTOM_STYLE_INDEX];
bits &= BORDER_BOTTOM_STYLE_MASK;
bits >>= BORDER_BOTTOM_STYLE_SHIFT;
@@ -1907,7 +1907,7 @@ static inline uint8_t get_border_bottom_style(
static inline uint8_t get_border_left_style(
const css_computed_style *style)
{
- uint8_t bits = style->bits[BORDER_LEFT_STYLE_INDEX];
+ uint8_t bits = style->i.bits[BORDER_LEFT_STYLE_INDEX];
bits &= BORDER_LEFT_STYLE_MASK;
bits >>= BORDER_LEFT_STYLE_SHIFT;
@@ -1924,7 +1924,7 @@ static inline uint8_t get_border_left_style(
static inline uint8_t get_font_weight(
const css_computed_style *style)
{
- uint8_t bits = style->bits[FONT_WEIGHT_INDEX];
+ uint8_t bits = style->i.bits[FONT_WEIGHT_INDEX];
bits &= FONT_WEIGHT_MASK;
bits >>= FONT_WEIGHT_SHIFT;
@@ -1941,7 +1941,7 @@ static inline uint8_t get_font_weight(
static inline uint8_t get_list_style_type(
const css_computed_style *style)
{
- uint8_t bits = style->bits[LIST_STYLE_TYPE_INDEX];
+ uint8_t bits = style->i.bits[LIST_STYLE_TYPE_INDEX];
bits &= LIST_STYLE_TYPE_MASK;
bits >>= LIST_STYLE_TYPE_SHIFT;
@@ -1958,7 +1958,7 @@ static inline uint8_t get_list_style_type(
static inline uint8_t get_outline_style(
const css_computed_style *style)
{
- uint8_t bits = style->bits[OUTLINE_STYLE_INDEX];
+ uint8_t bits = style->i.bits[OUTLINE_STYLE_INDEX];
bits &= OUTLINE_STYLE_MASK;
bits >>= OUTLINE_STYLE_SHIFT;
@@ -1975,7 +1975,7 @@ static inline uint8_t get_outline_style(
static inline uint8_t get_table_layout(
const css_computed_style *style)
{
- uint8_t bits = style->bits[TABLE_LAYOUT_INDEX];
+ uint8_t bits = style->i.bits[TABLE_LAYOUT_INDEX];
bits &= TABLE_LAYOUT_MASK;
bits >>= TABLE_LAYOUT_SHIFT;
@@ -1992,7 +1992,7 @@ static inline uint8_t get_table_layout(
static inline uint8_t get_unicode_bidi(
const css_computed_style *style)
{
- uint8_t bits = style->bits[UNICODE_BIDI_INDEX];
+ uint8_t bits = style->i.bits[UNICODE_BIDI_INDEX];
bits &= UNICODE_BIDI_MASK;
bits >>= UNICODE_BIDI_SHIFT;
@@ -2009,7 +2009,7 @@ static inline uint8_t get_unicode_bidi(
static inline uint8_t get_visibility(
const css_computed_style *style)
{
- uint8_t bits = style->bits[VISIBILITY_INDEX];
+ uint8_t bits = style->i.bits[VISIBILITY_INDEX];
bits &= VISIBILITY_MASK;
bits >>= VISIBILITY_SHIFT;
@@ -2026,7 +2026,7 @@ static inline uint8_t get_visibility(
static inline uint8_t get_list_style_position(
const css_computed_style *style)
{
- uint8_t bits = style->bits[LIST_STYLE_POSITION_INDEX];
+ uint8_t bits = style->i.bits[LIST_STYLE_POSITION_INDEX];
bits &= LIST_STYLE_POSITION_MASK;
bits >>= LIST_STYLE_POSITION_SHIFT;
@@ -2043,7 +2043,7 @@ static inline uint8_t get_list_style_position(
static inline uint8_t get_text_align(
const css_computed_style *style)
{
- uint8_t bits = style->bits[TEXT_ALIGN_INDEX];
+ uint8_t bits = style->i.bits[TEXT_ALIGN_INDEX];
bits &= TEXT_ALIGN_MASK;
bits >>= TEXT_ALIGN_SHIFT;
diff --git a/src/select/propset.h b/src/select/propset.h
index 928b9e3..76e4fe6 100644
--- a/src/select/propset.h
+++ b/src/select/propset.h
@@ -19,54 +19,60 @@
/** Default values are 'initial value', unless the property is inherited,
* in which case it is 'inherit'. */
static const css_computed_uncommon default_uncommon = {
- .bits = {
- (CSS_LETTER_SPACING_INHERIT << 2) |
- CSS_OUTLINE_COLOR_INVERT,
- (CSS_OUTLINE_WIDTH_MEDIUM << 1) |
- CSS_BORDER_SPACING_INHERIT,
- 0,
- (CSS_WORD_SPACING_INHERIT << 2) |
- (CSS_COUNTER_INCREMENT_NONE << 1) |
- CSS_COUNTER_RESET_NONE,
- (CSS_CURSOR_INHERIT << 3) |
- (CSS_WRITING_MODE_INHERIT << 1),
- 0,
- 0,
- (CSS_CLIP_AUTO << 2) | CSS_CONTENT_NORMAL,
- (CSS_COLUMN_COUNT_AUTO << 6) |
- (CSS_COLUMN_FILL_BALANCE << 4) |
- (CSS_COLUMN_RULE_STYLE_NONE << 0),
- (CSS_COLUMN_GAP_NORMAL << 2) |
- (CSS_COLUMN_RULE_COLOR_CURRENT_COLOR),
- (CSS_COLUMN_RULE_WIDTH_MEDIUM << 1),
- (CSS_COLUMN_SPAN_NONE << 6) | CSS_COLUMN_WIDTH_AUTO,
- (CSS_BREAK_BEFORE_AUTO << 4) | CSS_BREAK_AFTER_AUTO,
- (CSS_BREAK_INSIDE_AUTO)
+ .i = {
+ .bits = {
+ (CSS_LETTER_SPACING_INHERIT << 2) |
+ CSS_OUTLINE_COLOR_INVERT,
+ (CSS_OUTLINE_WIDTH_MEDIUM << 1) |
+ CSS_BORDER_SPACING_INHERIT,
+ 0,
+ (CSS_WORD_SPACING_INHERIT << 2) |
+ (CSS_COUNTER_INCREMENT_NONE << 1) |
+ CSS_COUNTER_RESET_NONE,
+ (CSS_CURSOR_INHERIT << 3) |
+ (CSS_WRITING_MODE_INHERIT << 1),
+ 0,
+ 0,
+ (CSS_CLIP_AUTO << 2) | CSS_CONTENT_NORMAL,
+ (CSS_COLUMN_COUNT_AUTO << 6) |
+ (CSS_COLUMN_FILL_BALANCE << 4) |
+ (CSS_COLUMN_RULE_STYLE_NONE << 0),
+ (CSS_COLUMN_GAP_NORMAL << 2) |
+ (CSS_COLUMN_RULE_COLOR_CURRENT_COLOR),
+ (CSS_COLUMN_RULE_WIDTH_MEDIUM << 1),
+ (CSS_COLUMN_SPAN_NONE << 6) | CSS_COLUMN_WIDTH_AUTO,
+ (CSS_BREAK_BEFORE_AUTO << 4) | CSS_BREAK_AFTER_AUTO,
+ (CSS_BREAK_INSIDE_AUTO)
+ },
+ .border_spacing = { 0, 0 },
+ .clip = { 0, 0, 0, 0 },
+ .letter_spacing = 0,
+ .outline_color = 0x0,
+ .outline_width = 0,
+ .word_spacing = 0,
+ .column_count = 0,
+ .column_gap = 0,
+ .column_rule_color = 0,
+ .column_rule_width = 0,
+ .column_width = 0
},
- .border_spacing = { 0, 0 },
- .clip = { 0, 0, 0, 0 },
- .letter_spacing = 0,
- .outline_color = 0x0,
- .outline_width = 0,
- .word_spacing = 0,
- .column_count = 0,
- .column_gap = 0,
- .column_rule_color = 0,
- .column_rule_width = 0,
- .column_width = 0,
.counter_increment = NULL,
.counter_reset = NULL,
.content = NULL,
- .cursor = NULL
+ .cursor = NULL,
+ .next = NULL,
+ .count = 0,
+ .bin = UINT32_MAX
};
#define ENSURE_UNCOMMON do { \
- if (style->uncommon == NULL) { \
- style->uncommon = malloc(sizeof(css_computed_uncommon));\
- if (style->uncommon == NULL) \
+ if (style->i.uncommon == NULL) { \
+ style->i.uncommon = malloc( \
+ sizeof(css_computed_uncommon)); \
+ if (style->i.uncommon == NULL) \
return CSS_NOMEM; \
\
- memcpy(style->uncommon, &default_uncommon, \
+ memcpy(style->i.uncommon, &default_uncommon, \
sizeof(css_computed_uncommon)); \
} \
} while(0)
@@ -105,13 +111,13 @@ static inline css_error set_letter_spacing(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[LETTER_SPACING_INDEX];
+ bits = &style->i.uncommon->i.bits[LETTER_SPACING_INDEX];
/* 6bits: uuuutt : unit | type */
*bits = (*bits & ~LETTER_SPACING_MASK) |
(((type & 0x3) | unit << 2) << LETTER_SPACING_SHIFT);
- style->uncommon->letter_spacing = length;
+ style->i.uncommon->i.letter_spacing = length;
return CSS_OK;
}
@@ -129,13 +135,13 @@ static inline css_error set_outline_color(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[OUTLINE_COLOR_INDEX];
+ bits = &style->i.uncommon->i.bits[OUTLINE_COLOR_INDEX];
/* 2bits: tt : type */
*bits = (*bits & ~OUTLINE_COLOR_MASK) |
((type & 0x3) << OUTLINE_COLOR_SHIFT);
- style->uncommon->outline_color = color;
+ style->i.uncommon->i.outline_color = color;
return CSS_OK;
}
@@ -154,13 +160,13 @@ static inline css_error set_outline_width(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[OUTLINE_WIDTH_INDEX];
+ bits = &style->i.uncommon->i.bits[OUTLINE_WIDTH_INDEX];
/* 7bits: uuuuttt : unit | type */
*bits = (*bits & ~OUTLINE_WIDTH_MASK) |
(((type & 0x7) | (unit << 3)) << OUTLINE_WIDTH_SHIFT);
- style->uncommon->outline_width = length;
+ style->i.uncommon->i.outline_width = length;
return CSS_OK;
}
@@ -182,20 +188,20 @@ static inline css_error set_border_spacing(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[BORDER_SPACING_INDEX];
+ bits = &style->i.uncommon->i.bits[BORDER_SPACING_INDEX];
/* 1 bit: type */
*bits = (*bits & ~BORDER_SPACING_MASK) |
((type & 0x1) << BORDER_SPACING_SHIFT);
- bits = &style->uncommon->bits[BORDER_SPACING_INDEX1];
+ bits = &style->i.uncommon->i.bits[BORDER_SPACING_INDEX1];
/* 8bits: hhhhvvvv : hunit | vunit */
*bits = (((hunit << 4) | vunit) << BORDER_SPACING_SHIFT1);
- style->uncommon->border_spacing[0] = hlength;
- style->uncommon->border_spacing[1] = vlength;
+ style->i.uncommon->i.border_spacing[0] = hlength;
+ style->i.uncommon->i.border_spacing[1] = vlength;
return CSS_OK;
}
@@ -215,7 +221,7 @@ static inline css_error set_break_after(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[BREAK_AFTER_INDEX];
+ bits = &style->i.uncommon->i.bits[BREAK_AFTER_INDEX];
/* 4bits: type */
*bits = (*bits & ~BREAK_AFTER_MASK) |
@@ -237,7 +243,7 @@ static inline css_error set_break_before(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[BREAK_BEFORE_INDEX];
+ bits = &style->i.uncommon->i.bits[BREAK_BEFORE_INDEX];
/* 4bits: type */
*bits = (*bits & ~BREAK_BEFORE_MASK) |
@@ -259,7 +265,7 @@ static inline css_error set_break_inside(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[BREAK_INSIDE_INDEX];
+ bits = &style->i.uncommon->i.bits[BREAK_INSIDE_INDEX];
/* 4bits: type */
*bits = (*bits & ~BREAK_INSIDE_MASK) |
@@ -282,13 +288,13 @@ static inline css_error set_word_spacing(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[WORD_SPACING_INDEX];
+ bits = &style->i.uncommon->i.bits[WORD_SPACING_INDEX];
/* 6bits: uuuutt : unit | type */
*bits = (*bits & ~WORD_SPACING_MASK) |
(((type & 0x3) | (unit << 2)) << WORD_SPACING_SHIFT);
- style->uncommon->word_spacing = length;
+ style->i.uncommon->i.word_spacing = length;
return CSS_OK;
}
@@ -306,7 +312,7 @@ static inline css_error set_writing_mode(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[WRITING_MODE_INDEX];
+ bits = &style->i.uncommon->i.bits[WRITING_MODE_INDEX];
/* 2bits: type */
*bits = (*bits & ~WRITING_MODE_MASK) |
@@ -331,8 +337,8 @@ static inline css_error set_counter_increment(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COUNTER_INCREMENT_INDEX];
- oldcounters = style->uncommon->counter_increment;
+ bits = &style->i.uncommon->i.bits[COUNTER_INCREMENT_INDEX];
+ oldcounters = style->i.uncommon->counter_increment;
/* 1bit: type */
*bits = (*bits & ~COUNTER_INCREMENT_MASK) |
@@ -341,7 +347,7 @@ static inline css_error set_counter_increment(
for (c = counters; c != NULL && c->name != NULL; c++)
c->name = lwc_string_ref(c->name);
- style->uncommon->counter_increment = counters;
+ style->i.uncommon->counter_increment = counters;
/* Free existing array */
if (oldcounters != NULL) {
@@ -371,8 +377,8 @@ static inline css_error set_counter_reset(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COUNTER_RESET_INDEX];
- oldcounters = style->uncommon->counter_reset;
+ bits = &style->i.uncommon->i.bits[COUNTER_RESET_INDEX];
+ oldcounters = style->i.uncommon->counter_reset;
/* 1bit: type */
*bits = (*bits & ~COUNTER_RESET_MASK) |
@@ -381,7 +387,7 @@ static inline css_error set_counter_reset(
for (c = counters; c != NULL && c->name != NULL; c++)
c->name = lwc_string_ref(c->name);
- style->uncommon->counter_reset = counters;
+ style->i.uncommon->counter_reset = counters;
/* Free existing array */
if (oldcounters != NULL) {
@@ -411,8 +417,8 @@ static inline css_error set_cursor(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[CURSOR_INDEX];
- oldurls = style->uncommon->cursor;
+ bits = &style->i.uncommon->i.bits[CURSOR_INDEX];
+ oldurls = style->i.uncommon->cursor;
/* 5bits: type */
*bits = (*bits & ~CURSOR_MASK) |
@@ -421,7 +427,7 @@ static inline css_error set_cursor(
for (s = urls; s != NULL && *s != NULL; s++)
*s = lwc_string_ref(*s);
- style->uncommon->cursor = urls;
+ style->i.uncommon->cursor = urls;
/* Free existing array */
if (oldurls != NULL) {
@@ -453,7 +459,7 @@ static inline css_error set_clip(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[CLIP_INDEX];
+ bits = &style->i.uncommon->i.bits[CLIP_INDEX];
/* 6bits: trblyy : top | right | bottom | left | type */
*bits = (*bits & ~CLIP_MASK) |
@@ -465,20 +471,20 @@ static inline css_error set_clip(
(rect->bottom_auto ? 0x8 : 0) |
(rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT);
- bits = &style->uncommon->bits[CLIP_INDEX1];
+ bits = &style->i.uncommon->i.bits[CLIP_INDEX1];
/* 8bits: ttttrrrr : top | right */
*bits = (((rect->tunit << 4) | rect->runit) << CLIP_SHIFT1);
- bits = &style->uncommon->bits[CLIP_INDEX2];
+ bits = &style->i.uncommon->i.bits[CLIP_INDEX2];
/* 8bits: bbbbllll : bottom | left */
*bits = (((rect->bunit << 4) | rect->lunit) << CLIP_SHIFT2);
- style->uncommon->clip[0] = rect->top;
- style->uncommon->clip[1] = rect->right;
- style->uncommon->clip[2] = rect->bottom;
- style->uncommon->clip[3] = rect->left;
+ style->i.uncommon->i.clip[0] = rect->top;
+ style->i.uncommon->i.clip[1] = rect->right;
+ style->i.uncommon->i.clip[2] = rect->bottom;
+ style->i.uncommon->i.clip[3] = rect->left;
}
return CSS_OK;
@@ -501,13 +507,13 @@ static inline css_error set_column_count(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_COUNT_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_COUNT_INDEX];
/* 2bits: tt : type */
*bits = (*bits & ~COLUMN_COUNT_MASK) |
((type & 0x3) << COLUMN_COUNT_SHIFT);
- style->uncommon->column_count = count;
+ style->i.uncommon->i.column_count = count;
return CSS_OK;
}
@@ -525,7 +531,7 @@ static inline css_error set_column_fill(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_FILL_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_FILL_INDEX];
/* 2bits: tt : type */
*bits = (*bits & ~COLUMN_FILL_MASK) |
@@ -548,13 +554,13 @@ static inline css_error set_column_gap(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_GAP_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_GAP_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~COLUMN_GAP_MASK) |
(((type & 0x3) | (unit << 2)) << COLUMN_GAP_SHIFT);
- style->uncommon->column_gap = length;
+ style->i.uncommon->i.column_gap = length;
return CSS_OK;
}
@@ -573,13 +579,13 @@ static inline css_error set_column_rule_color(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_RULE_COLOR_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_RULE_COLOR_INDEX];
/* 2bits: type */
*bits = (*bits & ~COLUMN_RULE_COLOR_MASK) |
((type & 0x3) << COLUMN_RULE_COLOR_SHIFT);
- style->uncommon->column_rule_color = color;
+ style->i.uncommon->i.column_rule_color = color;
return CSS_OK;
}
@@ -597,7 +603,7 @@ static inline css_error set_column_rule_style(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_RULE_STYLE_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_RULE_STYLE_INDEX];
/* 4bits: type */
*bits = (*bits & ~COLUMN_RULE_STYLE_MASK) |
@@ -620,13 +626,13 @@ static inline css_error set_column_rule_width(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_RULE_WIDTH_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_RULE_WIDTH_INDEX];
/* 7bits: uuuuttt : units | type */
*bits = (*bits & ~COLUMN_RULE_WIDTH_MASK) |
(((type & 0x7) | (unit << 3)) << COLUMN_RULE_WIDTH_SHIFT);
- style->uncommon->column_rule_width = length;
+ style->i.uncommon->i.column_rule_width = length;
return CSS_OK;
}
@@ -644,7 +650,7 @@ static inline css_error set_column_span(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_SPAN_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_SPAN_INDEX];
/* 2bits: tt : type */
*bits = (*bits & ~COLUMN_SPAN_MASK) |
@@ -667,13 +673,13 @@ static inline css_error set_column_width(
ENSURE_UNCOMMON;
- bits = &style->uncommon->bits[COLUMN_WIDTH_INDEX];
+ bits = &style->i.uncommon->i.bits[COLUMN_WIDTH_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~COLUMN_WIDTH_MASK) |
(((type & 0x3) | (unit << 2)) << COLUMN_WIDTH_SHIFT);
- style->uncommon->column_width = length;
+ style->i.uncommon->i.column_width = length;
return CSS_OK;
}
@@ -695,8 +701,8 @@ static inline css_error set_content(
ENSURE_UNCOMMON;
/* 2bits: type */
- bits = &style->uncommon->bits[CONTENT_INDEX];
- oldcontent = style->uncommon->content;
+ bits = &style->i.uncommon->i.bits[CONTENT_INDEX];
+ oldcontent = style->i.uncommon->content;
*bits = (*bits & ~CONTENT_MASK) |
((type & 0x3) << CONTENT_SHIFT);
@@ -728,7 +734,7 @@ static inline css_error set_content(
}
}
- style->uncommon->content = content;
+ style->i.uncommon->content = content;
/* Free existing array */
if (oldcontent != NULL) {
@@ -773,12 +779,12 @@ static inline css_error set_vertical_align(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[VERTICAL_ALIGN_INDEX];
+ uint8_t *bits = &style->i.bits[VERTICAL_ALIGN_INDEX];
/* 8bits: uuuutttt : units | type */
*bits = (((type & 0xf) | (unit << 4)) << VERTICAL_ALIGN_SHIFT);
- style->vertical_align = length;
+ style->i.vertical_align = length;
return CSS_OK;
}
@@ -791,12 +797,12 @@ static inline css_error set_font_size(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[FONT_SIZE_INDEX];
+ uint8_t *bits = &style->i.bits[FONT_SIZE_INDEX];
/* 8bits: uuuutttt : units | type */
*bits = (((type & 0xf) | (unit << 4)) << FONT_SIZE_SHIFT);
- style->font_size = length;
+ style->i.font_size = length;
return CSS_OK;
}
@@ -810,13 +816,13 @@ static inline css_error set_border_top_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[BORDER_TOP_WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_TOP_WIDTH_INDEX];
/* 7bits: uuuuttt : units | type */
*bits = (*bits & ~BORDER_TOP_WIDTH_MASK) |
(((type & 0x7) | (unit << 3)) << BORDER_TOP_WIDTH_SHIFT);
- style->border_width[0] = length;
+ style->i.border_width[0] = length;
return CSS_OK;
}
@@ -831,13 +837,13 @@ static inline css_error set_border_right_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[BORDER_RIGHT_WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_RIGHT_WIDTH_INDEX];
/* 7bits: uuuuttt : units | type */
*bits = (*bits & ~BORDER_RIGHT_WIDTH_MASK) |
(((type & 0x7) | (unit << 3)) << BORDER_RIGHT_WIDTH_SHIFT);
- style->border_width[1] = length;
+ style->i.border_width[1] = length;
return CSS_OK;
}
@@ -852,13 +858,13 @@ static inline css_error set_border_bottom_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[BORDER_BOTTOM_WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_BOTTOM_WIDTH_INDEX];
/* 7bits: uuuuttt : units | type */
*bits = (*bits & ~BORDER_BOTTOM_WIDTH_MASK) |
(((type & 0x7) | (unit << 3)) << BORDER_BOTTOM_WIDTH_SHIFT);
- style->border_width[2] = length;
+ style->i.border_width[2] = length;
return CSS_OK;
}
@@ -873,13 +879,13 @@ static inline css_error set_border_left_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[BORDER_LEFT_WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_LEFT_WIDTH_INDEX];
/* 7bits: uuuuttt : units | type */
*bits = (*bits & ~BORDER_LEFT_WIDTH_MASK) |
(((type & 0x7) | (unit << 3)) << BORDER_LEFT_WIDTH_SHIFT);
- style->border_width[3] = length;
+ style->i.border_width[3] = length;
return CSS_OK;
}
@@ -894,17 +900,17 @@ static inline css_error set_background_image(
css_computed_style *style, uint8_t type,
lwc_string *url)
{
- uint8_t *bits = &style->bits[BACKGROUND_IMAGE_INDEX];
- lwc_string *oldurl = style->background_image;
+ uint8_t *bits = &style->i.bits[BACKGROUND_IMAGE_INDEX];
+ lwc_string *oldurl = style->i.background_image;
/* 1bit: type */
*bits = (*bits & ~BACKGROUND_IMAGE_MASK) |
((type & 0x1) << BACKGROUND_IMAGE_SHIFT);
if (url != NULL) {
- style->background_image = lwc_string_ref(url);
+ style->i.background_image = lwc_string_ref(url);
} else {
- style->background_image = NULL;
+ style->i.background_image = NULL;
}
if (oldurl != NULL)
@@ -923,13 +929,13 @@ static inline css_error set_color(
css_computed_style *style, uint8_t type,
css_color color)
{
- uint8_t *bits = &style->bits[COLOR_INDEX];
+ uint8_t *bits = &style->i.bits[COLOR_INDEX];
/* 1bit: type */
*bits = (*bits & ~COLOR_MASK) |
((type & 0x1) << COLOR_SHIFT);
- style->color = color;
+ style->i.color = color;
return CSS_OK;
}
@@ -944,17 +950,17 @@ static inline css_error set_list_style_image(
css_computed_style *style, uint8_t type,
lwc_string *url)
{
- uint8_t *bits = &style->bits[LIST_STYLE_IMAGE_INDEX];
- lwc_string *oldurl = style->list_style_image;
+ uint8_t *bits = &style->i.bits[LIST_STYLE_IMAGE_INDEX];
+ lwc_string *oldurl = style->i.list_style_image;
/* 1bit: type */
*bits = (*bits & ~LIST_STYLE_IMAGE_MASK) |
((type & 0x1) << LIST_STYLE_IMAGE_SHIFT);
if (url != NULL) {
- style->list_style_image = lwc_string_ref(url);
+ style->i.list_style_image = lwc_string_ref(url);
} else {
- style->list_style_image = NULL;
+ style->i.list_style_image = NULL;
}
if (oldurl != NULL)
@@ -973,7 +979,7 @@ static inline css_error set_quotes(
css_computed_style *style, uint8_t type,
lwc_string **quotes)
{
- uint8_t *bits = &style->bits[QUOTES_INDEX];
+ uint8_t *bits = &style->i.bits[QUOTES_INDEX];
lwc_string **oldquotes = style->quotes;
lwc_string **s;
@@ -1008,13 +1014,13 @@ static inline css_error set_top(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[TOP_INDEX];
+ uint8_t *bits = &style->i.bits[TOP_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~TOP_MASK) |
(((type & 0x3) | (unit << 2)) << TOP_SHIFT);
- style->top = length;
+ style->i.top = length;
return CSS_OK;
}
@@ -1029,13 +1035,13 @@ static inline css_error set_right(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[RIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[RIGHT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~RIGHT_MASK) |
(((type & 0x3) | (unit << 2)) << RIGHT_SHIFT);
- style->right = length;
+ style->i.right = length;
return CSS_OK;
}
@@ -1050,13 +1056,13 @@ static inline css_error set_bottom(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[BOTTOM_INDEX];
+ uint8_t *bits = &style->i.bits[BOTTOM_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~BOTTOM_MASK) |
(((type & 0x3) | (unit << 2)) << BOTTOM_SHIFT);
- style->bottom = length;
+ style->i.bottom = length;
return CSS_OK;
}
@@ -1071,13 +1077,13 @@ static inline css_error set_left(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[LEFT_INDEX];
+ uint8_t *bits = &style->i.bits[LEFT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~LEFT_MASK) |
(((type & 0x3) | (unit << 2)) << LEFT_SHIFT);
- style->left = length;
+ style->i.left = length;
return CSS_OK;
}
@@ -1092,13 +1098,13 @@ static inline css_error set_border_top_color(
css_computed_style *style, uint8_t type,
css_color color)
{
- uint8_t *bits = &style->bits[BORDER_TOP_COLOR_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_TOP_COLOR_INDEX];
/* 2bits: type */
*bits = (*bits & ~BORDER_TOP_COLOR_MASK) |
((type & 0x3) << BORDER_TOP_COLOR_SHIFT);
- style->border_color[0] = color;
+ style->i.border_color[0] = color;
return CSS_OK;
}
@@ -1113,13 +1119,13 @@ static inline css_error set_border_right_color(
css_computed_style *style, uint8_t type,
css_color color)
{
- uint8_t *bits = &style->bits[BORDER_RIGHT_COLOR_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_RIGHT_COLOR_INDEX];
/* 2bits: type */
*bits = (*bits & ~BORDER_RIGHT_COLOR_MASK) |
((type & 0x3) << BORDER_RIGHT_COLOR_SHIFT);
- style->border_color[1] = color;
+ style->i.border_color[1] = color;
return CSS_OK;
}
@@ -1134,13 +1140,13 @@ static inline css_error set_border_bottom_color(
css_computed_style *style, uint8_t type,
css_color color)
{
- uint8_t *bits = &style->bits[BORDER_BOTTOM_COLOR_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_BOTTOM_COLOR_INDEX];
/* 2bits: type */
*bits = (*bits & ~BORDER_BOTTOM_COLOR_MASK) |
((type & 0x3) << BORDER_BOTTOM_COLOR_SHIFT);
- style->border_color[2] = color;
+ style->i.border_color[2] = color;
return CSS_OK;
}
@@ -1155,13 +1161,13 @@ static inline css_error set_border_left_color(
css_computed_style *style, uint8_t type,
css_color color)
{
- uint8_t *bits = &style->bits[BORDER_LEFT_COLOR_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_LEFT_COLOR_INDEX];
/* 2bits: type */
*bits = (*bits & ~BORDER_LEFT_COLOR_MASK) |
((type & 0x3) << BORDER_LEFT_COLOR_SHIFT);
- style->border_color[3] = color;
+ style->i.border_color[3] = color;
return CSS_OK;
}
@@ -1176,13 +1182,13 @@ static inline css_error set_height(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[HEIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[HEIGHT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~HEIGHT_MASK) |
(((type & 0x3) | (unit << 2)) << HEIGHT_SHIFT);
- style->height = length;
+ style->i.height = length;
return CSS_OK;
}
@@ -1197,13 +1203,13 @@ static inline css_error set_line_height(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[LINE_HEIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[LINE_HEIGHT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~LINE_HEIGHT_MASK) |
(((type & 0x3) | (unit << 2)) << LINE_HEIGHT_SHIFT);
- style->line_height = length;
+ style->i.line_height = length;
return CSS_OK;
}
@@ -1218,13 +1224,13 @@ static inline css_error set_background_color(
css_computed_style *style, uint8_t type,
css_color color)
{
- uint8_t *bits = &style->bits[BACKGROUND_COLOR_INDEX];
+ uint8_t *bits = &style->i.bits[BACKGROUND_COLOR_INDEX];
/* 2bits: type */
*bits = (*bits & ~BACKGROUND_COLOR_MASK) |
((type & 0x3) << BACKGROUND_COLOR_SHIFT);
- style->background_color = color;
+ style->i.background_color = color;
return CSS_OK;
}
@@ -1239,13 +1245,13 @@ static inline css_error set_z_index(
css_computed_style *style, uint8_t type,
int32_t z_index)
{
- uint8_t *bits = &style->bits[Z_INDEX_INDEX];
+ uint8_t *bits = &style->i.bits[Z_INDEX_INDEX];
/* 2bits: type */
*bits = (*bits & ~Z_INDEX_MASK) |
((type & 0x3) << Z_INDEX_SHIFT);
- style->z_index = z_index;
+ style->i.z_index = z_index;
return CSS_OK;
}
@@ -1260,13 +1266,13 @@ static inline css_error set_margin_top(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MARGIN_TOP_INDEX];
+ uint8_t *bits = &style->i.bits[MARGIN_TOP_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~MARGIN_TOP_MASK) |
(((type & 0x3) | (unit << 2)) << MARGIN_TOP_SHIFT);
- style->margin[0] = length;
+ style->i.margin[0] = length;
return CSS_OK;
}
@@ -1281,13 +1287,13 @@ static inline css_error set_margin_right(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MARGIN_RIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[MARGIN_RIGHT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~MARGIN_RIGHT_MASK) |
(((type & 0x3) | (unit << 2)) << MARGIN_RIGHT_SHIFT);
- style->margin[1] = length;
+ style->i.margin[1] = length;
return CSS_OK;
}
@@ -1302,13 +1308,13 @@ static inline css_error set_margin_bottom(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MARGIN_BOTTOM_INDEX];
+ uint8_t *bits = &style->i.bits[MARGIN_BOTTOM_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~MARGIN_BOTTOM_MASK) |
(((type & 0x3) | (unit << 2)) << MARGIN_BOTTOM_SHIFT);
- style->margin[2] = length;
+ style->i.margin[2] = length;
return CSS_OK;
}
@@ -1323,13 +1329,13 @@ static inline css_error set_margin_left(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MARGIN_LEFT_INDEX];
+ uint8_t *bits = &style->i.bits[MARGIN_LEFT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~MARGIN_LEFT_MASK) |
(((type & 0x3) | (unit << 2)) << MARGIN_LEFT_SHIFT);
- style->margin[3] = length;
+ style->i.margin[3] = length;
return CSS_OK;
}
@@ -1343,7 +1349,7 @@ static inline css_error set_margin_left(
static inline css_error set_background_attachment(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BACKGROUND_ATTACHMENT_INDEX];
+ uint8_t *bits = &style->i.bits[BACKGROUND_ATTACHMENT_INDEX];
/* 2bits: type */
*bits = (*bits & ~BACKGROUND_ATTACHMENT_MASK) |
@@ -1361,7 +1367,7 @@ static inline css_error set_background_attachment(
static inline css_error set_border_collapse(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BORDER_COLLAPSE_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_COLLAPSE_INDEX];
/* 2bits: type */
*bits = (*bits & ~BORDER_COLLAPSE_MASK) |
@@ -1379,7 +1385,7 @@ static inline css_error set_border_collapse(
static inline css_error set_caption_side(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[CAPTION_SIDE_INDEX];
+ uint8_t *bits = &style->i.bits[CAPTION_SIDE_INDEX];
/* 2bits: type */
*bits = (*bits & ~CAPTION_SIDE_MASK) |
@@ -1397,7 +1403,7 @@ static inline css_error set_caption_side(
static inline css_error set_direction(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[DIRECTION_INDEX];
+ uint8_t *bits = &style->i.bits[DIRECTION_INDEX];
/* 2bits: type */
*bits = (*bits & ~DIRECTION_MASK) |
@@ -1416,13 +1422,13 @@ static inline css_error set_max_height(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MAX_HEIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[MAX_HEIGHT_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~MAX_HEIGHT_MASK) |
(((type & 0x3) | (unit << 2)) << MAX_HEIGHT_SHIFT);
- style->max_height = length;
+ style->i.max_height = length;
return CSS_OK;
}
@@ -1437,13 +1443,13 @@ static inline css_error set_max_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MAX_WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[MAX_WIDTH_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~MAX_WIDTH_MASK) |
(((type & 0x3) | (unit << 2)) << MAX_WIDTH_SHIFT);
- style->max_width = length;
+ style->i.max_width = length;
return CSS_OK;
}
@@ -1458,13 +1464,13 @@ static inline css_error set_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[WIDTH_INDEX];
/* 6bits: uuuutt : units | type */
*bits = (*bits & ~WIDTH_MASK) |
(((type & 0x3) | (unit << 2)) << WIDTH_SHIFT);
- style->width = length;
+ style->i.width = length;
return CSS_OK;
}
@@ -1478,7 +1484,7 @@ static inline css_error set_width(
static inline css_error set_empty_cells(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[EMPTY_CELLS_INDEX];
+ uint8_t *bits = &style->i.bits[EMPTY_CELLS_INDEX];
/* 2bits: type */
*bits = (*bits & ~EMPTY_CELLS_MASK) |
@@ -1496,7 +1502,7 @@ static inline css_error set_empty_cells(
static inline css_error set_float(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[FLOAT_INDEX];
+ uint8_t *bits = &style->i.bits[FLOAT_INDEX];
/* 2bits: type */
*bits = (*bits & ~FLOAT_MASK) |
@@ -1514,7 +1520,7 @@ static inline css_error set_float(
static inline css_error set_font_style(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[FONT_STYLE_INDEX];
+ uint8_t *bits = &style->i.bits[FONT_STYLE_INDEX];
/* 2bits: type */
*bits = (*bits & ~FONT_STYLE_MASK) |
@@ -1533,13 +1539,13 @@ static inline css_error set_min_height(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MIN_HEIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[MIN_HEIGHT_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~MIN_HEIGHT_MASK) |
(((type & 0x1) | (unit << 1)) << MIN_HEIGHT_SHIFT);
- style->min_height = length;
+ style->i.min_height = length;
return CSS_OK;
}
@@ -1554,13 +1560,13 @@ static inline css_error set_min_width(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[MIN_WIDTH_INDEX];
+ uint8_t *bits = &style->i.bits[MIN_WIDTH_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~MIN_WIDTH_MASK) |
(((type & 0x1) | (unit << 1)) << MIN_WIDTH_SHIFT);
- style->min_width = length;
+ style->i.min_width = length;
return CSS_OK;
}
@@ -1574,7 +1580,7 @@ static inline css_error set_min_width(
static inline css_error set_background_repeat(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BACKGROUND_REPEAT_INDEX];
+ uint8_t *bits = &style->i.bits[BACKGROUND_REPEAT_INDEX];
/* 3bits: type */
*bits = (*bits & ~BACKGROUND_REPEAT_MASK) |
@@ -1592,7 +1598,7 @@ static inline css_error set_background_repeat(
static inline css_error set_clear(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[CLEAR_INDEX];
+ uint8_t *bits = &style->i.bits[CLEAR_INDEX];
/* 3bits: type */
*bits = (*bits & ~CLEAR_MASK) |
@@ -1611,13 +1617,13 @@ static inline css_error set_padding_top(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[PADDING_TOP_INDEX];
+ uint8_t *bits = &style->i.bits[PADDING_TOP_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~PADDING_TOP_MASK) |
(((type & 0x1) | (unit << 1)) << PADDING_TOP_SHIFT);
- style->padding[0] = length;
+ style->i.padding[0] = length;
return CSS_OK;
}
@@ -1632,13 +1638,13 @@ static inline css_error set_padding_right(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[PADDING_RIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[PADDING_RIGHT_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~PADDING_RIGHT_MASK) |
(((type & 0x1) | (unit << 1)) << PADDING_RIGHT_SHIFT);
- style->padding[1] = length;
+ style->i.padding[1] = length;
return CSS_OK;
}
@@ -1653,13 +1659,13 @@ static inline css_error set_padding_bottom(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[PADDING_BOTTOM_INDEX];
+ uint8_t *bits = &style->i.bits[PADDING_BOTTOM_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~PADDING_BOTTOM_MASK) |
(((type & 0x1) | (unit << 1)) << PADDING_BOTTOM_SHIFT);
- style->padding[2] = length;
+ style->i.padding[2] = length;
return CSS_OK;
}
@@ -1674,13 +1680,13 @@ static inline css_error set_padding_left(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[PADDING_LEFT_INDEX];
+ uint8_t *bits = &style->i.bits[PADDING_LEFT_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~PADDING_LEFT_MASK) |
(((type & 0x1) | (unit << 1)) << PADDING_LEFT_SHIFT);
- style->padding[3] = length;
+ style->i.padding[3] = length;
return CSS_OK;
}
@@ -1694,7 +1700,7 @@ static inline css_error set_padding_left(
static inline css_error set_overflow_x(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[OVERFLOW_X_INDEX];
+ uint8_t *bits = &style->i.bits[OVERFLOW_X_INDEX];
/* 3bits: type */
*bits = (*bits & ~OVERFLOW_X_MASK) |
@@ -1712,7 +1718,7 @@ static inline css_error set_overflow_x(
static inline css_error set_overflow_y(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[OVERFLOW_Y_INDEX];
+ uint8_t *bits = &style->i.bits[OVERFLOW_Y_INDEX];
/* 3bits: type */
*bits = (*bits & ~OVERFLOW_Y_MASK) |
@@ -1730,7 +1736,7 @@ static inline css_error set_overflow_y(
static inline css_error set_position(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[POSITION_INDEX];
+ uint8_t *bits = &style->i.bits[POSITION_INDEX];
/* 3bits: type */
*bits = (*bits & ~POSITION_MASK) |
@@ -1749,13 +1755,13 @@ static inline css_error set_opacity(
css_computed_style *style,
uint8_t type, css_fixed opacity)
{
- uint8_t *bits = &style->bits[OPACITY_INDEX];
+ uint8_t *bits = &style->i.bits[OPACITY_INDEX];
/* 1bit: t : type */
*bits = (*bits & ~OPACITY_MASK) |
((type & 0x1) << OPACITY_SHIFT);
- style->opacity = opacity;
+ style->i.opacity = opacity;
return CSS_OK;
}
@@ -1769,7 +1775,7 @@ static inline css_error set_opacity(
static inline css_error set_text_transform(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[TEXT_TRANSFORM_INDEX];
+ uint8_t *bits = &style->i.bits[TEXT_TRANSFORM_INDEX];
/* 3bits: type */
*bits = (*bits & ~TEXT_TRANSFORM_MASK) |
@@ -1788,13 +1794,13 @@ static inline css_error set_text_indent(
css_computed_style *style, uint8_t type,
css_fixed length, css_unit unit)
{
- uint8_t *bits = &style->bits[TEXT_INDENT_INDEX];
+ uint8_t *bits = &style->i.bits[TEXT_INDENT_INDEX];
/* 5bits: uuuut : units | type */
*bits = (*bits & ~TEXT_INDENT_MASK) |
(((type & 0x1) | (unit << 1)) << TEXT_INDENT_SHIFT);
- style->text_indent = length;
+ style->i.text_indent = length;
return CSS_OK;
}
@@ -1808,7 +1814,7 @@ static inline css_error set_text_indent(
static inline css_error set_white_space(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[WHITE_SPACE_INDEX];
+ uint8_t *bits = &style->i.bits[WHITE_SPACE_INDEX];
/* 3bits: type */
*bits = (*bits & ~WHITE_SPACE_MASK) |
@@ -1832,19 +1838,19 @@ static inline css_error set_background_position(
{
uint8_t *bits;
- bits = &style->bits[BACKGROUND_POSITION_INDEX];
+ bits = &style->i.bits[BACKGROUND_POSITION_INDEX];
/* 1 bit: type */
*bits = (*bits & ~BACKGROUND_POSITION_MASK) |
((type & 0x1) << BACKGROUND_POSITION_SHIFT);
- bits = &style->bits[BACKGROUND_POSITION_INDEX1];
+ bits = &style->i.bits[BACKGROUND_POSITION_INDEX1];
/* 8bits: hhhhvvvv : hunit | vunit */
*bits = (((hunit << 4) | vunit) << BACKGROUND_POSITION_SHIFT1);
- style->background_position[0] = hlength;
- style->background_position[1] = vlength;
+ style->i.background_position[0] = hlength;
+ style->i.background_position[1] = vlength;
return CSS_OK;
}
@@ -1860,7 +1866,7 @@ static inline css_error set_background_position(
static inline css_error set_display(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[DISPLAY_INDEX];
+ uint8_t *bits = &style->i.bits[DISPLAY_INDEX];
/* 5bits: type */
*bits = (*bits & ~DISPLAY_MASK) |
@@ -1878,7 +1884,7 @@ static inline css_error set_display(
static inline css_error set_font_variant(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[FONT_VARIANT_INDEX];
+ uint8_t *bits = &style->i.bits[FONT_VARIANT_INDEX];
/* 2bits: type */
*bits = (*bits & ~FONT_VARIANT_MASK) |
@@ -1896,7 +1902,7 @@ static inline css_error set_font_variant(
static inline css_error set_text_decoration(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[TEXT_DECORATION_INDEX];
+ uint8_t *bits = &style->i.bits[TEXT_DECORATION_INDEX];
/* 5bits: type */
*bits = (*bits & ~TEXT_DECORATION_MASK) |
@@ -1915,7 +1921,7 @@ static inline css_error set_font_family(
css_computed_style *style, uint8_t type,
lwc_string **names)
{
- uint8_t *bits = &style->bits[FONT_FAMILY_INDEX];
+ uint8_t *bits = &style->i.bits[FONT_FAMILY_INDEX];
lwc_string **oldnames = style->font_family;
lwc_string **s;
@@ -1949,7 +1955,7 @@ static inline css_error set_font_family(
static inline css_error set_border_top_style(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BORDER_TOP_STYLE_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_TOP_STYLE_INDEX];
/* 4bits: type */
*bits = (*bits & ~BORDER_TOP_STYLE_MASK) |
@@ -1967,7 +1973,7 @@ static inline css_error set_border_top_style(
static inline css_error set_border_right_style(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BORDER_RIGHT_STYLE_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_RIGHT_STYLE_INDEX];
/* 4bits: type */
*bits = (*bits & ~BORDER_RIGHT_STYLE_MASK) |
@@ -1985,7 +1991,7 @@ static inline css_error set_border_right_style(
static inline css_error set_border_bottom_style(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BORDER_BOTTOM_STYLE_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_BOTTOM_STYLE_INDEX];
/* 4bits: type */
*bits = (*bits & ~BORDER_BOTTOM_STYLE_MASK) |
@@ -2003,7 +2009,7 @@ static inline css_error set_border_bottom_style(
static inline css_error set_border_left_style(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[BORDER_LEFT_STYLE_INDEX];
+ uint8_t *bits = &style->i.bits[BORDER_LEFT_STYLE_INDEX];
/* 4bits: type */
*bits = (*bits & ~BORDER_LEFT_STYLE_MASK) |
@@ -2021,7 +2027,7 @@ static inline css_error set_border_left_style(
static inline css_error set_font_weight(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[FONT_WEIGHT_INDEX];
+ uint8_t *bits = &style->i.bits[FONT_WEIGHT_INDEX];
/* 4bits: type */
*bits = (*bits & ~FONT_WEIGHT_MASK) |
@@ -2039,7 +2045,7 @@ static inline css_error set_font_weight(
static inline css_error set_list_style_type(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[LIST_STYLE_TYPE_INDEX];
+ uint8_t *bits = &style->i.bits[LIST_STYLE_TYPE_INDEX];
/* 4bits: type */
*bits = (*bits & ~LIST_STYLE_TYPE_MASK) |
@@ -2057,7 +2063,7 @@ static inline css_error set_list_style_type(
static inline css_error set_outline_style(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[OUTLINE_STYLE_INDEX];
+ uint8_t *bits = &style->i.bits[OUTLINE_STYLE_INDEX];
/* 4bits: type */
*bits = (*bits & ~OUTLINE_STYLE_MASK) |
@@ -2075,7 +2081,7 @@ static inline css_error set_outline_style(
static inline css_error set_table_layout(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[TABLE_LAYOUT_INDEX];
+ uint8_t *bits = &style->i.bits[TABLE_LAYOUT_INDEX];
/* 2bits: type */
*bits = (*bits & ~TABLE_LAYOUT_MASK) |
@@ -2093,7 +2099,7 @@ static inline css_error set_table_layout(
static inline css_error set_unicode_bidi(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[UNICODE_BIDI_INDEX];
+ uint8_t *bits = &style->i.bits[UNICODE_BIDI_INDEX];
/* 2bits: type */
*bits = (*bits & ~UNICODE_BIDI_MASK) |
@@ -2111,7 +2117,7 @@ static inline css_error set_unicode_bidi(
static inline css_error set_visibility(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[VISIBILITY_INDEX];
+ uint8_t *bits = &style->i.bits[VISIBILITY_INDEX];
/* 2bits: type */
*bits = (*bits & ~VISIBILITY_MASK) |
@@ -2129,7 +2135,7 @@ static inline css_error set_visibility(
static inline css_error set_list_style_position(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[LIST_STYLE_POSITION_INDEX];
+ uint8_t *bits = &style->i.bits[LIST_STYLE_POSITION_INDEX];
/* 2bits: type */
*bits = (*bits & ~LIST_STYLE_POSITION_MASK) |
@@ -2147,7 +2153,7 @@ static inline css_error set_list_style_position(
static inline uint8_t set_text_align(
css_computed_style *style, uint8_t type)
{
- uint8_t *bits = &style->bits[TEXT_ALIGN_INDEX];
+ uint8_t *bits = &style->i.bits[TEXT_ALIGN_INDEX];
/* 4bits: type */
*bits = (*bits & ~TEXT_ALIGN_MASK) |
diff --git a/src/select/select.c b/src/select/select.c
index 17dff31..e250657 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -1177,7 +1177,7 @@ css_error set_initial(css_select_state *state,
case GROUP_NORMAL:
break;
case GROUP_UNCOMMON:
- if (state->computed->uncommon == NULL)
+ if (state->computed->i.uncommon == NULL)
return CSS_OK;
break;
case GROUP_PAGE:
@@ -1185,7 +1185,7 @@ css_error set_initial(css_select_state *state,
return CSS_OK;
break;
case GROUP_AURAL:
- if (state->computed->aural == NULL)
+ if (state->computed->i.aural == NULL)
return CSS_OK;
break;
}
-----------------------------------------------------------------------
Summary of changes:
src/select/computed.c | 32 ++++++++++++++++++--------------
src/select/select.c | 37 ++++++++++++++++++-------------------
2 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/src/select/computed.c b/src/select/computed.c
index 182a7e7..107c884 100644
--- a/src/select/computed.c
+++ b/src/select/computed.c
@@ -296,20 +296,24 @@ css_error css_computed_style_compose(const css_computed_style *parent,
/* Iterate through the properties */
for (i = 0; i < CSS_N_PROPERTIES; i++) {
- /* Skip any in extension blocks if the block does not exist */
- if (prop_dispatch[i].group == GROUP_UNCOMMON &&
- parent->i.uncommon == NULL &&
- child->i.uncommon == NULL)
- continue;
-
- if (prop_dispatch[i].group == GROUP_PAGE &&
- parent->page == NULL && child->page == NULL)
- continue;
-
- if (prop_dispatch[i].group == GROUP_AURAL &&
- parent->i.aural == NULL &&
- child->i.aural == NULL)
- continue;
+ /* Skip any in extension blocks if the block does not exist */
+ switch(prop_dispatch[i].group) {
+ case GROUP_NORMAL:
+ break;
+ case GROUP_UNCOMMON:
+ if (parent->i.uncommon == NULL &&
+ child->i.uncommon == NULL)
+ continue;
+ break;
+ case GROUP_PAGE:
+ if (parent->page == NULL && child->page == NULL)
+ continue;
+ break;
+ case GROUP_AURAL:
+ if (parent->i.aural == NULL && child->i.aural == NULL)
+ continue;
+ break;
+ }
/* Compose the property */
error = prop_dispatch[i].compose(parent, child, *result);
diff --git a/src/select/select.c b/src/select/select.c
index d484cc8..e250657 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -1173,26 +1173,25 @@ css_error set_initial(css_select_state *state,
* accessors to return the initial values for the
* property.
*/
- if (group == GROUP_NORMAL) {
- error = prop_dispatch[prop].initial(state);
- if (error != CSS_OK)
- return error;
- } else if (group == GROUP_UNCOMMON &&
- state->computed->i.uncommon != NULL) {
- error = prop_dispatch[prop].initial(state);
- if (error != CSS_OK)
- return error;
- } else if (group == GROUP_PAGE &&
- state->computed->page != NULL) {
- error = prop_dispatch[prop].initial(state);
- if (error != CSS_OK)
- return error;
- } else if (group == GROUP_AURAL &&
- state->computed->i.aural != NULL) {
- error = prop_dispatch[prop].initial(state);
- if (error != CSS_OK)
- return error;
+ switch (group) {
+ case GROUP_NORMAL:
+ break;
+ case GROUP_UNCOMMON:
+ if (state->computed->i.uncommon == NULL)
+ return CSS_OK;
+ break;
+ case GROUP_PAGE:
+ if (state->computed->page == NULL)
+ return CSS_OK;
+ break;
+ case GROUP_AURAL:
+ if (state->computed->i.aural == NULL)
+ return CSS_OK;
+ break;
}
+ error = prop_dispatch[prop].initial(state);
+ if (error != CSS_OK)
+ return error;
}
return CSS_OK;
--
Cascading Style Sheets library
8 years, 1 month
libdom: branch master updated. release/0.1.2-8-g3d7aaee
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libdom.git/shortlog/3d7aaee2fa5b61dc001f9c...
...commit http://git.netsurf-browser.org/libdom.git/commit/3d7aaee2fa5b61dc001f9ce7...
...tree http://git.netsurf-browser.org/libdom.git/tree/3d7aaee2fa5b61dc001f9ce799...
The branch, master has been updated
via 3d7aaee2fa5b61dc001f9ce79983f24c4ece87a1 (commit)
from 419b9a774b533462d9fa59e8733425a7e33c3efc (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/libdom.git/commit/?id=3d7aaee2fa5b61dc001f...
commit 3d7aaee2fa5b61dc001f9ce79983f24c4ece87a1
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Strip doc from event layer
diff --git a/include/dom/events/event.h b/include/dom/events/event.h
index 73e7ec0..e33758a 100644
--- a/include/dom/events/event.h
+++ b/include/dom/events/event.h
@@ -27,6 +27,9 @@ void _dom_event_ref(dom_event *evt);
void _dom_event_unref(dom_event *evt);
#define dom_event_unref(n) _dom_event_unref((dom_event *) (n))
+dom_exception _dom_event_create(dom_event **evt);
+#define dom_event_create(n) _dom_event_create((dom_event **) (n))
+
dom_exception _dom_event_get_type(dom_event *evt, dom_string **type);
#define dom_event_get_type(e, t) _dom_event_get_type((dom_event *) (e), \
(dom_string **) (t))
diff --git a/src/core/document.c b/src/core/document.c
index a78cde9..b68a066 100644
--- a/src/core/document.c
+++ b/src/core/document.c
@@ -266,7 +266,7 @@ dom_exception _dom_document_initialise(dom_document *doc,
}
/* We should not pass a NULL when all things hook up */
- return _dom_document_event_internal_initialise(doc, &doc->dei, daf, daf_ctx);
+ return _dom_document_event_internal_initialise(&doc->dei, daf, daf_ctx);
}
@@ -309,7 +309,7 @@ bool _dom_document_finalise(dom_document *doc)
dom_string_unref(doc->_memo_domcharacterdatamodified);
dom_string_unref(doc->_memo_domsubtreemodified);
- _dom_document_event_internal_finalise(doc, &doc->dei);
+ _dom_document_event_internal_finalise(&doc->dei);
return true;
}
diff --git a/src/core/node.c b/src/core/node.c
index e500f3a..49033c0 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -2360,9 +2360,6 @@ dom_exception _dom_node_dispatch_event(dom_event_target *et,
return DOM_UNSPECIFIED_EVENT_TYPE_ERR;
}
- if (evt->doc == NULL)
- return DOM_NOT_SUPPORTED_ERR;
-
doc = dom_node_get_owner(et);
if (doc == NULL) {
/* TODO: In the progress of parsing, many Nodes in the DTD has
diff --git a/src/events/custom_event.c b/src/events/custom_event.c
index 76d09bf..c3a99f9 100644
--- a/src/events/custom_event.c
+++ b/src/events/custom_event.c
@@ -18,8 +18,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_custom_event_create(struct dom_document *doc,
- struct dom_custom_event **evt)
+dom_exception _dom_custom_event_create(struct dom_custom_event **evt)
{
*evt = malloc(sizeof(dom_custom_event));
if (*evt == NULL)
@@ -27,7 +26,7 @@ dom_exception _dom_custom_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_custom_event_initialise(doc, *evt);
+ return _dom_custom_event_initialise(*evt);
}
/* Destructor */
@@ -39,11 +38,10 @@ void _dom_custom_event_destroy(struct dom_custom_event *evt)
}
/* Initialise function */
-dom_exception _dom_custom_event_initialise(struct dom_document *doc,
- struct dom_custom_event *evt)
+dom_exception _dom_custom_event_initialise(struct dom_custom_event *evt)
{
evt->detail = NULL;
- return _dom_event_initialise(doc, &evt->base);
+ return _dom_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/custom_event.h b/src/events/custom_event.h
index ed5d624..4c7a6fc 100644
--- a/src/events/custom_event.h
+++ b/src/events/custom_event.h
@@ -18,15 +18,13 @@ struct dom_custom_event {
};
/* Constructor */
-dom_exception _dom_custom_event_create(struct dom_document *doc,
- struct dom_custom_event **evt);
+dom_exception _dom_custom_event_create(struct dom_custom_event **evt);
/* Destructor */
void _dom_custom_event_destroy(struct dom_custom_event *evt);
/* Initialise function */
-dom_exception _dom_custom_event_initialise(struct dom_document *doc,
- struct dom_custom_event *evt);
+dom_exception _dom_custom_event_initialise(struct dom_custom_event *evt);
/* Finalise function */
void _dom_custom_event_finalise(struct dom_custom_event *evt);
diff --git a/src/events/dispatch.c b/src/events/dispatch.c
index 64664c7..0e0048d 100644
--- a/src/events/dispatch.c
+++ b/src/events/dispatch.c
@@ -31,7 +31,7 @@ dom_exception __dom_dispatch_node_change_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -77,7 +77,7 @@ dom_exception __dom_dispatch_node_change_document_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -128,7 +128,7 @@ dom_exception __dom_dispatch_attr_modified_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -172,7 +172,7 @@ dom_exception __dom_dispatch_characterdata_modified_event(
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -208,7 +208,7 @@ dom_exception __dom_dispatch_subtree_modified_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -248,7 +248,9 @@ dom_exception _dom_dispatch_generic_event(dom_document *doc,
struct dom_event *evt;
dom_exception err;
- err = _dom_event_create(doc, &evt);
+ UNUSED(doc);
+
+ err = _dom_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
diff --git a/src/events/document_event.c b/src/events/document_event.c
index cd312ea..edabd92 100644
--- a/src/events/document_event.c
+++ b/src/events/document_event.c
@@ -43,13 +43,12 @@ static const char *__event_types[] = {
/**
* Initialise this DocumentEvent
*
- * \param doc The document object
* \param dei The DocumentEvent internal object
* \param actions The default action fetcher, the browser should provide such
* a function to Event module.
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
-dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
+dom_exception _dom_document_event_internal_initialise(
dom_document_event_internal *dei,
dom_events_default_action_fetcher actions,
void *actions_ctx)
@@ -57,8 +56,6 @@ dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
lwc_error err;
int i;
- UNUSED(doc);
-
for (i = 0; i < DOM_EVENT_COUNT; i++) {
err = lwc_intern_string(__event_types[i],
strlen(__event_types[i]), &dei->event_types[i]);
@@ -73,13 +70,10 @@ dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
}
/* Finalise this DocumentEvent */
-void _dom_document_event_internal_finalise(struct dom_document *doc,
- dom_document_event_internal *dei)
+void _dom_document_event_internal_finalise(dom_document_event_internal *dei)
{
int i;
- UNUSED(doc);
-
for (i = 0; i < DOM_EVENT_COUNT; i++) {
if (dei->event_types[i] != NULL)
lwc_string_unref(dei->event_types[i]);
@@ -100,17 +94,17 @@ void _dom_document_event_internal_finalise(struct dom_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_document_event_create_event(dom_document_event *de,
- dom_string *type, struct dom_event **evt)
+ dom_string *type,
+ struct dom_event **evt)
{
lwc_string *t = NULL;
dom_exception err;
- struct dom_document *doc = de;
int i, et = 0;
dom_document_event_internal *dei;
err = dom_string_intern(type, &t);
if (err != DOM_NO_ERR)
- return err;
+ return err;
assert(t != NULL);
@@ -125,41 +119,39 @@ dom_exception _dom_document_event_create_event(dom_document_event *de,
switch (et) {
case DOM_EVENT:
- err = _dom_event_create(doc, evt);
+ err = _dom_event_create(evt);
break;
case DOM_CUSTOM_EVENT:
- err = _dom_custom_event_create(doc,
- (dom_custom_event **) evt);
+ err = _dom_custom_event_create((dom_custom_event **) evt);
break;
case DOM_UI_EVENT:
- err = _dom_ui_event_create(doc, (dom_ui_event **) evt);
+ err = _dom_ui_event_create((dom_ui_event **) evt);
break;
case DOM_TEXT_EVENT:
- err = _dom_text_event_create(doc,
- (dom_text_event **) evt);
+ err = _dom_text_event_create((dom_text_event **) evt);
break;
case DOM_KEYBOARD_EVENT:
- err = _dom_keyboard_event_create(doc,
+ err = _dom_keyboard_event_create(
(dom_keyboard_event **) evt);
break;
case DOM_MOUSE_EVENT:
- err = _dom_mouse_event_create(doc,
+ err = _dom_mouse_event_create(
(dom_mouse_event **) evt);
break;
case DOM_MOUSE_MULTI_WHEEL_EVENT:
- err = _dom_mouse_multi_wheel_event_create(doc,
+ err = _dom_mouse_multi_wheel_event_create(
(dom_mouse_multi_wheel_event **) evt);
break;
case DOM_MOUSE_WHEEL_EVENT:
- err = _dom_mouse_wheel_event_create(doc,
+ err = _dom_mouse_wheel_event_create(
(dom_mouse_wheel_event **) evt);
break;
case DOM_MUTATION_EVENT:
- err = _dom_mutation_event_create(doc,
+ err = _dom_mutation_event_create(
(dom_mutation_event **) evt);
break;
case DOM_MUTATION_NAME_EVENT:
- err = _dom_mutation_name_event_create(doc,
+ err = _dom_mutation_name_event_create(
(dom_mutation_name_event **) evt);
break;
}
@@ -180,8 +172,7 @@ dom_exception _dom_document_event_create_event(dom_document_event *de,
* DOM_NO_SUPPORTED_ERR.
*/
dom_exception _dom_document_event_can_dispatch(dom_document_event *de,
- dom_string *namespace, dom_string *type,
- bool *can)
+ dom_string *namespace, dom_string *type, bool *can)
{
UNUSED(de);
UNUSED(namespace);
diff --git a/src/events/document_event.h b/src/events/document_event.h
index 1e04045..fbc5542 100644
--- a/src/events/document_event.h
+++ b/src/events/document_event.h
@@ -52,13 +52,13 @@ typedef struct dom_document_event_internal dom_document_event_internal;
*/
/* Initialise this DocumentEvent */
-dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
+dom_exception _dom_document_event_internal_initialise(
dom_document_event_internal *dei,
dom_events_default_action_fetcher actions,
void *actions_ctx);
/* Finalise this DocumentEvent */
-void _dom_document_event_internal_finalise(struct dom_document *doc,
+void _dom_document_event_internal_finalise(
dom_document_event_internal *dei);
#endif
diff --git a/src/events/event.c b/src/events/event.c
index 8af111b..ebd4854 100644
--- a/src/events/event.c
+++ b/src/events/event.c
@@ -23,7 +23,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_event_create(dom_document *doc, dom_event **evt)
+dom_exception _dom_event_create(dom_event **evt)
{
*evt = (dom_event *) malloc(sizeof(dom_event));
if (*evt == NULL)
@@ -31,7 +31,7 @@ dom_exception _dom_event_create(dom_document *doc, dom_event **evt)
(*evt)->vtable = &_event_vtable;
- return _dom_event_initialise(doc, *evt);
+ return _dom_event_initialise(*evt);
}
/* Destructor */
@@ -43,11 +43,10 @@ void _dom_event_destroy(dom_event *evt)
}
/* Initialise function */
-dom_exception _dom_event_initialise(dom_document *doc, dom_event *evt)
+dom_exception _dom_event_initialise(dom_event *evt)
{
assert(doc != NULL);
- evt->doc = doc;
evt->stop = false;
evt->stop_now = false;
evt->prevent_default = false;
diff --git a/src/events/event.h b/src/events/event.h
index fa3d6b9..4835bd0 100644
--- a/src/events/event.h
+++ b/src/events/event.h
@@ -36,9 +36,6 @@ struct dom_event {
dom_string *namespace; /**< The namespace of this event */
- dom_document *doc;
- /**< The document which created this event */
-
bool stop; /**< Whether stopPropagation is called */
bool stop_now; /**< Whether stopImmediatePropagation is called */
bool prevent_default;
@@ -53,14 +50,11 @@ struct dom_event {
bool in_dispatch; /**< Whether this event is in dispatch */
};
-/* Constructor */
-dom_exception _dom_event_create(dom_document *doc, dom_event **evt);
-
/* Destructor */
void _dom_event_destroy(dom_event *evt);
/* Initialise function */
-dom_exception _dom_event_initialise(dom_document *doc, dom_event *evt);
+dom_exception _dom_event_initialise(dom_event *evt);
/* Finalise function */
void _dom_event_finalise(dom_event *evt);
diff --git a/src/events/keyboard_event.c b/src/events/keyboard_event.c
index 76f32ba..fb29c18 100644
--- a/src/events/keyboard_event.c
+++ b/src/events/keyboard_event.c
@@ -20,8 +20,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_keyboard_event_create(struct dom_document *doc,
- struct dom_keyboard_event **evt)
+dom_exception _dom_keyboard_event_create(struct dom_keyboard_event **evt)
{
*evt = malloc(sizeof(dom_keyboard_event));
if (*evt == NULL)
@@ -29,7 +28,7 @@ dom_exception _dom_keyboard_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_keyboard_event_initialise(doc, *evt);
+ return _dom_keyboard_event_initialise(*evt);
}
/* Destructor */
@@ -41,13 +40,12 @@ void _dom_keyboard_event_destroy(struct dom_keyboard_event *evt)
}
/* Initialise function */
-dom_exception _dom_keyboard_event_initialise(struct dom_document *doc,
- struct dom_keyboard_event *evt)
+dom_exception _dom_keyboard_event_initialise(struct dom_keyboard_event *evt)
{
evt->key_ident = NULL;
evt->modifier_state = 0;
- return _dom_ui_event_initialise(doc, &evt->base);
+ return _dom_ui_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/keyboard_event.h b/src/events/keyboard_event.h
index b51518f..d640bbb 100644
--- a/src/events/keyboard_event.h
+++ b/src/events/keyboard_event.h
@@ -32,15 +32,13 @@ struct dom_keyboard_event {
};
/* Constructor */
-dom_exception _dom_keyboard_event_create(struct dom_document *doc,
- struct dom_keyboard_event **evt);
+dom_exception _dom_keyboard_event_create(struct dom_keyboard_event **evt);
/* Destructor */
void _dom_keyboard_event_destroy(struct dom_keyboard_event *evt);
/* Initialise function */
-dom_exception _dom_keyboard_event_initialise(struct dom_document *doc,
- struct dom_keyboard_event *evt);
+dom_exception _dom_keyboard_event_initialise(struct dom_keyboard_event *evt);
/* Finalise function */
void _dom_keyboard_event_finalise(struct dom_keyboard_event *evt);
diff --git a/src/events/mouse_event.c b/src/events/mouse_event.c
index 3e76879..b3b2154 100644
--- a/src/events/mouse_event.c
+++ b/src/events/mouse_event.c
@@ -20,8 +20,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mouse_event_create(struct dom_document *doc,
- struct dom_mouse_event **evt)
+dom_exception _dom_mouse_event_create(struct dom_mouse_event **evt)
{
*evt = malloc(sizeof(dom_mouse_event));
if (*evt == NULL)
@@ -29,7 +28,7 @@ dom_exception _dom_mouse_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mouse_event_initialise(doc, *evt);
+ return _dom_mouse_event_initialise(*evt);
}
/* Destructor */
@@ -41,12 +40,11 @@ void _dom_mouse_event_destroy(struct dom_mouse_event *evt)
}
/* Initialise function */
-dom_exception _dom_mouse_event_initialise(struct dom_document *doc,
- struct dom_mouse_event *evt)
+dom_exception _dom_mouse_event_initialise(struct dom_mouse_event *evt)
{
evt->modifier_state = 0;
- return _dom_ui_event_initialise(doc, (dom_ui_event *) evt);
+ return _dom_ui_event_initialise((dom_ui_event *) evt);
}
/* The virtual destroy function */
diff --git a/src/events/mouse_event.h b/src/events/mouse_event.h
index e49bcd7..cb7a874 100644
--- a/src/events/mouse_event.h
+++ b/src/events/mouse_event.h
@@ -30,15 +30,13 @@ struct dom_mouse_event {
};
/* Constructor */
-dom_exception _dom_mouse_event_create(struct dom_document *doc,
- struct dom_mouse_event **evt);
+dom_exception _dom_mouse_event_create(struct dom_mouse_event **evt);
/* Destructor */
void _dom_mouse_event_destroy(struct dom_mouse_event *evt);
/* Initialise function */
-dom_exception _dom_mouse_event_initialise(struct dom_document *doc,
- struct dom_mouse_event *evt);
+dom_exception _dom_mouse_event_initialise(struct dom_mouse_event *evt);
/* Finalise function */
#define _dom_mouse_event_finalise _dom_ui_event_finalise
diff --git a/src/events/mouse_multi_wheel_event.c b/src/events/mouse_multi_wheel_event.c
index 35f91af..bcbe8d5 100644
--- a/src/events/mouse_multi_wheel_event.c
+++ b/src/events/mouse_multi_wheel_event.c
@@ -21,7 +21,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mouse_multi_wheel_event_create(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_create(
struct dom_mouse_multi_wheel_event **evt)
{
*evt = malloc(sizeof(dom_mouse_multi_wheel_event));
@@ -30,7 +30,7 @@ dom_exception _dom_mouse_multi_wheel_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mouse_multi_wheel_event_initialise(doc, *evt);
+ return _dom_mouse_multi_wheel_event_initialise(*evt);
}
/* Destructor */
@@ -43,10 +43,10 @@ void _dom_mouse_multi_wheel_event_destroy(
}
/* Initialise function */
-dom_exception _dom_mouse_multi_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_initialise(
struct dom_mouse_multi_wheel_event *evt)
{
- return _dom_mouse_event_initialise(doc, (dom_mouse_event *) evt);
+ return _dom_mouse_event_initialise((dom_mouse_event *) evt);
}
/* The virtual destroy function */
diff --git a/src/events/mouse_multi_wheel_event.h b/src/events/mouse_multi_wheel_event.h
index 0476911..2af1467 100644
--- a/src/events/mouse_multi_wheel_event.h
+++ b/src/events/mouse_multi_wheel_event.h
@@ -24,7 +24,7 @@ struct dom_mouse_multi_wheel_event {
};
/* Constructor */
-dom_exception _dom_mouse_multi_wheel_event_create(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_create(
struct dom_mouse_multi_wheel_event **evt);
/* Destructor */
@@ -32,7 +32,7 @@ void _dom_mouse_multi_wheel_event_destroy(
struct dom_mouse_multi_wheel_event *evt);
/* Initialise function */
-dom_exception _dom_mouse_multi_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_initialise(
struct dom_mouse_multi_wheel_event *evt);
/* Finalise function */
diff --git a/src/events/mouse_wheel_event.c b/src/events/mouse_wheel_event.c
index 778a53b..d59eab1 100644
--- a/src/events/mouse_wheel_event.c
+++ b/src/events/mouse_wheel_event.c
@@ -20,7 +20,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
+dom_exception _dom_mouse_wheel_event_create(
struct dom_mouse_wheel_event **evt)
{
*evt = malloc(sizeof(dom_mouse_wheel_event));
@@ -29,7 +29,7 @@ dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mouse_wheel_event_initialise(doc,
+ return _dom_mouse_wheel_event_initialise(
(dom_mouse_wheel_event *) *evt);
}
@@ -42,10 +42,10 @@ void _dom_mouse_wheel_event_destroy(struct dom_mouse_wheel_event *evt)
}
/* Initialise function */
-dom_exception _dom_mouse_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_wheel_event_initialise(
struct dom_mouse_wheel_event *evt)
{
- return _dom_mouse_event_initialise(doc, (dom_mouse_event *) evt);
+ return _dom_mouse_event_initialise((dom_mouse_event *) evt);
}
/* The virtual destroy function */
diff --git a/src/events/mouse_wheel_event.h b/src/events/mouse_wheel_event.h
index e78abf6..86f4919 100644
--- a/src/events/mouse_wheel_event.h
+++ b/src/events/mouse_wheel_event.h
@@ -22,14 +22,13 @@ struct dom_mouse_wheel_event {
};
/* Constructor */
-dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
- struct dom_mouse_wheel_event **evt);
+dom_exception _dom_mouse_wheel_event_create(struct dom_mouse_wheel_event **evt);
/* Destructor */
void _dom_mouse_wheel_event_destroy(struct dom_mouse_wheel_event *evt);
/* Initialise function */
-dom_exception _dom_mouse_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_wheel_event_initialise(
struct dom_mouse_wheel_event *evt);
/* Finalise function */
diff --git a/src/events/mutation_event.c b/src/events/mutation_event.c
index aeeefe7..df92c5f 100644
--- a/src/events/mutation_event.c
+++ b/src/events/mutation_event.c
@@ -8,7 +8,6 @@
#include <stdlib.h>
#include "events/mutation_event.h"
-#include "core/document.h"
static void _virtual_dom_mutation_event_destroy(struct dom_event *evt);
@@ -17,8 +16,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mutation_event_create(struct dom_document *doc,
- struct dom_mutation_event **evt)
+dom_exception _dom_mutation_event_create(struct dom_mutation_event **evt)
{
*evt = malloc(sizeof(dom_mutation_event));
if (*evt == NULL)
@@ -26,7 +24,7 @@ dom_exception _dom_mutation_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mutation_event_initialise(doc, *evt);
+ return _dom_mutation_event_initialise(*evt);
}
/* Destructor */
@@ -38,15 +36,14 @@ void _dom_mutation_event_destroy(struct dom_mutation_event *evt)
}
/* Initialise function */
-dom_exception _dom_mutation_event_initialise(struct dom_document *doc,
- struct dom_mutation_event *evt)
+dom_exception _dom_mutation_event_initialise(struct dom_mutation_event *evt)
{
evt->related_node = NULL;
evt->prev_value = NULL;
evt->new_value = NULL;
evt->attr_name = NULL;
- return _dom_event_initialise(doc, &evt->base);
+ return _dom_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/mutation_event.h b/src/events/mutation_event.h
index 142e18c..800f5c6 100644
--- a/src/events/mutation_event.h
+++ b/src/events/mutation_event.h
@@ -26,15 +26,13 @@ struct dom_mutation_event {
};
/* Constructor */
-dom_exception _dom_mutation_event_create(struct dom_document *doc,
- struct dom_mutation_event **evt);
+dom_exception _dom_mutation_event_create(struct dom_mutation_event **evt);
/* Destructor */
void _dom_mutation_event_destroy(struct dom_mutation_event *evt);
/* Initialise function */
-dom_exception _dom_mutation_event_initialise(struct dom_document *doc,
- struct dom_mutation_event *evt);
+dom_exception _dom_mutation_event_initialise(struct dom_mutation_event *evt);
/* Finalise function */
void _dom_mutation_event_finalise(struct dom_mutation_event *evt);
diff --git a/src/events/mutation_name_event.c b/src/events/mutation_name_event.c
index c5c9345..e0ba82e 100644
--- a/src/events/mutation_name_event.c
+++ b/src/events/mutation_name_event.c
@@ -19,7 +19,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_create(
struct dom_mutation_name_event **evt)
{
*evt = malloc(sizeof(dom_mutation_name_event));
@@ -28,7 +28,7 @@ dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mutation_name_event_initialise(doc, *evt);
+ return _dom_mutation_name_event_initialise(*evt);
}
/* Destructor */
@@ -40,13 +40,13 @@ void _dom_mutation_name_event_destroy(struct dom_mutation_name_event *evt)
}
/* Initialise function */
-dom_exception _dom_mutation_name_event_initialise(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_initialise(
struct dom_mutation_name_event *evt)
{
evt->prev_namespace = NULL;
evt->prev_nodename = NULL;
- return _dom_event_initialise(doc, (dom_event *) evt);
+ return _dom_event_initialise((dom_event *) evt);
}
/* Finalise function */
diff --git a/src/events/mutation_name_event.h b/src/events/mutation_name_event.h
index 8849059..c7bd13d 100644
--- a/src/events/mutation_name_event.h
+++ b/src/events/mutation_name_event.h
@@ -23,14 +23,14 @@ struct dom_mutation_name_event {
};
/* Constructor */
-dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_create(
struct dom_mutation_name_event **evt);
/* Destructor */
void _dom_mutation_name_event_destroy(struct dom_mutation_name_event *evt);
/* Initialise function */
-dom_exception _dom_mutation_name_event_initialise(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_initialise(
struct dom_mutation_name_event *evt);
/* Finalise function */
diff --git a/src/events/text_event.c b/src/events/text_event.c
index 8457fe8..3437716 100644
--- a/src/events/text_event.c
+++ b/src/events/text_event.c
@@ -17,8 +17,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_text_event_create(struct dom_document *doc,
- struct dom_text_event **evt)
+dom_exception _dom_text_event_create(struct dom_text_event **evt)
{
*evt = malloc(sizeof(dom_text_event));
if (*evt == NULL)
@@ -26,7 +25,7 @@ dom_exception _dom_text_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_text_event_initialise(doc, *evt);
+ return _dom_text_event_initialise(*evt);
}
/* Destructor */
@@ -38,11 +37,10 @@ void _dom_text_event_destroy(struct dom_text_event *evt)
}
/* Initialise function */
-dom_exception _dom_text_event_initialise(struct dom_document *doc,
- struct dom_text_event *evt)
+dom_exception _dom_text_event_initialise(struct dom_text_event *evt)
{
evt->data = NULL;
- return _dom_ui_event_initialise(doc, &evt->base);
+ return _dom_ui_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/text_event.h b/src/events/text_event.h
index 8d9f063..e35e71c 100644
--- a/src/events/text_event.h
+++ b/src/events/text_event.h
@@ -21,15 +21,13 @@ struct dom_text_event {
};
/* Constructor */
-dom_exception _dom_text_event_create(struct dom_document *doc,
- struct dom_text_event **evt);
+dom_exception _dom_text_event_create(struct dom_text_event **evt);
/* Destructor */
void _dom_text_event_destroy(struct dom_text_event *evt);
/* Initialise function */
-dom_exception _dom_text_event_initialise(struct dom_document *doc,
- struct dom_text_event *evt);
+dom_exception _dom_text_event_initialise(struct dom_text_event *evt);
/* Finalise function */
void _dom_text_event_finalise(struct dom_text_event *evt);
diff --git a/src/events/ui_event.c b/src/events/ui_event.c
index 911b0d0..4fac3b6 100644
--- a/src/events/ui_event.c
+++ b/src/events/ui_event.c
@@ -8,7 +8,6 @@
#include <stdlib.h>
#include "events/ui_event.h"
-#include "core/document.h"
static void _virtual_dom_ui_event_destroy(struct dom_event *evt);
@@ -17,8 +16,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_ui_event_create(struct dom_document *doc,
- struct dom_ui_event **evt)
+dom_exception _dom_ui_event_create(struct dom_ui_event **evt)
{
*evt = malloc(sizeof(dom_ui_event));
if (*evt == NULL)
@@ -26,7 +24,7 @@ dom_exception _dom_ui_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_ui_event_initialise(doc, *evt);
+ return _dom_ui_event_initialise(*evt);
}
/* Destructor */
@@ -38,11 +36,10 @@ void _dom_ui_event_destroy(struct dom_ui_event *evt)
}
/* Initialise function */
-dom_exception _dom_ui_event_initialise(struct dom_document *doc,
- struct dom_ui_event *evt)
+dom_exception _dom_ui_event_initialise(struct dom_ui_event *evt)
{
evt->view = NULL;
- return _dom_event_initialise(doc, &evt->base);
+ return _dom_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/ui_event.h b/src/events/ui_event.h
index e60ed35..8f57677 100644
--- a/src/events/ui_event.h
+++ b/src/events/ui_event.h
@@ -36,15 +36,13 @@ struct dom_ui_event {
};
/* Constructor */
-dom_exception _dom_ui_event_create(struct dom_document *doc,
- struct dom_ui_event **evt);
+dom_exception _dom_ui_event_create(struct dom_ui_event **evt);
/* Destructor */
void _dom_ui_event_destroy(struct dom_ui_event *evt);
/* Initialise function */
-dom_exception _dom_ui_event_initialise(struct dom_document *doc,
- struct dom_ui_event *evt);
+dom_exception _dom_ui_event_initialise(struct dom_ui_event *evt);
/* Finalise function */
void _dom_ui_event_finalise(struct dom_ui_event *evt);
-----------------------------------------------------------------------
Summary of changes:
include/dom/events/event.h | 3 +++
src/core/document.c | 4 ++--
src/core/node.c | 3 ---
src/events/custom_event.c | 10 ++++-----
src/events/custom_event.h | 6 ++---
src/events/dispatch.c | 14 +++++++-----
src/events/document_event.c | 41 +++++++++++++---------------------
src/events/document_event.h | 4 ++--
src/events/event.c | 7 +++---
src/events/event.h | 8 +------
src/events/keyboard_event.c | 10 ++++-----
src/events/keyboard_event.h | 6 ++---
src/events/mouse_event.c | 10 ++++-----
src/events/mouse_event.h | 6 ++---
src/events/mouse_multi_wheel_event.c | 8 +++----
src/events/mouse_multi_wheel_event.h | 4 ++--
src/events/mouse_wheel_event.c | 8 +++----
src/events/mouse_wheel_event.h | 5 ++---
src/events/mutation_event.c | 11 ++++-----
src/events/mutation_event.h | 6 ++---
src/events/mutation_name_event.c | 8 +++----
src/events/mutation_name_event.h | 4 ++--
src/events/text_event.c | 10 ++++-----
src/events/text_event.h | 6 ++---
src/events/ui_event.c | 11 ++++-----
src/events/ui_event.h | 6 ++---
26 files changed, 89 insertions(+), 130 deletions(-)
diff --git a/include/dom/events/event.h b/include/dom/events/event.h
index 73e7ec0..e33758a 100644
--- a/include/dom/events/event.h
+++ b/include/dom/events/event.h
@@ -27,6 +27,9 @@ void _dom_event_ref(dom_event *evt);
void _dom_event_unref(dom_event *evt);
#define dom_event_unref(n) _dom_event_unref((dom_event *) (n))
+dom_exception _dom_event_create(dom_event **evt);
+#define dom_event_create(n) _dom_event_create((dom_event **) (n))
+
dom_exception _dom_event_get_type(dom_event *evt, dom_string **type);
#define dom_event_get_type(e, t) _dom_event_get_type((dom_event *) (e), \
(dom_string **) (t))
diff --git a/src/core/document.c b/src/core/document.c
index a78cde9..b68a066 100644
--- a/src/core/document.c
+++ b/src/core/document.c
@@ -266,7 +266,7 @@ dom_exception _dom_document_initialise(dom_document *doc,
}
/* We should not pass a NULL when all things hook up */
- return _dom_document_event_internal_initialise(doc, &doc->dei, daf, daf_ctx);
+ return _dom_document_event_internal_initialise(&doc->dei, daf, daf_ctx);
}
@@ -309,7 +309,7 @@ bool _dom_document_finalise(dom_document *doc)
dom_string_unref(doc->_memo_domcharacterdatamodified);
dom_string_unref(doc->_memo_domsubtreemodified);
- _dom_document_event_internal_finalise(doc, &doc->dei);
+ _dom_document_event_internal_finalise(&doc->dei);
return true;
}
diff --git a/src/core/node.c b/src/core/node.c
index e500f3a..49033c0 100644
--- a/src/core/node.c
+++ b/src/core/node.c
@@ -2360,9 +2360,6 @@ dom_exception _dom_node_dispatch_event(dom_event_target *et,
return DOM_UNSPECIFIED_EVENT_TYPE_ERR;
}
- if (evt->doc == NULL)
- return DOM_NOT_SUPPORTED_ERR;
-
doc = dom_node_get_owner(et);
if (doc == NULL) {
/* TODO: In the progress of parsing, many Nodes in the DTD has
diff --git a/src/events/custom_event.c b/src/events/custom_event.c
index 76d09bf..c3a99f9 100644
--- a/src/events/custom_event.c
+++ b/src/events/custom_event.c
@@ -18,8 +18,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_custom_event_create(struct dom_document *doc,
- struct dom_custom_event **evt)
+dom_exception _dom_custom_event_create(struct dom_custom_event **evt)
{
*evt = malloc(sizeof(dom_custom_event));
if (*evt == NULL)
@@ -27,7 +26,7 @@ dom_exception _dom_custom_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_custom_event_initialise(doc, *evt);
+ return _dom_custom_event_initialise(*evt);
}
/* Destructor */
@@ -39,11 +38,10 @@ void _dom_custom_event_destroy(struct dom_custom_event *evt)
}
/* Initialise function */
-dom_exception _dom_custom_event_initialise(struct dom_document *doc,
- struct dom_custom_event *evt)
+dom_exception _dom_custom_event_initialise(struct dom_custom_event *evt)
{
evt->detail = NULL;
- return _dom_event_initialise(doc, &evt->base);
+ return _dom_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/custom_event.h b/src/events/custom_event.h
index ed5d624..4c7a6fc 100644
--- a/src/events/custom_event.h
+++ b/src/events/custom_event.h
@@ -18,15 +18,13 @@ struct dom_custom_event {
};
/* Constructor */
-dom_exception _dom_custom_event_create(struct dom_document *doc,
- struct dom_custom_event **evt);
+dom_exception _dom_custom_event_create(struct dom_custom_event **evt);
/* Destructor */
void _dom_custom_event_destroy(struct dom_custom_event *evt);
/* Initialise function */
-dom_exception _dom_custom_event_initialise(struct dom_document *doc,
- struct dom_custom_event *evt);
+dom_exception _dom_custom_event_initialise(struct dom_custom_event *evt);
/* Finalise function */
void _dom_custom_event_finalise(struct dom_custom_event *evt);
diff --git a/src/events/dispatch.c b/src/events/dispatch.c
index 64664c7..0e0048d 100644
--- a/src/events/dispatch.c
+++ b/src/events/dispatch.c
@@ -31,7 +31,7 @@ dom_exception __dom_dispatch_node_change_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -77,7 +77,7 @@ dom_exception __dom_dispatch_node_change_document_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -128,7 +128,7 @@ dom_exception __dom_dispatch_attr_modified_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -172,7 +172,7 @@ dom_exception __dom_dispatch_characterdata_modified_event(
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -208,7 +208,7 @@ dom_exception __dom_dispatch_subtree_modified_event(dom_document *doc,
dom_string *type = NULL;
dom_exception err;
- err = _dom_mutation_event_create(doc, &evt);
+ err = _dom_mutation_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
@@ -248,7 +248,9 @@ dom_exception _dom_dispatch_generic_event(dom_document *doc,
struct dom_event *evt;
dom_exception err;
- err = _dom_event_create(doc, &evt);
+ UNUSED(doc);
+
+ err = _dom_event_create(&evt);
if (err != DOM_NO_ERR)
return err;
diff --git a/src/events/document_event.c b/src/events/document_event.c
index cd312ea..edabd92 100644
--- a/src/events/document_event.c
+++ b/src/events/document_event.c
@@ -43,13 +43,12 @@ static const char *__event_types[] = {
/**
* Initialise this DocumentEvent
*
- * \param doc The document object
* \param dei The DocumentEvent internal object
* \param actions The default action fetcher, the browser should provide such
* a function to Event module.
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
-dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
+dom_exception _dom_document_event_internal_initialise(
dom_document_event_internal *dei,
dom_events_default_action_fetcher actions,
void *actions_ctx)
@@ -57,8 +56,6 @@ dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
lwc_error err;
int i;
- UNUSED(doc);
-
for (i = 0; i < DOM_EVENT_COUNT; i++) {
err = lwc_intern_string(__event_types[i],
strlen(__event_types[i]), &dei->event_types[i]);
@@ -73,13 +70,10 @@ dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
}
/* Finalise this DocumentEvent */
-void _dom_document_event_internal_finalise(struct dom_document *doc,
- dom_document_event_internal *dei)
+void _dom_document_event_internal_finalise(dom_document_event_internal *dei)
{
int i;
- UNUSED(doc);
-
for (i = 0; i < DOM_EVENT_COUNT; i++) {
if (dei->event_types[i] != NULL)
lwc_string_unref(dei->event_types[i]);
@@ -100,17 +94,17 @@ void _dom_document_event_internal_finalise(struct dom_document *doc,
* \return DOM_NO_ERR on success, appropriate dom_exception on failure.
*/
dom_exception _dom_document_event_create_event(dom_document_event *de,
- dom_string *type, struct dom_event **evt)
+ dom_string *type,
+ struct dom_event **evt)
{
lwc_string *t = NULL;
dom_exception err;
- struct dom_document *doc = de;
int i, et = 0;
dom_document_event_internal *dei;
err = dom_string_intern(type, &t);
if (err != DOM_NO_ERR)
- return err;
+ return err;
assert(t != NULL);
@@ -125,41 +119,39 @@ dom_exception _dom_document_event_create_event(dom_document_event *de,
switch (et) {
case DOM_EVENT:
- err = _dom_event_create(doc, evt);
+ err = _dom_event_create(evt);
break;
case DOM_CUSTOM_EVENT:
- err = _dom_custom_event_create(doc,
- (dom_custom_event **) evt);
+ err = _dom_custom_event_create((dom_custom_event **) evt);
break;
case DOM_UI_EVENT:
- err = _dom_ui_event_create(doc, (dom_ui_event **) evt);
+ err = _dom_ui_event_create((dom_ui_event **) evt);
break;
case DOM_TEXT_EVENT:
- err = _dom_text_event_create(doc,
- (dom_text_event **) evt);
+ err = _dom_text_event_create((dom_text_event **) evt);
break;
case DOM_KEYBOARD_EVENT:
- err = _dom_keyboard_event_create(doc,
+ err = _dom_keyboard_event_create(
(dom_keyboard_event **) evt);
break;
case DOM_MOUSE_EVENT:
- err = _dom_mouse_event_create(doc,
+ err = _dom_mouse_event_create(
(dom_mouse_event **) evt);
break;
case DOM_MOUSE_MULTI_WHEEL_EVENT:
- err = _dom_mouse_multi_wheel_event_create(doc,
+ err = _dom_mouse_multi_wheel_event_create(
(dom_mouse_multi_wheel_event **) evt);
break;
case DOM_MOUSE_WHEEL_EVENT:
- err = _dom_mouse_wheel_event_create(doc,
+ err = _dom_mouse_wheel_event_create(
(dom_mouse_wheel_event **) evt);
break;
case DOM_MUTATION_EVENT:
- err = _dom_mutation_event_create(doc,
+ err = _dom_mutation_event_create(
(dom_mutation_event **) evt);
break;
case DOM_MUTATION_NAME_EVENT:
- err = _dom_mutation_name_event_create(doc,
+ err = _dom_mutation_name_event_create(
(dom_mutation_name_event **) evt);
break;
}
@@ -180,8 +172,7 @@ dom_exception _dom_document_event_create_event(dom_document_event *de,
* DOM_NO_SUPPORTED_ERR.
*/
dom_exception _dom_document_event_can_dispatch(dom_document_event *de,
- dom_string *namespace, dom_string *type,
- bool *can)
+ dom_string *namespace, dom_string *type, bool *can)
{
UNUSED(de);
UNUSED(namespace);
diff --git a/src/events/document_event.h b/src/events/document_event.h
index 1e04045..fbc5542 100644
--- a/src/events/document_event.h
+++ b/src/events/document_event.h
@@ -52,13 +52,13 @@ typedef struct dom_document_event_internal dom_document_event_internal;
*/
/* Initialise this DocumentEvent */
-dom_exception _dom_document_event_internal_initialise(struct dom_document *doc,
+dom_exception _dom_document_event_internal_initialise(
dom_document_event_internal *dei,
dom_events_default_action_fetcher actions,
void *actions_ctx);
/* Finalise this DocumentEvent */
-void _dom_document_event_internal_finalise(struct dom_document *doc,
+void _dom_document_event_internal_finalise(
dom_document_event_internal *dei);
#endif
diff --git a/src/events/event.c b/src/events/event.c
index 8af111b..ebd4854 100644
--- a/src/events/event.c
+++ b/src/events/event.c
@@ -23,7 +23,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_event_create(dom_document *doc, dom_event **evt)
+dom_exception _dom_event_create(dom_event **evt)
{
*evt = (dom_event *) malloc(sizeof(dom_event));
if (*evt == NULL)
@@ -31,7 +31,7 @@ dom_exception _dom_event_create(dom_document *doc, dom_event **evt)
(*evt)->vtable = &_event_vtable;
- return _dom_event_initialise(doc, *evt);
+ return _dom_event_initialise(*evt);
}
/* Destructor */
@@ -43,11 +43,10 @@ void _dom_event_destroy(dom_event *evt)
}
/* Initialise function */
-dom_exception _dom_event_initialise(dom_document *doc, dom_event *evt)
+dom_exception _dom_event_initialise(dom_event *evt)
{
assert(doc != NULL);
- evt->doc = doc;
evt->stop = false;
evt->stop_now = false;
evt->prevent_default = false;
diff --git a/src/events/event.h b/src/events/event.h
index fa3d6b9..4835bd0 100644
--- a/src/events/event.h
+++ b/src/events/event.h
@@ -36,9 +36,6 @@ struct dom_event {
dom_string *namespace; /**< The namespace of this event */
- dom_document *doc;
- /**< The document which created this event */
-
bool stop; /**< Whether stopPropagation is called */
bool stop_now; /**< Whether stopImmediatePropagation is called */
bool prevent_default;
@@ -53,14 +50,11 @@ struct dom_event {
bool in_dispatch; /**< Whether this event is in dispatch */
};
-/* Constructor */
-dom_exception _dom_event_create(dom_document *doc, dom_event **evt);
-
/* Destructor */
void _dom_event_destroy(dom_event *evt);
/* Initialise function */
-dom_exception _dom_event_initialise(dom_document *doc, dom_event *evt);
+dom_exception _dom_event_initialise(dom_event *evt);
/* Finalise function */
void _dom_event_finalise(dom_event *evt);
diff --git a/src/events/keyboard_event.c b/src/events/keyboard_event.c
index 76f32ba..fb29c18 100644
--- a/src/events/keyboard_event.c
+++ b/src/events/keyboard_event.c
@@ -20,8 +20,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_keyboard_event_create(struct dom_document *doc,
- struct dom_keyboard_event **evt)
+dom_exception _dom_keyboard_event_create(struct dom_keyboard_event **evt)
{
*evt = malloc(sizeof(dom_keyboard_event));
if (*evt == NULL)
@@ -29,7 +28,7 @@ dom_exception _dom_keyboard_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_keyboard_event_initialise(doc, *evt);
+ return _dom_keyboard_event_initialise(*evt);
}
/* Destructor */
@@ -41,13 +40,12 @@ void _dom_keyboard_event_destroy(struct dom_keyboard_event *evt)
}
/* Initialise function */
-dom_exception _dom_keyboard_event_initialise(struct dom_document *doc,
- struct dom_keyboard_event *evt)
+dom_exception _dom_keyboard_event_initialise(struct dom_keyboard_event *evt)
{
evt->key_ident = NULL;
evt->modifier_state = 0;
- return _dom_ui_event_initialise(doc, &evt->base);
+ return _dom_ui_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/keyboard_event.h b/src/events/keyboard_event.h
index b51518f..d640bbb 100644
--- a/src/events/keyboard_event.h
+++ b/src/events/keyboard_event.h
@@ -32,15 +32,13 @@ struct dom_keyboard_event {
};
/* Constructor */
-dom_exception _dom_keyboard_event_create(struct dom_document *doc,
- struct dom_keyboard_event **evt);
+dom_exception _dom_keyboard_event_create(struct dom_keyboard_event **evt);
/* Destructor */
void _dom_keyboard_event_destroy(struct dom_keyboard_event *evt);
/* Initialise function */
-dom_exception _dom_keyboard_event_initialise(struct dom_document *doc,
- struct dom_keyboard_event *evt);
+dom_exception _dom_keyboard_event_initialise(struct dom_keyboard_event *evt);
/* Finalise function */
void _dom_keyboard_event_finalise(struct dom_keyboard_event *evt);
diff --git a/src/events/mouse_event.c b/src/events/mouse_event.c
index 3e76879..b3b2154 100644
--- a/src/events/mouse_event.c
+++ b/src/events/mouse_event.c
@@ -20,8 +20,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mouse_event_create(struct dom_document *doc,
- struct dom_mouse_event **evt)
+dom_exception _dom_mouse_event_create(struct dom_mouse_event **evt)
{
*evt = malloc(sizeof(dom_mouse_event));
if (*evt == NULL)
@@ -29,7 +28,7 @@ dom_exception _dom_mouse_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mouse_event_initialise(doc, *evt);
+ return _dom_mouse_event_initialise(*evt);
}
/* Destructor */
@@ -41,12 +40,11 @@ void _dom_mouse_event_destroy(struct dom_mouse_event *evt)
}
/* Initialise function */
-dom_exception _dom_mouse_event_initialise(struct dom_document *doc,
- struct dom_mouse_event *evt)
+dom_exception _dom_mouse_event_initialise(struct dom_mouse_event *evt)
{
evt->modifier_state = 0;
- return _dom_ui_event_initialise(doc, (dom_ui_event *) evt);
+ return _dom_ui_event_initialise((dom_ui_event *) evt);
}
/* The virtual destroy function */
diff --git a/src/events/mouse_event.h b/src/events/mouse_event.h
index e49bcd7..cb7a874 100644
--- a/src/events/mouse_event.h
+++ b/src/events/mouse_event.h
@@ -30,15 +30,13 @@ struct dom_mouse_event {
};
/* Constructor */
-dom_exception _dom_mouse_event_create(struct dom_document *doc,
- struct dom_mouse_event **evt);
+dom_exception _dom_mouse_event_create(struct dom_mouse_event **evt);
/* Destructor */
void _dom_mouse_event_destroy(struct dom_mouse_event *evt);
/* Initialise function */
-dom_exception _dom_mouse_event_initialise(struct dom_document *doc,
- struct dom_mouse_event *evt);
+dom_exception _dom_mouse_event_initialise(struct dom_mouse_event *evt);
/* Finalise function */
#define _dom_mouse_event_finalise _dom_ui_event_finalise
diff --git a/src/events/mouse_multi_wheel_event.c b/src/events/mouse_multi_wheel_event.c
index 35f91af..bcbe8d5 100644
--- a/src/events/mouse_multi_wheel_event.c
+++ b/src/events/mouse_multi_wheel_event.c
@@ -21,7 +21,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mouse_multi_wheel_event_create(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_create(
struct dom_mouse_multi_wheel_event **evt)
{
*evt = malloc(sizeof(dom_mouse_multi_wheel_event));
@@ -30,7 +30,7 @@ dom_exception _dom_mouse_multi_wheel_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mouse_multi_wheel_event_initialise(doc, *evt);
+ return _dom_mouse_multi_wheel_event_initialise(*evt);
}
/* Destructor */
@@ -43,10 +43,10 @@ void _dom_mouse_multi_wheel_event_destroy(
}
/* Initialise function */
-dom_exception _dom_mouse_multi_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_initialise(
struct dom_mouse_multi_wheel_event *evt)
{
- return _dom_mouse_event_initialise(doc, (dom_mouse_event *) evt);
+ return _dom_mouse_event_initialise((dom_mouse_event *) evt);
}
/* The virtual destroy function */
diff --git a/src/events/mouse_multi_wheel_event.h b/src/events/mouse_multi_wheel_event.h
index 0476911..2af1467 100644
--- a/src/events/mouse_multi_wheel_event.h
+++ b/src/events/mouse_multi_wheel_event.h
@@ -24,7 +24,7 @@ struct dom_mouse_multi_wheel_event {
};
/* Constructor */
-dom_exception _dom_mouse_multi_wheel_event_create(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_create(
struct dom_mouse_multi_wheel_event **evt);
/* Destructor */
@@ -32,7 +32,7 @@ void _dom_mouse_multi_wheel_event_destroy(
struct dom_mouse_multi_wheel_event *evt);
/* Initialise function */
-dom_exception _dom_mouse_multi_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_multi_wheel_event_initialise(
struct dom_mouse_multi_wheel_event *evt);
/* Finalise function */
diff --git a/src/events/mouse_wheel_event.c b/src/events/mouse_wheel_event.c
index 778a53b..d59eab1 100644
--- a/src/events/mouse_wheel_event.c
+++ b/src/events/mouse_wheel_event.c
@@ -20,7 +20,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
+dom_exception _dom_mouse_wheel_event_create(
struct dom_mouse_wheel_event **evt)
{
*evt = malloc(sizeof(dom_mouse_wheel_event));
@@ -29,7 +29,7 @@ dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mouse_wheel_event_initialise(doc,
+ return _dom_mouse_wheel_event_initialise(
(dom_mouse_wheel_event *) *evt);
}
@@ -42,10 +42,10 @@ void _dom_mouse_wheel_event_destroy(struct dom_mouse_wheel_event *evt)
}
/* Initialise function */
-dom_exception _dom_mouse_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_wheel_event_initialise(
struct dom_mouse_wheel_event *evt)
{
- return _dom_mouse_event_initialise(doc, (dom_mouse_event *) evt);
+ return _dom_mouse_event_initialise((dom_mouse_event *) evt);
}
/* The virtual destroy function */
diff --git a/src/events/mouse_wheel_event.h b/src/events/mouse_wheel_event.h
index e78abf6..86f4919 100644
--- a/src/events/mouse_wheel_event.h
+++ b/src/events/mouse_wheel_event.h
@@ -22,14 +22,13 @@ struct dom_mouse_wheel_event {
};
/* Constructor */
-dom_exception _dom_mouse_wheel_event_create(struct dom_document *doc,
- struct dom_mouse_wheel_event **evt);
+dom_exception _dom_mouse_wheel_event_create(struct dom_mouse_wheel_event **evt);
/* Destructor */
void _dom_mouse_wheel_event_destroy(struct dom_mouse_wheel_event *evt);
/* Initialise function */
-dom_exception _dom_mouse_wheel_event_initialise(struct dom_document *doc,
+dom_exception _dom_mouse_wheel_event_initialise(
struct dom_mouse_wheel_event *evt);
/* Finalise function */
diff --git a/src/events/mutation_event.c b/src/events/mutation_event.c
index aeeefe7..df92c5f 100644
--- a/src/events/mutation_event.c
+++ b/src/events/mutation_event.c
@@ -8,7 +8,6 @@
#include <stdlib.h>
#include "events/mutation_event.h"
-#include "core/document.h"
static void _virtual_dom_mutation_event_destroy(struct dom_event *evt);
@@ -17,8 +16,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mutation_event_create(struct dom_document *doc,
- struct dom_mutation_event **evt)
+dom_exception _dom_mutation_event_create(struct dom_mutation_event **evt)
{
*evt = malloc(sizeof(dom_mutation_event));
if (*evt == NULL)
@@ -26,7 +24,7 @@ dom_exception _dom_mutation_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mutation_event_initialise(doc, *evt);
+ return _dom_mutation_event_initialise(*evt);
}
/* Destructor */
@@ -38,15 +36,14 @@ void _dom_mutation_event_destroy(struct dom_mutation_event *evt)
}
/* Initialise function */
-dom_exception _dom_mutation_event_initialise(struct dom_document *doc,
- struct dom_mutation_event *evt)
+dom_exception _dom_mutation_event_initialise(struct dom_mutation_event *evt)
{
evt->related_node = NULL;
evt->prev_value = NULL;
evt->new_value = NULL;
evt->attr_name = NULL;
- return _dom_event_initialise(doc, &evt->base);
+ return _dom_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/mutation_event.h b/src/events/mutation_event.h
index 142e18c..800f5c6 100644
--- a/src/events/mutation_event.h
+++ b/src/events/mutation_event.h
@@ -26,15 +26,13 @@ struct dom_mutation_event {
};
/* Constructor */
-dom_exception _dom_mutation_event_create(struct dom_document *doc,
- struct dom_mutation_event **evt);
+dom_exception _dom_mutation_event_create(struct dom_mutation_event **evt);
/* Destructor */
void _dom_mutation_event_destroy(struct dom_mutation_event *evt);
/* Initialise function */
-dom_exception _dom_mutation_event_initialise(struct dom_document *doc,
- struct dom_mutation_event *evt);
+dom_exception _dom_mutation_event_initialise(struct dom_mutation_event *evt);
/* Finalise function */
void _dom_mutation_event_finalise(struct dom_mutation_event *evt);
diff --git a/src/events/mutation_name_event.c b/src/events/mutation_name_event.c
index c5c9345..e0ba82e 100644
--- a/src/events/mutation_name_event.c
+++ b/src/events/mutation_name_event.c
@@ -19,7 +19,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_create(
struct dom_mutation_name_event **evt)
{
*evt = malloc(sizeof(dom_mutation_name_event));
@@ -28,7 +28,7 @@ dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_mutation_name_event_initialise(doc, *evt);
+ return _dom_mutation_name_event_initialise(*evt);
}
/* Destructor */
@@ -40,13 +40,13 @@ void _dom_mutation_name_event_destroy(struct dom_mutation_name_event *evt)
}
/* Initialise function */
-dom_exception _dom_mutation_name_event_initialise(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_initialise(
struct dom_mutation_name_event *evt)
{
evt->prev_namespace = NULL;
evt->prev_nodename = NULL;
- return _dom_event_initialise(doc, (dom_event *) evt);
+ return _dom_event_initialise((dom_event *) evt);
}
/* Finalise function */
diff --git a/src/events/mutation_name_event.h b/src/events/mutation_name_event.h
index 8849059..c7bd13d 100644
--- a/src/events/mutation_name_event.h
+++ b/src/events/mutation_name_event.h
@@ -23,14 +23,14 @@ struct dom_mutation_name_event {
};
/* Constructor */
-dom_exception _dom_mutation_name_event_create(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_create(
struct dom_mutation_name_event **evt);
/* Destructor */
void _dom_mutation_name_event_destroy(struct dom_mutation_name_event *evt);
/* Initialise function */
-dom_exception _dom_mutation_name_event_initialise(struct dom_document *doc,
+dom_exception _dom_mutation_name_event_initialise(
struct dom_mutation_name_event *evt);
/* Finalise function */
diff --git a/src/events/text_event.c b/src/events/text_event.c
index 8457fe8..3437716 100644
--- a/src/events/text_event.c
+++ b/src/events/text_event.c
@@ -17,8 +17,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_text_event_create(struct dom_document *doc,
- struct dom_text_event **evt)
+dom_exception _dom_text_event_create(struct dom_text_event **evt)
{
*evt = malloc(sizeof(dom_text_event));
if (*evt == NULL)
@@ -26,7 +25,7 @@ dom_exception _dom_text_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_text_event_initialise(doc, *evt);
+ return _dom_text_event_initialise(*evt);
}
/* Destructor */
@@ -38,11 +37,10 @@ void _dom_text_event_destroy(struct dom_text_event *evt)
}
/* Initialise function */
-dom_exception _dom_text_event_initialise(struct dom_document *doc,
- struct dom_text_event *evt)
+dom_exception _dom_text_event_initialise(struct dom_text_event *evt)
{
evt->data = NULL;
- return _dom_ui_event_initialise(doc, &evt->base);
+ return _dom_ui_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/text_event.h b/src/events/text_event.h
index 8d9f063..e35e71c 100644
--- a/src/events/text_event.h
+++ b/src/events/text_event.h
@@ -21,15 +21,13 @@ struct dom_text_event {
};
/* Constructor */
-dom_exception _dom_text_event_create(struct dom_document *doc,
- struct dom_text_event **evt);
+dom_exception _dom_text_event_create(struct dom_text_event **evt);
/* Destructor */
void _dom_text_event_destroy(struct dom_text_event *evt);
/* Initialise function */
-dom_exception _dom_text_event_initialise(struct dom_document *doc,
- struct dom_text_event *evt);
+dom_exception _dom_text_event_initialise(struct dom_text_event *evt);
/* Finalise function */
void _dom_text_event_finalise(struct dom_text_event *evt);
diff --git a/src/events/ui_event.c b/src/events/ui_event.c
index 911b0d0..4fac3b6 100644
--- a/src/events/ui_event.c
+++ b/src/events/ui_event.c
@@ -8,7 +8,6 @@
#include <stdlib.h>
#include "events/ui_event.h"
-#include "core/document.h"
static void _virtual_dom_ui_event_destroy(struct dom_event *evt);
@@ -17,8 +16,7 @@ static struct dom_event_private_vtable _event_vtable = {
};
/* Constructor */
-dom_exception _dom_ui_event_create(struct dom_document *doc,
- struct dom_ui_event **evt)
+dom_exception _dom_ui_event_create(struct dom_ui_event **evt)
{
*evt = malloc(sizeof(dom_ui_event));
if (*evt == NULL)
@@ -26,7 +24,7 @@ dom_exception _dom_ui_event_create(struct dom_document *doc,
((struct dom_event *) *evt)->vtable = &_event_vtable;
- return _dom_ui_event_initialise(doc, *evt);
+ return _dom_ui_event_initialise(*evt);
}
/* Destructor */
@@ -38,11 +36,10 @@ void _dom_ui_event_destroy(struct dom_ui_event *evt)
}
/* Initialise function */
-dom_exception _dom_ui_event_initialise(struct dom_document *doc,
- struct dom_ui_event *evt)
+dom_exception _dom_ui_event_initialise(struct dom_ui_event *evt)
{
evt->view = NULL;
- return _dom_event_initialise(doc, &evt->base);
+ return _dom_event_initialise(&evt->base);
}
/* Finalise function */
diff --git a/src/events/ui_event.h b/src/events/ui_event.h
index e60ed35..8f57677 100644
--- a/src/events/ui_event.h
+++ b/src/events/ui_event.h
@@ -36,15 +36,13 @@ struct dom_ui_event {
};
/* Constructor */
-dom_exception _dom_ui_event_create(struct dom_document *doc,
- struct dom_ui_event **evt);
+dom_exception _dom_ui_event_create(struct dom_ui_event **evt);
/* Destructor */
void _dom_ui_event_destroy(struct dom_ui_event *evt);
/* Initialise function */
-dom_exception _dom_ui_event_initialise(struct dom_document *doc,
- struct dom_ui_event *evt);
+dom_exception _dom_ui_event_initialise(struct dom_ui_event *evt);
/* Finalise function */
void _dom_ui_event_finalise(struct dom_ui_event *evt);
--
Document Object Model library
8 years, 1 month
nsgenbind: branch master updated. release/0.1.2-56-g8912c51
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenbind.git/shortlog/8912c51fe275a7d8deb...
...commit http://git.netsurf-browser.org/nsgenbind.git/commit/8912c51fe275a7d8debe1...
...tree http://git.netsurf-browser.org/nsgenbind.git/tree/8912c51fe275a7d8debe12f...
The branch, master has been updated
via 8912c51fe275a7d8debe12f84f7e86ce4a240266 (commit)
from b0f64cff2c94d1a208528e2ed91c15ab037dbbb1 (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=8912c51fe275a7d8d...
commit 8912c51fe275a7d8debe12f84f7e86ce4a240266
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
only publicly export initialisors and finalisors if necessary
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");
-----------------------------------------------------------------------
Summary of changes:
src/duk-libdom-dictionary.c | 6 ++++++
src/duk-libdom-interface.c | 7 +++++++
src/duk-libdom.c | 39 ++++++++++++++++++++-------------------
3 files changed, 33 insertions(+), 19 deletions(-)
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");
--
NetSurf Generator for JavaScript bindings
8 years, 1 month
nsgenbind: branch master updated. release/0.1.2-55-gb0f64cf
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/nsgenbind.git/shortlog/b0f64cff2c94d1a2085...
...commit http://git.netsurf-browser.org/nsgenbind.git/commit/b0f64cff2c94d1a208528...
...tree http://git.netsurf-browser.org/nsgenbind.git/tree/b0f64cff2c94d1a208528e2...
The branch, master has been updated
via b0f64cff2c94d1a208528e2ed91c15ab037dbbb1 (commit)
from 56eee21ccb63cb7f040c5ce07bc226fbd229330d (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=b0f64cff2c94d1a20...
commit b0f64cff2c94d1a208528e2ed91c15ab037dbbb1
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
split up duk-libdom generation source as it had grown unweildy
diff --git a/src/Makefile b/src/Makefile
index 9905baf..3ecfbe1 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.c duk-libdom-interface.c duk-libdom-dictionary.c duk-libdom-common.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
SOURCES := $(SOURCES) $(BUILDDIR)/nsgenbind-parser.c $(BUILDDIR)/nsgenbind-lexer.c $(BUILDDIR)/webidl-parser.c $(BUILDDIR)/webidl-lexer.c
diff --git a/src/duk-libdom-common.c b/src/duk-libdom-common.c
new file mode 100644
index 0000000..9a0f660
--- /dev/null
+++ b/src/duk-libdom-common.c
@@ -0,0 +1,78 @@
+/* duktape 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(a)netsurf-browser.org>
+ */
+
+#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"
+
+#define NSGENBIND_PREFACE \
+ "/* Generated by nsgenbind\n" \
+ " *\n" \
+ " * nsgenbind is published under the MIT Licence.\n" \
+ " * nsgenbind is similar to a compiler is a purely transformative tool which\n" \
+ " * explicitly makes no copyright claim on this generated output\n" \
+ " */"
+
+/* exported interface documented in duk-libdom.h */
+int output_tool_preface(FILE* outf)
+{
+ fprintf(outf, "%s\n", NSGENBIND_PREFACE);
+
+ return 0;
+}
+
+/* exported interface documented in duk-libdom.h */
+int output_cdata(FILE* outf,
+ struct genbind_node *node,
+ 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 res;
+}
+
+/* exported interface documented in duk-libdom.h */
+int output_tool_prologue(FILE* outf)
+{
+ char *fpath;
+
+ fpath = genb_fpath("binding.h");
+ fprintf(outf, "\n#include \"%s\"\n", fpath);
+ free(fpath);
+
+ fpath = genb_fpath("private.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
+
+ fpath = genb_fpath("prototype.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
+
+ return 0;
+}
diff --git a/src/duk-libdom-dictionary.c b/src/duk-libdom-dictionary.c
new file mode 100644
index 0000000..275855e
--- /dev/null
+++ b/src/duk-libdom-dictionary.c
@@ -0,0 +1,571 @@
+/* duktape binding generation implementation
+ *
+ * This file is part of nsgenbind.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ */
+
+#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"
+
+/** prefix for all generated functions */
+#define DLPFX "dukky"
+
+#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
+
+/**
+ * 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, %s_magic_string_private);\n\n",
+ DLPFX);
+
+ 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, %s_magic_string_private);\n",
+ idx, DLPFX);
+ 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 the dictionary constructor
+ */
+static int
+output_dictionary_constructor(FILE* outf, struct ir_entry *dictionarye)
+{
+ int init_argc;
+
+ /* constructor definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
+ DLPFX, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ output_create_private(outf, dictionarye->class_name);
+
+ /* generate call to initialisor */
+ fprintf(outf,
+ "\t%s_%s___init(ctx, priv",
+ DLPFX, dictionarye->class_name);
+ for (init_argc = 1;
+ init_argc <= dictionarye->class_init_argc;
+ init_argc++) {
+ fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
+ }
+ fprintf(outf, ");\n");
+
+
+ fprintf(outf, "\tduk_set_top(ctx, 1);\n");
+ fprintf(outf, "\treturn 1;\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate a duktape prototype name
+ */
+static char *get_prototype_name(const char *dictionary_name)
+{
+ char *proto_name;
+ int pnamelen;
+ int pfxlen;
+
+ /* duplicate the dictionary name in upper case */
+ pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
+ pnamelen = strlen(dictionary_name) + 1;
+
+ proto_name = malloc(pnamelen + pfxlen);
+ snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, dictionary_name);
+ for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen + pfxlen] = toupper(dictionary_name[pnamelen]);
+ }
+ return proto_name;
+}
+
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *dictionary_name)
+{
+ char *proto_name;
+
+ proto_name = get_prototype_name(dictionary_name);
+
+ fprintf(outf,
+ "\t/* get prototype */\n");
+ fprintf(outf,
+ "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
+ DLPFX);
+ fprintf(outf,
+ "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
+ MAGICPFX);
+ fprintf(outf, "\tduk_pop(ctx);\n\n");
+
+ return 0;
+}
+
+/**
+ * generate the dictionary prototype creator
+ */
+static int
+output_dictionary_prototype(FILE* outf,
+ struct ir *ir,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *proto_node;
+
+ /* find the prototype method on the class */
+ proto_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_PROTOTYPE);
+
+ /* prototype definition */
+ fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
+ DLPFX, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ /* Output any binding data first */
+ if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
+ fprintf(outf,"\n");
+ }
+
+ /* generate prototype chaining if dictionary has a parent */
+ if (inherite != NULL) {
+ fprintf(outf,
+ "\t/* Set this prototype's prototype (left-parent) */\n");
+ output_get_prototype(outf, inherite->name);
+ fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
+ }
+
+ /* dictionary members*/
+
+
+ /* generate setting of destructor */
+ output_set_destructor(outf, dictionarye->class_name, 0);
+
+ /* generate setting of constructor */
+ output_set_constructor(outf,
+ dictionarye->class_name,
+ 0,
+ dictionarye->class_init_argc);
+
+ fprintf(outf,"\treturn 1; /* The prototype object */\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate the dictionary destructor
+ */
+static int
+output_dictionary_destructor(FILE* outf, struct ir_entry *dictionarye)
+{
+ /* destructor definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
+ DLPFX, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ output_safe_get_private(outf, dictionarye->class_name, 0);
+
+ /* generate call to finaliser */
+ fprintf(outf,
+ "\t%s_%s___fini(ctx, priv);\n",
+ DLPFX, dictionarye->class_name);
+
+ fprintf(outf,"\tfree(priv);\n");
+ fprintf(outf,"\treturn 0;\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate an initialisor call to parent dictionary
+ */
+static int
+output_dictionary_inherit_init(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *init_node;
+ struct genbind_node *inh_init_node;
+ struct genbind_node *param_node;
+ struct genbind_node *inh_param_node;
+
+ /* only need to call parent initialisor if there is one */
+ if (inherite == NULL) {
+ return 0;
+ }
+
+ /* find the initialisor method on the class (if any) */
+ init_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+
+ inh_init_node = genbind_node_find_method(inherite->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+
+
+ fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
+ DLPFX, inherite->class_name);
+
+ /* for each parameter in the parent find a matching named
+ * parameter to pass and cast if necessary
+ */
+
+ inh_param_node = genbind_node_find_type(
+ genbind_node_getnode(inh_init_node),
+ NULL, GENBIND_NODE_TYPE_PARAMETER);
+ while (inh_param_node != NULL) {
+ char *param_name;
+ param_name = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(inh_param_node),
+ NULL,
+ GENBIND_NODE_TYPE_IDENT));
+
+ param_node = genbind_node_find_type_ident(
+ genbind_node_getnode(init_node),
+ NULL,
+ GENBIND_NODE_TYPE_PARAMETER,
+ param_name);
+ if (param_node == NULL) {
+ fprintf(stderr, "class \"%s\" (dictionary %s) parent class \"%s\" (dictionary %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
+ dictionarye->class_name,
+ dictionarye->name,
+ inherite->class_name,
+ inherite->name,
+ param_name);
+ return -1;
+ } else {
+ char *param_type;
+ char *inh_param_type;
+
+ fprintf(outf, ", ");
+
+ /* cast the parameter if required */
+ param_type = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(param_node),
+ NULL,
+ GENBIND_NODE_TYPE_TYPE));
+
+ inh_param_type = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(inh_param_node),
+ NULL,
+ GENBIND_NODE_TYPE_TYPE));
+
+ if (strcmp(param_type, inh_param_type) != 0) {
+ fprintf(outf, "(%s)", inh_param_type);
+ }
+
+ /* output the parameter identifier */
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
+ }
+
+ inh_param_node = genbind_node_find_type(
+ genbind_node_getnode(inh_init_node),
+ inh_param_node, GENBIND_NODE_TYPE_METHOD);
+ }
+
+ fprintf(outf, ");\n");
+
+ return 0;
+}
+
+static int
+output_dictionary_init_declaration(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct genbind_node *init_node)
+{
+ struct genbind_node *param_node;
+
+ fprintf(outf,
+ "void %s_%s___init(duk_context *ctx, %s_private_t *priv",
+ DLPFX, dictionarye->class_name, dictionarye->class_name);
+
+ /* count the number of arguments on the initializer */
+ dictionarye->class_init_argc = 0;
+
+ /* output the paramters on the method (if any) */
+ param_node = genbind_node_find_type(
+ genbind_node_getnode(init_node),
+ NULL, GENBIND_NODE_TYPE_PARAMETER);
+ while (param_node != NULL) {
+ dictionarye->class_init_argc++;
+ fprintf(outf, ", ");
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
+
+ param_node = genbind_node_find_type(
+ genbind_node_getnode(init_node),
+ param_node, GENBIND_NODE_TYPE_PARAMETER);
+ }
+
+ fprintf(outf,")");
+
+ return 0;
+}
+
+static int
+output_dictionary_init(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *init_node;
+ int res;
+
+ /* find the initialisor method on the class (if any) */
+ init_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+ /* initialisor definition */
+ output_dictionary_init_declaration(outf, dictionarye, init_node);
+
+ fprintf(outf,"\n{\n");
+
+ /* if this dictionary inherits ensure we call its initialisor */
+ res = output_dictionary_inherit_init(outf, dictionarye, inherite);
+ if (res != 0) {
+ return res;
+ }
+
+ /* generate log statement */
+ if (options->dbglog) {
+ fprintf(outf,
+ "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
+ }
+
+ /* output the initaliser code from the binding */
+ output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+
+}
+
+static int
+output_dictionary_fini(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *fini_node;
+
+ /* find the finaliser method on the class (if any) */
+ fini_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_FINI);
+
+ /* finaliser definition */
+ fprintf(outf,
+ "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n",
+ DLPFX, dictionarye->class_name, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ /* generate log statement */
+ if (options->dbglog) {
+ fprintf(outf,
+ "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
+ }
+
+ /* output the finialisor code from the binding */
+ output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
+
+ /* if this dictionary inherits ensure we call its finaliser */
+ if (inherite != NULL) {
+ fprintf(outf,
+ "\t%s_%s___fini(ctx, &priv->parent);\n",
+ DLPFX, inherite->class_name);
+ }
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+
+/**
+ * generate a source file to implement a dictionary using duk and libdom.
+ */
+int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
+{
+ FILE *ifacef;
+ struct ir_entry *inherite;
+ int res = 0;
+
+ /* open output file */
+ ifacef = genb_fopen_tmp(dictionarye->filename);
+ if (ifacef == NULL) {
+ return -1;
+ }
+
+ /* find parent dictionary entry */
+ inherite = ir_inherit_entry(ir, dictionarye);
+
+ /* tool preface */
+ output_tool_preface(ifacef);
+
+ /* binding preface */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* class preface */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool prologue */
+ output_tool_prologue(ifacef);
+
+ /* binding prologue */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_PROLOGUE);
+
+ /* class prologue */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PROLOGUE);
+
+ fprintf(ifacef, "\n");
+
+ /* initialisor */
+ res = output_dictionary_init(ifacef, dictionarye, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* finaliser */
+ res = output_dictionary_fini(ifacef, dictionarye, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* constructor */
+ res = output_dictionary_constructor(ifacef, dictionarye);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* destructor */
+ res = output_dictionary_destructor(ifacef, dictionarye);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /** todo property handlers */
+
+ /* prototype */
+ res = output_dictionary_prototype(ifacef, ir, dictionarye, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ fprintf(ifacef, "\n");
+
+ /* class epilogue */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_EPILOGUE);
+
+ /* binding epilogue */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_EPILOGUE);
+
+ /* class postface */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_POSTFACE);
+
+ /* binding postface */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+op_error:
+ genb_fclose_tmp(ifacef, dictionarye->filename);
+
+ return res;
+}
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c
new file mode 100644
index 0000000..7501bea
--- /dev/null
+++ b/src/duk-libdom-interface.c
@@ -0,0 +1,1334 @@
+/* duktape binding generation implementation
+ *
+ * This file is part of nsgenbind.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ */
+
+#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"
+
+/** prefix for all generated functions */
+#define DLPFX "dukky"
+
+#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
+
+/**
+ * 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, %s_magic_string_private);\n\n",
+ DLPFX);
+
+ 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, %s_magic_string_private);\n",
+ idx, DLPFX);
+ 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 a duktape prototype name
+ */
+static char *get_prototype_name(const char *interface_name)
+{
+ char *proto_name;
+ int pnamelen;
+ int pfxlen;
+
+ /* duplicate the interface name in upper case */
+ pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
+ pnamelen = strlen(interface_name) + 1;
+
+ proto_name = malloc(pnamelen + pfxlen);
+ snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, interface_name);
+ for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen + pfxlen] = toupper(interface_name[pnamelen]);
+ }
+ return proto_name;
+}
+
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *interface_name)
+{
+ char *proto_name;
+
+ proto_name = get_prototype_name(interface_name);
+
+ fprintf(outf,
+ "\t/* get prototype */\n");
+ fprintf(outf,
+ "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
+ DLPFX);
+ fprintf(outf,
+ "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
+ MAGICPFX);
+ 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,
+ const char *class_name,
+ const char *method)
+{
+ 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, DUK_VARARGS);\n",
+ DLPFX, class_name, method);
+ 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);
+ output_dump_stack(outf);
+ fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
+ fprintf(outf, "\t\tDUK_DEFPROP_HAVE_SETTER |\n");
+ fprintf(outf, "\t\tDUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t\tDUK_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);
+ output_dump_stack(outf);
+ fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_GETTER |\n");
+ fprintf(outf, "\t\tDUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |\n");
+ fprintf(outf, "\t\tDUK_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, %s_magic_string_private);\n",
+ DLPFX);
+ fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
+ fprintf(outf, "\tduk_pop_2(ctx);\n");
+ fprintf(outf, "\tif (priv == NULL) {\n");
+ if (options->dbglog) {
+ fprintf(outf, "\t\tLOG(\"priv failed\");\n");
+ }
+ fprintf(outf, "\t\treturn 0; /* can do? No can do. */\n");
+ fprintf(outf, "\t}\n\n");
+
+ return 0;
+}
+
+
+/**
+ * generate the interface constructor
+ */
+static int
+output_interface_constructor(FILE* outf, struct ir_entry *interfacee)
+{
+ int init_argc;
+
+ /* constructor definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name);
+ fprintf(outf,"{\n");
+
+ output_create_private(outf, interfacee->class_name);
+
+ /* generate call to initialisor */
+ fprintf(outf,
+ "\t%s_%s___init(ctx, priv",
+ DLPFX, interfacee->class_name);
+ for (init_argc = 1;
+ init_argc <= interfacee->class_init_argc;
+ init_argc++) {
+ fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
+ }
+ fprintf(outf, ");\n");
+
+
+ fprintf(outf, "\tduk_set_top(ctx, 1);\n");
+ fprintf(outf, "\treturn 1;\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate the interface destructor
+ */
+static int
+output_interface_destructor(FILE* outf, struct ir_entry *interfacee)
+{
+ /* destructor definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name);
+ fprintf(outf,"{\n");
+
+ output_safe_get_private(outf, interfacee->class_name, 0);
+
+ /* generate call to finaliser */
+ fprintf(outf,
+ "\t%s_%s___fini(ctx, priv);\n",
+ DLPFX, interfacee->class_name);
+
+ fprintf(outf,"\tfree(priv);\n");
+ fprintf(outf,"\treturn 0;\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate an initialisor call to parent interface
+ */
+static int
+output_interface_inherit_init(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *init_node;
+ struct genbind_node *inh_init_node;
+ struct genbind_node *param_node;
+ struct genbind_node *inh_param_node;
+
+ /* only need to call parent initialisor if there is one */
+ if (inherite == NULL) {
+ return 0;
+ }
+
+ /* find the initialisor method on the class (if any) */
+ init_node = genbind_node_find_method(interfacee->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+
+ inh_init_node = genbind_node_find_method(inherite->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+
+
+ fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
+ DLPFX, inherite->class_name);
+
+ /* for each parameter in the parent find a matching named
+ * parameter to pass and cast if necessary
+ */
+
+ inh_param_node = genbind_node_find_type(
+ genbind_node_getnode(inh_init_node),
+ NULL, GENBIND_NODE_TYPE_PARAMETER);
+ while (inh_param_node != NULL) {
+ char *param_name;
+ param_name = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(inh_param_node),
+ NULL,
+ GENBIND_NODE_TYPE_IDENT));
+
+ param_node = genbind_node_find_type_ident(
+ genbind_node_getnode(init_node),
+ NULL,
+ GENBIND_NODE_TYPE_PARAMETER,
+ param_name);
+ if (param_node == NULL) {
+ fprintf(stderr, "class \"%s\" (interface %s) parent class \"%s\" (interface %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
+ interfacee->class_name,
+ interfacee->name,
+ inherite->class_name,
+ inherite->name,
+ param_name);
+ return -1;
+ } else {
+ char *param_type;
+ char *inh_param_type;
+
+ fprintf(outf, ", ");
+
+ /* cast the parameter if required */
+ param_type = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(param_node),
+ NULL,
+ GENBIND_NODE_TYPE_TYPE));
+
+ inh_param_type = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(inh_param_node),
+ NULL,
+ GENBIND_NODE_TYPE_TYPE));
+
+ if (strcmp(param_type, inh_param_type) != 0) {
+ fprintf(outf, "(%s)", inh_param_type);
+ }
+
+ /* output the parameter identifier */
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
+ }
+
+ inh_param_node = genbind_node_find_type(
+ genbind_node_getnode(inh_init_node),
+ inh_param_node, GENBIND_NODE_TYPE_METHOD);
+ }
+
+ fprintf(outf, ");\n");
+
+ return 0;
+}
+
+static int
+output_interface_init_declaration(FILE* outf,
+ struct ir_entry *interfacee,
+ struct genbind_node *init_node)
+{
+ struct genbind_node *param_node;
+
+ fprintf(outf,
+ "void %s_%s___init(duk_context *ctx, %s_private_t *priv",
+ DLPFX, interfacee->class_name, interfacee->class_name);
+
+ /* count the number of arguments on the initializer */
+ interfacee->class_init_argc = 0;
+
+ /* output the paramters on the method (if any) */
+ param_node = genbind_node_find_type(
+ genbind_node_getnode(init_node),
+ NULL, GENBIND_NODE_TYPE_PARAMETER);
+ while (param_node != NULL) {
+ interfacee->class_init_argc++;
+ fprintf(outf, ", ");
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
+
+ param_node = genbind_node_find_type(
+ genbind_node_getnode(init_node),
+ param_node, GENBIND_NODE_TYPE_PARAMETER);
+ }
+
+ fprintf(outf,")");
+
+ return 0;
+}
+
+static int
+output_interface_init(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_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);
+ if (res != 0) {
+ return res;
+ }
+
+ /* generate log statement */
+ if (options->dbglog) {
+ fprintf(outf,
+ "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
+ }
+
+ /* output the initaliser code from the binding */
+ output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+
+}
+
+static int
+output_interface_fini(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *fini_node;
+
+ /* find the finaliser method on the class (if any) */
+ fini_node = genbind_node_find_method(interfacee->class,
+ NULL,
+ GENBIND_METHOD_TYPE_FINI);
+
+ /* finaliser definition */
+ fprintf(outf,
+ "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n",
+ DLPFX, interfacee->class_name, interfacee->class_name);
+ fprintf(outf,"{\n");
+
+ /* generate log statement */
+ if (options->dbglog) {
+ fprintf(outf,
+ "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
+ }
+
+ /* output the finialisor code from the binding */
+ output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
+
+ /* if this interface inherits ensure we call its finaliser */
+ if (inherite != NULL) {
+ fprintf(outf,
+ "\t%s_%s___fini(ctx, &priv->parent);\n",
+ DLPFX, inherite->class_name);
+ }
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+
+/**
+ * generate a prototype add for a single class method
+ */
+static int
+output_prototype_method(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_operation_entry *operatione)
+{
+
+ if (operatione->name != NULL) {
+ /* normal method on prototype */
+ output_add_method(outf,
+ interfacee->class_name,
+ operatione->name);
+ } else {
+ /* special method on prototype */
+ fprintf(outf,
+ "\t/* Special method on prototype - UNIMPLEMENTED */\n\n");
+ }
+
+ return 0;
+}
+
+/**
+ * generate prototype method definitions
+ */
+static int
+output_prototype_methods(FILE *outf, struct ir_entry *entry)
+{
+ int opc;
+ int res = 0;
+
+ for (opc = 0; opc < entry->u.interface.operationc; opc++) {
+ res = output_prototype_method(
+ outf,
+ entry,
+ entry->u.interface.operationv + opc);
+ if (res != 0) {
+ break;
+ }
+ }
+
+ return res;
+}
+
+
+static int
+output_prototype_attribute(FILE *outf,
+ struct ir_entry *interfacee,
+ struct ir_attribute_entry *attributee)
+{
+ if (attributee->modifier == WEBIDL_TYPE_MODIFIER_READONLY) {
+ return output_populate_ro_property(outf,
+ interfacee->class_name,
+ attributee->name);
+ }
+ return output_populate_rw_property(outf,
+ interfacee->class_name,
+ attributee->name);
+}
+
+/**
+ * generate prototype attribute definitions
+ */
+static int
+output_prototype_attributes(FILE *outf, struct ir_entry *entry)
+{
+ int attrc;
+ int res = 0;
+
+ for (attrc = 0; attrc < entry->u.interface.attributec; attrc++) {
+ res = output_prototype_attribute(
+ outf,
+ entry,
+ entry->u.interface.attributev + attrc);
+ if (res != 0) {
+ break;
+ }
+ }
+
+ return res;
+}
+
+/**
+ * output constants on the prototype
+ *
+ * \todo This implementation assumes the constant is a literal int and should
+ * check the type node base value.
+ */
+static int
+output_prototype_constant(FILE *outf,
+ struct ir_constant_entry *constante)
+{
+ int *value;
+
+ value = webidl_node_getint(
+ webidl_node_find_type(
+ webidl_node_getnode(constante->node),
+ NULL,
+ WEBIDL_NODE_TYPE_LITERAL_INT));
+
+ output_prototype_constant_int(outf, constante->name, *value);
+
+ return 0;
+}
+
+/**
+ * generate prototype constant definitions
+ */
+static int
+output_prototype_constants(FILE *outf, struct ir_entry *entry)
+{
+ int attrc;
+ int res = 0;
+
+ for (attrc = 0; attrc < entry->u.interface.constantc; attrc++) {
+ res = output_prototype_constant(
+ outf,
+ entry->u.interface.constantv + attrc);
+ if (res != 0) {
+ break;
+ }
+ }
+
+ return res;
+}
+
+static int
+output_global_create_prototype(FILE* outf,
+ struct ir *ir,
+ struct ir_entry *interfacee)
+{
+ int idx;
+
+ fprintf(outf, "\t/* Create interface objects */\n");
+ for (idx = 0; idx < ir->entryc; idx++) {
+ struct ir_entry *entry;
+
+ entry = ir->entries + idx;
+
+ if (entry->type == IR_ENTRY_TYPE_INTERFACE) {
+
+ if (entry->u.interface.noobject) {
+ continue;
+ }
+
+ if (entry == interfacee) {
+ fprintf(outf, "\tduk_dup(ctx, 0);\n");
+ } else {
+ output_get_prototype(outf, entry->name);
+ }
+
+ fprintf(outf,
+ "\tdukky_inject_not_ctr(ctx, 0, \"%s\");\n",
+ entry->name);
+ }
+ }
+ return 0;
+}
+
+
+/**
+ * generate the interface prototype creator
+ */
+static int
+output_interface_prototype(FILE* outf,
+ struct ir *ir,
+ struct ir_entry *interfacee,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *proto_node;
+
+ /* find the prototype method on the class */
+ proto_node = genbind_node_find_method(interfacee->class,
+ NULL,
+ GENBIND_METHOD_TYPE_PROTOTYPE);
+
+ /* prototype definition */
+ fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name);
+ fprintf(outf,"{\n");
+
+ /* Output any binding data first */
+ if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
+ fprintf(outf,"\n");
+ }
+
+ /* generate prototype chaining if interface has a parent */
+ if (inherite != NULL) {
+ fprintf(outf,
+ "\t/* Set this prototype's prototype (left-parent) */\n");
+ output_get_prototype(outf, inherite->name);
+ fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
+ }
+
+ /* generate setting of methods */
+ output_prototype_methods(outf, interfacee);
+
+ /* generate setting of attributes */
+ output_prototype_attributes(outf, interfacee);
+
+ /* generate setting of constants */
+ output_prototype_constants(outf, interfacee);
+
+ /* if this is the global object, output all interfaces which do not
+ * prevent us from doing so
+ */
+ if (interfacee->u.interface.primary_global) {
+ output_global_create_prototype(outf, ir, interfacee);
+ }
+
+ /* generate setting of destructor */
+ output_set_destructor(outf, interfacee->class_name, 0);
+
+ /* generate setting of constructor */
+ output_set_constructor(outf,
+ interfacee->class_name,
+ 0,
+ interfacee->class_init_argc);
+
+ fprintf(outf,"\treturn 1; /* The prototype object */\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate a single class method for an interface operation with elipsis
+ */
+static int
+output_interface_elipsis_operation(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_operation_entry *operatione)
+{
+ int cdatac; /* cdata blocks output */
+
+ /* overloaded method definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name, operatione->name);
+ fprintf(outf,"{\n");
+
+ /**
+ * \todo This is where the checking of the parameters to the
+ * operation with elipsis should go
+ */
+ WARN(WARNING_UNIMPLEMENTED,
+ "Elipsis parameetrs not checked: method %s::%s();",
+ interfacee->name, operatione->name);
+
+ output_get_method_private(outf, interfacee->class_name);
+
+ cdatac = output_cdata(outf,
+ operatione->method,
+ GENBIND_NODE_TYPE_CDATA);
+
+ if (cdatac == 0) {
+ /* no implementation so generate default */
+ WARN(WARNING_UNIMPLEMENTED,
+ "Unimplemented: method %s::%s();",
+ interfacee->name, operatione->name);
+ fprintf(outf,"\treturn 0;\n");
+ }
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate a single class method for an interface overloaded operation
+ */
+static int
+output_interface_overloaded_operation(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_operation_entry *operatione)
+{
+ int cdatac; /* cdata blocks output */
+
+ /* overloaded method definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name, operatione->name);
+ fprintf(outf,"{\n");
+
+ /** \todo This is where the checking of the parameters to the
+ * overloaded operation should go
+ */
+
+ output_get_method_private(outf, interfacee->class_name);
+
+ cdatac = output_cdata(outf,
+ operatione->method,
+ GENBIND_NODE_TYPE_CDATA);
+
+ if (cdatac == 0) {
+ /* no implementation so generate default */
+ WARN(WARNING_UNIMPLEMENTED,
+ "Unimplemented: method %s::%s();",
+ interfacee->name, operatione->name);
+ fprintf(outf,"\treturn 0;\n");
+ }
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate a single class method for an interface special operation
+ */
+static int
+output_interface_special_operation(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_operation_entry *operatione)
+{
+ /* special method definition */
+ fprintf(outf, "/* Special method definition - UNIMPLEMENTED */\n\n");
+
+ WARN(WARNING_UNIMPLEMENTED,
+ "Special operation on interface %s (operation entry %p)",
+ interfacee->name,
+ operatione);
+
+ return 0;
+}
+
+/**
+ * generate default values on the duk stack
+ */
+static int
+output_operation_optional_defaults(FILE* outf,
+ struct ir_operation_argument_entry *argumentv,
+ int argumentc)
+{
+ int argc;
+ for (argc = 0; argc < argumentc; argc++) {
+ struct ir_operation_argument_entry *cure;
+ struct webidl_node *lit_node; /* literal node */
+ enum webidl_node_type lit_type;
+ int *lit_int;
+ char *lit_str;
+
+ cure = argumentv + argc;
+
+ lit_node = webidl_node_getnode(
+ webidl_node_find_type(
+ webidl_node_getnode(cure->node),
+ NULL,
+ WEBIDL_NODE_TYPE_OPTIONAL));
+
+ if (lit_node != NULL) {
+
+ lit_type = webidl_node_gettype(lit_node);
+
+ switch (lit_type) {
+ case WEBIDL_NODE_TYPE_LITERAL_NULL:
+ fprintf(outf,
+ "\t\tduk_push_null(ctx);\n");
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_INT:
+ lit_int = webidl_node_getint(lit_node);
+ fprintf(outf,
+ "\t\tduk_push_int(ctx, %d);\n",
+ *lit_int);
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_BOOL:
+ lit_int = webidl_node_getint(lit_node);
+ fprintf(outf,
+ "\t\tduk_push_boolean(ctx, %d);\n",
+ *lit_int);
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_STRING:
+ lit_str = webidl_node_gettext(lit_node);
+ fprintf(outf,
+ "\t\tduk_push_string(ctx, \"%s\");\n",
+ lit_str);
+ break;
+
+ case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
+ default:
+ fprintf(outf,
+ "\t\tduk_push_undefined(ctx);\n");
+ break;
+ }
+ } else {
+ fprintf(outf, "\t\tduk_push_undefined(ctx);\n");
+ }
+ }
+ return 0;
+}
+
+static int
+output_operation_argument_type_check(
+ FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_operation_entry *operatione,
+ struct ir_operation_overload_entry *overloade,
+ int argidx)
+{
+ struct ir_operation_argument_entry *argumente;
+ struct webidl_node *type_node;
+ enum webidl_type *argument_type;
+
+ argumente = overloade->argumentv + argidx;
+
+ type_node = webidl_node_find_type(
+ webidl_node_getnode(argumente->node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
+
+ if (type_node == NULL) {
+ fprintf(stderr, "%s:%s %dth argument %s has no type\n",
+ interfacee->name,
+ operatione->name,
+ argidx,
+ argumente->name);
+ return -1;
+ }
+
+ argument_type = (enum webidl_type *)webidl_node_getint(
+ webidl_node_find_type(
+ webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE_BASE));
+
+ if (argument_type == NULL) {
+ fprintf(stderr,
+ "%s:%s %dth argument %s has no type base\n",
+ interfacee->name,
+ operatione->name,
+ argidx,
+ argumente->name);
+ return -1;
+ }
+
+ if (*argument_type == WEBIDL_TYPE_ANY) {
+ /* allowing any type needs no check */
+ return 0;
+ }
+
+ fprintf(outf, "\tif (%s_argc > %d) {\n", DLPFX, argidx);
+
+ switch (*argument_type) {
+ case WEBIDL_TYPE_STRING:
+ fprintf(outf,
+ "\t\tif (!duk_is_string(ctx, %d)) {\n"
+ "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_string_type, %d, \"%s\");\n"
+ "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
+ break;
+
+ case WEBIDL_TYPE_BOOL:
+ fprintf(outf,
+ "\t\tif (!duk_is_boolean(ctx, %d)) {\n"
+ "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_bool_type, %d, \"%s\");\n"
+ "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
+ break;
+
+ case WEBIDL_TYPE_FLOAT:
+ case WEBIDL_TYPE_DOUBLE:
+ case WEBIDL_TYPE_SHORT:
+ case WEBIDL_TYPE_LONG:
+ case WEBIDL_TYPE_LONGLONG:
+ fprintf(outf,
+ "\t\tif (!duk_is_number(ctx, %d)) {\n"
+ "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_number_type, %d, \"%s\");\n"
+ "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
+ break;
+
+
+ default:
+ fprintf(outf,
+ "\t\t/* unhandled type check */\n");
+ }
+
+ fprintf(outf, "\t}\n");
+
+ return 0;
+}
+
+
+/**
+ * generate a single class method for an interface operation
+ */
+static int
+output_interface_operation(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_operation_entry *operatione)
+{
+ int cdatac; /* cdata blocks output */
+ struct ir_operation_overload_entry *overloade;
+ int fixedargc; /* number of non optional arguments */
+ int argidx; /* loop counter for arguments */
+ int optargc; /* loop counter for optional arguments */
+
+ if (operatione->name == NULL) {
+ return output_interface_special_operation(outf,
+ interfacee,
+ operatione);
+ }
+
+ if (operatione->overloadc != 1) {
+ return output_interface_overloaded_operation(outf,
+ interfacee,
+ operatione);
+ }
+
+ if (operatione->overloadv->elipsisc != 0) {
+ return output_interface_elipsis_operation(outf,
+ interfacee,
+ operatione);
+ }
+
+ /* normal method definition */
+ overloade = operatione->overloadv;
+
+ fprintf(outf,
+ "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name, operatione->name);
+ fprintf(outf,"{\n");
+
+ /* check arguments */
+
+ /* generate check for minimum number of parameters */
+
+ fixedargc = overloade->argumentc - overloade->optionalc;
+
+ fprintf(outf,
+ "\t/* ensure the parameters are present */\n"
+ "\tduk_idx_t %s_argc = duk_get_top(ctx);\n\t", DLPFX);
+
+ if (fixedargc > 0) {
+ fprintf(outf,
+ "if (%s_argc < %d) {\n"
+ "\t\t/* not enough arguments */\n"
+ "\t\tduk_error(ctx, DUK_RET_TYPE_ERROR, %s_error_fmt_argument, %d, %s_argc);\n"
+ "\t} else ",
+ DLPFX,
+ fixedargc,
+ DLPFX,
+ fixedargc,
+ DLPFX);
+ }
+
+ for (optargc = fixedargc;
+ optargc < overloade->argumentc;
+ optargc++) {
+ fprintf(outf,
+ "if (%s_argc == %d) {\n"
+ "\t\t/* %d optional arguments need adding */\n",
+ DLPFX,
+ optargc,
+ overloade->argumentc - optargc);
+ output_operation_optional_defaults(outf,
+ overloade->argumentv + optargc,
+ overloade->argumentc - optargc);
+ fprintf(outf,
+ "\t} else ");
+ }
+
+ fprintf(outf,
+ "if (%s_argc > %d) {\n"
+ "\t\t/* remove extraneous parameters */\n"
+ "\t\tduk_set_top(ctx, %d);\n"
+ "\t}\n",
+ DLPFX,
+ overloade->argumentc,
+ overloade->argumentc);
+ fprintf(outf, "\n");
+
+ /* generate argument type checks */
+
+ fprintf(outf, "\t/* check types of passed arguments are correct */\n");
+
+ for (argidx = 0; argidx < overloade->argumentc; argidx++) {
+ output_operation_argument_type_check(outf,
+ interfacee,
+ operatione,
+ overloade,
+ argidx);
+ }
+
+ output_get_method_private(outf, interfacee->class_name);
+
+ cdatac = output_cdata(outf,
+ operatione->method,
+ GENBIND_NODE_TYPE_CDATA);
+
+ if (cdatac == 0) {
+ /* no implementation so generate default */
+ WARN(WARNING_UNIMPLEMENTED,
+ "Unimplemented: method %s::%s();",
+ interfacee->name, operatione->name);
+ fprintf(outf,"\treturn 0;\n");
+ }
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate class methods for each interface operation
+ */
+static int
+output_interface_operations(FILE* outf, struct ir_entry *ife)
+{
+ int opc;
+ int res = 0;
+
+ for (opc = 0; opc < ife->u.interface.operationc; opc++) {
+ res = output_interface_operation(
+ outf,
+ ife,
+ ife->u.interface.operationv + opc);
+ if (res != 0) {
+ break;
+ }
+ }
+
+ return res;
+}
+
+/**
+ * Generate class property getter/setter for a single attribute
+ */
+static int
+output_interface_attribute(FILE* outf,
+ struct ir_entry *interfacee,
+ struct ir_attribute_entry *atributee)
+{
+ int cdatac;
+
+ /* getter definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s_%s_getter(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name, atributee->name);
+ fprintf(outf,"{\n");
+
+ output_get_method_private(outf, interfacee->class_name);
+
+ cdatac = output_cdata(outf, atributee->getter, GENBIND_NODE_TYPE_CDATA);
+
+ if (cdatac == 0) {
+ WARN(WARNING_UNIMPLEMENTED,
+ "Unimplemented: getter %s::%s();",
+ interfacee->name, atributee->name);
+
+ /* no implementation so generate default */
+ fprintf(outf,"\treturn 0;\n");
+ }
+
+ fprintf(outf, "}\n\n");
+
+ /* readonly attributes have no setter */
+ if (atributee->modifier == WEBIDL_TYPE_MODIFIER_READONLY) {
+ return 0;
+ }
+
+ /* setter definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s_%s_setter(duk_context *ctx)\n",
+ DLPFX, interfacee->class_name, atributee->name);
+ fprintf(outf,"{\n");
+
+ output_get_method_private(outf, interfacee->class_name);
+
+ cdatac = output_cdata(outf, atributee->setter, GENBIND_NODE_TYPE_CDATA);
+
+ if (cdatac == 0) {
+ WARN(WARNING_UNIMPLEMENTED,
+ "Unimplemented: setter %s::%s();",
+ interfacee->name, atributee->name);
+
+ /* no implementation so generate default */
+ fprintf(outf,"\treturn 0;\n");
+ }
+
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate class property getters and setters for each interface attribute
+ */
+static int
+output_interface_attributes(FILE* outf, struct ir_entry *ife)
+{
+ int attrc;
+
+ for (attrc = 0; attrc < ife->u.interface.attributec; attrc++) {
+ output_interface_attribute(
+ outf,
+ ife,
+ ife->u.interface.attributev + attrc);
+ }
+
+ return 0;
+}
+
+
+/* exported interface documented in duk-libdom.h */
+int output_interface(struct ir *ir, struct ir_entry *interfacee)
+{
+ FILE *ifacef;
+ struct ir_entry *inherite;
+ int res = 0;
+
+ /* open output file */
+ ifacef = genb_fopen_tmp(interfacee->filename);
+ if (ifacef == NULL) {
+ return -1;
+ }
+
+ /* find parent interface entry */
+ inherite = ir_inherit_entry(ir, interfacee);
+
+ /* tool preface */
+ output_tool_preface(ifacef);
+
+ /* binding preface */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* class preface */
+ output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool prologue */
+ output_tool_prologue(ifacef);
+
+ /* binding prologue */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_PROLOGUE);
+
+ /* class prologue */
+ output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PROLOGUE);
+
+ fprintf(ifacef, "\n");
+
+ /* initialisor */
+ res = output_interface_init(ifacef, interfacee, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* finaliser */
+ output_interface_fini(ifacef, interfacee, inherite);
+
+ /* constructor */
+ output_interface_constructor(ifacef, interfacee);
+
+ /* destructor */
+ output_interface_destructor(ifacef, interfacee);
+
+ /* operations */
+ output_interface_operations(ifacef, interfacee);
+
+ /* attributes */
+ output_interface_attributes(ifacef, interfacee);
+
+ /* prototype */
+ output_interface_prototype(ifacef, ir, interfacee, inherite);
+
+ fprintf(ifacef, "\n");
+
+ /* class epilogue */
+ output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_EPILOGUE);
+
+ /* binding epilogue */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_EPILOGUE);
+
+ /* class postface */
+ output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_POSTFACE);
+
+ /* binding postface */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+op_error:
+ genb_fclose_tmp(ifacef, interfacee->filename);
+
+ return res;
+}
+
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 3e20d13..45e7e79 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -3,7 +3,7 @@
* This file is part of nsgenbind.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
*/
#include <stdio.h>
@@ -27,53 +27,6 @@
#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
-#define NSGENBIND_PREAMBLE \
- "/* Generated by nsgenbind\n" \
- " *\n" \
- " * nsgenbind is published under the MIT Licence.\n" \
- " * nsgenbind is similar to a compiler is a purely transformative tool which\n" \
- " * explicitly makes no copyright claim on this generated output\n" \
- " */"
-
-/**
- * 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, %s_magic_string_private);\n\n",
- DLPFX);
-
- 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, %s_magic_string_private);\n",
- idx, DLPFX);
- 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 a duktape prototype name
*/
@@ -95,190 +48,6 @@ static char *get_prototype_name(const char *interface_name)
return proto_name;
}
-/**
- * generate code that gets a prototype by name
- */
-static int output_get_prototype(FILE* outf, const char *interface_name)
-{
- char *proto_name;
-
- proto_name = get_prototype_name(interface_name);
-
- fprintf(outf,
- "\t/* get prototype */\n");
- fprintf(outf,
- "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
- DLPFX);
- fprintf(outf,
- "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
- MAGICPFX);
- 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,
- const char *class_name,
- const char *method)
-{
- 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, DUK_VARARGS);\n",
- DLPFX, class_name, method);
- 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);
- output_dump_stack(outf);
- fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t\tDUK_DEFPROP_HAVE_SETTER |\n");
- fprintf(outf, "\t\tDUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t\tDUK_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);
- output_dump_stack(outf);
- fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t\tDUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t\tDUK_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, %s_magic_string_private);\n",
- DLPFX);
- fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
- fprintf(outf, "\tduk_pop_2(ctx);\n");
- fprintf(outf, "\tif (priv == NULL) {\n");
- if (options->dbglog) {
- fprintf(outf, "\t\tLOG(\"priv failed\");\n");
- }
- fprintf(outf, "\t\treturn 0; /* can do? No can do. */\n");
- fprintf(outf, "\t}\n\n");
-
- return 0;
-}
-
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_preface(FILE* outf)
-{
- fprintf(outf, "%s\n", NSGENBIND_PREAMBLE);
-
- return 0;
-}
/**
* Generate a C class name for the interface.
@@ -345,34 +114,6 @@ static char *gen_class_name(struct ir_entry *interfacee)
return name;
}
-/**
- * output character data of node of given type.
- *
- * 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,
- struct genbind_node *node,
- 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 res;
-}
static FILE *open_header(struct ir *ir, const char *name)
{
@@ -431,166 +172,7 @@ static int close_header(struct ir *ir,
}
-/**
- * generate the interface constructor
- */
-static int
-output_interface_constructor(FILE* outf, struct ir_entry *interfacee)
-{
- int init_argc;
-
- /* constructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
- DLPFX, interfacee->class_name);
- fprintf(outf,"{\n");
-
- output_create_private(outf, interfacee->class_name);
-
- /* generate call to initialisor */
- fprintf(outf,
- "\t%s_%s___init(ctx, priv",
- DLPFX, interfacee->class_name);
- for (init_argc = 1;
- init_argc <= interfacee->class_init_argc;
- init_argc++) {
- fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
- }
- fprintf(outf, ");\n");
-
-
- fprintf(outf, "\tduk_set_top(ctx, 1);\n");
- fprintf(outf, "\treturn 1;\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate the interface destructor
- */
-static int
-output_interface_destructor(FILE* outf, struct ir_entry *interfacee)
-{
- /* destructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
- DLPFX, interfacee->class_name);
- fprintf(outf,"{\n");
-
- output_safe_get_private(outf, interfacee->class_name, 0);
-
- /* generate call to finaliser */
- fprintf(outf,
- "\t%s_%s___fini(ctx, priv);\n",
- DLPFX, interfacee->class_name);
-
- fprintf(outf,"\tfree(priv);\n");
- fprintf(outf,"\treturn 0;\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate an initialisor call to parent interface
- */
-static int
-output_interface_inherit_init(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_entry *inherite)
-{
- struct genbind_node *init_node;
- struct genbind_node *inh_init_node;
- struct genbind_node *param_node;
- struct genbind_node *inh_param_node;
-
- /* only need to call parent initialisor if there is one */
- if (inherite == NULL) {
- return 0;
- }
-
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
- inh_init_node = genbind_node_find_method(inherite->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
-
-
- fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
- DLPFX, inherite->class_name);
-
- /* for each parameter in the parent find a matching named
- * parameter to pass and cast if necessary
- */
-
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (inh_param_node != NULL) {
- char *param_name;
- param_name = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_IDENT));
-
- param_node = genbind_node_find_type_ident(
- genbind_node_getnode(init_node),
- NULL,
- GENBIND_NODE_TYPE_PARAMETER,
- param_name);
- if (param_node == NULL) {
- fprintf(stderr, "class \"%s\" (interface %s) parent class \"%s\" (interface %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
- interfacee->class_name,
- interfacee->name,
- inherite->class_name,
- inherite->name,
- param_name);
- return -1;
- } else {
- char *param_type;
- char *inh_param_type;
-
- fprintf(outf, ", ");
-
- /* cast the parameter if required */
- param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- inh_param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- if (strcmp(param_type, inh_param_type) != 0) {
- fprintf(outf, "(%s)", inh_param_type);
- }
-
- /* output the parameter identifier */
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
- }
-
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- inh_param_node, GENBIND_NODE_TYPE_METHOD);
- }
-
- fprintf(outf, ");\n");
-
- return 0;
-}
static int
output_interface_init_declaration(FILE* outf,
@@ -626,997 +208,6 @@ output_interface_init_declaration(FILE* outf,
return 0;
}
-static int
-output_interface_init(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_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);
- if (res != 0) {
- return res;
- }
-
- /* generate log statement */
- if (options->dbglog) {
- fprintf(outf,
- "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
- }
-
- /* output the initaliser code from the binding */
- output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
-
- fprintf(outf, "}\n\n");
-
- return 0;
-
-}
-
-static int
-output_interface_fini(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_entry *inherite)
-{
- struct genbind_node *fini_node;
-
- /* find the finaliser method on the class (if any) */
- fini_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_FINI);
-
- /* finaliser definition */
- fprintf(outf,
- "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n",
- DLPFX, interfacee->class_name, interfacee->class_name);
- fprintf(outf,"{\n");
-
- /* generate log statement */
- if (options->dbglog) {
- fprintf(outf,
- "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
- }
-
- /* output the finialisor code from the binding */
- output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
-
- /* if this interface inherits ensure we call its finaliser */
- if (inherite != NULL) {
- fprintf(outf,
- "\t%s_%s___fini(ctx, &priv->parent);\n",
- DLPFX, inherite->class_name);
- }
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-
-/**
- * generate a prototype add for a single class method
- */
-static int
-output_prototype_method(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
-
- if (operatione->name != NULL) {
- /* normal method on prototype */
- output_add_method(outf,
- interfacee->class_name,
- operatione->name);
- } else {
- /* special method on prototype */
- fprintf(outf,
- "\t/* Special method on prototype - UNIMPLEMENTED */\n\n");
- }
-
- return 0;
-}
-
-/**
- * generate prototype method definitions
- */
-static int
-output_prototype_methods(FILE *outf, struct ir_entry *entry)
-{
- int opc;
- int res = 0;
-
- for (opc = 0; opc < entry->u.interface.operationc; opc++) {
- res = output_prototype_method(
- outf,
- entry,
- entry->u.interface.operationv + opc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-
-static int
-output_prototype_attribute(FILE *outf,
- struct ir_entry *interfacee,
- struct ir_attribute_entry *attributee)
-{
- if (attributee->modifier == WEBIDL_TYPE_MODIFIER_READONLY) {
- return output_populate_ro_property(outf,
- interfacee->class_name,
- attributee->name);
- }
- return output_populate_rw_property(outf,
- interfacee->class_name,
- attributee->name);
-}
-
-/**
- * generate prototype attribute definitions
- */
-static int
-output_prototype_attributes(FILE *outf, struct ir_entry *entry)
-{
- int attrc;
- int res = 0;
-
- for (attrc = 0; attrc < entry->u.interface.attributec; attrc++) {
- res = output_prototype_attribute(
- outf,
- entry,
- entry->u.interface.attributev + attrc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-/**
- * output constants on the prototype
- *
- * \todo This implementation assumes the constant is a literal int and should
- * check the type node base value.
- */
-static int
-output_prototype_constant(FILE *outf,
- struct ir_constant_entry *constante)
-{
- int *value;
-
- value = webidl_node_getint(
- webidl_node_find_type(
- webidl_node_getnode(constante->node),
- NULL,
- WEBIDL_NODE_TYPE_LITERAL_INT));
-
- output_prototype_constant_int(outf, constante->name, *value);
-
- return 0;
-}
-
-/**
- * generate prototype constant definitions
- */
-static int
-output_prototype_constants(FILE *outf, struct ir_entry *entry)
-{
- int attrc;
- int res = 0;
-
- for (attrc = 0; attrc < entry->u.interface.constantc; attrc++) {
- res = output_prototype_constant(
- outf,
- entry->u.interface.constantv + attrc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-static int
-output_global_create_prototype(FILE* outf,
- struct ir *ir,
- struct ir_entry *interfacee)
-{
- int idx;
-
- fprintf(outf, "\t/* Create interface objects */\n");
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *entry;
-
- entry = ir->entries + idx;
-
- if (entry->type == IR_ENTRY_TYPE_INTERFACE) {
-
- if (entry->u.interface.noobject) {
- continue;
- }
-
- if (entry == interfacee) {
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- } else {
- output_get_prototype(outf, entry->name);
- }
-
- fprintf(outf,
- "\tdukky_inject_not_ctr(ctx, 0, \"%s\");\n",
- entry->name);
- }
- }
- return 0;
-}
-/**
- * generate the interface prototype creator
- */
-static int
-output_interface_prototype(FILE* outf,
- struct ir *ir,
- struct ir_entry *interfacee,
- struct ir_entry *inherite)
-{
- struct genbind_node *proto_node;
-
- /* find the prototype method on the class */
- proto_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_PROTOTYPE);
-
- /* prototype definition */
- fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
- DLPFX, interfacee->class_name);
- fprintf(outf,"{\n");
-
- /* Output any binding data first */
- if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
- fprintf(outf,"\n");
- }
-
- /* generate prototype chaining if interface has a parent */
- if (inherite != NULL) {
- fprintf(outf,
- "\t/* Set this prototype's prototype (left-parent) */\n");
- output_get_prototype(outf, inherite->name);
- fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
- }
-
- /* generate setting of methods */
- output_prototype_methods(outf, interfacee);
-
- /* generate setting of attributes */
- output_prototype_attributes(outf, interfacee);
-
- /* generate setting of constants */
- output_prototype_constants(outf, interfacee);
-
- /* if this is the global object, output all interfaces which do not
- * prevent us from doing so
- */
- if (interfacee->u.interface.primary_global) {
- output_global_create_prototype(outf, ir, interfacee);
- }
-
- /* generate setting of destructor */
- output_set_destructor(outf, interfacee->class_name, 0);
-
- /* generate setting of constructor */
- output_set_constructor(outf,
- interfacee->class_name,
- 0,
- interfacee->class_init_argc);
-
- fprintf(outf,"\treturn 1; /* The prototype object */\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a single class method for an interface operation with elipsis
- */
-static int
-output_interface_elipsis_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- int cdatac; /* cdata blocks output */
-
- /* overloaded method definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, operatione->name);
- fprintf(outf,"{\n");
-
- /**
- * \todo This is where the checking of the parameters to the
- * operation with elipsis should go
- */
- WARN(WARNING_UNIMPLEMENTED,
- "Elipsis parameetrs not checked: method %s::%s();",
- interfacee->name, operatione->name);
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf,
- operatione->method,
- GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- /* no implementation so generate default */
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: method %s::%s();",
- interfacee->name, operatione->name);
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a single class method for an interface overloaded operation
- */
-static int
-output_interface_overloaded_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- int cdatac; /* cdata blocks output */
-
- /* overloaded method definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, operatione->name);
- fprintf(outf,"{\n");
-
- /** \todo This is where the checking of the parameters to the
- * overloaded operation should go
- */
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf,
- operatione->method,
- GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- /* no implementation so generate default */
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: method %s::%s();",
- interfacee->name, operatione->name);
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a single class method for an interface special operation
- */
-static int
-output_interface_special_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- /* special method definition */
- fprintf(outf, "/* Special method definition - UNIMPLEMENTED */\n\n");
-
- WARN(WARNING_UNIMPLEMENTED,
- "Special operation on interface %s (operation entry %p)",
- interfacee->name,
- operatione);
-
- return 0;
-}
-
-/**
- * generate default values on the duk stack
- */
-static int
-output_operation_optional_defaults(FILE* outf,
- struct ir_operation_argument_entry *argumentv,
- int argumentc)
-{
- int argc;
- for (argc = 0; argc < argumentc; argc++) {
- struct ir_operation_argument_entry *cure;
- struct webidl_node *lit_node; /* literal node */
- enum webidl_node_type lit_type;
- int *lit_int;
- char *lit_str;
-
- cure = argumentv + argc;
-
- lit_node = webidl_node_getnode(
- webidl_node_find_type(
- webidl_node_getnode(cure->node),
- NULL,
- WEBIDL_NODE_TYPE_OPTIONAL));
-
- if (lit_node != NULL) {
-
- lit_type = webidl_node_gettype(lit_node);
-
- switch (lit_type) {
- case WEBIDL_NODE_TYPE_LITERAL_NULL:
- fprintf(outf,
- "\t\tduk_push_null(ctx);\n");
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_INT:
- lit_int = webidl_node_getint(lit_node);
- fprintf(outf,
- "\t\tduk_push_int(ctx, %d);\n",
- *lit_int);
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_BOOL:
- lit_int = webidl_node_getint(lit_node);
- fprintf(outf,
- "\t\tduk_push_boolean(ctx, %d);\n",
- *lit_int);
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_STRING:
- lit_str = webidl_node_gettext(lit_node);
- fprintf(outf,
- "\t\tduk_push_string(ctx, \"%s\");\n",
- lit_str);
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
- default:
- fprintf(outf,
- "\t\tduk_push_undefined(ctx);\n");
- break;
- }
- } else {
- fprintf(outf, "\t\tduk_push_undefined(ctx);\n");
- }
- }
- return 0;
-}
-
-static int
-output_operation_argument_type_check(
- FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione,
- struct ir_operation_overload_entry *overloade,
- int argidx)
-{
- struct ir_operation_argument_entry *argumente;
- struct webidl_node *type_node;
- enum webidl_type *argument_type;
-
- argumente = overloade->argumentv + argidx;
-
- type_node = webidl_node_find_type(
- webidl_node_getnode(argumente->node),
- NULL,
- WEBIDL_NODE_TYPE_TYPE);
-
- if (type_node == NULL) {
- fprintf(stderr, "%s:%s %dth argument %s has no type\n",
- interfacee->name,
- operatione->name,
- argidx,
- argumente->name);
- return -1;
- }
-
- argument_type = (enum webidl_type *)webidl_node_getint(
- webidl_node_find_type(
- webidl_node_getnode(type_node),
- NULL,
- WEBIDL_NODE_TYPE_TYPE_BASE));
-
- if (argument_type == NULL) {
- fprintf(stderr,
- "%s:%s %dth argument %s has no type base\n",
- interfacee->name,
- operatione->name,
- argidx,
- argumente->name);
- return -1;
- }
-
- if (*argument_type == WEBIDL_TYPE_ANY) {
- /* allowing any type needs no check */
- return 0;
- }
-
- fprintf(outf, "\tif (%s_argc > %d) {\n", DLPFX, argidx);
-
- switch (*argument_type) {
- case WEBIDL_TYPE_STRING:
- fprintf(outf,
- "\t\tif (!duk_is_string(ctx, %d)) {\n"
- "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_string_type, %d, \"%s\");\n"
- "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
- break;
-
- case WEBIDL_TYPE_BOOL:
- fprintf(outf,
- "\t\tif (!duk_is_boolean(ctx, %d)) {\n"
- "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_bool_type, %d, \"%s\");\n"
- "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
- break;
-
- case WEBIDL_TYPE_FLOAT:
- case WEBIDL_TYPE_DOUBLE:
- case WEBIDL_TYPE_SHORT:
- case WEBIDL_TYPE_LONG:
- case WEBIDL_TYPE_LONGLONG:
- fprintf(outf,
- "\t\tif (!duk_is_number(ctx, %d)) {\n"
- "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_number_type, %d, \"%s\");\n"
- "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
- break;
-
-
- default:
- fprintf(outf,
- "\t\t/* unhandled type check */\n");
- }
-
- fprintf(outf, "\t}\n");
-
- return 0;
-}
-
-
-/**
- * generate a single class method for an interface operation
- */
-static int
-output_interface_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- int cdatac; /* cdata blocks output */
- struct ir_operation_overload_entry *overloade;
- int fixedargc; /* number of non optional arguments */
- int argidx; /* loop counter for arguments */
- int optargc; /* loop counter for optional arguments */
-
- if (operatione->name == NULL) {
- return output_interface_special_operation(outf,
- interfacee,
- operatione);
- }
-
- if (operatione->overloadc != 1) {
- return output_interface_overloaded_operation(outf,
- interfacee,
- operatione);
- }
-
- if (operatione->overloadv->elipsisc != 0) {
- return output_interface_elipsis_operation(outf,
- interfacee,
- operatione);
- }
-
- /* normal method definition */
- overloade = operatione->overloadv;
-
- fprintf(outf,
- "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, operatione->name);
- fprintf(outf,"{\n");
-
- /* check arguments */
-
- /* generate check for minimum number of parameters */
-
- fixedargc = overloade->argumentc - overloade->optionalc;
-
- fprintf(outf,
- "\t/* ensure the parameters are present */\n"
- "\tduk_idx_t %s_argc = duk_get_top(ctx);\n\t", DLPFX);
-
- if (fixedargc > 0) {
- fprintf(outf,
- "if (%s_argc < %d) {\n"
- "\t\t/* not enough arguments */\n"
- "\t\tduk_error(ctx, DUK_RET_TYPE_ERROR, %s_error_fmt_argument, %d, %s_argc);\n"
- "\t} else ",
- DLPFX,
- fixedargc,
- DLPFX,
- fixedargc,
- DLPFX);
- }
-
- for (optargc = fixedargc;
- optargc < overloade->argumentc;
- optargc++) {
- fprintf(outf,
- "if (%s_argc == %d) {\n"
- "\t\t/* %d optional arguments need adding */\n",
- DLPFX,
- optargc,
- overloade->argumentc - optargc);
- output_operation_optional_defaults(outf,
- overloade->argumentv + optargc,
- overloade->argumentc - optargc);
- fprintf(outf,
- "\t} else ");
- }
-
- fprintf(outf,
- "if (%s_argc > %d) {\n"
- "\t\t/* remove extraneous parameters */\n"
- "\t\tduk_set_top(ctx, %d);\n"
- "\t}\n",
- DLPFX,
- overloade->argumentc,
- overloade->argumentc);
- fprintf(outf, "\n");
-
- /* generate argument type checks */
-
- fprintf(outf, "\t/* check types of passed arguments are correct */\n");
-
- for (argidx = 0; argidx < overloade->argumentc; argidx++) {
- output_operation_argument_type_check(outf,
- interfacee,
- operatione,
- overloade,
- argidx);
- }
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf,
- operatione->method,
- GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- /* no implementation so generate default */
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: method %s::%s();",
- interfacee->name, operatione->name);
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate class methods for each interface operation
- */
-static int
-output_interface_operations(FILE* outf, struct ir_entry *ife)
-{
- int opc;
- int res = 0;
-
- for (opc = 0; opc < ife->u.interface.operationc; opc++) {
- res = output_interface_operation(
- outf,
- ife,
- ife->u.interface.operationv + opc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-/**
- * Generate class property getter/setter for a single attribute
- */
-static int
-output_interface_attribute(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_attribute_entry *atributee)
-{
- int cdatac;
-
- /* getter definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s_getter(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, atributee->name);
- fprintf(outf,"{\n");
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf, atributee->getter, GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: getter %s::%s();",
- interfacee->name, atributee->name);
-
- /* no implementation so generate default */
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- /* readonly attributes have no setter */
- if (atributee->modifier == WEBIDL_TYPE_MODIFIER_READONLY) {
- return 0;
- }
-
- /* setter definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s_setter(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, atributee->name);
- fprintf(outf,"{\n");
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf, atributee->setter, GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: setter %s::%s();",
- interfacee->name, atributee->name);
-
- /* no implementation so generate default */
- fprintf(outf,"\treturn 0;\n");
- }
-
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate class property getters and setters for each interface attribute
- */
-static int
-output_interface_attributes(FILE* outf, struct ir_entry *ife)
-{
- int attrc;
-
- for (attrc = 0; attrc < ife->u.interface.attributec; attrc++) {
- output_interface_attribute(
- outf,
- ife,
- ife->u.interface.attributev + attrc);
- }
-
- return 0;
-}
-
-
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_prologue(FILE* outf)
-{
- char *fpath;
-
- fpath = genb_fpath("binding.h");
- fprintf(outf, "\n#include \"%s\"\n", fpath);
- free(fpath);
-
- fpath = genb_fpath("private.h");
- fprintf(outf, "#include \"%s\"\n", fpath);
- free(fpath);
-
- fpath = genb_fpath("prototype.h");
- fprintf(outf, "#include \"%s\"\n", fpath);
- free(fpath);
-
- return 0;
-}
-
-/**
- * generate a source file to implement a dictionary using duk and libdom.
- */
-static int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
-{
- FILE *ifacef;
- struct ir_entry *inherite;
- int res = 0;
-
- /* open output file */
- ifacef = genb_fopen_tmp(dictionarye->filename);
- if (ifacef == NULL) {
- return -1;
- }
-
- /* find parent interface entry */
- inherite = ir_inherit_entry(ir, dictionarye);
-
- /* tool preface */
- output_tool_preface(ifacef);
-
- /* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* class preface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PREFACE);
-
- /* tool prologue */
- output_tool_prologue(ifacef);
-
- /* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
- /* class prologue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PROLOGUE);
-
- fprintf(ifacef, "\n");
-
- /* initialisor */
- res = output_interface_init(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- res = output_interface_fini(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* constructor */
- res = output_interface_constructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* destructor */
- res = output_interface_destructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* prototype */
- res = output_interface_prototype(ifacef, ir, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
-
- fprintf(ifacef, "\n");
-
- /* class epilogue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_EPILOGUE);
-
- /* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
-
- /* class postface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_POSTFACE);
-
- /* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
-op_error:
- genb_fclose_tmp(ifacef, dictionarye->filename);
-
- return res;
-}
-
-/**
- * generate a source file to implement an interface using duk and libdom.
- */
-static int output_interface(struct ir *ir, struct ir_entry *interfacee)
-{
- FILE *ifacef;
- struct ir_entry *inherite;
- int res = 0;
-
- /* open output file */
- ifacef = genb_fopen_tmp(interfacee->filename);
- if (ifacef == NULL) {
- return -1;
- }
-
- /* find parent interface entry */
- inherite = ir_inherit_entry(ir, interfacee);
-
- /* tool preface */
- output_tool_preface(ifacef);
-
- /* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* class preface */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PREFACE);
-
- /* tool prologue */
- output_tool_prologue(ifacef);
-
- /* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
- /* class prologue */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PROLOGUE);
-
- fprintf(ifacef, "\n");
-
- /* initialisor */
- res = output_interface_init(ifacef, interfacee, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- output_interface_fini(ifacef, interfacee, inherite);
-
- /* constructor */
- output_interface_constructor(ifacef, interfacee);
-
- /* destructor */
- output_interface_destructor(ifacef, interfacee);
-
- /* operations */
- output_interface_operations(ifacef, interfacee);
-
- /* attributes */
- output_interface_attributes(ifacef, interfacee);
-
- /* prototype */
- output_interface_prototype(ifacef, ir, interfacee, inherite);
-
- fprintf(ifacef, "\n");
-
- /* class epilogue */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_EPILOGUE);
-
- /* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
-
- /* class postface */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_POSTFACE);
-
- /* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
-op_error:
- genb_fclose_tmp(ifacef, interfacee->filename);
-
- return res;
-}
/**
* generate private header
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index 2ecd482..84fc497 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -9,6 +9,41 @@
#ifndef nsgenbind_duk_libdom_h
#define nsgenbind_duk_libdom_h
+/**
+ * Generate output for duktape and libdom bindings.
+ */
int duk_libdom_output(struct ir *ir);
+/**
+ * generate a source file to implement an interface using duk and libdom.
+ */
+int output_interface(struct ir *ir, struct ir_entry *interfacee);
+
+/**
+ * generate a source file to implement a dictionary using duk and libdom.
+ */
+int output_dictionary(struct ir *ir, struct ir_entry *dictionarye);
+
+/**
+ * generate preface block for nsgenbind
+ */
+int output_tool_preface(FILE* outf);
+
+/**
+ * generate preface block for nsgenbind
+ */
+int output_tool_prologue(FILE* outf);
+
+/**
+ * output character data of node of given type.
+ *
+ * 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.
+ */
+int output_cdata(FILE* outf, struct genbind_node *node, enum genbind_node_type nodetype);
+
#endif
-----------------------------------------------------------------------
Summary of changes:
src/Makefile | 3 +-
src/duk-libdom-common.c | 78 ++
src/duk-libdom-dictionary.c | 571 +++++++++++
src/{duk-libdom.c => duk-libdom-interface.c} | 853 +---------------
src/duk-libdom.c | 1411 +-------------------------
src/duk-libdom.h | 35 +
6 files changed, 692 insertions(+), 2259 deletions(-)
create mode 100644 src/duk-libdom-common.c
create mode 100644 src/duk-libdom-dictionary.c
copy src/{duk-libdom.c => duk-libdom-interface.c} (61%)
diff --git a/src/Makefile b/src/Makefile
index 9905baf..3ecfbe1 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.c duk-libdom-interface.c duk-libdom-dictionary.c duk-libdom-common.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
SOURCES := $(SOURCES) $(BUILDDIR)/nsgenbind-parser.c $(BUILDDIR)/nsgenbind-lexer.c $(BUILDDIR)/webidl-parser.c $(BUILDDIR)/webidl-lexer.c
diff --git a/src/duk-libdom-common.c b/src/duk-libdom-common.c
new file mode 100644
index 0000000..9a0f660
--- /dev/null
+++ b/src/duk-libdom-common.c
@@ -0,0 +1,78 @@
+/* duktape 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(a)netsurf-browser.org>
+ */
+
+#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"
+
+#define NSGENBIND_PREFACE \
+ "/* Generated by nsgenbind\n" \
+ " *\n" \
+ " * nsgenbind is published under the MIT Licence.\n" \
+ " * nsgenbind is similar to a compiler is a purely transformative tool which\n" \
+ " * explicitly makes no copyright claim on this generated output\n" \
+ " */"
+
+/* exported interface documented in duk-libdom.h */
+int output_tool_preface(FILE* outf)
+{
+ fprintf(outf, "%s\n", NSGENBIND_PREFACE);
+
+ return 0;
+}
+
+/* exported interface documented in duk-libdom.h */
+int output_cdata(FILE* outf,
+ struct genbind_node *node,
+ 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 res;
+}
+
+/* exported interface documented in duk-libdom.h */
+int output_tool_prologue(FILE* outf)
+{
+ char *fpath;
+
+ fpath = genb_fpath("binding.h");
+ fprintf(outf, "\n#include \"%s\"\n", fpath);
+ free(fpath);
+
+ fpath = genb_fpath("private.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
+
+ fpath = genb_fpath("prototype.h");
+ fprintf(outf, "#include \"%s\"\n", fpath);
+ free(fpath);
+
+ return 0;
+}
diff --git a/src/duk-libdom-dictionary.c b/src/duk-libdom-dictionary.c
new file mode 100644
index 0000000..275855e
--- /dev/null
+++ b/src/duk-libdom-dictionary.c
@@ -0,0 +1,571 @@
+/* duktape binding generation implementation
+ *
+ * This file is part of nsgenbind.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ */
+
+#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"
+
+/** prefix for all generated functions */
+#define DLPFX "dukky"
+
+#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
+
+/**
+ * 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, %s_magic_string_private);\n\n",
+ DLPFX);
+
+ 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, %s_magic_string_private);\n",
+ idx, DLPFX);
+ 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 the dictionary constructor
+ */
+static int
+output_dictionary_constructor(FILE* outf, struct ir_entry *dictionarye)
+{
+ int init_argc;
+
+ /* constructor definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
+ DLPFX, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ output_create_private(outf, dictionarye->class_name);
+
+ /* generate call to initialisor */
+ fprintf(outf,
+ "\t%s_%s___init(ctx, priv",
+ DLPFX, dictionarye->class_name);
+ for (init_argc = 1;
+ init_argc <= dictionarye->class_init_argc;
+ init_argc++) {
+ fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
+ }
+ fprintf(outf, ");\n");
+
+
+ fprintf(outf, "\tduk_set_top(ctx, 1);\n");
+ fprintf(outf, "\treturn 1;\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate a duktape prototype name
+ */
+static char *get_prototype_name(const char *dictionary_name)
+{
+ char *proto_name;
+ int pnamelen;
+ int pfxlen;
+
+ /* duplicate the dictionary name in upper case */
+ pfxlen = SLEN(MAGICPFX) + SLEN("PROTOTYPE_");
+ pnamelen = strlen(dictionary_name) + 1;
+
+ proto_name = malloc(pnamelen + pfxlen);
+ snprintf(proto_name, pnamelen + pfxlen, "%sPROTOTYPE_%s", MAGICPFX, dictionary_name);
+ for (pnamelen-- ; pnamelen >= 0; pnamelen--) {
+ proto_name[pnamelen + pfxlen] = toupper(dictionary_name[pnamelen]);
+ }
+ return proto_name;
+}
+
+
+/**
+ * generate code that gets a prototype by name
+ */
+static int output_get_prototype(FILE* outf, const char *dictionary_name)
+{
+ char *proto_name;
+
+ proto_name = get_prototype_name(dictionary_name);
+
+ fprintf(outf,
+ "\t/* get prototype */\n");
+ fprintf(outf,
+ "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
+ DLPFX);
+ fprintf(outf,
+ "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
+ MAGICPFX);
+ fprintf(outf, "\tduk_pop(ctx);\n\n");
+
+ return 0;
+}
+
+/**
+ * generate the dictionary prototype creator
+ */
+static int
+output_dictionary_prototype(FILE* outf,
+ struct ir *ir,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *proto_node;
+
+ /* find the prototype method on the class */
+ proto_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_PROTOTYPE);
+
+ /* prototype definition */
+ fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
+ DLPFX, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ /* Output any binding data first */
+ if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
+ fprintf(outf,"\n");
+ }
+
+ /* generate prototype chaining if dictionary has a parent */
+ if (inherite != NULL) {
+ fprintf(outf,
+ "\t/* Set this prototype's prototype (left-parent) */\n");
+ output_get_prototype(outf, inherite->name);
+ fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
+ }
+
+ /* dictionary members*/
+
+
+ /* generate setting of destructor */
+ output_set_destructor(outf, dictionarye->class_name, 0);
+
+ /* generate setting of constructor */
+ output_set_constructor(outf,
+ dictionarye->class_name,
+ 0,
+ dictionarye->class_init_argc);
+
+ fprintf(outf,"\treturn 1; /* The prototype object */\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate the dictionary destructor
+ */
+static int
+output_dictionary_destructor(FILE* outf, struct ir_entry *dictionarye)
+{
+ /* destructor definition */
+ fprintf(outf,
+ "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
+ DLPFX, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ output_safe_get_private(outf, dictionarye->class_name, 0);
+
+ /* generate call to finaliser */
+ fprintf(outf,
+ "\t%s_%s___fini(ctx, priv);\n",
+ DLPFX, dictionarye->class_name);
+
+ fprintf(outf,"\tfree(priv);\n");
+ fprintf(outf,"\treturn 0;\n");
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+/**
+ * generate an initialisor call to parent dictionary
+ */
+static int
+output_dictionary_inherit_init(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *init_node;
+ struct genbind_node *inh_init_node;
+ struct genbind_node *param_node;
+ struct genbind_node *inh_param_node;
+
+ /* only need to call parent initialisor if there is one */
+ if (inherite == NULL) {
+ return 0;
+ }
+
+ /* find the initialisor method on the class (if any) */
+ init_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+
+ inh_init_node = genbind_node_find_method(inherite->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+
+
+ fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
+ DLPFX, inherite->class_name);
+
+ /* for each parameter in the parent find a matching named
+ * parameter to pass and cast if necessary
+ */
+
+ inh_param_node = genbind_node_find_type(
+ genbind_node_getnode(inh_init_node),
+ NULL, GENBIND_NODE_TYPE_PARAMETER);
+ while (inh_param_node != NULL) {
+ char *param_name;
+ param_name = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(inh_param_node),
+ NULL,
+ GENBIND_NODE_TYPE_IDENT));
+
+ param_node = genbind_node_find_type_ident(
+ genbind_node_getnode(init_node),
+ NULL,
+ GENBIND_NODE_TYPE_PARAMETER,
+ param_name);
+ if (param_node == NULL) {
+ fprintf(stderr, "class \"%s\" (dictionary %s) parent class \"%s\" (dictionary %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
+ dictionarye->class_name,
+ dictionarye->name,
+ inherite->class_name,
+ inherite->name,
+ param_name);
+ return -1;
+ } else {
+ char *param_type;
+ char *inh_param_type;
+
+ fprintf(outf, ", ");
+
+ /* cast the parameter if required */
+ param_type = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(param_node),
+ NULL,
+ GENBIND_NODE_TYPE_TYPE));
+
+ inh_param_type = genbind_node_gettext(
+ genbind_node_find_type(
+ genbind_node_getnode(inh_param_node),
+ NULL,
+ GENBIND_NODE_TYPE_TYPE));
+
+ if (strcmp(param_type, inh_param_type) != 0) {
+ fprintf(outf, "(%s)", inh_param_type);
+ }
+
+ /* output the parameter identifier */
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
+ }
+
+ inh_param_node = genbind_node_find_type(
+ genbind_node_getnode(inh_init_node),
+ inh_param_node, GENBIND_NODE_TYPE_METHOD);
+ }
+
+ fprintf(outf, ");\n");
+
+ return 0;
+}
+
+static int
+output_dictionary_init_declaration(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct genbind_node *init_node)
+{
+ struct genbind_node *param_node;
+
+ fprintf(outf,
+ "void %s_%s___init(duk_context *ctx, %s_private_t *priv",
+ DLPFX, dictionarye->class_name, dictionarye->class_name);
+
+ /* count the number of arguments on the initializer */
+ dictionarye->class_init_argc = 0;
+
+ /* output the paramters on the method (if any) */
+ param_node = genbind_node_find_type(
+ genbind_node_getnode(init_node),
+ NULL, GENBIND_NODE_TYPE_PARAMETER);
+ while (param_node != NULL) {
+ dictionarye->class_init_argc++;
+ fprintf(outf, ", ");
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE);
+ output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
+
+ param_node = genbind_node_find_type(
+ genbind_node_getnode(init_node),
+ param_node, GENBIND_NODE_TYPE_PARAMETER);
+ }
+
+ fprintf(outf,")");
+
+ return 0;
+}
+
+static int
+output_dictionary_init(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *init_node;
+ int res;
+
+ /* find the initialisor method on the class (if any) */
+ init_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_INIT);
+
+ /* initialisor definition */
+ output_dictionary_init_declaration(outf, dictionarye, init_node);
+
+ fprintf(outf,"\n{\n");
+
+ /* if this dictionary inherits ensure we call its initialisor */
+ res = output_dictionary_inherit_init(outf, dictionarye, inherite);
+ if (res != 0) {
+ return res;
+ }
+
+ /* generate log statement */
+ if (options->dbglog) {
+ fprintf(outf,
+ "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
+ }
+
+ /* output the initaliser code from the binding */
+ output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
+
+ fprintf(outf, "}\n\n");
+
+ return 0;
+
+}
+
+static int
+output_dictionary_fini(FILE* outf,
+ struct ir_entry *dictionarye,
+ struct ir_entry *inherite)
+{
+ struct genbind_node *fini_node;
+
+ /* find the finaliser method on the class (if any) */
+ fini_node = genbind_node_find_method(dictionarye->class,
+ NULL,
+ GENBIND_METHOD_TYPE_FINI);
+
+ /* finaliser definition */
+ fprintf(outf,
+ "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n",
+ DLPFX, dictionarye->class_name, dictionarye->class_name);
+ fprintf(outf,"{\n");
+
+ /* generate log statement */
+ if (options->dbglog) {
+ fprintf(outf,
+ "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
+ }
+
+ /* output the finialisor code from the binding */
+ output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
+
+ /* if this dictionary inherits ensure we call its finaliser */
+ if (inherite != NULL) {
+ fprintf(outf,
+ "\t%s_%s___fini(ctx, &priv->parent);\n",
+ DLPFX, inherite->class_name);
+ }
+ fprintf(outf, "}\n\n");
+
+ return 0;
+}
+
+
+/**
+ * generate a source file to implement a dictionary using duk and libdom.
+ */
+int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
+{
+ FILE *ifacef;
+ struct ir_entry *inherite;
+ int res = 0;
+
+ /* open output file */
+ ifacef = genb_fopen_tmp(dictionarye->filename);
+ if (ifacef == NULL) {
+ return -1;
+ }
+
+ /* find parent dictionary entry */
+ inherite = ir_inherit_entry(ir, dictionarye);
+
+ /* tool preface */
+ output_tool_preface(ifacef);
+
+ /* binding preface */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_PREFACE);
+
+ /* class preface */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PREFACE);
+
+ /* tool prologue */
+ output_tool_prologue(ifacef);
+
+ /* binding prologue */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_PROLOGUE);
+
+ /* class prologue */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PROLOGUE);
+
+ fprintf(ifacef, "\n");
+
+ /* initialisor */
+ res = output_dictionary_init(ifacef, dictionarye, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* finaliser */
+ res = output_dictionary_fini(ifacef, dictionarye, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* constructor */
+ res = output_dictionary_constructor(ifacef, dictionarye);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /* destructor */
+ res = output_dictionary_destructor(ifacef, dictionarye);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ /** todo property handlers */
+
+ /* prototype */
+ res = output_dictionary_prototype(ifacef, ir, dictionarye, inherite);
+ if (res != 0) {
+ goto op_error;
+ }
+
+ fprintf(ifacef, "\n");
+
+ /* class epilogue */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_EPILOGUE);
+
+ /* binding epilogue */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_EPILOGUE);
+
+ /* class postface */
+ output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_POSTFACE);
+
+ /* binding postface */
+ output_cdata(ifacef,
+ ir->binding_node,
+ GENBIND_NODE_TYPE_POSTFACE);
+
+op_error:
+ genb_fclose_tmp(ifacef, dictionarye->filename);
+
+ return res;
+}
diff --git a/src/duk-libdom.c b/src/duk-libdom-interface.c
similarity index 61%
copy from src/duk-libdom.c
copy to src/duk-libdom-interface.c
index 3e20d13..7501bea 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom-interface.c
@@ -27,14 +27,6 @@
#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
-#define NSGENBIND_PREAMBLE \
- "/* Generated by nsgenbind\n" \
- " *\n" \
- " * nsgenbind is published under the MIT Licence.\n" \
- " * nsgenbind is similar to a compiler is a purely transformative tool which\n" \
- " * explicitly makes no copyright claim on this generated output\n" \
- " */"
-
/**
* Output code to create a private structure
*
@@ -95,6 +87,7 @@ static char *get_prototype_name(const char *interface_name)
return proto_name;
}
+
/**
* generate code that gets a prototype by name
*/
@@ -270,166 +263,6 @@ output_get_method_private(FILE* outf, char *class_name)
return 0;
}
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_preface(FILE* outf)
-{
- fprintf(outf, "%s\n", NSGENBIND_PREAMBLE);
-
- return 0;
-}
-
-/**
- * Generate a C class name for the interface.
- *
- * The IDL interface names are camelcase and not similar to libdom naming so it
- * is necessary to convert them to a libdom compatible class name. This
- * implementation is simple ASCII capable only and cannot cope with multibyte
- * codepoints.
- *
- * The algorithm is:
- * - copy characters to output lowering their case
- * - if the previous character in the input name was uppercase and the current
- * one is lowercase insert an underscore before the *previous* character.
- */
-static char *gen_class_name(struct ir_entry *interfacee)
-{
- const char *inc;
- char *outc;
- char *name;
- int wasupper;
-
- /* enpty strings are a bad idea */
- if ((interfacee->name == NULL) ||
- (interfacee->name[0] == 0)) {
- return NULL;
- }
-
- /* allocate result buffer as twice the input length as thats the
- * absolute worst case.
- */
- name = calloc(2, strlen(interfacee->name));
-
- outc = name;
- inc = interfacee->name;
- wasupper = 0;
-
- /* first character handled separately as inserting a leading underscore
- * is undesirable
- */
- *outc++ = tolower(*inc++);
- /* copy input to output */
- while (*inc != 0) {
- /* ugly hack as html IDL is always prefixed uppercase and needs
- * an underscore there
- */
- if ((inc == (interfacee->name + 4)) &&
- (interfacee->name[0] == 'H') &&
- (interfacee->name[1] == 'T') &&
- (interfacee->name[2] == 'M') &&
- (interfacee->name[3] == 'L') &&
- (islower(inc[1]) == 0)) {
- *outc++ = '_';
- }
- if ((islower(*inc) != 0) && (wasupper != 0)) {
- *outc = *(outc - 1);
- *(outc - 1) = '_';
- outc++;
- wasupper = 0;
- } else {
- wasupper = isupper(*inc);
- }
- *outc++ = tolower(*inc++);
- }
- return name;
-}
-
-/**
- * output character data of node of given type.
- *
- * 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,
- struct genbind_node *node,
- 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 res;
-}
-
-static FILE *open_header(struct ir *ir, const char *name)
-{
- FILE *hdrf;
- char *fname;
- int fnamel;
-
- fnamel = strlen(name) + 4;
- fname = malloc(fnamel);
- snprintf(fname, fnamel, "%s.h", name);
-
- /* open output file */
- hdrf = genb_fopen_tmp(fname);
- free(fname);
- if (hdrf == NULL) {
- return NULL;
- }
-
- /* binding preface */
- output_cdata(hdrf,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* tool preface */
- output_tool_preface(hdrf);
-
- /* header guard */
- fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
- fprintf(hdrf, "#define %s_%s_h\n\n", DLPFX, name);
-
- return hdrf;
-}
-
-static int close_header(struct ir *ir,
- FILE *hdrf,
- const char *name)
-{
- char *fname;
- int fnamel;
-
- fnamel = strlen(name) + 4;
- fname = malloc(fnamel);
- snprintf(fname, fnamel, "%s.h", name);
-
- fprintf(hdrf, "\n#endif\n");
-
- /* binding postface */
- output_cdata(hdrf,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
- genb_fclose_tmp(hdrf, fname);
- free(fname);
-
- return 0;
-}
-
/**
* generate the interface constructor
@@ -863,6 +696,8 @@ output_global_create_prototype(FILE* outf,
}
return 0;
}
+
+
/**
* generate the interface prototype creator
*/
@@ -1409,129 +1244,8 @@ output_interface_attributes(FILE* outf, struct ir_entry *ife)
}
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_prologue(FILE* outf)
-{
- char *fpath;
-
- fpath = genb_fpath("binding.h");
- fprintf(outf, "\n#include \"%s\"\n", fpath);
- free(fpath);
-
- fpath = genb_fpath("private.h");
- fprintf(outf, "#include \"%s\"\n", fpath);
- free(fpath);
-
- fpath = genb_fpath("prototype.h");
- fprintf(outf, "#include \"%s\"\n", fpath);
- free(fpath);
-
- return 0;
-}
-
-/**
- * generate a source file to implement a dictionary using duk and libdom.
- */
-static int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
-{
- FILE *ifacef;
- struct ir_entry *inherite;
- int res = 0;
-
- /* open output file */
- ifacef = genb_fopen_tmp(dictionarye->filename);
- if (ifacef == NULL) {
- return -1;
- }
-
- /* find parent interface entry */
- inherite = ir_inherit_entry(ir, dictionarye);
-
- /* tool preface */
- output_tool_preface(ifacef);
-
- /* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* class preface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PREFACE);
-
- /* tool prologue */
- output_tool_prologue(ifacef);
-
- /* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
- /* class prologue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PROLOGUE);
-
- fprintf(ifacef, "\n");
-
- /* initialisor */
- res = output_interface_init(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- res = output_interface_fini(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* constructor */
- res = output_interface_constructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* destructor */
- res = output_interface_destructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* prototype */
- res = output_interface_prototype(ifacef, ir, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
-
- fprintf(ifacef, "\n");
-
- /* class epilogue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_EPILOGUE);
-
- /* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
-
- /* class postface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_POSTFACE);
-
- /* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
-op_error:
- genb_fclose_tmp(ifacef, dictionarye->filename);
-
- return res;
-}
-
-/**
- * generate a source file to implement an interface using duk and libdom.
- */
-static int output_interface(struct ir *ir, struct ir_entry *interfacee)
+/* exported interface documented in duk-libdom.h */
+int output_interface(struct ir *ir, struct ir_entry *interfacee)
{
FILE *ifacef;
struct ir_entry *inherite;
@@ -1618,560 +1332,3 @@ op_error:
return res;
}
-/**
- * generate private header
- */
-static int
-output_private_header(struct ir *ir)
-{
- int idx;
- FILE *privf;
-
- /* open header */
- privf = open_header(ir, "private");
-
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
- struct ir_entry *inherite;
- struct genbind_node *priv_node;
-
- interfacee = ir->entries + idx;
-
- /* do not generate private structs for interfaces marked no
- * output
- */
- if ((interfacee->type == IR_ENTRY_TYPE_INTERFACE) &&
- (interfacee->u.interface.noobject)) {
- continue;
- }
-
- switch (interfacee->type) {
- case IR_ENTRY_TYPE_INTERFACE:
- fprintf(privf,
- "/* Private data for %s interface */\n",
- interfacee->name);
- break;
-
- case IR_ENTRY_TYPE_DICTIONARY:
- fprintf(privf,
- "/* Private data for %s dictionary */\n",
- interfacee->name);
- break;
- }
-
- fprintf(privf, "typedef struct {\n");
-
- /* find parent entry and include in private */
- inherite = ir_inherit_entry(ir, interfacee);
- if (inherite != NULL) {
- fprintf(privf, "\t%s_private_t parent;\n",
- inherite->class_name);
- }
-
- /* for each private variable on the class output it here. */
- priv_node = genbind_node_find_type(
- genbind_node_getnode(interfacee->class),
- NULL,
- GENBIND_NODE_TYPE_PRIVATE);
- while (priv_node != NULL) {
- /* generate the private variable definition ensuring
- * the type is separated from the identifier with
- * either a * or space.
- */
- const char *type_cdata;
- char cdatae;
- type_cdata = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(priv_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- fprintf(privf, "\t%s", type_cdata);
- cdatae = type_cdata[strlen(type_cdata) - 1];
- if ((cdatae != '*') && (cdatae != ' ')) {
- fputc(' ', privf);
- }
-
- output_cdata(privf, priv_node, GENBIND_NODE_TYPE_IDENT);
- fprintf(privf, ";\n");
-
- priv_node = genbind_node_find_type(
- genbind_node_getnode(interfacee->class),
- priv_node,
- GENBIND_NODE_TYPE_PRIVATE);
- }
-
- fprintf(privf, "} %s_private_t;\n\n", interfacee->class_name);
-
- }
-
- close_header(ir, privf, "private");
-
- return 0;
-}
-
-/**
- * generate prototype header
- */
-static int
-output_prototype_header(struct ir *ir)
-{
- int idx;
- FILE *protof;
-
- /* open header */
- protof = open_header(ir, "prototype");
-
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
- struct genbind_node *init_node;
-
- interfacee = ir->entries + idx;
-
- /* do not generate prototype declarations for interfaces marked
- * no output
- */
- if ((interfacee->type == IR_ENTRY_TYPE_INTERFACE) &&
- (interfacee->u.interface.noobject)) {
- continue;
- }
-
- /* prototype declaration */
- 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.
- */
-
- /* 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");
- }
-
- close_header(ir, protof, "prototype");
-
- return 0;
-}
-
-/**
- * generate makefile fragment
- */
-static int
-output_makefile(struct ir *ir)
-{
- int idx;
- FILE *makef;
-
- /* open output file */
- makef = genb_fopen_tmp("Makefile");
- if (makef == NULL) {
- return -1;
- }
-
- fprintf(makef, "# duk libdom makefile fragment\n\n");
-
- fprintf(makef, "NSGENBIND_SOURCES:=binding.c ");
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
-
- interfacee = ir->entries + idx;
-
- /* no source for interfaces marked no output */
- if ((interfacee->type == IR_ENTRY_TYPE_INTERFACE) &&
- (interfacee->u.interface.noobject)) {
- continue;
- }
-
- fprintf(makef, "%s ", interfacee->filename);
- }
- fprintf(makef, "\nNSGENBIND_PREFIX:=%s\n", options->outdirname);
-
- genb_fclose_tmp(makef, "Makefile");
-
- return 0;
-}
-
-
-/**
- * generate binding header
- *
- * The binding header contains all the duk-libdom specific binding interface
- * macros and definitions.
- *
- * the create prototypes interface is used to cause all the prototype creation
- * functions for all generated classes to be called in the correct order with
- * the primary global (if any) generated last.
- */
-static int
-output_binding_header(struct ir *ir)
-{
- FILE *bindf;
-
- /* open header */
- bindf = open_header(ir, "binding");
-
- fprintf(bindf,
- "#define _MAGIC(S) (\"%s\" S)\n"
- "#define MAGIC(S) _MAGIC(#S)\n"
- "#define PROTO_MAGIC MAGIC(PROTOTYPES)\n"
- "#define PRIVATE_MAGIC MAGIC(PRIVATE)\n"
- "#define INIT_MAGIC MAGIC(INIT)\n"
- "#define NODE_MAGIC MAGIC(NODE_MAP)\n"
- "#define _PROTO_NAME(K) _MAGIC(\"PROTOTYPE_\" K)\n"
- "#define PROTO_NAME(K) _PROTO_NAME(#K)\n"
- "#define _PROP_NAME(K,V) _MAGIC(K \"_PROPERTY_\" V)\n"
- "#define PROP_NAME(K,V) _PROP_NAME(#K,#V)\n"
- "\n",
- MAGICPFX);
-
- /* declaration of constant string values */
- fprintf(bindf,
- "/* Constant strings */\n"
- "extern const char *%s_error_fmt_argument;\n"
- "extern const char *%s_error_fmt_string_type;\n"
- "extern const char *%s_error_fmt_bool_type;\n"
- "extern const char *%s_error_fmt_number_type;\n"
- "extern const char *%s_magic_string_private;\n"
- "extern const char *%s_magic_string_prototypes;\n"
- "\n",
- DLPFX, DLPFX, DLPFX, DLPFX, DLPFX, DLPFX);
-
- fprintf(bindf,
- "duk_bool_t %s_instanceof(duk_context *ctx, const char *klass);\n",
- DLPFX);
-
- fprintf(bindf,
- "duk_ret_t %s_create_prototypes(duk_context *ctx);\n", DLPFX);
-
- close_header(ir, bindf, "binding");
-
- return 0;
-}
-
-
-/**
- * generate binding source
- *
- * The binding header contains all the duk-libdom specific binding
- * implementations.
- */
-static int
-output_binding_src(struct ir *ir)
-{
- int idx;
- FILE *bindf;
- struct ir_entry *pglobale = NULL;
- char *proto_name;
-
- /* open output file */
- bindf = genb_fopen_tmp("binding.c");
- if (bindf == NULL) {
- return -1;
- }
-
- /* tool preface */
- output_tool_preface(bindf);
-
- /* binding preface */
- output_cdata(bindf,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- output_tool_prologue(bindf);
-
- /* binding prologue */
- output_cdata(bindf,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
-
- fprintf(bindf, "\n");
-
- fprintf(bindf,
- "/* Error format strings */\n"
- "const char *%s_error_fmt_argument =\"%%d argument required, but ony %%d present.\";\n"
- "const char *%s_error_fmt_string_type =\"argument %%d (%%s) requires a string\";\n"
- "const char *%s_error_fmt_bool_type =\"argument %%d (%%s) requires a bool\";\n"
- "const char *%s_error_fmt_number_type =\"argument %%d (%%s) requires a number\";\n",
- DLPFX, DLPFX, DLPFX, DLPFX);
-
- fprintf(bindf, "\n");
-
- fprintf(bindf,
- "/* Magic identifiers */\n"
- "const char *%s_magic_string_private =\"%sPRIVATE\";\n"
- "const char *%s_magic_string_prototypes =\"%sPROTOTYPES\";\n",
- DLPFX, MAGICPFX, DLPFX, MAGICPFX);
-
- fprintf(bindf, "\n");
-
-
- /* instance of helper */
- fprintf(bindf,
- "duk_bool_t\n"
- "%s_instanceof(duk_context *ctx, const char *klass)\n",
- DLPFX);
- fprintf(bindf,
- "{\n"
- "\t/* ... ??? */\n"
- "\tif (!duk_check_type(ctx, -1, DUK_TYPE_OBJECT)) {\n"
- "\t\treturn false;\n"
- "\t}\n"
- "\t/* ... obj */\n"
- "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n"
- "\t/* ... obj protos */\n"
- "\tduk_get_prop_string(ctx, -1, klass);\n"
- "\t/* ... obj protos goalproto */\n"
- "\tduk_get_prototype(ctx, -3);\n"
- "\t/* ... obj protos goalproto proto? */\n"
- "\twhile (!duk_is_undefined(ctx, -1)) {\n"
- "\t\tif (duk_strict_equals(ctx, -1, -2)) {\n"
- "\t\t\tduk_pop_3(ctx);\n"
- "\t\t\treturn true;\n"
- "\t\t}\n"
- "\t\tduk_get_prototype(ctx, -1);\n"
- "\t\t/* ... obj protos goalproto proto proto? */\n"
- "\t\tduk_replace(ctx, -2);\n"
- "\t\t/* ... obj protos goalproto proto? */\n"
- "\t}\n"
- "\tduk_pop_3(ctx);\n"
- "\t/* ... obj */\n"
- "\treturn false;\n"
- "}\n"
- "\n",
- DLPFX);
-
- /* prototype creation helper function */
- fprintf(bindf,
- "static duk_ret_t\n"
- "%s_to_string(duk_context *ctx)\n"
- "{\n"
- "\t/* */\n"
- "\tduk_push_this(ctx);\n"
- "\t/* this */\n"
- "\tduk_get_prototype(ctx, -1);\n"
- "\t/* this proto */\n"
- "\tduk_get_prop_string(ctx, -1, \"%sklass_name\");\n"
- "\t/* this proto classname */\n"
- "\tduk_push_string(ctx, \"[object \");\n"
- "\t/* this proto classname str */\n"
- "\tduk_insert(ctx, -2);\n"
- "\t/* this proto str classname */\n"
- "\tduk_push_string(ctx, \"]\");\n"
- "\t/* this proto str classname str */\n"
- "\tduk_concat(ctx, 3);\n"
- "\t/* this proto str */\n"
- "\treturn 1;\n"
- "}\n"
- "\n",
- DLPFX,
- MAGICPFX);
-
- fprintf(bindf,
- "static duk_ret_t %s_create_prototype(duk_context *ctx,\n",
- DLPFX);
- fprintf(bindf,
- "\t\t\t\t\tduk_safe_call_function genproto,\n"
- "\t\t\t\t\tconst char *proto_name,\n"
- "\t\t\t\t\tconst char *klass_name)\n"
- "{\n"
- "\tduk_int_t ret;\n"
- "\tduk_push_object(ctx);\n"
- "\tif ((ret = duk_safe_call(ctx, genproto, 1, 1)) != DUK_EXEC_SUCCESS) {\n"
- "\t\tduk_pop(ctx);\n"
- "\t\tLOG(\"Failed to register prototype for %%s\", proto_name + 2);\n"
- "\t\treturn ret;\n"
- "\t}\n"
- "\t/* top of stack is the ready prototype, inject it */\n"
- "\tduk_push_string(ctx, klass_name);\n"
- "\tduk_put_prop_string(ctx, -2, \"%sklass_name\");\n"
- "\tduk_push_c_function(ctx, %s_to_string, 0);\n"
- "\tduk_put_prop_string(ctx, -2, \"toString\");\n"
- "\tduk_push_string(ctx, \"toString\");\n"
- "\tduk_def_prop(ctx, -2, DUK_DEFPROP_HAVE_ENUMERABLE);\n"
- "\tduk_put_global_string(ctx, proto_name);\n"
- "\treturn DUK_ERR_NONE;\n"
- "}\n\n",
- MAGICPFX,
- DLPFX);
-
- /* generate prototype creation */
- fprintf(bindf,
- "duk_ret_t %s_create_prototypes(duk_context *ctx)\n", DLPFX);
-
- fprintf(bindf, "{\n");
-
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
-
- interfacee = ir->entries + idx;
-
- /* do not generate prototype calls for interfaces marked
- * no output
- */
- if (interfacee->type == IR_ENTRY_TYPE_INTERFACE) {
- if (interfacee->u.interface.noobject) {
- continue;
- }
-
- if (interfacee->u.interface.primary_global) {
- pglobale = interfacee;
- continue;
- }
- }
- proto_name = get_prototype_name(interfacee->name);
-
- fprintf(bindf,
- "\t%s_create_prototype(ctx, %s_%s___proto, \"%s\", \"%s\");\n",
- DLPFX,
- DLPFX,
- interfacee->class_name,
- proto_name,
- interfacee->name);
-
- free(proto_name);
- }
-
- if (pglobale != NULL) {
- fprintf(bindf, "\n\t/* Global object prototype is last */\n");
-
- proto_name = get_prototype_name(pglobale->name);
- fprintf(bindf,
- "\t%s_create_prototype(ctx, %s_%s___proto, \"%s\", \"%s\");\n",
- DLPFX,
- DLPFX,
- pglobale->class_name,
- proto_name,
- pglobale->name);
- free(proto_name);
- }
-
- fprintf(bindf, "\n\treturn DUK_ERR_NONE;\n");
-
- fprintf(bindf, "}\n");
-
- /* binding postface */
- output_cdata(bindf,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
- genb_fclose_tmp(bindf, "binding.c");
-
- return 0;
-}
-
-static int output_interfaces_dictionaries(struct ir *ir)
-{
- int res;
- int idx;
-
- /* generate interfaces */
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *irentry;
-
- irentry = ir->entries + idx;
-
- switch (irentry->type) {
- case IR_ENTRY_TYPE_INTERFACE:
- /* do not generate class for interfaces marked no
- * output
- */
- if (!irentry->u.interface.noobject) {
- res = output_interface(ir, irentry);
- if (res != 0) {
- return res;
- }
- }
- break;
-
- case IR_ENTRY_TYPE_DICTIONARY:
- res = output_dictionary(ir, irentry);
- if (res != 0) {
- return res;
- }
-
- default:
- break;
- }
- }
-
- return 0;
-}
-
-int duk_libdom_output(struct ir *ir)
-{
- int idx;
- int res = 0;
-
- /* process ir entries for output */
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *irentry;
-
- irentry = ir->entries + idx;
-
- /* compute class name */
- irentry->class_name = gen_class_name(irentry);
-
- if (irentry->class_name != NULL) {
- int ifacenamelen;
-
- /* generate source filename */
- ifacenamelen = strlen(irentry->class_name) + 4;
- irentry->filename = malloc(ifacenamelen);
- snprintf(irentry->filename,
- ifacenamelen,
- "%s.c",
- irentry->class_name);
- }
- }
-
- res = output_interfaces_dictionaries(ir);
- if (res != 0) {
- goto output_err;
- }
-
- /* generate private header */
- res = output_private_header(ir);
- if (res != 0) {
- goto output_err;
- }
-
- /* generate prototype header */
- res = output_prototype_header(ir);
- if (res != 0) {
- goto output_err;
- }
-
- /* generate binding header */
- res = output_binding_header(ir);
- if (res != 0) {
- goto output_err;
- }
-
- /* generate binding source */
- res = output_binding_src(ir);
- if (res != 0) {
- goto output_err;
- }
-
- /* generate makefile fragment */
- res = output_makefile(ir);
-
-output_err:
-
- return res;
-}
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 3e20d13..45e7e79 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -3,7 +3,7 @@
* This file is part of nsgenbind.
* Licensed under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
- * Copyright 2012 Vincent Sanders <vince(a)netsurf-browser.org>
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
*/
#include <stdio.h>
@@ -27,53 +27,6 @@
#define MAGICPFX "\\xFF\\xFFNETSURF_DUKTAPE_"
-#define NSGENBIND_PREAMBLE \
- "/* Generated by nsgenbind\n" \
- " *\n" \
- " * nsgenbind is published under the MIT Licence.\n" \
- " * nsgenbind is similar to a compiler is a purely transformative tool which\n" \
- " * explicitly makes no copyright claim on this generated output\n" \
- " */"
-
-/**
- * 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, %s_magic_string_private);\n\n",
- DLPFX);
-
- 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, %s_magic_string_private);\n",
- idx, DLPFX);
- 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 a duktape prototype name
*/
@@ -95,190 +48,6 @@ static char *get_prototype_name(const char *interface_name)
return proto_name;
}
-/**
- * generate code that gets a prototype by name
- */
-static int output_get_prototype(FILE* outf, const char *interface_name)
-{
- char *proto_name;
-
- proto_name = get_prototype_name(interface_name);
-
- fprintf(outf,
- "\t/* get prototype */\n");
- fprintf(outf,
- "\tduk_get_global_string(ctx, %s_magic_string_prototypes);\n",
- DLPFX);
- fprintf(outf,
- "\tduk_get_prop_string(ctx, -1, \"%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, \"%sINIT\");\n",
- MAGICPFX);
- 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,
- const char *class_name,
- const char *method)
-{
- 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, DUK_VARARGS);\n",
- DLPFX, class_name, method);
- 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);
- output_dump_stack(outf);
- fprintf(outf, "\tduk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t\tDUK_DEFPROP_HAVE_SETTER |\n");
- fprintf(outf, "\t\tDUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t\tDUK_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);
- output_dump_stack(outf);
- fprintf(outf, "\tduk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_GETTER |\n");
- fprintf(outf, "\t\tDUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |\n");
- fprintf(outf, "\t\tDUK_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, %s_magic_string_private);\n",
- DLPFX);
- fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n");
- fprintf(outf, "\tduk_pop_2(ctx);\n");
- fprintf(outf, "\tif (priv == NULL) {\n");
- if (options->dbglog) {
- fprintf(outf, "\t\tLOG(\"priv failed\");\n");
- }
- fprintf(outf, "\t\treturn 0; /* can do? No can do. */\n");
- fprintf(outf, "\t}\n\n");
-
- return 0;
-}
-
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_preface(FILE* outf)
-{
- fprintf(outf, "%s\n", NSGENBIND_PREAMBLE);
-
- return 0;
-}
/**
* Generate a C class name for the interface.
@@ -345,34 +114,6 @@ static char *gen_class_name(struct ir_entry *interfacee)
return name;
}
-/**
- * output character data of node of given type.
- *
- * 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,
- struct genbind_node *node,
- 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 res;
-}
static FILE *open_header(struct ir *ir, const char *name)
{
@@ -431,166 +172,7 @@ static int close_header(struct ir *ir,
}
-/**
- * generate the interface constructor
- */
-static int
-output_interface_constructor(FILE* outf, struct ir_entry *interfacee)
-{
- int init_argc;
-
- /* constructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___constructor(duk_context *ctx)\n",
- DLPFX, interfacee->class_name);
- fprintf(outf,"{\n");
-
- output_create_private(outf, interfacee->class_name);
-
- /* generate call to initialisor */
- fprintf(outf,
- "\t%s_%s___init(ctx, priv",
- DLPFX, interfacee->class_name);
- for (init_argc = 1;
- init_argc <= interfacee->class_init_argc;
- init_argc++) {
- fprintf(outf, ", duk_get_pointer(ctx, %d)", init_argc);
- }
- fprintf(outf, ");\n");
-
-
- fprintf(outf, "\tduk_set_top(ctx, 1);\n");
- fprintf(outf, "\treturn 1;\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate the interface destructor
- */
-static int
-output_interface_destructor(FILE* outf, struct ir_entry *interfacee)
-{
- /* destructor definition */
- fprintf(outf,
- "static duk_ret_t %s_%s___destructor(duk_context *ctx)\n",
- DLPFX, interfacee->class_name);
- fprintf(outf,"{\n");
-
- output_safe_get_private(outf, interfacee->class_name, 0);
-
- /* generate call to finaliser */
- fprintf(outf,
- "\t%s_%s___fini(ctx, priv);\n",
- DLPFX, interfacee->class_name);
-
- fprintf(outf,"\tfree(priv);\n");
- fprintf(outf,"\treturn 0;\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate an initialisor call to parent interface
- */
-static int
-output_interface_inherit_init(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_entry *inherite)
-{
- struct genbind_node *init_node;
- struct genbind_node *inh_init_node;
- struct genbind_node *param_node;
- struct genbind_node *inh_param_node;
-
- /* only need to call parent initialisor if there is one */
- if (inherite == NULL) {
- return 0;
- }
-
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
- inh_init_node = genbind_node_find_method(inherite->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
-
-
- fprintf(outf, "\t%s_%s___init(ctx, &priv->parent",
- DLPFX, inherite->class_name);
-
- /* for each parameter in the parent find a matching named
- * parameter to pass and cast if necessary
- */
-
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- while (inh_param_node != NULL) {
- char *param_name;
- param_name = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_IDENT));
-
- param_node = genbind_node_find_type_ident(
- genbind_node_getnode(init_node),
- NULL,
- GENBIND_NODE_TYPE_PARAMETER,
- param_name);
- if (param_node == NULL) {
- fprintf(stderr, "class \"%s\" (interface %s) parent class \"%s\" (interface %s) initialisor requires a parameter \"%s\" with compatible identifier\n",
- interfacee->class_name,
- interfacee->name,
- inherite->class_name,
- inherite->name,
- param_name);
- return -1;
- } else {
- char *param_type;
- char *inh_param_type;
-
- fprintf(outf, ", ");
-
- /* cast the parameter if required */
- param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- inh_param_type = genbind_node_gettext(
- genbind_node_find_type(
- genbind_node_getnode(inh_param_node),
- NULL,
- GENBIND_NODE_TYPE_TYPE));
-
- if (strcmp(param_type, inh_param_type) != 0) {
- fprintf(outf, "(%s)", inh_param_type);
- }
-
- /* output the parameter identifier */
- output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT);
- }
-
- inh_param_node = genbind_node_find_type(
- genbind_node_getnode(inh_init_node),
- inh_param_node, GENBIND_NODE_TYPE_METHOD);
- }
-
- fprintf(outf, ");\n");
-
- return 0;
-}
static int
output_interface_init_declaration(FILE* outf,
@@ -626,997 +208,6 @@ output_interface_init_declaration(FILE* outf,
return 0;
}
-static int
-output_interface_init(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_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);
- if (res != 0) {
- return res;
- }
-
- /* generate log statement */
- if (options->dbglog) {
- fprintf(outf,
- "\tLOG(\"Initialise %%p (priv=%%p)\", duk_get_heapptr(ctx, 0), priv);\n" );
- }
-
- /* output the initaliser code from the binding */
- output_cdata(outf, init_node, GENBIND_NODE_TYPE_CDATA);
-
- fprintf(outf, "}\n\n");
-
- return 0;
-
-}
-
-static int
-output_interface_fini(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_entry *inherite)
-{
- struct genbind_node *fini_node;
-
- /* find the finaliser method on the class (if any) */
- fini_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_FINI);
-
- /* finaliser definition */
- fprintf(outf,
- "void %s_%s___fini(duk_context *ctx, %s_private_t *priv)\n",
- DLPFX, interfacee->class_name, interfacee->class_name);
- fprintf(outf,"{\n");
-
- /* generate log statement */
- if (options->dbglog) {
- fprintf(outf,
- "\tLOG(\"Finalise %%p\", duk_get_heapptr(ctx, 0));\n" );
- }
-
- /* output the finialisor code from the binding */
- output_cdata(outf, fini_node, GENBIND_NODE_TYPE_CDATA);
-
- /* if this interface inherits ensure we call its finaliser */
- if (inherite != NULL) {
- fprintf(outf,
- "\t%s_%s___fini(ctx, &priv->parent);\n",
- DLPFX, inherite->class_name);
- }
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-
-/**
- * generate a prototype add for a single class method
- */
-static int
-output_prototype_method(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
-
- if (operatione->name != NULL) {
- /* normal method on prototype */
- output_add_method(outf,
- interfacee->class_name,
- operatione->name);
- } else {
- /* special method on prototype */
- fprintf(outf,
- "\t/* Special method on prototype - UNIMPLEMENTED */\n\n");
- }
-
- return 0;
-}
-
-/**
- * generate prototype method definitions
- */
-static int
-output_prototype_methods(FILE *outf, struct ir_entry *entry)
-{
- int opc;
- int res = 0;
-
- for (opc = 0; opc < entry->u.interface.operationc; opc++) {
- res = output_prototype_method(
- outf,
- entry,
- entry->u.interface.operationv + opc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-
-static int
-output_prototype_attribute(FILE *outf,
- struct ir_entry *interfacee,
- struct ir_attribute_entry *attributee)
-{
- if (attributee->modifier == WEBIDL_TYPE_MODIFIER_READONLY) {
- return output_populate_ro_property(outf,
- interfacee->class_name,
- attributee->name);
- }
- return output_populate_rw_property(outf,
- interfacee->class_name,
- attributee->name);
-}
-
-/**
- * generate prototype attribute definitions
- */
-static int
-output_prototype_attributes(FILE *outf, struct ir_entry *entry)
-{
- int attrc;
- int res = 0;
-
- for (attrc = 0; attrc < entry->u.interface.attributec; attrc++) {
- res = output_prototype_attribute(
- outf,
- entry,
- entry->u.interface.attributev + attrc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-/**
- * output constants on the prototype
- *
- * \todo This implementation assumes the constant is a literal int and should
- * check the type node base value.
- */
-static int
-output_prototype_constant(FILE *outf,
- struct ir_constant_entry *constante)
-{
- int *value;
-
- value = webidl_node_getint(
- webidl_node_find_type(
- webidl_node_getnode(constante->node),
- NULL,
- WEBIDL_NODE_TYPE_LITERAL_INT));
-
- output_prototype_constant_int(outf, constante->name, *value);
-
- return 0;
-}
-
-/**
- * generate prototype constant definitions
- */
-static int
-output_prototype_constants(FILE *outf, struct ir_entry *entry)
-{
- int attrc;
- int res = 0;
-
- for (attrc = 0; attrc < entry->u.interface.constantc; attrc++) {
- res = output_prototype_constant(
- outf,
- entry->u.interface.constantv + attrc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-static int
-output_global_create_prototype(FILE* outf,
- struct ir *ir,
- struct ir_entry *interfacee)
-{
- int idx;
-
- fprintf(outf, "\t/* Create interface objects */\n");
- for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *entry;
-
- entry = ir->entries + idx;
-
- if (entry->type == IR_ENTRY_TYPE_INTERFACE) {
-
- if (entry->u.interface.noobject) {
- continue;
- }
-
- if (entry == interfacee) {
- fprintf(outf, "\tduk_dup(ctx, 0);\n");
- } else {
- output_get_prototype(outf, entry->name);
- }
-
- fprintf(outf,
- "\tdukky_inject_not_ctr(ctx, 0, \"%s\");\n",
- entry->name);
- }
- }
- return 0;
-}
-/**
- * generate the interface prototype creator
- */
-static int
-output_interface_prototype(FILE* outf,
- struct ir *ir,
- struct ir_entry *interfacee,
- struct ir_entry *inherite)
-{
- struct genbind_node *proto_node;
-
- /* find the prototype method on the class */
- proto_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_PROTOTYPE);
-
- /* prototype definition */
- fprintf(outf, "duk_ret_t %s_%s___proto(duk_context *ctx)\n",
- DLPFX, interfacee->class_name);
- fprintf(outf,"{\n");
-
- /* Output any binding data first */
- if (output_cdata(outf, proto_node, GENBIND_NODE_TYPE_CDATA) != 0) {
- fprintf(outf,"\n");
- }
-
- /* generate prototype chaining if interface has a parent */
- if (inherite != NULL) {
- fprintf(outf,
- "\t/* Set this prototype's prototype (left-parent) */\n");
- output_get_prototype(outf, inherite->name);
- fprintf(outf, "\tduk_set_prototype(ctx, 0);\n\n");
- }
-
- /* generate setting of methods */
- output_prototype_methods(outf, interfacee);
-
- /* generate setting of attributes */
- output_prototype_attributes(outf, interfacee);
-
- /* generate setting of constants */
- output_prototype_constants(outf, interfacee);
-
- /* if this is the global object, output all interfaces which do not
- * prevent us from doing so
- */
- if (interfacee->u.interface.primary_global) {
- output_global_create_prototype(outf, ir, interfacee);
- }
-
- /* generate setting of destructor */
- output_set_destructor(outf, interfacee->class_name, 0);
-
- /* generate setting of constructor */
- output_set_constructor(outf,
- interfacee->class_name,
- 0,
- interfacee->class_init_argc);
-
- fprintf(outf,"\treturn 1; /* The prototype object */\n");
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a single class method for an interface operation with elipsis
- */
-static int
-output_interface_elipsis_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- int cdatac; /* cdata blocks output */
-
- /* overloaded method definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, operatione->name);
- fprintf(outf,"{\n");
-
- /**
- * \todo This is where the checking of the parameters to the
- * operation with elipsis should go
- */
- WARN(WARNING_UNIMPLEMENTED,
- "Elipsis parameetrs not checked: method %s::%s();",
- interfacee->name, operatione->name);
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf,
- operatione->method,
- GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- /* no implementation so generate default */
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: method %s::%s();",
- interfacee->name, operatione->name);
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a single class method for an interface overloaded operation
- */
-static int
-output_interface_overloaded_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- int cdatac; /* cdata blocks output */
-
- /* overloaded method definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, operatione->name);
- fprintf(outf,"{\n");
-
- /** \todo This is where the checking of the parameters to the
- * overloaded operation should go
- */
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf,
- operatione->method,
- GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- /* no implementation so generate default */
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: method %s::%s();",
- interfacee->name, operatione->name);
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate a single class method for an interface special operation
- */
-static int
-output_interface_special_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- /* special method definition */
- fprintf(outf, "/* Special method definition - UNIMPLEMENTED */\n\n");
-
- WARN(WARNING_UNIMPLEMENTED,
- "Special operation on interface %s (operation entry %p)",
- interfacee->name,
- operatione);
-
- return 0;
-}
-
-/**
- * generate default values on the duk stack
- */
-static int
-output_operation_optional_defaults(FILE* outf,
- struct ir_operation_argument_entry *argumentv,
- int argumentc)
-{
- int argc;
- for (argc = 0; argc < argumentc; argc++) {
- struct ir_operation_argument_entry *cure;
- struct webidl_node *lit_node; /* literal node */
- enum webidl_node_type lit_type;
- int *lit_int;
- char *lit_str;
-
- cure = argumentv + argc;
-
- lit_node = webidl_node_getnode(
- webidl_node_find_type(
- webidl_node_getnode(cure->node),
- NULL,
- WEBIDL_NODE_TYPE_OPTIONAL));
-
- if (lit_node != NULL) {
-
- lit_type = webidl_node_gettype(lit_node);
-
- switch (lit_type) {
- case WEBIDL_NODE_TYPE_LITERAL_NULL:
- fprintf(outf,
- "\t\tduk_push_null(ctx);\n");
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_INT:
- lit_int = webidl_node_getint(lit_node);
- fprintf(outf,
- "\t\tduk_push_int(ctx, %d);\n",
- *lit_int);
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_BOOL:
- lit_int = webidl_node_getint(lit_node);
- fprintf(outf,
- "\t\tduk_push_boolean(ctx, %d);\n",
- *lit_int);
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_STRING:
- lit_str = webidl_node_gettext(lit_node);
- fprintf(outf,
- "\t\tduk_push_string(ctx, \"%s\");\n",
- lit_str);
- break;
-
- case WEBIDL_NODE_TYPE_LITERAL_FLOAT:
- default:
- fprintf(outf,
- "\t\tduk_push_undefined(ctx);\n");
- break;
- }
- } else {
- fprintf(outf, "\t\tduk_push_undefined(ctx);\n");
- }
- }
- return 0;
-}
-
-static int
-output_operation_argument_type_check(
- FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione,
- struct ir_operation_overload_entry *overloade,
- int argidx)
-{
- struct ir_operation_argument_entry *argumente;
- struct webidl_node *type_node;
- enum webidl_type *argument_type;
-
- argumente = overloade->argumentv + argidx;
-
- type_node = webidl_node_find_type(
- webidl_node_getnode(argumente->node),
- NULL,
- WEBIDL_NODE_TYPE_TYPE);
-
- if (type_node == NULL) {
- fprintf(stderr, "%s:%s %dth argument %s has no type\n",
- interfacee->name,
- operatione->name,
- argidx,
- argumente->name);
- return -1;
- }
-
- argument_type = (enum webidl_type *)webidl_node_getint(
- webidl_node_find_type(
- webidl_node_getnode(type_node),
- NULL,
- WEBIDL_NODE_TYPE_TYPE_BASE));
-
- if (argument_type == NULL) {
- fprintf(stderr,
- "%s:%s %dth argument %s has no type base\n",
- interfacee->name,
- operatione->name,
- argidx,
- argumente->name);
- return -1;
- }
-
- if (*argument_type == WEBIDL_TYPE_ANY) {
- /* allowing any type needs no check */
- return 0;
- }
-
- fprintf(outf, "\tif (%s_argc > %d) {\n", DLPFX, argidx);
-
- switch (*argument_type) {
- case WEBIDL_TYPE_STRING:
- fprintf(outf,
- "\t\tif (!duk_is_string(ctx, %d)) {\n"
- "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_string_type, %d, \"%s\");\n"
- "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
- break;
-
- case WEBIDL_TYPE_BOOL:
- fprintf(outf,
- "\t\tif (!duk_is_boolean(ctx, %d)) {\n"
- "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_bool_type, %d, \"%s\");\n"
- "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
- break;
-
- case WEBIDL_TYPE_FLOAT:
- case WEBIDL_TYPE_DOUBLE:
- case WEBIDL_TYPE_SHORT:
- case WEBIDL_TYPE_LONG:
- case WEBIDL_TYPE_LONGLONG:
- fprintf(outf,
- "\t\tif (!duk_is_number(ctx, %d)) {\n"
- "\t\t\tduk_error(ctx, DUK_ERR_ERROR, %s_error_fmt_number_type, %d, \"%s\");\n"
- "\t\t}\n", argidx, DLPFX, argidx, argumente->name);
- break;
-
-
- default:
- fprintf(outf,
- "\t\t/* unhandled type check */\n");
- }
-
- fprintf(outf, "\t}\n");
-
- return 0;
-}
-
-
-/**
- * generate a single class method for an interface operation
- */
-static int
-output_interface_operation(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_operation_entry *operatione)
-{
- int cdatac; /* cdata blocks output */
- struct ir_operation_overload_entry *overloade;
- int fixedargc; /* number of non optional arguments */
- int argidx; /* loop counter for arguments */
- int optargc; /* loop counter for optional arguments */
-
- if (operatione->name == NULL) {
- return output_interface_special_operation(outf,
- interfacee,
- operatione);
- }
-
- if (operatione->overloadc != 1) {
- return output_interface_overloaded_operation(outf,
- interfacee,
- operatione);
- }
-
- if (operatione->overloadv->elipsisc != 0) {
- return output_interface_elipsis_operation(outf,
- interfacee,
- operatione);
- }
-
- /* normal method definition */
- overloade = operatione->overloadv;
-
- fprintf(outf,
- "static duk_ret_t %s_%s_%s(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, operatione->name);
- fprintf(outf,"{\n");
-
- /* check arguments */
-
- /* generate check for minimum number of parameters */
-
- fixedargc = overloade->argumentc - overloade->optionalc;
-
- fprintf(outf,
- "\t/* ensure the parameters are present */\n"
- "\tduk_idx_t %s_argc = duk_get_top(ctx);\n\t", DLPFX);
-
- if (fixedargc > 0) {
- fprintf(outf,
- "if (%s_argc < %d) {\n"
- "\t\t/* not enough arguments */\n"
- "\t\tduk_error(ctx, DUK_RET_TYPE_ERROR, %s_error_fmt_argument, %d, %s_argc);\n"
- "\t} else ",
- DLPFX,
- fixedargc,
- DLPFX,
- fixedargc,
- DLPFX);
- }
-
- for (optargc = fixedargc;
- optargc < overloade->argumentc;
- optargc++) {
- fprintf(outf,
- "if (%s_argc == %d) {\n"
- "\t\t/* %d optional arguments need adding */\n",
- DLPFX,
- optargc,
- overloade->argumentc - optargc);
- output_operation_optional_defaults(outf,
- overloade->argumentv + optargc,
- overloade->argumentc - optargc);
- fprintf(outf,
- "\t} else ");
- }
-
- fprintf(outf,
- "if (%s_argc > %d) {\n"
- "\t\t/* remove extraneous parameters */\n"
- "\t\tduk_set_top(ctx, %d);\n"
- "\t}\n",
- DLPFX,
- overloade->argumentc,
- overloade->argumentc);
- fprintf(outf, "\n");
-
- /* generate argument type checks */
-
- fprintf(outf, "\t/* check types of passed arguments are correct */\n");
-
- for (argidx = 0; argidx < overloade->argumentc; argidx++) {
- output_operation_argument_type_check(outf,
- interfacee,
- operatione,
- overloade,
- argidx);
- }
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf,
- operatione->method,
- GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- /* no implementation so generate default */
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: method %s::%s();",
- interfacee->name, operatione->name);
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate class methods for each interface operation
- */
-static int
-output_interface_operations(FILE* outf, struct ir_entry *ife)
-{
- int opc;
- int res = 0;
-
- for (opc = 0; opc < ife->u.interface.operationc; opc++) {
- res = output_interface_operation(
- outf,
- ife,
- ife->u.interface.operationv + opc);
- if (res != 0) {
- break;
- }
- }
-
- return res;
-}
-
-/**
- * Generate class property getter/setter for a single attribute
- */
-static int
-output_interface_attribute(FILE* outf,
- struct ir_entry *interfacee,
- struct ir_attribute_entry *atributee)
-{
- int cdatac;
-
- /* getter definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s_getter(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, atributee->name);
- fprintf(outf,"{\n");
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf, atributee->getter, GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: getter %s::%s();",
- interfacee->name, atributee->name);
-
- /* no implementation so generate default */
- fprintf(outf,"\treturn 0;\n");
- }
-
- fprintf(outf, "}\n\n");
-
- /* readonly attributes have no setter */
- if (atributee->modifier == WEBIDL_TYPE_MODIFIER_READONLY) {
- return 0;
- }
-
- /* setter definition */
- fprintf(outf,
- "static duk_ret_t %s_%s_%s_setter(duk_context *ctx)\n",
- DLPFX, interfacee->class_name, atributee->name);
- fprintf(outf,"{\n");
-
- output_get_method_private(outf, interfacee->class_name);
-
- cdatac = output_cdata(outf, atributee->setter, GENBIND_NODE_TYPE_CDATA);
-
- if (cdatac == 0) {
- WARN(WARNING_UNIMPLEMENTED,
- "Unimplemented: setter %s::%s();",
- interfacee->name, atributee->name);
-
- /* no implementation so generate default */
- fprintf(outf,"\treturn 0;\n");
- }
-
-
- fprintf(outf, "}\n\n");
-
- return 0;
-}
-
-/**
- * generate class property getters and setters for each interface attribute
- */
-static int
-output_interface_attributes(FILE* outf, struct ir_entry *ife)
-{
- int attrc;
-
- for (attrc = 0; attrc < ife->u.interface.attributec; attrc++) {
- output_interface_attribute(
- outf,
- ife,
- ife->u.interface.attributev + attrc);
- }
-
- return 0;
-}
-
-
-/**
- * generate preface block for nsgenbind
- */
-static int output_tool_prologue(FILE* outf)
-{
- char *fpath;
-
- fpath = genb_fpath("binding.h");
- fprintf(outf, "\n#include \"%s\"\n", fpath);
- free(fpath);
-
- fpath = genb_fpath("private.h");
- fprintf(outf, "#include \"%s\"\n", fpath);
- free(fpath);
-
- fpath = genb_fpath("prototype.h");
- fprintf(outf, "#include \"%s\"\n", fpath);
- free(fpath);
-
- return 0;
-}
-
-/**
- * generate a source file to implement a dictionary using duk and libdom.
- */
-static int output_dictionary(struct ir *ir, struct ir_entry *dictionarye)
-{
- FILE *ifacef;
- struct ir_entry *inherite;
- int res = 0;
-
- /* open output file */
- ifacef = genb_fopen_tmp(dictionarye->filename);
- if (ifacef == NULL) {
- return -1;
- }
-
- /* find parent interface entry */
- inherite = ir_inherit_entry(ir, dictionarye);
-
- /* tool preface */
- output_tool_preface(ifacef);
-
- /* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* class preface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PREFACE);
-
- /* tool prologue */
- output_tool_prologue(ifacef);
-
- /* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
- /* class prologue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_PROLOGUE);
-
- fprintf(ifacef, "\n");
-
- /* initialisor */
- res = output_interface_init(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- res = output_interface_fini(ifacef, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* constructor */
- res = output_interface_constructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* destructor */
- res = output_interface_destructor(ifacef, dictionarye);
- if (res != 0) {
- goto op_error;
- }
-
- /* prototype */
- res = output_interface_prototype(ifacef, ir, dictionarye, inherite);
- if (res != 0) {
- goto op_error;
- }
-
-
- fprintf(ifacef, "\n");
-
- /* class epilogue */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_EPILOGUE);
-
- /* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
-
- /* class postface */
- output_cdata(ifacef, dictionarye->class, GENBIND_NODE_TYPE_POSTFACE);
-
- /* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
-op_error:
- genb_fclose_tmp(ifacef, dictionarye->filename);
-
- return res;
-}
-
-/**
- * generate a source file to implement an interface using duk and libdom.
- */
-static int output_interface(struct ir *ir, struct ir_entry *interfacee)
-{
- FILE *ifacef;
- struct ir_entry *inherite;
- int res = 0;
-
- /* open output file */
- ifacef = genb_fopen_tmp(interfacee->filename);
- if (ifacef == NULL) {
- return -1;
- }
-
- /* find parent interface entry */
- inherite = ir_inherit_entry(ir, interfacee);
-
- /* tool preface */
- output_tool_preface(ifacef);
-
- /* binding preface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PREFACE);
-
- /* class preface */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PREFACE);
-
- /* tool prologue */
- output_tool_prologue(ifacef);
-
- /* binding prologue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_PROLOGUE);
-
- /* class prologue */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_PROLOGUE);
-
- fprintf(ifacef, "\n");
-
- /* initialisor */
- res = output_interface_init(ifacef, interfacee, inherite);
- if (res != 0) {
- goto op_error;
- }
-
- /* finaliser */
- output_interface_fini(ifacef, interfacee, inherite);
-
- /* constructor */
- output_interface_constructor(ifacef, interfacee);
-
- /* destructor */
- output_interface_destructor(ifacef, interfacee);
-
- /* operations */
- output_interface_operations(ifacef, interfacee);
-
- /* attributes */
- output_interface_attributes(ifacef, interfacee);
-
- /* prototype */
- output_interface_prototype(ifacef, ir, interfacee, inherite);
-
- fprintf(ifacef, "\n");
-
- /* class epilogue */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_EPILOGUE);
-
- /* binding epilogue */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_EPILOGUE);
-
- /* class postface */
- output_cdata(ifacef, interfacee->class, GENBIND_NODE_TYPE_POSTFACE);
-
- /* binding postface */
- output_cdata(ifacef,
- ir->binding_node,
- GENBIND_NODE_TYPE_POSTFACE);
-
-op_error:
- genb_fclose_tmp(ifacef, interfacee->filename);
-
- return res;
-}
/**
* generate private header
diff --git a/src/duk-libdom.h b/src/duk-libdom.h
index 2ecd482..84fc497 100644
--- a/src/duk-libdom.h
+++ b/src/duk-libdom.h
@@ -9,6 +9,41 @@
#ifndef nsgenbind_duk_libdom_h
#define nsgenbind_duk_libdom_h
+/**
+ * Generate output for duktape and libdom bindings.
+ */
int duk_libdom_output(struct ir *ir);
+/**
+ * generate a source file to implement an interface using duk and libdom.
+ */
+int output_interface(struct ir *ir, struct ir_entry *interfacee);
+
+/**
+ * generate a source file to implement a dictionary using duk and libdom.
+ */
+int output_dictionary(struct ir *ir, struct ir_entry *dictionarye);
+
+/**
+ * generate preface block for nsgenbind
+ */
+int output_tool_preface(FILE* outf);
+
+/**
+ * generate preface block for nsgenbind
+ */
+int output_tool_prologue(FILE* outf);
+
+/**
+ * output character data of node of given type.
+ *
+ * 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.
+ */
+int output_cdata(FILE* outf, struct genbind_node *node, enum genbind_node_type nodetype);
+
#endif
--
NetSurf Generator for JavaScript bindings
8 years, 1 month