diff options
author | Vincent Sanders <vince@kyllikki.org> | 2013-01-02 21:47:13 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2013-01-02 21:47:13 +0000 |
commit | 2b722f1ccfecc75ed93651543c9ba22a849396a1 (patch) | |
tree | 23c681240e72b15aa65f418ce78b385c2d13f33a /src | |
parent | 3b19d1d1ad88ba63ae821b2aedd4005466ed52fa (diff) | |
download | nsgenbind-2b722f1ccfecc75ed93651543c9ba22a849396a1.tar.gz nsgenbind-2b722f1ccfecc75ed93651543c9ba22a849396a1.tar.bz2 |
extend binding DSL with prologue and epilogue stanzas
Diffstat (limited to 'src')
-rw-r--r-- | src/jsapi-libdom.c | 78 | ||||
-rw-r--r-- | src/nsgenbind-ast.c | 2 | ||||
-rw-r--r-- | src/nsgenbind-lexer.l | 4 | ||||
-rw-r--r-- | src/nsgenbind-parser.y | 28 |
4 files changed, 88 insertions, 24 deletions
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index 39225ea..2c1278d 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -69,6 +69,15 @@ static int webidl_preamble_cb(struct genbind_node *node, void *ctx) return 0; } +static int webidl_prologue_cb(struct genbind_node *node, void *ctx) +{ + struct binding *binding = ctx; + + fprintf(binding->outfile, "%s", genbind_node_gettext(node)); + + return 0; +} + static int webidl_epilogue_cb(struct genbind_node *node, void *ctx) { struct binding *binding = ctx; @@ -172,6 +181,46 @@ static int webidl_private_assign_cb(struct genbind_node *node, void *ctx) return 0; } +/* section output generators */ + +/** Output the epilogue right at the end of the generated program */ +static int +output_epilogue(struct binding *binding) +{ + genbind_node_for_each_type(binding->gb_ast, + GENBIND_NODE_TYPE_EPILOGUE, + webidl_epilogue_cb, + binding); + + fprintf(binding->outfile,"\n\n"); + + if (binding->hdrfile) { + binding->outfile = binding->hdrfile; + + fprintf(binding->outfile, + "\n\n#endif /* _%s_ */\n", + binding->hdrguard); + + binding->outfile = binding->srcfile; + } + + return 0; +} + +/** Output the prologue right before the generated function bodies */ +static int +output_prologue(struct binding *binding) +{ + genbind_node_for_each_type(binding->gb_ast, + GENBIND_NODE_TYPE_PROLOGUE, + webidl_prologue_cb, + binding); + + fprintf(binding->outfile,"\n\n"); + + return 0; +} + static int output_api_operations(struct binding *binding) @@ -623,28 +672,6 @@ output_preamble(struct binding *binding) return 0; } -static int -output_epilogue(struct binding *binding) -{ - genbind_node_for_each_type(binding->gb_ast, - GENBIND_NODE_TYPE_EPILOGUE, - webidl_epilogue_cb, - binding); - - fprintf(binding->outfile,"\n\n"); - - if (binding->hdrfile) { - binding->outfile = binding->hdrfile; - - fprintf(binding->outfile, - "\n\n#endif /* _%s_ */\n", - binding->hdrguard); - - binding->outfile = binding->srcfile; - } - - return 0; -} static int output_header_comments(struct binding *binding) @@ -843,6 +870,7 @@ jsapi_libdom_output(char *outfilename, return 40; } + /* start with comment block */ res = output_header_comments(binding); if (res) { return 50; @@ -868,6 +896,12 @@ jsapi_libdom_output(char *outfilename, return 85; } + /* user code outout just before function bodies emitted */ + res = output_prologue(binding); + if (res) { + return 89; + } + /* operator and atrtribute body generation */ res = output_operator_body(binding, binding->interface); diff --git a/src/nsgenbind-ast.c b/src/nsgenbind-ast.c index f5cdc78..6b7bf5d 100644 --- a/src/nsgenbind-ast.c +++ b/src/nsgenbind-ast.c @@ -207,6 +207,8 @@ char *genbind_node_gettext(struct genbind_node *node) case GENBIND_NODE_TYPE_WEBIDLFILE: case GENBIND_NODE_TYPE_STRING: case GENBIND_NODE_TYPE_PREAMBLE: + case GENBIND_NODE_TYPE_PROLOGUE: + case GENBIND_NODE_TYPE_EPILOGUE: case GENBIND_NODE_TYPE_IDENT: case GENBIND_NODE_TYPE_TYPE: case GENBIND_NODE_TYPE_BINDING_INTERFACE: diff --git a/src/nsgenbind-lexer.l b/src/nsgenbind-lexer.l index e1c7740..b257c83 100644 --- a/src/nsgenbind-lexer.l +++ b/src/nsgenbind-lexer.l @@ -86,6 +86,10 @@ hdrcomment return TOK_HDR_COMMENT; preamble return TOK_PREAMBLE; +prologue return TOK_PROLOGUE; + +epilogue return TOK_EPILOGUE; + binding return TOK_BINDING; interface return TOK_INTERFACE; diff --git a/src/nsgenbind-parser.y b/src/nsgenbind-parser.y index 984513e..472e655 100644 --- a/src/nsgenbind-parser.y +++ b/src/nsgenbind-parser.y @@ -42,6 +42,8 @@ char *errtxt; %token TOK_IDLFILE %token TOK_HDR_COMMENT %token TOK_PREAMBLE +%token TOK_PROLOGUE; +%token TOK_EPILOGUE; %token TOK_API %token TOK_BINDING @@ -69,6 +71,8 @@ char *errtxt; %type <node> Statements %type <node> IdlFile %type <node> Preamble +%type <node> Prologue +%type <node> Epilogue %type <node> HdrComment %type <node> Strings %type <node> Binding @@ -120,7 +124,11 @@ Statement HdrComment | Preamble - | + | + Prologue + | + Epilogue + | Binding | Operation @@ -164,12 +172,28 @@ Strings Preamble : - TOK_PREAMBLE CBlock + TOK_PREAMBLE CBlock { $$ = genbind_new_node(GENBIND_NODE_TYPE_PREAMBLE, NULL, $2); } ; +Prologue + : + TOK_PROLOGUE CBlock + { + $$ = genbind_new_node(GENBIND_NODE_TYPE_PROLOGUE, NULL, $2); + } + ; + +Epilogue + : + TOK_EPILOGUE CBlock + { + $$ = genbind_new_node(GENBIND_NODE_TYPE_EPILOGUE, NULL, $2); + } + ; + CBlock : TOK_CCODE_LITERAL |