diff options
author | Vincent Sanders <vince@kyllikki.org> | 2012-09-17 01:22:22 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2012-09-17 01:22:22 +0100 |
commit | d5c2e8d0843abd94e4fed57f25186147f56a3976 (patch) | |
tree | a9e74c36c4a875df8f84905b6fd82109a4f733af | |
parent | cdd39954a238ec07224c3c9cff66a4f8f101d71c (diff) | |
download | nsgenbind-d5c2e8d0843abd94e4fed57f25186147f56a3976.tar.gz nsgenbind-d5c2e8d0843abd94e4fed57f25186147f56a3976.tar.bz2 |
add search function
-rw-r--r-- | src/genjsbind-ast.c | 34 | ||||
-rw-r--r-- | src/genjsbind-ast.h | 21 | ||||
-rw-r--r-- | src/jsapi-libdom.c | 48 | ||||
-rw-r--r-- | src/webidl-ast.c | 4 |
4 files changed, 93 insertions, 14 deletions
diff --git a/src/genjsbind-ast.c b/src/genjsbind-ast.c index ebdb5b3..28208e0 100644 --- a/src/genjsbind-ast.c +++ b/src/genjsbind-ast.c @@ -89,6 +89,40 @@ genbind_node_for_each_type(struct genbind_node *node, return 0; } +/* exported interface defined in genjsbind-ast.h */ +struct genbind_node * +genbind_node_find(struct genbind_node *node, + struct genbind_node *prev, + genbind_callback_t *cb, + void *ctx) +{ + struct genbind_node *ret; + + if (node == NULL) { + return NULL; + } + + if (node->l != prev) { + ret = genbind_node_find(node->l, prev, cb, ctx); + if (ret != NULL) { + return ret; + } + } + + if (cb(node, ctx) != 0) { + return node; + } + + return NULL; +} + +int genbind_cmp_node_type(struct genbind_node *node, void *ctx) +{ + if (node->type == (enum genbind_node_type)ctx) + return 1; + return 0; +} + char *genbind_node_gettext(struct genbind_node *node) { switch(node->type) { diff --git a/src/genjsbind-ast.h b/src/genjsbind-ast.h index 27d5505..eaa42f9 100644 --- a/src/genjsbind-ast.h +++ b/src/genjsbind-ast.h @@ -30,6 +30,7 @@ struct genbind_node; /** callback for search and iteration routines */ typedef int (genbind_callback_t)(struct genbind_node *node, void *ctx); +int genbind_cmp_node_type(struct genbind_node *node, void *ctx); int genbind_parsefile(char *infilename, struct genbind_node **ast); @@ -38,11 +39,27 @@ char *genbind_strapp(char *a, char *b); struct genbind_node *genbind_new_node(enum genbind_node_type type, struct genbind_node *l, void *r); struct genbind_node *genbind_node_link(struct genbind_node *tgt, struct genbind_node *src); +int genbind_ast_dump(struct genbind_node *ast); + +/** 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 + * of a previous search to continue. + * @param cb Comparison callback + * @param ctx Context for callback + */ +struct genbind_node * +genbind_node_find(struct genbind_node *node, + struct genbind_node *prev, + genbind_callback_t *cb, + void *ctx); + int genbind_node_for_each_type(struct genbind_node *node, enum genbind_node_type type, genbind_callback_t *cb, void *ctx); char *genbind_node_gettext(struct genbind_node *node); struct genbind_node *genbind_node_getnode(struct genbind_node *node); -int genbind_ast_dump(struct genbind_node *ast); - #endif diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index 3cae66f..505f115 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -82,10 +82,37 @@ static int webidl_file_cb(struct genbind_node *node, void *ctx) static int read_webidl(struct genbind_node *genbind_ast, struct webidl_node **webidl_ast) { - return genbind_node_for_each_type(genbind_ast, - GENBIND_NODE_TYPE_WEBIDLFILE, - webidl_file_cb, - webidl_ast); + int res; + + res = genbind_node_for_each_type(genbind_ast, + GENBIND_NODE_TYPE_WEBIDLFILE, + webidl_file_cb, + webidl_ast); + + /* debug dump of web idl AST */ + if (options->verbose) { + webidl_ast_dump(webidl_ast, 0); + } + return res; +} + +struct binding { + const char *name; /* name of the binding */ + const char *interface; /* webidl interface binding is for */ +}; + + +static struct binding *binding_new(struct genbind_node *genbind_ast) +{ + struct binding *nb; + nb = calloc(1, sizeof(struct binding)); + + struct genbind_node *binding_node; + + binding_node = genbind_node_find(genbind_ast, + NULL, + genbind_cmp_node_type, + GENBIND_NODE_TYPE_BINDING); } @@ -94,16 +121,17 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) FILE *outfile = NULL; struct webidl_node *webidl_ast = NULL; int res; + struct binding *binding; + /* walk ast and load any web IDL files required */ res = read_webidl(genbind_ast, &webidl_ast); if (res != 0) { fprintf(stderr, "Error reading Web IDL files\n"); return 5; } - if (options->verbose) { - webidl_ast_dump(webidl_ast, 0); - } + /* get general binding information used in output */ + binding = binding_new(genbind_ast); /* open output file */ if (outfilename == NULL) { @@ -123,10 +151,10 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) output_preamble(outfile, genbind_ast); - /* + //output_function_spec(outfile, genbind_ast); + + //output_property_spec(outfile, genbind_ast); - fprintf(outfile, " interface %s \n\n", genbind_ast->ifname); -*/ fclose(outfile); return 0; diff --git a/src/webidl-ast.c b/src/webidl-ast.c index fecf0da..810ac24 100644 --- a/src/webidl-ast.c +++ b/src/webidl-ast.c @@ -125,11 +125,11 @@ static const char *webidl_node_type_to_str(enum webidl_node_type type) } } -const char *SPACES=" "; + int webidl_ast_dump(struct webidl_node *node, int indent) { - char *txt; + const char *SPACES=" "; char *txt; while (node != NULL) { printf("%.*s%s", indent, SPACES, webidl_node_type_to_str(node->type)); |