summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2013-12-21 22:29:42 +0000
committerVincent Sanders <vince@kyllikki.org>2014-05-16 14:38:56 +0100
commitc25cc0e348a1abf0ee0719cf30515b3cc07f1848 (patch)
tree08458682835c7d4177ad785f423467e64e51fcc0
parentabec5defbb553588dce1c317b74570061705f6d0 (diff)
downloadnsgenbind-c25cc0e348a1abf0ee0719cf30515b3cc07f1848.tar.gz
nsgenbind-c25cc0e348a1abf0ee0719cf30515b3cc07f1848.tar.bz2
move flag indicating jsapi object for an interface should be a global from api definition to the interface flags
-rw-r--r--src/jsapi-libdom-property.c26
-rw-r--r--src/jsapi-libdom.c94
-rw-r--r--src/jsapi-libdom.h1
-rw-r--r--src/nsgenbind-ast.c30
-rw-r--r--src/nsgenbind-ast.h42
-rw-r--r--src/nsgenbind.c8
-rw-r--r--test/data/bindings/window.bnd6
7 files changed, 124 insertions, 83 deletions
diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c
index 091b2c6..7e67bae 100644
--- a/src/jsapi-libdom-property.c
+++ b/src/jsapi-libdom-property.c
@@ -108,7 +108,7 @@ output_property_tinyid_get(struct binding *binding, const char *argname)
/******************************** tinyid ********************************/
-static int
+static int
webidl_property_tinyid_cb(struct webidl_node *node, void *ctx)
{
struct binding *binding = ctx;
@@ -132,7 +132,7 @@ webidl_property_tinyid_cb(struct webidl_node *node, void *ctx)
}
/* callback to emit implements property spec */
-static int
+static int
webidl_property_tinyid_implements_cb(struct webidl_node *node, void *ctx)
{
struct binding *binding = ctx;
@@ -211,7 +211,7 @@ output_property_tinyid(struct binding *binding)
res = generate_property_tinyid(binding, binding->interface);
- fprintf(binding->outfile,
+ fprintf(binding->outfile,
"\tJSAPI_PROP_TINYID_END,\n"
"};\n\n");
@@ -386,21 +386,21 @@ static int webidl_property_spec_cb(struct webidl_node *node, void *ctx)
* js doesnt provide storage and setter/getter must
* perform all GC management.
*/
- fprintf(binding->outfile,
+ fprintf(binding->outfile,
"\t\t%s,\n"
"\t\tJSAPI_PROP_TINYID_%s,\n"
- "\t\tJSPROP_SHARED | ",
- ident,
+ "\t\tJSPROP_SHARED | ",
+ ident,
ident);
break;
case GENBIND_TYPE_TYPE:
/* shared property with a type handler */
- fprintf(binding->outfile,
+ fprintf(binding->outfile,
"\t\t%s,\n"
"\t\tJSAPI_PROP_TINYID_%s,\n"
- "\t\tJSPROP_SHARED | ",
- type,
+ "\t\tJSPROP_SHARED | ",
+ type,
ident);
break;
@@ -1028,9 +1028,9 @@ generate_property_body(struct binding *binding, const char *interface)
/* setter for type handler */
-static int
-output_property_type_setter(struct binding *binding,
- struct genbind_node *node,
+static int
+output_property_type_setter(struct binding *binding,
+ struct genbind_node *node,
const char *type)
{
struct genbind_node *property_node;
@@ -1149,7 +1149,7 @@ output_property_body(struct binding *binding)
res = generate_property_body(binding, binding->interface);
if (res == 0) {
- res = genbind_node_for_each_type(binding->binding_list,
+ res = genbind_node_foreach_type(binding->binding_list,
GENBIND_NODE_TYPE_BINDING_PROPERTY,
typehandler_property_cb,
binding);
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c
index 2389a57..f0dc5a3 100644
--- a/src/jsapi-libdom.c
+++ b/src/jsapi-libdom.c
@@ -47,7 +47,7 @@ read_webidl(struct genbind_node *genbind_ast, struct webidl_node **webidl_ast)
{
int res;
- res = genbind_node_for_each_type(genbind_ast,
+ res = genbind_node_foreach_type(genbind_ast,
GENBIND_NODE_TYPE_WEBIDLFILE,
webidl_file_cb,
webidl_ast);
@@ -101,7 +101,7 @@ static int webidl_hdrcomments_cb(struct genbind_node *node, void *ctx)
static int webidl_hdrcomment_cb(struct genbind_node *node, void *ctx)
{
- genbind_node_for_each_type(genbind_node_getnode(node),
+ genbind_node_foreach_type(genbind_node_getnode(node),
GENBIND_NODE_TYPE_STRING,
webidl_hdrcomments_cb,
ctx);
@@ -187,7 +187,7 @@ static int webidl_private_assign_cb(struct genbind_node *node, void *ctx)
static int
output_epilogue(struct binding *binding)
{
- genbind_node_for_each_type(binding->gb_ast,
+ genbind_node_foreach_type(binding->gb_ast,
GENBIND_NODE_TYPE_EPILOGUE,
webidl_epilogue_cb,
binding);
@@ -215,7 +215,7 @@ output_prologue(struct binding *binding)
fprintf(binding->outfile,
"static JSPropertySpec jsclass_properties[];\n\n");
- genbind_node_for_each_type(binding->gb_ast,
+ genbind_node_foreach_type(binding->gb_ast,
GENBIND_NODE_TYPE_PROLOGUE,
webidl_prologue_cb,
binding);
@@ -604,7 +604,7 @@ output_class_new(struct binding *binding)
"\t\tJSObject *parent",
binding->interface);
- genbind_node_for_each_type(binding->binding_list,
+ genbind_node_foreach_type(binding->binding_list,
GENBIND_NODE_TYPE_BINDING_PRIVATE,
webidl_private_param_cb,
binding);
@@ -621,7 +621,7 @@ output_class_new(struct binding *binding)
"\t\tJSObject *parent",
binding->interface);
- genbind_node_for_each_type(binding->binding_list,
+ genbind_node_foreach_type(binding->binding_list,
GENBIND_NODE_TYPE_BINDING_PRIVATE,
webidl_private_param_cb,
binding);
@@ -641,7 +641,7 @@ output_class_new(struct binding *binding)
"\t\treturn NULL;\n"
"\t}\n");
- genbind_node_for_each_type(binding->binding_list,
+ genbind_node_foreach_type(binding->binding_list,
GENBIND_NODE_TYPE_BINDING_PRIVATE,
webidl_private_assign_cb,
binding);
@@ -785,21 +785,48 @@ output_forward_declarations(struct binding *binding)
return 0;
}
-static int
-output_jsclass(struct binding *binding)
+static bool interface_is_global(struct genbind_node *interface_node)
{
+ if (genbind_node_find_type_ident(
+ genbind_node_getnode(interface_node),
+ NULL,
+ GENBIND_NODE_TYPE_BINDING_INTERFACE_FLAGS,
+ "global") != NULL) {
+ return true;
+ }
+
+ return false;
+}
+
+static int output_jsclass(struct genbind_node *interface_node, void *ctx)
+{
+ struct binding *binding = ctx;
+ struct genbind_node *interface_list;
+ const char *interface_ident;
+
+ interface_list = genbind_node_getnode(interface_node);
+ if (interface_list == NULL)
+ return -1; /* bad AST */
+
+ interface_ident = genbind_node_gettext(
+ genbind_node_find_type(interface_list,
+ NULL,
+ GENBIND_NODE_TYPE_IDENT));
+ if (interface_ident == NULL)
+ return -1; /* bad AST */
+
/* output the class declaration */
- HDROUTF(binding, "JSClass JSClass_%s;\n", binding->interface);
+ HDROUTF(binding, "JSClass JSClass_%s;\n", interface_ident);
/* output the class definition */
fprintf(binding->outfile,
"JSClass JSClass_%s = {\n"
"\t\"%s\",\n",
- binding->interface,
- binding->interface);
+ interface_ident,
+ interface_ident);
/* generate class flags */
- if (binding->has_global) {
+ if (interface_is_global(interface_node)) {
fprintf(binding->outfile, "\tJSCLASS_GLOBAL_FLAGS");
} else {
fprintf(binding->outfile, "\t0");
@@ -901,9 +928,21 @@ output_jsclass(struct binding *binding)
fprintf(binding->outfile,
"\tJSAPI_CLASS_NO_INTERNAL_MEMBERS\n"
"};\n\n");
+
return 0;
}
+static int
+output_jsclasses(struct binding *binding)
+{
+
+ return genbind_node_foreach_type(binding->binding_list,
+ GENBIND_NODE_TYPE_BINDING_INTERFACE,
+ output_jsclass,
+ binding);
+
+}
+
/** generate structure definition for internal class data
*
* Every javascript object instance has an internal context to keep
@@ -927,12 +966,12 @@ output_private_declaration(struct binding *binding)
fprintf(binding->outfile, "struct jsclass_private {\n");
- genbind_node_for_each_type(binding->binding_list,
+ genbind_node_foreach_type(binding->binding_list,
GENBIND_NODE_TYPE_BINDING_PRIVATE,
webidl_private_cb,
binding);
- genbind_node_for_each_type(binding->binding_list,
+ genbind_node_foreach_type(binding->binding_list,
GENBIND_NODE_TYPE_BINDING_INTERNAL,
webidl_private_cb,
binding);
@@ -946,7 +985,7 @@ output_private_declaration(struct binding *binding)
static int
output_preamble(struct binding *binding)
{
- genbind_node_for_each_type(binding->gb_ast,
+ genbind_node_foreach_type(binding->gb_ast,
GENBIND_NODE_TYPE_PREAMBLE,
webidl_preamble_cb,
binding);
@@ -976,7 +1015,7 @@ output_header_comments(struct binding *binding)
const char *preamble = HDR_COMMENT_PREAMBLE;
fprintf(binding->outfile, preamble, options->infilename);
- genbind_node_for_each_type(binding->gb_ast,
+ genbind_node_foreach_type(binding->gb_ast,
GENBIND_NODE_TYPE_HDRCOMMENT,
webidl_hdrcomment_cb,
binding);
@@ -988,7 +1027,7 @@ output_header_comments(struct binding *binding)
fprintf(binding->outfile, preamble, options->infilename);
- genbind_node_for_each_type(binding->gb_ast,
+ genbind_node_foreach_type(binding->gb_ast,
GENBIND_NODE_TYPE_HDRCOMMENT,
webidl_hdrcomment_cb,
binding);
@@ -1022,22 +1061,6 @@ binding_has_private(struct genbind_node *binding_list)
return false;
}
-/* determine if the binding has a global api marker */
-static bool
-binding_has_global(struct binding *binding)
-{
- struct genbind_node *api_node;
-
- api_node = genbind_node_find_type_ident(binding->gb_ast,
- NULL,
- GENBIND_NODE_TYPE_API,
- "global");
- if (api_node != NULL) {
- return true;
- }
- return false;
-}
-
static struct binding *
binding_new(struct options *options,
struct genbind_node *genbind_ast,
@@ -1109,7 +1132,6 @@ binding_new(struct options *options,
nb->hdrfile = options->hdrfilehandle;
nb->hdrguard = hdrguard;
nb->has_private = binding_has_private(binding_list);
- nb->has_global = binding_has_global(nb);
nb->binding_list = binding_list;
/* class API */
@@ -1191,7 +1213,7 @@ jsapi_libdom_output(struct options *options,
return 75;
}
- res = output_jsclass(binding);
+ res = output_jsclasses(binding);
if (res) {
return 80;
}
diff --git a/src/jsapi-libdom.h b/src/jsapi-libdom.h
index 5a93ff1..b83eeb0 100644
--- a/src/jsapi-libdom.h
+++ b/src/jsapi-libdom.h
@@ -18,7 +18,6 @@ struct binding {
const char *interface; /* webidl interface binding is for */
bool has_private; /* true if the binding requires a private structure */
- bool has_global; /* true if the binding is for a global */
struct genbind_node *binding_list; /* node list of the binding */
struct genbind_node *addproperty; /* binding api add property node or NULL */
diff --git a/src/nsgenbind-ast.c b/src/nsgenbind-ast.c
index d20975f..fc1e196 100644
--- a/src/nsgenbind-ast.c
+++ b/src/nsgenbind-ast.c
@@ -49,7 +49,8 @@ char *genbind_strapp(char *a, char *b)
return fullstr;
}
-struct genbind_node *genbind_node_link(struct genbind_node *tgt, struct genbind_node *src)
+struct genbind_node *
+genbind_node_link(struct genbind_node *tgt, struct genbind_node *src)
{
tgt->l = src;
return tgt;
@@ -68,7 +69,7 @@ genbind_new_node(enum genbind_node_type type, struct genbind_node *l, void *r)
}
int
-genbind_node_for_each_type(struct genbind_node *node,
+genbind_node_foreach_type(struct genbind_node *node,
enum genbind_node_type type,
genbind_callback_t *cb,
void *ctx)
@@ -79,7 +80,7 @@ genbind_node_for_each_type(struct genbind_node *node,
return -1;
}
if (node->l != NULL) {
- ret = genbind_node_for_each_type(node->l, type, cb, ctx);
+ ret = genbind_node_foreach_type(node->l, type, cb, ctx);
if (ret != 0) {
return ret;
}
@@ -147,17 +148,26 @@ genbind_node_find_type_ident(struct genbind_node *node,
found_node = genbind_node_find_type(node, prev, type);
-
while (found_node != NULL) {
/* look for an ident node */
- ident_node = genbind_node_find_type(genbind_node_getnode(found_node),
- NULL,
- GENBIND_NODE_TYPE_IDENT);
- if (ident_node != NULL) {
- if (strcmp(ident_node->r.text, ident) == 0)
- break;
+ ident_node = genbind_node_find_type(
+ genbind_node_getnode(found_node),
+ NULL,
+ GENBIND_NODE_TYPE_IDENT);
+
+ while (ident_node != NULL) {
+ /* check for matching text */
+ if (strcmp(ident_node->r.text, ident) == 0) {
+ return found_node;
+ }
+
+ ident_node = genbind_node_find_type(
+ genbind_node_getnode(found_node),
+ ident_node,
+ GENBIND_NODE_TYPE_IDENT);
}
+
/* look for next matching node */
found_node = genbind_node_find_type(node, found_node, type);
}
diff --git a/src/nsgenbind-ast.h b/src/nsgenbind-ast.h
index d59aeba..128dce7 100644
--- a/src/nsgenbind-ast.h
+++ b/src/nsgenbind-ast.h
@@ -1,4 +1,4 @@
-/* binding file AST interface
+/* binding file AST interface
*
* This file is part of nsnsgenbind.
* Licensed under the MIT License,
@@ -42,12 +42,6 @@ enum genbind_type_modifier {
GENBIND_TYPE_TYPE_UNSHARED = 3, /**< identifies a unshared type handler */
};
-/* interface flags */
-enum genbind_interface_flags {
- GENBIND_INTERFACE_FLAG_NONE = 0,
- GENBIND_INTERFACE_FLAG_GLOBAL = 1, /**< interface is global */
-};
-
struct genbind_node;
/** callback for search and iteration routines */
@@ -66,11 +60,11 @@ struct genbind_node *genbind_node_link(struct genbind_node *tgt, struct genbind_
int genbind_ast_dump(struct genbind_node *ast, int indent);
-/** Depth first left hand search using user provided comparison
+/** Depth first left hand search using user provided comparison
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
- * search the full tree depth (initial search) or the result
+ * search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param cb Comparison callback
* @param ctx Context for callback
@@ -85,7 +79,7 @@ genbind_node_find(struct genbind_node *node,
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
- * search the full tree depth (initial search) or the result
+ * search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param nodetype The type of node to seach for
*/
@@ -99,7 +93,7 @@ genbind_node_find_type(struct genbind_node *node,
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
- * search the full tree depth (initial search) or the result
+ * search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param nodetype The type of node to seach for
* @param ident The text to match the ident child node to
@@ -110,12 +104,18 @@ genbind_node_find_type_ident(struct genbind_node *node,
enum genbind_node_type nodetype,
const char *ident);
-/** Depth first left hand search returning nodes of the specified type
- * and a type child node with matching text
+/** Returning node of the specified type with a GENBIND_NODE_TYPE_TYPE
+ * subnode with matching text.
+ *
+ * This is a conveniance wrapper around nested calls to
+ * genbind_node_find_type() which performs a depth first left hand
+ * search returning nodes of the specified type and a child node of
+ * GENBIND_NODE_TYPE_TYPE with matching text.
+ *
*
* @param node The node to start the search from
* @param prev The node at which to stop the search, either NULL to
- * search the full tree depth (initial search) or the result
+ * search the full tree depth (initial search) or the result
* of a previous search to continue.
* @param nodetype The type of node to seach for.
* @param type The text to match the type child node to.
@@ -124,9 +124,19 @@ struct genbind_node *
genbind_node_find_type_type(struct genbind_node *node,
struct genbind_node *prev,
enum genbind_node_type nodetype,
- const char *type);
+ const char *type_text);
-int genbind_node_for_each_type(struct genbind_node *node, enum genbind_node_type type, genbind_callback_t *cb, void *ctx);
+/** Iterate all nodes of a certian type from a node with a callback.
+ *
+ * Depth first search for nodes of the given type calling the callback
+ * with context.
+ *
+ * @param node The node to start the search from.
+ */
+int genbind_node_foreach_type(struct genbind_node *node,
+ enum genbind_node_type type,
+ genbind_callback_t *cb,
+ void *ctx);
/** get a nodes node list content
*
diff --git a/src/nsgenbind.c b/src/nsgenbind.c
index 636c22b..d81f30f 100644
--- a/src/nsgenbind.c
+++ b/src/nsgenbind.c
@@ -202,10 +202,10 @@ int main(int argc, char **argv)
}
/* generate output for each binding */
- res = genbind_node_for_each_type(genbind_root,
- GENBIND_NODE_TYPE_BINDING,
- generate_binding,
- genbind_root);
+ res = genbind_node_foreach_type(genbind_root,
+ GENBIND_NODE_TYPE_BINDING,
+ generate_binding,
+ genbind_root);
if (res != 0) {
fprintf(stderr, "Error: output failed with code %d\n", res);
if (options->outfilename != NULL) {
diff --git a/test/data/bindings/window.bnd b/test/data/bindings/window.bnd
index 2f26f56..4fb5a46 100644
--- a/test/data/bindings/window.bnd
+++ b/test/data/bindings/window.bnd
@@ -29,7 +29,9 @@ epilogue %{
binding jsapi_libdom {
- interface Window; /* Web IDL interface to generate */
+ interface Window {
+ flags global;
+ }
private "struct browser_window *" bw;
private "struct html_content *" htmlc;
@@ -62,8 +64,6 @@ api mark %{
}
%}
-api global %{
-%}
api init %{
JSObject *user_proto;