diff options
author | Vincent Sanders <vincent.sanders@collabora.co.uk> | 2012-10-11 18:52:30 +0100 |
---|---|---|
committer | Vincent Sanders <vincent.sanders@collabora.co.uk> | 2012-10-11 18:52:30 +0100 |
commit | b5c56b56cebe3f46c05823300783d1c88c02f12e (patch) | |
tree | 1d07ed50e320934c46415c092b008051b0131b4a /src | |
parent | d3b66100f5fc6459d9d466e20bf0b2054d617b85 (diff) | |
download | nsgenbind-b5c56b56cebe3f46c05823300783d1c88c02f12e.tar.gz nsgenbind-b5c56b56cebe3f46c05823300783d1c88c02f12e.tar.bz2 |
construct input variables
Diffstat (limited to 'src')
-rw-r--r-- | src/jsapi-libdom-operator.c | 51 | ||||
-rw-r--r-- | src/webidl-ast.c | 23 | ||||
-rw-r--r-- | src/webidl-ast.h | 5 |
3 files changed, 61 insertions, 18 deletions
diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c index 64a5059..90a67a7 100644 --- a/src/jsapi-libdom-operator.c +++ b/src/jsapi-libdom-operator.c @@ -17,8 +17,13 @@ #include "webidl-ast.h" #include "jsapi-libdom.h" +/** creates all the variable definitions + * + * generate functions variables (including return value) with default + * values as appropriate + */ static void -define_ret_value(struct binding *binding, struct webidl_node *operator_list) +output_variable_definitions(struct binding *binding, struct webidl_node *operator_list) { operator_list = operator_list; fprintf(binding->outfile, "\tjsval jsretval = JSVAL_VOID;\n"); @@ -28,23 +33,42 @@ static void output_operation_input(struct binding *binding, struct webidl_node *operation_list) { + + struct webidl_node *arglist_node; + struct webidl_node *arg_node = NULL; + + arglist_node = webidl_node_find(operation_list, + NULL, + webidl_cmp_node_type, + (void *)WEBIDL_NODE_TYPE_LIST); + + if (arglist_node == NULL) { + return; /* @todo check if this is broken AST */ + } + + arglist = webidl_node_getnode(arglist_node); + + arg_node = webidl_node_for_each_type(arglist, + arg_node, + WEBIDL_NODE_TYPE_ARGUMENT); + while (arg_node != NULL) { + /* - if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) { - return JS_FALSE; - } + if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt)) { + return JS_FALSE; + } - JSString_to_char(u16_txt, txt, length); + JSString_to_char(u16_txt, txt, length); */ - struct webidl_node *arglist; - arglist = webidl_node_find(operation_list, - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_LIST); + arg_node = webidl_node_for_each_type(arglist, + arg_node, + WEBIDL_NODE_TYPE_ARGUMENT); + } + - arglist = webidl_node_getnode(arglist); } @@ -92,8 +116,7 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx) fprintf(binding->outfile, "\tstruct jsclass_private *private;\n"); - /* creates the return value variable with a default value */ - define_ret_value(binding, webidl_node_getnode(node)); + output_variable_definitions(binding, webidl_node_getnode(node)); fprintf(binding->outfile, "\n" @@ -102,7 +125,7 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx) "\t\t\t&jsclass_object,\n" "\t\t\tNULL);\n" "\tif (priv == NULL)\n" - "\t\treturn JS_FALSE;\n"); + "\t\treturn JS_FALSE;\n\n"); output_operation_input(binding, webidl_node_getnode(node)); diff --git a/src/webidl-ast.c b/src/webidl-ast.c index 084c199..75dbdeb 100644 --- a/src/webidl-ast.c +++ b/src/webidl-ast.c @@ -137,6 +137,14 @@ webidl_node_for_each_type(struct webidl_node *node, } /* exported interface defined in genjsbind-ast.h */ +int webidl_cmp_node_type(struct webidl_node *node, void *ctx) +{ + if (node->type == (enum webidl_node_type)ctx) + return 1; + return 0; +} + +/* exported interface defined in genjsbind-ast.h */ struct webidl_node * webidl_node_find(struct webidl_node *node, struct webidl_node *prev, @@ -163,13 +171,20 @@ webidl_node_find(struct webidl_node *node, return NULL; } -int webidl_cmp_node_type(struct webidl_node *node, void *ctx) + +/* exported interface defined in genjsbind-ast.h */ +struct webidl_node * +webidl_node_find_type(struct webidl_node *node, + struct webidl_node *prev, + enum webidl_node_type type) { - if (node->type == (enum webidl_node_type)ctx) - return 1; - return 0; + return webidl_node_find(node, + prev, + webidl_cmp_node_type, + (void *)type); } + struct webidl_node * webidl_node_find_type_ident(struct webidl_node *root_node, enum webidl_node_type type, diff --git a/src/webidl-ast.h b/src/webidl-ast.h index 0e38b8c..8e14fa4 100644 --- a/src/webidl-ast.h +++ b/src/webidl-ast.h @@ -89,6 +89,11 @@ webidl_node_find(struct webidl_node *node, void *ctx); struct webidl_node * +webidl_node_find_type(struct webidl_node *node, + struct webidl_node *prev, + enum webidl_node_type type); + +struct webidl_node * webidl_node_find_type_ident(struct webidl_node *root_node, enum webidl_node_type type, const char *ident); |