diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/jsapi-libdom-property.c | 231 | ||||
-rw-r--r-- | src/jsapi-libdom.c | 208 | ||||
-rw-r--r-- | src/jsapi-libdom.h | 8 |
4 files changed, 238 insertions, 211 deletions
diff --git a/src/Makefile b/src/Makefile index 2716fa8..e2f2eab 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ CFLAGS := $(CFLAGS) -I$(BUILDDIR) -Isrc/ -g # Sources in this directory -DIR_SOURCES := nsgenbind.c webidl-ast.c nsgenbind-ast.c jsapi-libdom.c jsapi-libdom-operator.c +DIR_SOURCES := nsgenbind.c webidl-ast.c nsgenbind-ast.c jsapi-libdom.c jsapi-libdom-operator.c jsapi-libdom-property.c SOURCES := $(SOURCES) $(BUILDDIR)/nsgenbind-parser.c $(BUILDDIR)/nsgenbind-lexer.c $(BUILDDIR)/webidl-parser.c $(BUILDDIR)/webidl-lexer.c diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c new file mode 100644 index 0000000..8d8afa2 --- /dev/null +++ b/src/jsapi-libdom-property.c @@ -0,0 +1,231 @@ +/* property generation + * + * This file is part of nsgenbind. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org> + */ + +#include <stdbool.h> +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> + +#include "options.h" +#include "nsgenbind-ast.h" +#include "webidl-ast.h" +#include "jsapi-libdom.h" + +static int webidl_property_spec_cb(struct webidl_node *node, void *ctx) +{ + struct binding *binding = ctx; + struct webidl_node *ident_node; + struct webidl_node *modifier_node; + + ident_node = webidl_node_find(webidl_node_getnode(node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_IDENT); + + modifier_node = webidl_node_find(webidl_node_getnode(node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_MODIFIER); + + if (ident_node == NULL) { + /* properties must have an operator + * http://www.w3.org/TR/WebIDL/#idl-attributes + */ + return 1; + } else { + if (webidl_node_getint(modifier_node) == WEBIDL_TYPE_READONLY) { + fprintf(binding->outfile, + " JSAPI_PS_RO(%s, 0, JSPROP_ENUMERATE | JSPROP_SHARED),\n", + webidl_node_gettext(ident_node)); + } else { + fprintf(binding->outfile, + " JSAPI_PS(%s, 0, JSPROP_ENUMERATE | JSPROP_SHARED),\n", + webidl_node_gettext(ident_node)); + } + } + return 0; +} + +static int +generate_property_spec(struct binding *binding, const char *interface) +{ + struct webidl_node *interface_node; + struct webidl_node *members_node; + struct webidl_node *inherit_node; + + + /* find interface in webidl with correct ident attached */ + interface_node = webidl_node_find_type_ident(binding->wi_ast, + WEBIDL_NODE_TYPE_INTERFACE, + interface); + + if (interface_node == NULL) { + fprintf(stderr, + "Unable to find interface %s in loaded WebIDL\n", + interface); + return -1; + } + + members_node = webidl_node_find(webidl_node_getnode(interface_node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_LIST); + + while (members_node != NULL) { + + fprintf(binding->outfile," /**** %s ****/\n", interface); + + + /* for each function emit a JSAPI_FS()*/ + webidl_node_for_each_type(webidl_node_getnode(members_node), + WEBIDL_NODE_TYPE_ATTRIBUTE, + webidl_property_spec_cb, + binding); + + + members_node = webidl_node_find(webidl_node_getnode(interface_node), + members_node, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_LIST); + + } + /* check for inherited nodes and insert them too */ + inherit_node = webidl_node_find(webidl_node_getnode(interface_node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE); + + if (inherit_node != NULL) { + return generate_property_spec(binding, + webidl_node_gettext(inherit_node)); + } + + return 0; +} + +int +output_property_spec(struct binding *binding) +{ + int res; + + fprintf(binding->outfile, + "static JSPropertySpec jsclass_properties[] = {\n"); + + res = generate_property_spec(binding, binding->interface); + + fprintf(binding->outfile, " JSAPI_PS_END\n};\n\n"); + + return res; +} + +static int webidl_property_body_cb(struct webidl_node *node, void *ctx) +{ + struct binding *binding = ctx; + struct webidl_node *ident_node; + struct webidl_node *modifier_node; + + ident_node = webidl_node_find(webidl_node_getnode(node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_IDENT); + + if (ident_node == NULL) { + /* properties must have an operator + * http://www.w3.org/TR/WebIDL/#idl-attributes + */ + return 1; + } + + modifier_node = webidl_node_find(webidl_node_getnode(node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_MODIFIER); + + + if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) { + /* no readonly so a set function is required */ + + fprintf(binding->outfile, + "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n", + webidl_node_gettext(ident_node)); + fprintf(binding->outfile, + "{\n" + " return JS_FALSE;\n" + "}\n\n"); + } + + fprintf(binding->outfile, + "static JSBool JSAPI_PROPERTYGET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n", + webidl_node_gettext(ident_node)); + fprintf(binding->outfile, + "{\n" + " JS_SET_RVAL(cx, vp, JSVAL_NULL);\n" + " return JS_TRUE;\n"); + fprintf(binding->outfile, "}\n\n"); + + + return 0; +} + + +int +output_property_body(struct binding *binding, const char *interface) +{ + struct webidl_node *interface_node; + struct webidl_node *members_node; + struct webidl_node *inherit_node; + + + /* find interface in webidl with correct ident attached */ + interface_node = webidl_node_find_type_ident(binding->wi_ast, + WEBIDL_NODE_TYPE_INTERFACE, + interface); + + if (interface_node == NULL) { + fprintf(stderr, + "Unable to find interface %s in loaded WebIDL\n", + interface); + return -1; + } + + members_node = webidl_node_find(webidl_node_getnode(interface_node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_LIST); + + while (members_node != NULL) { + + fprintf(binding->outfile,"/**** %s ****/\n", interface); + + /* for each function emit property body */ + webidl_node_for_each_type(webidl_node_getnode(members_node), + WEBIDL_NODE_TYPE_ATTRIBUTE, + webidl_property_body_cb, + binding); + + + members_node = webidl_node_find(webidl_node_getnode(interface_node), + members_node, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_LIST); + + } + /* check for inherited nodes and insert them too */ + inherit_node = webidl_node_find(webidl_node_getnode(interface_node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE); + + if (inherit_node != NULL) { + return output_property_body(binding, + webidl_node_gettext(inherit_node)); + } + + return 0; +} diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index 240171b..8a688b0 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -80,97 +80,6 @@ static int webidl_hdrcomment_cb(struct genbind_node *node, void *ctx) return 0; } -static int webidl_property_spec_cb(struct webidl_node *node, void *ctx) -{ - struct binding *binding = ctx; - struct webidl_node *ident_node; - struct webidl_node *modifier_node; - - ident_node = webidl_node_find(webidl_node_getnode(node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_IDENT); - - modifier_node = webidl_node_find(webidl_node_getnode(node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_MODIFIER); - - if (ident_node == NULL) { - /* properties must have an operator - * http://www.w3.org/TR/WebIDL/#idl-attributes - */ - return 1; - } else { - if (webidl_node_getint(modifier_node) == WEBIDL_TYPE_READONLY) { - fprintf(binding->outfile, - " JSAPI_PS_RO(%s, 0, JSPROP_ENUMERATE | JSPROP_SHARED),\n", - webidl_node_gettext(ident_node)); - } else { - fprintf(binding->outfile, - " JSAPI_PS(%s, 0, JSPROP_ENUMERATE | JSPROP_SHARED),\n", - webidl_node_gettext(ident_node)); - } - } - return 0; -} - -static int -generate_property_spec(struct binding *binding, const char *interface) -{ - struct webidl_node *interface_node; - struct webidl_node *members_node; - struct webidl_node *inherit_node; - - - /* find interface in webidl with correct ident attached */ - interface_node = webidl_node_find_type_ident(binding->wi_ast, - WEBIDL_NODE_TYPE_INTERFACE, - interface); - - if (interface_node == NULL) { - fprintf(stderr, - "Unable to find interface %s in loaded WebIDL\n", - interface); - return -1; - } - - members_node = webidl_node_find(webidl_node_getnode(interface_node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_LIST); - - while (members_node != NULL) { - - fprintf(binding->outfile," /**** %s ****/\n", interface); - - - /* for each function emit a JSAPI_FS()*/ - webidl_node_for_each_type(webidl_node_getnode(members_node), - WEBIDL_NODE_TYPE_ATTRIBUTE, - webidl_property_spec_cb, - binding); - - - members_node = webidl_node_find(webidl_node_getnode(interface_node), - members_node, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_LIST); - - } - /* check for inherited nodes and insert them too */ - inherit_node = webidl_node_find(webidl_node_getnode(interface_node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE); - - if (inherit_node != NULL) { - return generate_property_spec(binding, - webidl_node_gettext(inherit_node)); - } - - return 0; -} @@ -256,54 +165,6 @@ generate_function_spec(struct binding *binding, const char *interface) -static int webidl_property_body_cb(struct webidl_node *node, void *ctx) -{ - struct binding *binding = ctx; - struct webidl_node *ident_node; - struct webidl_node *modifier_node; - - ident_node = webidl_node_find(webidl_node_getnode(node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_IDENT); - - if (ident_node == NULL) { - /* properties must have an operator - * http://www.w3.org/TR/WebIDL/#idl-attributes - */ - return 1; - } - - modifier_node = webidl_node_find(webidl_node_getnode(node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_MODIFIER); - - - if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) { - /* no readonly so a set function is required */ - - fprintf(binding->outfile, - "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n", - webidl_node_gettext(ident_node)); - fprintf(binding->outfile, - "{\n" - " return JS_FALSE;\n" - "}\n\n"); - } - - fprintf(binding->outfile, - "static JSBool JSAPI_PROPERTYGET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n", - webidl_node_gettext(ident_node)); - fprintf(binding->outfile, - "{\n" - " JS_SET_RVAL(cx, vp, JSVAL_NULL);\n" - " return JS_TRUE;\n"); - fprintf(binding->outfile, "}\n\n"); - - - return 0; -} @@ -545,20 +406,6 @@ output_class_new(struct binding *binding) return res; } -static int -output_property_spec(struct binding *binding) -{ - int res; - - fprintf(binding->outfile, - "static JSPropertySpec jsclass_properties[] = {\n"); - - res = generate_property_spec(binding, binding->interface); - - fprintf(binding->outfile, " JSAPI_PS_END\n};\n\n"); - - return res; -} static int output_function_spec(struct binding *binding) @@ -575,61 +422,6 @@ output_function_spec(struct binding *binding) return res; } -static int -output_property_body(struct binding *binding, const char *interface) -{ - struct webidl_node *interface_node; - struct webidl_node *members_node; - struct webidl_node *inherit_node; - - - /* find interface in webidl with correct ident attached */ - interface_node = webidl_node_find_type_ident(binding->wi_ast, - WEBIDL_NODE_TYPE_INTERFACE, - interface); - - if (interface_node == NULL) { - fprintf(stderr, - "Unable to find interface %s in loaded WebIDL\n", - interface); - return -1; - } - - members_node = webidl_node_find(webidl_node_getnode(interface_node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_LIST); - - while (members_node != NULL) { - - fprintf(binding->outfile,"/**** %s ****/\n", interface); - - /* for each function emit property body */ - webidl_node_for_each_type(webidl_node_getnode(members_node), - WEBIDL_NODE_TYPE_ATTRIBUTE, - webidl_property_body_cb, - binding); - - - members_node = webidl_node_find(webidl_node_getnode(interface_node), - members_node, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_LIST); - - } - /* check for inherited nodes and insert them too */ - inherit_node = webidl_node_find(webidl_node_getnode(interface_node), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE); - - if (inherit_node != NULL) { - return output_property_body(binding, - webidl_node_gettext(inherit_node)); - } - - return 0; -} static int diff --git a/src/jsapi-libdom.h b/src/jsapi-libdom.h index d4c37eb..f318b5d 100644 --- a/src/jsapi-libdom.h +++ b/src/jsapi-libdom.h @@ -17,6 +17,9 @@ struct binding { FILE *outfile ; /* output file */ }; +/** output code block from a node */ +void output_code_block(struct binding *binding, struct genbind_node *codelist); + /* Generate jsapi native function bodys * * web IDL describes methods as operators @@ -34,11 +37,12 @@ struct binding { */ int output_operator_body(struct binding *binding, const char *interface); +int output_property_spec(struct binding *binding); +int output_property_body(struct binding *binding, const char *interface); + /** Generate binding between jsapi and netsurf libdom */ int jsapi_libdom_output(char *outfile, struct genbind_node *genbind_root); -/** output code block from a node */ -void output_code_block(struct binding *binding, struct genbind_node *codelist); #endif |