diff options
author | Vincent Sanders <vincent.sanders@collabora.co.uk> | 2012-09-13 17:33:21 +0100 |
---|---|---|
committer | Vincent Sanders <vincent.sanders@collabora.co.uk> | 2012-09-13 17:33:21 +0100 |
commit | deadfe6cfb87ee537ed38e0ce87601f492078aab (patch) | |
tree | 9a3178955ae42f3ee7d7223fbb71d505b16fa6f7 | |
parent | eeaa03bf10aa41656b798ef8df7f42140c66e766 (diff) | |
download | nsgenbind-deadfe6cfb87ee537ed38e0ce87601f492078aab.tar.gz nsgenbind-deadfe6cfb87ee537ed38e0ce87601f492078aab.tar.bz2 |
add debug dump to webidl
-rw-r--r-- | src/genjsbind-ast.c | 99 | ||||
-rw-r--r-- | src/genjsbind-ast.h | 6 | ||||
-rw-r--r-- | src/jsapi-libdom.c | 35 | ||||
-rw-r--r-- | src/webidl-ast.c | 135 | ||||
-rw-r--r-- | src/webidl-ast.h | 25 | ||||
-rw-r--r-- | src/webidl-parser.y | 30 |
6 files changed, 221 insertions, 109 deletions
diff --git a/src/genjsbind-ast.c b/src/genjsbind-ast.c index 1645f78..ebdb5b3 100644 --- a/src/genjsbind-ast.c +++ b/src/genjsbind-ast.c @@ -120,63 +120,56 @@ struct genbind_node *genbind_node_getnode(struct genbind_node *node) } } +static const char *genbind_node_type_to_str(enum genbind_node_type type) +{ + switch(type) { + case GENBIND_NODE_TYPE_ROOT: + return "Root"; + + case GENBIND_NODE_TYPE_WEBIDLFILE: + return "webidlfile"; + + case GENBIND_NODE_TYPE_HDRCOMMENT: + return "HdrComment"; + + case GENBIND_NODE_TYPE_STRING: + return "String"; + + case GENBIND_NODE_TYPE_PREAMBLE: + return "Preamble"; + + case GENBIND_NODE_TYPE_BINDING: + return "Binding"; + + case GENBIND_NODE_TYPE_BINDING_IDENT: + return "Binding: Ident"; + + case GENBIND_NODE_TYPE_TYPE: + return "Type"; + + case GENBIND_NODE_TYPE_TYPE_IDENT: + return "Type: Ident"; + + case GENBIND_NODE_TYPE_TYPE_NODE: + return "Type: Node"; + + case GENBIND_NODE_TYPE_TYPE_EXTRA: + return "Type: Extra"; + + case GENBIND_NODE_TYPE_TYPE_INTERFACE: + return "Type: Interface"; + + default: + return "Unknown"; + } +} + int genbind_ast_dump(struct genbind_node *node) { char *txt; while (node != NULL) { - switch(node->type) { - case GENBIND_NODE_TYPE_ROOT: - printf("root\n"); - break; - - case GENBIND_NODE_TYPE_WEBIDLFILE: - printf("webidlfile\n"); - break; - - case GENBIND_NODE_TYPE_HDRCOMMENT: - printf("hdrcomment\n"); - break; - - case GENBIND_NODE_TYPE_STRING: - printf("string\n"); - break; - - case GENBIND_NODE_TYPE_PREAMBLE: - printf("preamble\n"); - break; - - case GENBIND_NODE_TYPE_BINDING: - printf("binding\n"); - break; - - case GENBIND_NODE_TYPE_BINDING_IDENT: - printf("binding ident\n"); - break; - - case GENBIND_NODE_TYPE_TYPE: - printf("type\n"); - break; - - case GENBIND_NODE_TYPE_TYPE_IDENT: - printf("type ident\n"); - break; - - case GENBIND_NODE_TYPE_TYPE_NODE: - printf("type node\n"); - break; - - case GENBIND_NODE_TYPE_TYPE_EXTRA: - printf("type extra\n"); - break; - - case GENBIND_NODE_TYPE_TYPE_INTERFACE: - printf("\n"); - break; - - default: - printf("Unknown node type!\n"); - break; - } + + printf("%s\n", genbind_node_type_to_str(node->type)); txt = genbind_node_gettext(node); if (txt == NULL) { diff --git a/src/genjsbind-ast.h b/src/genjsbind-ast.h index 20ee028..27d5505 100644 --- a/src/genjsbind-ast.h +++ b/src/genjsbind-ast.h @@ -27,6 +27,10 @@ enum genbind_node_type { struct genbind_node; +/** callback for search and iteration routines */ +typedef int (genbind_callback_t)(struct genbind_node *node, void *ctx); + + int genbind_parsefile(char *infilename, struct genbind_node **ast); char *genbind_strapp(char *a, char *b); @@ -34,8 +38,6 @@ 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); -typedef int (genbind_callback_t)(struct genbind_node *node, 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); diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index d1ac37c..0f4ebc4 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -9,7 +9,9 @@ #include <stdio.h> #include <errno.h> #include <string.h> +#include <stdbool.h> +#include "options.h" #include "genjsbind-ast.h" #include "webidl-ast.h" #include "jsapi-libdom.h" @@ -17,35 +19,6 @@ #define HDR_COMMENT_SEP "\n * " #define HDR_COMMENT_PREABLE "Generated by nsgenjsapi" -/* -#define HDR_COMMENT_SEP_LEN 4 - -int genbind_header_comment(char *comment) -{ - char *fullstr; - int fulllen; - fulllen = strlen(genbind_ast->hdr_comments) + - strlen(comment) + HDR_COMMENT_SEP_LEN + 1; - fullstr = malloc(fulllen); - snprintf(fullstr, fulllen, "%s"HDR_COMMENT_SEP"%s", genbind_ast->hdr_comments , comment); - free(genbind_ast->hdr_comments); - free(comment); - genbind_ast->hdr_comments = fullstr; - - return 0; -} - -{ - if (webidl_parsefile($2) != 0) { - YYABORT; -} -} -*/ - /* initialise root IDL node */ -/* webidl_root = - -*/ - static int webidl_hdrcomments_cb(struct genbind_node *node, void *ctx) { FILE *outfile = ctx; @@ -109,6 +82,10 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) return 5; } + if (options->verbose) { + webidl_ast_dump(webidl_ast); + } + /* open output file */ if (outfilename == NULL) { outfile = stdout; diff --git a/src/webidl-ast.c b/src/webidl-ast.c index e19fb80..be52490 100644 --- a/src/webidl-ast.c +++ b/src/webidl-ast.c @@ -21,6 +21,120 @@ extern void webidl_restart(FILE*); extern int webidl_parse(struct webidl_node **webidl_ast); + +struct webidl_node * +webidl_node_link(struct webidl_node *tgt, struct webidl_node *src) +{ + if (tgt != NULL) { + tgt->l = src; + return tgt; + } + return src; +} + +struct webidl_node *webidl_node_new(enum webidl_node_type type, struct webidl_node *l, void *r) +{ + struct webidl_node *nn; + nn = calloc(1, sizeof(struct webidl_node)); + nn->type = type; + nn->l = l; + nn->r.text = r; + return nn; +} + + +int +webidl_node_for_each_type(struct webidl_node *node, + enum webidl_node_type type, + webidl_callback_t *cb, + void *ctx) +{ + int ret; + + if (node == NULL) { + return -1; + } + if (node->l != NULL) { + ret = webidl_node_for_each_type(node->l, type, cb, ctx); + if (ret != 0) { + return ret; + } + } + if (node->type == type) { + return cb(node, ctx); + } + + return 0; +} + + +char *webidl_node_gettext(struct webidl_node *node) +{ + switch(node->type) { + case WEBIDL_NODE_TYPE_INTERFACE_IDENT: + case WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE: + + return node->r.text; + + default: + return NULL; + } +} + +struct webidl_node *webidl_node_getnode(struct webidl_node *node) +{ + switch(node->type) { + case WEBIDL_NODE_TYPE_ROOT: + case WEBIDL_NODE_TYPE_INTERFACE: + case WEBIDL_NODE_TYPE_INTERFACE_MEMBERS: + return node->r.node; + + default: + return NULL; + } +} + +static const char *webidl_node_type_to_str(enum webidl_node_type type) +{ + switch(type) { + case WEBIDL_NODE_TYPE_ROOT: + return "root"; + + case WEBIDL_NODE_TYPE_INTERFACE_IDENT: + return "Interface: Ident"; + + case WEBIDL_NODE_TYPE_INTERFACE_INHERITANCE: + return "Interface: Inherit"; + + case WEBIDL_NODE_TYPE_INTERFACE: + return "Interface"; + + case WEBIDL_NODE_TYPE_INTERFACE_MEMBERS: + return "Interface: Members"; + + default: + return "Unknown"; + } + +} + +int webidl_ast_dump(struct webidl_node *node) +{ + char *txt; + while (node != NULL) { + printf("%s\n", webidl_node_type_to_str(node->type)); + + txt = webidl_node_gettext(node); + if (txt == NULL) { + webidl_ast_dump(webidl_node_getnode(node)); + } else { + printf(" %s\n", txt); + } + node = node->l; + } + return 0; +} + static FILE *idlopen(const char *filename) { FILE *idlfile; @@ -44,27 +158,6 @@ static FILE *idlopen(const char *filename) return idlfile; } -struct webidl_node * -webidl_node_link(struct webidl_node *tgt, struct webidl_node *src) -{ - if (tgt != NULL) { - tgt->l = src; - return tgt; - } - return src; -} - -struct webidl_node *webidl_node_new(int type, struct webidl_node *l, void *r) -{ - struct webidl_node *nn; - nn = calloc(1, sizeof(struct webidl_node)); - nn->type = type; - nn->l = l; - nn->r.text = r; - return nn; -} - - int webidl_parsefile(char *filename, struct webidl_node **webidl_ast) { diff --git a/src/webidl-ast.h b/src/webidl-ast.h index 2798fa6..9a516af 100644 --- a/src/webidl-ast.h +++ b/src/webidl-ast.h @@ -18,7 +18,7 @@ enum webidl_node_type { }; struct webidl_node { - int type; + enum webidl_node_type type; struct webidl_node *l; union { struct webidl_node *node; @@ -26,12 +26,29 @@ struct webidl_node { } r; }; +/** callback for search and iteration routines */ +typedef int (webidl_callback_t)(struct webidl_node *node, void *ctx); -/** parse web idl file */ -int webidl_parsefile(char *filename, struct webidl_node **webidl_ast); -struct webidl_node *webidl_node_new(int type, struct webidl_node *l, void *r); +struct webidl_node *webidl_node_new(enum webidl_node_type, struct webidl_node *l, void *r); struct webidl_node *webidl_node_link(struct webidl_node *tgt, struct webidl_node *src); +/* node contents acessors */ +char *webidl_node_gettext(struct webidl_node *node); +struct webidl_node *webidl_node_getnode(struct webidl_node *node); + + +/* node searches */ +int webidl_node_for_each_type(struct webidl_node *node, + enum webidl_node_type type, + webidl_callback_t *cb, + void *ctx); + +/* debug dump */ +int webidl_ast_dump(struct webidl_node *node); + +/** parse web idl file */ +int webidl_parsefile(char *filename, struct webidl_node **webidl_ast); + #endif diff --git a/src/webidl-parser.y b/src/webidl-parser.y index 2fd907f..788aff4 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -110,8 +110,14 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %type <node> Definitions %type <node> Definition + %type <node> Partial +%type <node> PartialDefinition +%type <node> PartialInterface + %type <node> Dictionary +%type <node> PartialDictionary + %type <node> Exception %type <node> Enum %type <node> Typedef @@ -208,6 +214,9 @@ Interface: /* [6] */ Partial: TOK_PARTIAL PartialDefinition + { + $$ = $2; + } ; /* [7] */ @@ -220,6 +229,9 @@ PartialDefinition: /* [8] */ PartialInterface: TOK_INTERFACE TOK_IDENTIFIER '{' InterfaceMembers '}' ';' + { + $$=NULL; + } ; /* [9] slightly altered from original grammar to be left recursive */ @@ -245,6 +257,9 @@ InterfaceMember: /* [11] */ Dictionary: TOK_DICTIONARY TOK_IDENTIFIER Inheritance '{' DictionaryMembers '}' ';' + { + $$ = NULL; + } ; /* [12] */ @@ -262,6 +277,9 @@ DictionaryMember: /* [14] */ PartialDictionary: TOK_DICTIONARY TOK_IDENTIFIER '{' DictionaryMembers '}' ';' + { + $$=NULL; + } /* [15] */ Default: @@ -281,6 +299,9 @@ DefaultValue: /* [17] */ Exception: TOK_EXCEPTION TOK_IDENTIFIER Inheritance '{' ExceptionMembers '}' ';' + { + $$ = NULL; + } ; /* [18] */ @@ -306,6 +327,9 @@ Inheritance: /* [20] */ Enum: TOK_ENUM TOK_IDENTIFIER '{' EnumValueList '}' ';' + { + $$ = NULL; + } ; /* [21] */ @@ -331,11 +355,17 @@ CallbackRest: /* [24] */ Typedef: TOK_TYPEDEF ExtendedAttributeList Type TOK_IDENTIFIER ';' + { + $$ = NULL; + } ; /* [25] */ ImplementsStatement: TOK_IDENTIFIER TOK_IMPLEMENTS TOK_IDENTIFIER ';' + { + $$ = NULL; + } ; /* [26] */ |