summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2012-10-06 15:33:33 +0100
committerVincent Sanders <vince@kyllikki.org>2012-10-06 15:33:33 +0100
commitf072d31de069e378af37a15d1e1433e5a9e15275 (patch)
treead48d5491b9d7e1f17550550dfae07aaa3c3099e
parentd1ff941d4c2ef089eb671953a012d5ae550b0742 (diff)
downloadnsgenbind-f072d31de069e378af37a15d1e1433e5a9e15275.tar.gz
nsgenbind-f072d31de069e378af37a15d1e1433e5a9e15275.tar.bz2
add operation body output override
-rw-r--r--src/genjsbind-ast.c54
-rw-r--r--src/genjsbind-ast.h11
-rw-r--r--src/jsapi-libdom.c22
3 files changed, 86 insertions, 1 deletions
diff --git a/src/genjsbind-ast.c b/src/genjsbind-ast.c
index 2927eab..21be715 100644
--- a/src/genjsbind-ast.c
+++ b/src/genjsbind-ast.c
@@ -54,6 +54,7 @@ struct genbind_node *genbind_node_link(struct genbind_node *tgt, struct genbind_
return tgt;
}
+
struct genbind_node *
genbind_new_node(enum genbind_node_type type, struct genbind_node *l, void *r)
{
@@ -89,6 +90,7 @@ 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,
@@ -116,6 +118,53 @@ genbind_node_find(struct genbind_node *node,
return NULL;
}
+/* exported interface defined in genjsbind-ast.h */
+struct genbind_node *
+genbind_node_find_type(struct genbind_node *node,
+ struct genbind_node *prev,
+ enum genbind_node_type type)
+{
+ return genbind_node_find(node,
+ prev,
+ genbind_cmp_node_type,
+ (void *)type);
+}
+
+struct genbind_node *
+genbind_node_find_type_ident(struct genbind_node *node,
+ struct genbind_node *prev,
+ enum genbind_node_type type,
+ const char *ident)
+{
+ struct genbind_node *found_node;
+ struct genbind_node *ident_node;
+
+ found_node = genbind_node_find(node,
+ prev,
+ genbind_cmp_node_type,
+ (void *)type);
+
+ while (found_node != NULL) {
+
+ ident_node = genbind_node_find(genbind_node_getnode(found_node),
+ NULL,
+ genbind_cmp_node_type,
+ (void *)GENBIND_NODE_TYPE_IDENT);
+ if (ident_node != NULL) {
+ if (strcmp(ident_node->r.text, ident) == 0)
+ break;
+ }
+
+ /* look for next matching node */
+ found_node = genbind_node_find(node,
+ found_node,
+ genbind_cmp_node_type,
+ (void *)type);
+
+ }
+ return found_node;
+}
+
int genbind_cmp_node_type(struct genbind_node *node, void *ctx)
{
if (node->type == (enum genbind_node_type)ctx)
@@ -190,6 +239,9 @@ static const char *genbind_node_type_to_str(enum genbind_node_type type)
case GENBIND_NODE_TYPE_OPERATION:
return "Operation";
+ case GENBIND_NODE_TYPE_CBLOCK:
+ return "CBlock";
+
default:
return "Unknown";
}
@@ -197,7 +249,7 @@ static const char *genbind_node_type_to_str(enum genbind_node_type type)
int genbind_ast_dump(struct genbind_node *node, int indent)
{
- const char *SPACES=" ";
+ const char *SPACES=" ";
char *txt;
while (node != NULL) {
diff --git a/src/genjsbind-ast.h b/src/genjsbind-ast.h
index 0772169..6be13f9 100644
--- a/src/genjsbind-ast.h
+++ b/src/genjsbind-ast.h
@@ -57,6 +57,17 @@ genbind_node_find(struct genbind_node *node,
genbind_callback_t *cb,
void *ctx);
+struct genbind_node *
+genbind_node_find_type(struct genbind_node *node,
+ struct genbind_node *prev,
+ enum genbind_node_type type);
+
+struct genbind_node *
+genbind_node_find_type_ident(struct genbind_node *node,
+ struct genbind_node *prev,
+ enum genbind_node_type type,
+ const char *ident);
+
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);
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c
index 0ff8d5a..f5b9ed5 100644
--- a/src/jsapi-libdom.c
+++ b/src/jsapi-libdom.c
@@ -263,6 +263,7 @@ static int webidl_function_body_cb(struct webidl_node *node, void *ctx)
{
struct binding *binding = ctx;
struct webidl_node *ident_node;
+ struct genbind_node *operation_node;
ident_node = webidl_node_find(webidl_node_getnode(node),
NULL,
@@ -298,6 +299,24 @@ static int webidl_function_body_cb(struct webidl_node *node, void *ctx)
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
*/
+ operation_node = genbind_node_find_type_ident(binding->gb_ast,
+ NULL,
+ GENBIND_NODE_TYPE_OPERATION,
+ webidl_node_gettext(ident_node));
+
+ if (operation_node != NULL) {
+ struct genbind_node *code_node;
+
+ code_node = genbind_node_find_type(genbind_node_getnode(operation_node),
+ NULL,
+ GENBIND_NODE_TYPE_CBLOCK);
+ if (code_node != NULL) {
+ fprintf(binding->outfile,
+ "%s\n",
+ genbind_node_gettext(code_node));
+ }
+ }
+
fprintf(binding->outfile, "}\n\n");
@@ -585,6 +604,9 @@ output_preamble(struct binding *binding)
GENBIND_NODE_TYPE_PREAMBLE,
webidl_preamble_cb,
binding);
+
+ fprintf(binding->outfile,"\n\n");
+
return 0;
}