diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-09-25 11:44:59 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-09-25 11:44:59 +0100 |
commit | 4a7185fd4a25b1456737b8fa2ac6a770a3e1721e (patch) | |
tree | 65280034968b4b04e000b43bcb3b8b4e1856c21e /src/duk-libdom-interface.c | |
parent | 5b0ac4502fd4407d51c165e0ea4ef814b3253fa9 (diff) | |
download | nsgenbind-4a7185fd4a25b1456737b8fa2ac6a770a3e1721e.tar.gz nsgenbind-4a7185fd4a25b1456737b8fa2ac6a770a3e1721e.tar.bz2 |
Make the binding parser understand c types
Instead of c types being opaque strings this makes the bindig parser
understand them. This is necessary for extended attribute parsing in
future but also makes the binding more easily understandable.
Diffstat (limited to 'src/duk-libdom-interface.c')
-rw-r--r-- | src/duk-libdom-interface.c | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c index ad40741..38e1277 100644 --- a/src/duk-libdom-interface.c +++ b/src/duk-libdom-interface.c @@ -328,6 +328,42 @@ output_interface_destructor(FILE* outf, struct ir_entry *interfacee) } /** + * Compare two nodes to check their c types match. + */ +static bool compare_ctypes(struct genbind_node *a, struct genbind_node *b) +{ + struct genbind_node *ta; + struct genbind_node *tb; + + ta = genbind_node_find_type(genbind_node_getnode(a), + NULL, GENBIND_NODE_TYPE_NAME); + tb = genbind_node_find_type(genbind_node_getnode(b), + NULL, GENBIND_NODE_TYPE_NAME); + + while ((ta != NULL) && (tb != NULL)) { + char *txt_a; + char *txt_b; + + txt_a = genbind_node_gettext(ta); + txt_b = genbind_node_gettext(tb); + + if (strcmp(txt_a, txt_b) != 0) { + return false; /* missmatch */ + } + + ta = genbind_node_find_type(genbind_node_getnode(a), + ta, GENBIND_NODE_TYPE_NAME); + tb = genbind_node_find_type(genbind_node_getnode(b), + tb, GENBIND_NODE_TYPE_NAME); + } + if (ta != tb) { + return false; + } + + return true; +} + +/** * generate an initialisor call to parent interface */ static int @@ -389,26 +425,14 @@ output_interface_inherit_init(FILE* outf, param_name); return -1; } else { - char *param_type; - char *inh_param_type; - fprintf(outf, ", "); /* cast the parameter if required */ - param_type = genbind_node_gettext( - genbind_node_find_type( - genbind_node_getnode(param_node), - NULL, - GENBIND_NODE_TYPE_TYPE)); - - inh_param_type = genbind_node_gettext( - genbind_node_find_type( - genbind_node_getnode(inh_param_node), - NULL, - GENBIND_NODE_TYPE_TYPE)); - - if (strcmp(param_type, inh_param_type) != 0) { - fprintf(outf, "(%s)", inh_param_type); + if (compare_ctypes(param_node, + inh_param_node) == false) { + fputc('(', outf); + output_ctype(outf, inh_param_node, false); + fputc(')', outf); } /* output the parameter identifier */ @@ -449,8 +473,8 @@ output_interface_init_declaration(FILE* outf, while (param_node != NULL) { interfacee->class_init_argc++; fprintf(outf, ", "); - output_cdata(outf, param_node, GENBIND_NODE_TYPE_TYPE); - output_cdata(outf, param_node, GENBIND_NODE_TYPE_IDENT); + + output_ctype(outf, param_node, true); param_node = genbind_node_find_type( genbind_node_getnode(init_node), |