summaryrefslogtreecommitdiff
path: root/src/duk-libdom.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-08-30 09:14:38 +0100
committerVincent Sanders <vince@kyllikki.org>2015-08-30 09:14:38 +0100
commit83956295f66576becbf5de8cef915cd0d54f409b (patch)
treeb8040d623ed6d0998ddb23224f364cc1b4be2460 /src/duk-libdom.c
parentd6f41574a18866ebfbb8b61f9afcd0a0de2d40cf (diff)
downloadnsgenbind-83956295f66576becbf5de8cef915cd0d54f409b.tar.gz
nsgenbind-83956295f66576becbf5de8cef915cd0d54f409b.tar.bz2
Change dictionary generation to produce C accessors.
This generates routines which correctly handle reading a member from a dictionary and returning it as the correct c type. Currently the types "any", "user" and "sequence" remain unhandled.
Diffstat (limited to 'src/duk-libdom.c')
-rw-r--r--src/duk-libdom.c90
1 files changed, 16 insertions, 74 deletions
diff --git a/src/duk-libdom.c b/src/duk-libdom.c
index 02b41b3..f72bc96 100644
--- a/src/duk-libdom.c
+++ b/src/duk-libdom.c
@@ -132,14 +132,14 @@ static FILE *open_header(struct ir *ir, const char *name)
return NULL;
}
+ /* tool preface */
+ output_tool_preface(hdrf);
+
/* binding preface */
output_cdata(hdrf,
ir->binding_node,
GENBIND_NODE_TYPE_PREFACE);
- /* tool preface */
- output_tool_preface(hdrf);
-
/* header guard */
fprintf(hdrf, "\n#ifndef %s_%s_h\n", DLPFX, name);
fprintf(hdrf, "#define %s_%s_h\n\n", DLPFX, name);
@@ -172,43 +172,6 @@ static int close_header(struct ir *ir,
}
-
-
-static int
-output_interface_init_declaration(FILE* outf,
- struct ir_entry *interfacee,
- struct genbind_node *init_node)
-{
- struct genbind_node *param_node;
-
- fprintf(outf,
- "void %s_%s___init(duk_context *ctx, %s_private_t *priv",
- DLPFX, interfacee->class_name, interfacee->class_name);
-
- /* count the number of arguments on the initializer */
- interfacee->class_init_argc = 0;
-
- /* output the paramters on the method (if any) */
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- NULL, GENBIND_NODE_TYPE_PARAMETER);
- 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);
-
- param_node = genbind_node_find_type(
- genbind_node_getnode(init_node),
- param_node, GENBIND_NODE_TYPE_PARAMETER);
- }
-
- fprintf(outf,")");
-
- return 0;
-}
-
-
/**
* generate private header
*/
@@ -314,44 +277,19 @@ output_prototype_header(struct ir *ir)
protof = open_header(ir, "prototype");
for (idx = 0; idx < ir->entryc; idx++) {
- struct ir_entry *interfacee;
- struct genbind_node *init_node;
-
- interfacee = ir->entries + idx;
+ struct ir_entry *entry;
- /* do not generate prototype declarations for interfaces marked
- * no output
- */
- if ((interfacee->type == IR_ENTRY_TYPE_INTERFACE) &&
- (interfacee->u.interface.noobject)) {
- continue;
- }
+ entry = ir->entries + idx;
- /* prototype declaration */
- fprintf(protof, "duk_ret_t %s_%s___proto(duk_context *ctx);\n",
- DLPFX, interfacee->class_name);
+ switch (entry->type) {
+ case IR_ENTRY_TYPE_INTERFACE:
+ output_interface_declaration(protof, entry);
+ break;
- /* if the interface has no references (no other interface
- * inherits from it) there is no reason to export the
- * initalisor/finaliser as no other class
- * constructor/destructor should call them.
- */
- if (interfacee->refcount > 0) {
- /* finaliser declaration */
- fprintf(protof,
- "void %s_%s___fini(duk_context *ctx, %s_private_t *priv);\n",
- DLPFX, interfacee->class_name, interfacee->class_name);
-
- /* find the initialisor method on the class (if any) */
- init_node = genbind_node_find_method(interfacee->class,
- NULL,
- GENBIND_METHOD_TYPE_INIT);
-
- /* initialisor definition */
- output_interface_init_declaration(protof, interfacee, init_node);
- fprintf(protof, ";\n\n");
+ case IR_ENTRY_TYPE_DICTIONARY:
+ output_dictionary_declaration(protof, entry);
+ break;
}
- fprintf(protof, "\n");
}
close_header(ir, protof, "prototype");
@@ -612,6 +550,10 @@ output_binding_src(struct ir *ir)
interfacee = ir->entries + idx;
+ if (interfacee->type == IR_ENTRY_TYPE_DICTIONARY) {
+ continue;
+ }
+
/* do not generate prototype calls for interfaces marked
* no output
*/