summaryrefslogtreecommitdiff
path: root/src/jsapi-libdom-function.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/jsapi-libdom-function.c')
-rw-r--r--src/jsapi-libdom-function.c252
1 files changed, 99 insertions, 153 deletions
diff --git a/src/jsapi-libdom-function.c b/src/jsapi-libdom-function.c
index 5540b0e..af9c215 100644
--- a/src/jsapi-libdom-function.c
+++ b/src/jsapi-libdom-function.c
@@ -17,101 +17,85 @@
#include "webidl-ast.h"
#include "jsapi-libdom.h"
-static int output_function_body(struct binding *binding, struct webidl_node *node);
-
-static int webidl_func_spec_cb(struct webidl_node *node, void *ctx)
+static int webidl_operator_spec(struct binding *binding,
+ struct binding_interface *inf,
+ struct webidl_node *node)
{
- struct binding *binding = 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);
-
+ ident_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ 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(binding->outfile,
- "\tJSAPI_FS(%s, 0, JSPROP_ENUMERATE ),\n",
+ "\tJSAPI_FS(%s, %s, 0, JSPROP_ENUMERATE ),\n",
+ inf->name,
webidl_node_gettext(ident_node));
/* @todo number of args to that FN_FS() call should be correct */
}
return 0;
}
-
-static int generate_function_spec(struct binding *binding, const char *interface);
-
-
-static int
-generate_function_spec(struct binding *binding, const char *interface)
+int output_function_spec(struct binding *binding)
{
- struct webidl_node *interface_node;
- struct webidl_node *members_node;
- struct webidl_node *inherit_node;
- int res = 0;
-
- /* 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,"\t/**** %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_func_spec_cb,
- binding);
-
- members_node = webidl_node_find(webidl_node_getnode(interface_node),
- members_node,
- webidl_cmp_node_type,
- (void *)WEBIDL_NODE_TYPE_LIST);
- }
+ int inf;
+ int res;
+ struct webidl_node *list_node;
+ struct webidl_node *op_node; /* operation on list node */
- /* 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);
+ /* generate functions for each interface in the map */
+ for (inf = 0; inf < binding->interfacec; inf++) {
+ if (binding->interfaces[inf].own_functions == 0) {
+ continue;
+ }
- if (inherit_node != NULL) {
- res = generate_function_spec(binding,
- webidl_node_gettext(inherit_node));
- }
+ fprintf(binding->outfile,
+ "static JSFunctionSpec JSClass_%s_functions[] = {\n",
+ binding->interfaces[inf].name);
- return res;
-}
+ /* iterate each list within an interface */
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(binding->interfaces[inf].widl_node),
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
-int output_function_spec(struct binding *binding)
-{
- int res;
+ while (list_node != NULL) {
+ /* iterate through operations in a list */
+ op_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ NULL,
+ WEBIDL_NODE_TYPE_OPERATION);
+
+ while (op_node != NULL) {
+ res = webidl_operator_spec(
+ binding,
+ &binding->interfaces[inf],
+ op_node);
+ if (res != 0) {
+ return res;
+ }
+
+ op_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ op_node,
+ WEBIDL_NODE_TYPE_OPERATION);
+ }
- fprintf(binding->outfile,
- "static JSFunctionSpec jsclass_functions[] = {\n");
- res = generate_function_spec(binding, binding->interface);
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(binding->interfaces[inf].widl_node),
+ list_node,
+ WEBIDL_NODE_TYPE_LIST);
+ }
- fprintf(binding->outfile, "\tJSAPI_FS_END\n};\n\n");
+ fprintf(binding->outfile, "\tJSAPI_FS_END\n};\n\n");
- return res;
+ }
+ return 0;
}
static int output_return(struct binding *binding,
@@ -736,10 +720,10 @@ output_private_get(struct binding *binding, const char *argname)
return ret;
}
-static int
-webidl_operator_body_cb(struct webidl_node *node, void *ctx)
+static int webidl_operator_body(struct binding *binding,
+ struct binding_interface *inf,
+ struct webidl_node *node)
{
- struct binding *binding = ctx;
struct webidl_node *ident_node;
struct genbind_node *operation_node;
@@ -761,9 +745,10 @@ webidl_operator_body_cb(struct webidl_node *node, void *ctx)
/* normal operation with identifier */
fprintf(binding->outfile,
- "static JSBool JSAPI_FUNC(%s, JSContext *cx, uintN argc, jsval *vp)\n",
+ "static JSBool JSAPI_FUNC(%s, %s, JSContext *cx, uintN argc, jsval *vp)\n"
+ "{\n",
+ inf->name,
webidl_node_gettext(ident_node));
- fprintf(binding->outfile, "{\n");
/* return value declaration */
output_return_declaration(binding, "jsret", webidl_node_getnode(node));
@@ -797,90 +782,51 @@ webidl_operator_body_cb(struct webidl_node *node, void *ctx)
return 0;
}
-static int
-output_interface_functions(struct binding *binding,
- struct webidl_node *interface_node)
-{
- struct webidl_node *members_node;
-
- members_node = webidl_node_find_type(
- webidl_node_getnode(interface_node),
- NULL,
- WEBIDL_NODE_TYPE_LIST);
-
- while (members_node != NULL) {
- /* for each function emit a JSAPI_FS()*/
- webidl_node_for_each_type(webidl_node_getnode(members_node),
- WEBIDL_NODE_TYPE_OPERATION,
- webidl_operator_body_cb,
- binding);
-
- members_node = webidl_node_find_type(
- webidl_node_getnode(interface_node),
- members_node,
- WEBIDL_NODE_TYPE_LIST);
- }
- return 0;
-}
-
-/* callback to emit implements operator bodys */
-static int webidl_implements_cb(struct webidl_node *node, void *ctx)
-{
- struct binding *binding = ctx;
- struct webidl_node *interface_node;
-
- interface_node = webidl_node_find_type_ident(binding->wi_ast,
- WEBIDL_NODE_TYPE_INTERFACE,
- webidl_node_gettext(node));
-
- return output_function_body(binding, interface_node);
-}
/* exported interface documented in jsapi-libdom.h */
-static int
-output_function_body(struct binding *binding,
- struct webidl_node *interface_node)
+int output_function_bodies(struct binding *binding)
{
- struct webidl_node *inherit_node;
- int res = 0;
-
- res = output_interface_functions(binding, interface_node);
+ int inf;
+ int res;
+ struct webidl_node *list_node;
+ struct webidl_node *op_node; /* operation on list node */
+
+ /* generate functions for each interface in the map */
+ for (inf = 0; inf < binding->interfacec; inf++) {
+ /* iterate each list within an interface */
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(binding->interfaces[inf].widl_node),
+ NULL,
+ WEBIDL_NODE_TYPE_LIST);
- fprintf(binding->outfile,
- "/**** %s ****/\n",
- webidl_node_gettext(
- webidl_node_find_type(
- webidl_node_getnode(interface_node),
+ while (list_node != NULL) {
+ /* iterate through operations in a list */
+ op_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
NULL,
- WEBIDL_NODE_TYPE_IDENT)));
-
- /* check for inherited nodes and insert them too */
- inherit_node = webidl_node_find_type(
- webidl_node_getnode(interface_node),
- NULL,
- WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE);
-
- if (inherit_node != NULL) {
- res = webidl_implements_cb(inherit_node, binding);
- }
+ WEBIDL_NODE_TYPE_OPERATION);
+
+ while (op_node != NULL) {
+ res = webidl_operator_body(
+ binding,
+ &binding->interfaces[inf],
+ op_node);
+ if (res != 0) {
+ return res;
+ }
+
+ op_node = webidl_node_find_type(
+ webidl_node_getnode(list_node),
+ op_node,
+ WEBIDL_NODE_TYPE_OPERATION);
+ }
- return res;
-}
-int
-output_function_bodies(struct binding *binding)
-{
- int inf;
- int res = 0;
-
- for (inf=0; inf < binding->interfacec; inf++) {
- if (binding->interfaces[inf].inherit_idx == -1) {
- res = output_function_body(binding,
- binding->interfaces[inf].widl_node);
- } else {
- res = output_interface_functions(binding,
- binding->interfaces[inf].widl_node);
+ list_node = webidl_node_find_type(
+ webidl_node_getnode(binding->interfaces[inf].widl_node),
+ list_node,
+ WEBIDL_NODE_TYPE_LIST);
}
}
- return res;
+ return 0;
}