summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2012-10-29 13:40:13 +0000
committerVincent Sanders <vince@kyllikki.org>2012-10-29 13:40:13 +0000
commitade96212575df58bc0f714168a87d9975eea273a (patch)
tree7ff0a1888948e6e59e00eecc00d19a21fd040d9d /src
parent2931cd7597b8a41941e5cc3a1f869d36446c6006 (diff)
downloadnsgenbind-ade96212575df58bc0f714168a87d9975eea273a.tar.gz
nsgenbind-ade96212575df58bc0f714168a87d9975eea273a.tar.bz2
add internal and API to binding language
split out class operation, initialisation and new generation
Diffstat (limited to 'src')
-rw-r--r--src/jsapi-libdom.c54
-rw-r--r--src/nsgenbind-ast.c8
-rw-r--r--src/nsgenbind-ast.h2
-rw-r--r--src/nsgenbind-lexer.l4
-rw-r--r--src/nsgenbind-parser.y43
5 files changed, 102 insertions, 9 deletions
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c
index 866f8be..30c8d26 100644
--- a/src/jsapi-libdom.c
+++ b/src/jsapi-libdom.c
@@ -365,7 +365,6 @@ static int webidl_private_assign_cb(struct genbind_node *node, void *ctx)
{
struct binding *binding = ctx;
struct genbind_node *ident_node;
- struct genbind_node *type_node;
ident_node = genbind_node_find_type(genbind_node_getnode(node),
NULL,
@@ -382,7 +381,7 @@ static int webidl_private_assign_cb(struct genbind_node *node, void *ctx)
static int
-output_con_de_structors(struct binding *binding)
+output_class_operations(struct binding *binding)
{
int res = 0;
struct genbind_node *binding_node;
@@ -416,6 +415,23 @@ output_con_de_structors(struct binding *binding)
"\t*objp = NULL;\n"
"\treturn JS_TRUE;\n"
"}\n\n");
+ return res;
+}
+
+static int
+output_class_init(struct binding *binding)
+{
+ int res = 0;
+ struct genbind_node *binding_node;
+
+ binding_node = genbind_node_find(binding->gb_ast,
+ NULL,
+ genbind_cmp_node_type,
+ (void *)GENBIND_NODE_TYPE_BINDING);
+
+ if (binding_node == NULL) {
+ return -1;
+ }
/* class Initialisor */
fprintf(binding->outfile,
@@ -436,6 +452,23 @@ output_con_de_structors(struct binding *binding)
"\treturn jsobject;\n"
"}\n\n",
binding->interface);
+ return res;
+}
+
+static int
+output_class_new(struct binding *binding)
+{
+ int res = 0;
+ struct genbind_node *binding_node;
+
+ binding_node = genbind_node_find(binding->gb_ast,
+ NULL,
+ genbind_cmp_node_type,
+ (void *)GENBIND_NODE_TYPE_BINDING);
+
+ if (binding_node == NULL) {
+ return -1;
+ }
/* constructor */
@@ -634,6 +667,11 @@ output_private_declaration(struct binding *binding)
webidl_private_cb,
binding);
+ genbind_node_for_each_type(genbind_node_getnode(binding_node),
+ GENBIND_NODE_TYPE_BINDING_INTERNAL,
+ webidl_private_cb,
+ binding);
+
fprintf(binding->outfile, "};\n\n");
@@ -782,11 +820,21 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast)
return 12;
}
- res = output_con_de_structors(binding);
+ res = output_class_operations(binding);
if (res) {
return 13;
}
+ res = output_class_init(binding);
+ if (res) {
+ return 14;
+ }
+
+ res = output_class_new(binding);
+ if (res) {
+ return 15;
+ }
+
fclose(binding->outfile);
return 0;
diff --git a/src/nsgenbind-ast.c b/src/nsgenbind-ast.c
index 646548b..e192d74 100644
--- a/src/nsgenbind-ast.c
+++ b/src/nsgenbind-ast.c
@@ -195,7 +195,9 @@ struct genbind_node *genbind_node_getnode(struct genbind_node *node)
case GENBIND_NODE_TYPE_HDRCOMMENT:
case GENBIND_NODE_TYPE_BINDING:
case GENBIND_NODE_TYPE_BINDING_PRIVATE:
+ case GENBIND_NODE_TYPE_BINDING_INTERNAL:
case GENBIND_NODE_TYPE_OPERATION:
+ case GENBIND_NODE_TYPE_API:
return node->r.node;
default:
@@ -233,12 +235,18 @@ static const char *genbind_node_type_to_str(enum genbind_node_type type)
case GENBIND_NODE_TYPE_BINDING_PRIVATE:
return "Private";
+ case GENBIND_NODE_TYPE_BINDING_INTERNAL:
+ return "Internal";
+
case GENBIND_NODE_TYPE_BINDING_INTERFACE:
return "Interface";
case GENBIND_NODE_TYPE_OPERATION:
return "Operation";
+ case GENBIND_NODE_TYPE_API:
+ return "API";
+
case GENBIND_NODE_TYPE_CBLOCK:
return "CBlock";
diff --git a/src/nsgenbind-ast.h b/src/nsgenbind-ast.h
index b51e6b8..0006153 100644
--- a/src/nsgenbind-ast.h
+++ b/src/nsgenbind-ast.h
@@ -20,7 +20,9 @@ enum genbind_node_type {
GENBIND_NODE_TYPE_BINDING,
GENBIND_NODE_TYPE_BINDING_TYPE,
GENBIND_NODE_TYPE_BINDING_PRIVATE,
+ GENBIND_NODE_TYPE_BINDING_INTERNAL,
GENBIND_NODE_TYPE_BINDING_INTERFACE,
+ GENBIND_NODE_TYPE_API,
GENBIND_NODE_TYPE_OPERATION,
};
diff --git a/src/nsgenbind-lexer.l b/src/nsgenbind-lexer.l
index 4bdc803..040d7e9 100644
--- a/src/nsgenbind-lexer.l
+++ b/src/nsgenbind-lexer.l
@@ -94,8 +94,12 @@ type return TOK_TYPE;
private return TOK_PRIVATE;
+internal return TOK_INTERNAL;
+
operation return TOK_OPERATION;
+api return TOK_API;
+
{cblockopen} BEGIN(cblock);
{identifier} {
diff --git a/src/nsgenbind-parser.y b/src/nsgenbind-parser.y
index 500f4b8..ea0a625 100644
--- a/src/nsgenbind-parser.y
+++ b/src/nsgenbind-parser.y
@@ -42,11 +42,13 @@ char *errtxt;
%token TOK_HDR_COMMENT
%token TOK_PREAMBLE
+%token TOK_API
%token TOK_BINDING
%token TOK_OPERATION
%token TOK_INTERFACE
%token TOK_TYPE
%token TOK_PRIVATE
+%token TOK_INTERNAL
%token <text> TOK_IDENTIFIER
%token <text> TOK_STRING_LITERAL
@@ -65,8 +67,10 @@ char *errtxt;
%type <node> BindingArg
%type <node> Type
%type <node> Private
+%type <node> Internal
%type <node> Interface
%type <node> Operation
+%type <node> Api
%%
@@ -107,6 +111,8 @@ Statement
Binding
|
Operation
+ |
+ Api
;
/* [3] load a web IDL file */
@@ -162,12 +168,25 @@ Operation
TOK_OPERATION TOK_IDENTIFIER CBlock
{
$$ = genbind_new_node(GENBIND_NODE_TYPE_OPERATION,
- NULL,
- genbind_new_node(GENBIND_NODE_TYPE_IDENT,
- genbind_new_node(GENBIND_NODE_TYPE_CBLOCK,
- NULL,
- $3),
- $2));
+ NULL,
+ genbind_new_node(GENBIND_NODE_TYPE_IDENT,
+ genbind_new_node(GENBIND_NODE_TYPE_CBLOCK,
+ NULL,
+ $3),
+ $2));
+ }
+
+Api
+ :
+ TOK_API TOK_IDENTIFIER CBlock
+ {
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_API,
+ NULL,
+ genbind_new_node(GENBIND_NODE_TYPE_IDENT,
+ genbind_new_node(GENBIND_NODE_TYPE_CBLOCK,
+ NULL,
+ $3),
+ $2));
}
Binding
@@ -196,6 +215,8 @@ BindingArg
|
Private
|
+ Internal
+ |
Interface
;
@@ -217,6 +238,16 @@ Private
}
;
+Internal
+ :
+ TOK_INTERNAL TOK_STRING_LITERAL TOK_IDENTIFIER ';'
+ {
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_INTERNAL, NULL,
+ genbind_new_node(GENBIND_NODE_TYPE_IDENT,
+ genbind_new_node(GENBIND_NODE_TYPE_STRING, NULL, $2), $3));
+ }
+ ;
+
Interface
:
TOK_INTERFACE TOK_IDENTIFIER ';'