diff options
-rw-r--r-- | src/jsapi-libdom.c | 106 | ||||
-rw-r--r-- | src/webidl-ast.c | 6 | ||||
-rw-r--r-- | src/webidl-ast.h | 2 | ||||
-rw-r--r-- | src/webidl-parser.y | 2 |
4 files changed, 113 insertions, 3 deletions
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index aba6bdf..13af77b 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -200,7 +200,7 @@ output_property_spec(FILE *outfile, res = generate_property_spec(outfile, binding->interface, webidl_ast); - fprintf(outfile, " JSAPI_PS_END\n};\n"); + fprintf(outfile, " JSAPI_PS_END\n};\n\n"); return res; } @@ -297,11 +297,107 @@ output_function_spec(FILE *outfile, res = generate_function_spec(outfile, binding->interface, webidl_ast); - fprintf(outfile, " JSAPI_FS_END\n};\n"); + fprintf(outfile, " JSAPI_FS_END\n};\n\n"); return res; } +static int webidl_function_body_cb(struct webidl_node *node, void *ctx) +{ + FILE *outfile = ctx; + struct webidl_node *ident_node; + + ident_node = webidl_node_find(webidl_node_getnode(node), + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_IDENT); + + if (ident_node == NULL) { + /* operation without identifier - must have special keyword + * http://www.w3.org/TR/WebIDL/#idl-operations + */ + } else { + fprintf(outfile, + "static JSBool JSAPI_NATIVE(%s, JSContext *cx, uintN argc, jsval *vp)\n", + webidl_node_gettext(ident_node)); + fprintf(outfile, "{\n"); + fprintf(outfile, "}\n\n"); + + } + return 0; +} + +static int +generate_function_body(FILE *outfile, + const char *interface, + struct webidl_node *webidl_ast) +{ + 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(webidl_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_INTERFACE_MEMBERS); + while (members_node != NULL) { + + fprintf(outfile,"/**** %s ****/\n", interface); + + /* for each function emit a JSAPI_FS()*/ + webidl_node_for_each_type(webidl_node_getnode(members_node), + WEBIDL_NODE_TYPE_OPERATION, + webidl_function_body_cb, + outfile); + + members_node = webidl_node_find(webidl_node_getnode(interface_node), + members_node, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_INTERFACE_MEMBERS); + } + + /* 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_function_body(outfile, + webidl_node_gettext(inherit_node), + webidl_ast); + } + + return 0; +} + +static int +output_function_body(FILE *outfile, + struct binding *binding, + struct webidl_node *webidl_ast) +{ + int res; + + res = generate_function_body(outfile, binding->interface, webidl_ast); + + return res; +} + + + static struct binding *binding_new(struct genbind_node *genbind_ast) { struct binding *nb; @@ -379,6 +475,12 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) output_preamble(outfile, genbind_ast); + res = output_function_body(outfile, binding, webidl_ast); + if (res) { + return 5; + } + + res = output_function_spec(outfile, binding, webidl_ast); if (res) { return 5; diff --git a/src/webidl-ast.c b/src/webidl-ast.c index aa8e279..d698fff 100644 --- a/src/webidl-ast.c +++ b/src/webidl-ast.c @@ -41,6 +41,12 @@ webidl_node_link(struct webidl_node *tgt, struct webidl_node *src) return src; } +struct webidl_node * +webidl_add_interface_member(struct webidl_node *list, struct webidl_node *new) +{ + return webidl_node_link(new, list); +} + struct webidl_node *webidl_node_new(enum webidl_node_type type, struct webidl_node *l, void *r) { struct webidl_node *nn; diff --git a/src/webidl-ast.h b/src/webidl-ast.h index b421615..c86d59b 100644 --- a/src/webidl-ast.h +++ b/src/webidl-ast.h @@ -32,6 +32,8 @@ void webidl_node_set(struct webidl_node *node, enum webidl_node_type type, void struct webidl_node *webidl_node_link(struct webidl_node *tgt, struct webidl_node *src); +struct webidl_node *webidl_add_interface_member(struct webidl_node *list, struct webidl_node *new); + /* node contents acessors */ char *webidl_node_gettext(struct webidl_node *node); struct webidl_node *webidl_node_getnode(struct webidl_node *node); diff --git a/src/webidl-parser.y b/src/webidl-parser.y index d9be0b9..9b3eb12 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -307,7 +307,7 @@ InterfaceMembers: | InterfaceMembers ExtendedAttributeList InterfaceMember { - $$ = webidl_node_link($3, $1); + $$ = webidl_add_interface_member($1, $3); } ; |