summaryrefslogtreecommitdiff
path: root/src/nsgenbind.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-07-22 22:12:05 +0100
committerVincent Sanders <vince@kyllikki.org>2015-07-22 22:12:05 +0100
commitd36c21c4f53270f9ba8137bb1e84a7de45fea0f3 (patch)
tree4adbd1bc49738ae348009b1be6ec54c43d038d8f /src/nsgenbind.c
parent8bc392a91daf4cc1a27a8e6777af1a29ed24e3c4 (diff)
downloadnsgenbind-d36c21c4f53270f9ba8137bb1e84a7de45fea0f3.tar.gz
nsgenbind-d36c21c4f53270f9ba8137bb1e84a7de45fea0f3.tar.bz2
Load the WebIDL files specified in the binding
This loads the WebIDL specified in the bindings into an Abstract Syntax Tree (AST) and performs the mixin operations for implements. Additionally the specs now use a slightly extended IDL syntax. Instead of wholesale implementing the second edition of the IDL spec the parser has been updated to cope with iterator and Promise keywords as those are the only changes used in the dom and html specifications. A bug was also fixed in the lexer where negative int literals were not recognised.
Diffstat (limited to 'src/nsgenbind.c')
-rw-r--r--src/nsgenbind.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/nsgenbind.c b/src/nsgenbind.c
index 8d83d13..914f58e 100644
--- a/src/nsgenbind.c
+++ b/src/nsgenbind.c
@@ -15,6 +15,7 @@
#include <errno.h>
#include "nsgenbind-ast.h"
+#include "webidl-ast.h"
#include "jsapi-libdom.h"
#include "options.h"
@@ -104,6 +105,51 @@ static int generate_binding(struct genbind_node *binding_node, void *ctx)
return res;
}
+
+static int webidl_file_cb(struct genbind_node *node, void *ctx)
+{
+ struct webidl_node **webidl_ast = ctx;
+ char *filename;
+
+ filename = genbind_node_gettext(node);
+
+ if (options->verbose) {
+ printf("Opening IDL file \"%s\"\n", filename);
+ }
+
+ return webidl_parsefile(filename, webidl_ast);
+}
+
+static int genbind_load_idl(struct genbind_node *genbind,
+ struct webidl_node **webidl_out)
+{
+ int res;
+ struct genbind_node *binding_node;
+
+ binding_node = genbind_node_find_type(genbind, NULL,
+ GENBIND_NODE_TYPE_BINDING);
+
+ /* walk AST and load any web IDL files required */
+ res = genbind_node_foreach_type(
+ genbind_node_getnode(binding_node),
+ GENBIND_NODE_TYPE_WEBIDL,
+ webidl_file_cb,
+ webidl_out);
+ if (res != 0) {
+ fprintf(stderr, "Error: failed reading Web IDL\n");
+ return -1;
+ }
+
+ /* implements are implemented as mixins so intercalate them */
+ res = webidl_intercalate_implements(*webidl_out);
+ if (res != 0) {
+ fprintf(stderr, "Error: Failed to intercalate implements\n");
+ return -1;
+ }
+
+ return 0;
+}
+
/**
* get the type of binding
*/
@@ -147,6 +193,7 @@ int main(int argc, char **argv)
{
int res;
struct genbind_node *genbind_root = NULL;
+ struct webidl_node *webidl_root = NULL;
enum bindingtype_e bindingtype;
options = process_cmdline(argc, argv);
@@ -170,8 +217,16 @@ int main(int argc, char **argv)
return 3;
}
+ /* load the IDL files specified in the binding */
+ res = genbind_load_idl(genbind_root, &webidl_root);
+ if (res != 0) {
+ return 4;
+ }
+
+ /* debug dump of web idl AST */
+ webidl_dump_ast(webidl_root);
+
#if 0
- genbind_load_idl(genbind_root);
/* generate output for each binding */
res = genbind_node_foreach_type(genbind_root,