summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2012-11-21 16:18:37 +0000
committerVincent Sanders <vincent.sanders@collabora.co.uk>2012-11-21 16:18:37 +0000
commit2bfd4d2720b55df0141189633ef6fae530663d04 (patch)
treea71fb8a50c0152ad1729523735e290a8d8aba365
parent93c89193c1f2a29b00741d1494f262642108abe2 (diff)
downloadnsgenbind-2bfd4d2720b55df0141189633ef6fae530663d04.tar.gz
nsgenbind-2bfd4d2720b55df0141189633ef6fae530663d04.tar.bz2
name and docuemnt the binding property attribute
-rw-r--r--doc/example.bnd57
-rw-r--r--src/jsapi-libdom-property.c6
-rw-r--r--src/nsgenbind-ast.c6
-rw-r--r--src/nsgenbind-ast.h2
-rw-r--r--src/nsgenbind-lexer.l2
-rw-r--r--src/nsgenbind-parser.y24
-rw-r--r--test/data/bindings/window.bnd10
7 files changed, 66 insertions, 41 deletions
diff --git a/doc/example.bnd b/doc/example.bnd
index a57d970..6bd051c 100644
--- a/doc/example.bnd
+++ b/doc/example.bnd
@@ -27,14 +27,14 @@ hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/";
hdrcomment "Released under the terms of the MIT License,";
hdrcomment " http://www.opensource.org/licenses/mit-license";
-/* the preamble block is copied verbatum into the generated output
+/* the preamble block is copied verbatum into the generated output
*
- * This can be used for includes, comments or whatever else is desired
+ * This can be used for includes, comments or whatever else is desired
*/
preamble %{
#include <dom/dom.h>
-
+
#include "utils/config.h"
#include "utils/log.h"
@@ -46,8 +46,8 @@ preamble %{
/* this block describes the binding to be generated
*
* Depending on the type of binding being generated multiple blocks
- * may be allowed.
- *
+ * may be allowed.
+ *
* Note: the js_libdom (javascript to libdom) binding as currently
* implemented only allows for a single binding per file, this may
* be improved in future.
@@ -71,12 +71,23 @@ binding example {
* - are considered for property getters/setters.
*/
internal "void *" fluff;
-
+
+ /* property handler specifiers:
+ * - (un)shared flag allows control of the properties JSAPI shared state.
+ * The default for all unnamed properties on the interface
+ * is shared without a type handler.
+ * - type flag allows a set of properties whose type matches the
+ * identifier to be handled by the same callback function.
+ */
+ property shared bar; /* the default - a noop */
+ property shared type EventHandler;
+ property unshared foo;
+ property unshared type WindowProxy;
}
-/* operation implementation code.
+/* operation implementation code.
*
- * The body is copied verbatum into operation binding
+ * The body is copied verbatum into operation binding
*
* several values are generated automatically:
*
@@ -94,7 +105,7 @@ binding example {
*
* - Arguments are automatically converted into c variables (named as
* per the WebIDL names.
- *
+ *
* - Return values (excepting void return types where its omitted) are
* always named "retval" and are of the appropriate c type. The
* initial value is set appropriately.
@@ -103,9 +114,9 @@ operation foo %{
retval = JS_NewStringCopyN(cx, "foo", SLEN("foo"));
%}
-/* property getter implementation code.
+/* property getter implementation code.
*
- * The body is copied verbatum into property getter binding
+ * The body is copied verbatum into property getter binding
*
* several values are generated automatically:
*
@@ -132,9 +143,9 @@ getter bar %{
retval = JS_NewStringCopyN(cx, "bar", SLEN("bar"));
%}
-/* property setter implementation code.
+/* property setter implementation code.
*
- * The body is copied verbatum into property getter binding
+ * The body is copied verbatum into property getter binding
*
* several values are generated automatically:
*
@@ -163,7 +174,7 @@ setter baz %{
printf("%s\n", setval);
%}
-/* implementation of the class initilisation
+/* implementation of the class initilisation
*
* This allows the default JS_InitClass to be overriden - currently
* only used for the window (global) object to cause all the other class
@@ -178,7 +189,7 @@ api init %{
/* implementation of the c instance creation
*
* This allows the overriding of the construction of an interface instance.
- *
+ *
* The body is copied verbatum and must return the new object in the
* "newobject" variable.
*
@@ -189,9 +200,9 @@ api init %{
* If there are private or internal values the private struct is
* constructed and instantiated. The struct is available during the
* new function and is automatically attached as the private value to
- * the object.
+ * the object.
*
- * The default implemenattion simply calls JS_NewObject()
+ * The default implemenattion simply calls JS_NewObject()
*
* Note this does *not* rely upon (or even call) the instances
* javascript constructor allowing the c code to create objects that
@@ -203,11 +214,11 @@ api new %{
/* additional code in the instance finalise operation.
*
- * The body is copied verbatim into the output
+ * The body is copied verbatim into the output
*
- * Prototype is
+ * Prototype is
* void jsclass_finalize(JSContext *cx, JSObject *obj)
- *
+ *
* private is available (if appropriate) and freed after the body
*/
api finalise %{
@@ -219,7 +230,7 @@ api finalise %{
* JSResolveOp with JSCLASS_NEW_RESOLVE specified and must provide a
* complete implementation.
*
- * The body is copied verbatim into the output
+ * The body is copied verbatim into the output
*
* Prototype is:
* JSBool jsclass_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp)
@@ -227,7 +238,7 @@ api finalise %{
* By default returns JS_TRUE implying that *objp has been updated
*
* The minimal implementation would be "*objp = NULL;" but is
- * equivalent to simply omitting this directive and using the defaul stub.
+ * equivalent to simply omitting this directive and using the defaul stub.
*/
api resolve %{
%}
@@ -237,4 +248,4 @@ api resolve %{
* The body is discarded.
*/
api global %{
-%} \ No newline at end of file
+%}
diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c
index 5502030..2bfb591 100644
--- a/src/jsapi-libdom-property.c
+++ b/src/jsapi-libdom-property.c
@@ -31,14 +31,14 @@ get_binding_shared_modifier(struct binding *binding, const char *type, const cha
/* look for node matching the ident first */
shared_node = genbind_node_find_type_ident(binding->binding_list,
NULL,
- GENBIND_NODE_TYPE_BINDING_SHARED,
+ GENBIND_NODE_TYPE_BINDING_PROPERTY,
ident);
/* look for a node matching the type */
if (shared_node == NULL) {
shared_node = genbind_node_find_type_ident(binding->binding_list,
NULL,
- GENBIND_NODE_TYPE_BINDING_SHARED,
+ GENBIND_NODE_TYPE_BINDING_PROPERTY,
type);
}
@@ -779,7 +779,7 @@ output_property_body(struct binding *binding)
if (res == 0) {
res = genbind_node_for_each_type(binding->binding_list,
- GENBIND_NODE_TYPE_BINDING_SHARED,
+ GENBIND_NODE_TYPE_BINDING_PROPERTY,
typehandler_property_cb,
binding);
}
diff --git a/src/nsgenbind-ast.c b/src/nsgenbind-ast.c
index fba7dcb..f5cdc78 100644
--- a/src/nsgenbind-ast.c
+++ b/src/nsgenbind-ast.c
@@ -228,7 +228,7 @@ struct genbind_node *genbind_node_getnode(struct genbind_node *node)
case GENBIND_NODE_TYPE_BINDING:
case GENBIND_NODE_TYPE_BINDING_PRIVATE:
case GENBIND_NODE_TYPE_BINDING_INTERNAL:
- case GENBIND_NODE_TYPE_BINDING_SHARED:
+ case GENBIND_NODE_TYPE_BINDING_PROPERTY:
case GENBIND_NODE_TYPE_OPERATION:
case GENBIND_NODE_TYPE_API:
case GENBIND_NODE_TYPE_GETTER:
@@ -294,8 +294,8 @@ static const char *genbind_node_type_to_str(enum genbind_node_type type)
case GENBIND_NODE_TYPE_BINDING_INTERFACE:
return "Interface";
- case GENBIND_NODE_TYPE_BINDING_SHARED:
- return "Shared";
+ case GENBIND_NODE_TYPE_BINDING_PROPERTY:
+ return "Property";
case GENBIND_NODE_TYPE_OPERATION:
return "Operation";
diff --git a/src/nsgenbind-ast.h b/src/nsgenbind-ast.h
index cddf608..6368519 100644
--- a/src/nsgenbind-ast.h
+++ b/src/nsgenbind-ast.h
@@ -24,7 +24,7 @@ enum genbind_node_type {
GENBIND_NODE_TYPE_BINDING_PRIVATE,
GENBIND_NODE_TYPE_BINDING_INTERNAL,
GENBIND_NODE_TYPE_BINDING_INTERFACE,
- GENBIND_NODE_TYPE_BINDING_SHARED,
+ GENBIND_NODE_TYPE_BINDING_PROPERTY,
GENBIND_NODE_TYPE_API,
GENBIND_NODE_TYPE_OPERATION,
GENBIND_NODE_TYPE_GETTER,
diff --git a/src/nsgenbind-lexer.l b/src/nsgenbind-lexer.l
index 313d37b..e1c7740 100644
--- a/src/nsgenbind-lexer.l
+++ b/src/nsgenbind-lexer.l
@@ -100,6 +100,8 @@ unshared return TOK_UNSHARED;
shared return TOK_SHARED;
+property return TOK_PROPERTY;
+
operation return TOK_OPERATION;
api return TOK_API;
diff --git a/src/nsgenbind-parser.y b/src/nsgenbind-parser.y
index b104f2f..984513e 100644
--- a/src/nsgenbind-parser.y
+++ b/src/nsgenbind-parser.y
@@ -36,7 +36,7 @@ char *errtxt;
{
char* text;
struct genbind_node *node;
- int number;
+ long value;
}
%token TOK_IDLFILE
@@ -54,6 +54,7 @@ char *errtxt;
%token TOK_INTERNAL
%token TOK_UNSHARED
%token TOK_SHARED
+%token TOK_PROPERTY
%token <text> TOK_IDENTIFIER
%token <text> TOK_STRING_LITERAL
@@ -61,8 +62,8 @@ char *errtxt;
%type <text> CBlock
-%type <number> Modifiers
-%type <number> Modifier
+%type <value> Modifiers
+%type <value> Modifier
%type <node> Statement
%type <node> Statements
@@ -77,7 +78,7 @@ char *errtxt;
%type <node> Private
%type <node> Internal
%type <node> Interface
-%type <node> Shared
+%type <node> Property
%type <node> Operation
%type <node> Api
%type <node> Getter
@@ -261,7 +262,7 @@ BindingArg
|
Interface
|
- Shared
+ Property
;
Type
@@ -300,11 +301,11 @@ Interface
}
;
-Shared
+Property
:
- TOK_SHARED Modifiers TOK_IDENTIFIER ';'
+ TOK_PROPERTY Modifiers TOK_IDENTIFIER ';'
{
- $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_SHARED,
+ $$ = genbind_new_node(GENBIND_NODE_TYPE_BINDING_PROPERTY,
NULL,
genbind_new_node(GENBIND_NODE_TYPE_MODIFIER,
genbind_new_node(GENBIND_NODE_TYPE_IDENT,
@@ -318,7 +319,7 @@ Modifiers
:
/* empty */
{
- $$ = 0;
+ $$ = GENBIND_TYPE_NONE;
}
|
Modifiers Modifier
@@ -338,6 +339,11 @@ Modifier
{
$$ = GENBIND_TYPE_UNSHARED;
}
+ |
+ TOK_SHARED
+ {
+ $$ = GENBIND_TYPE_NONE;
+ }
;
%%
diff --git a/test/data/bindings/window.bnd b/test/data/bindings/window.bnd
index 7b411b1..50ffe51 100644
--- a/test/data/bindings/window.bnd
+++ b/test/data/bindings/window.bnd
@@ -31,8 +31,10 @@ binding window {
internal "JSObject *" console;
internal "JSObject *" location;
- shared unshared type EventHandler;
- shared unshared foo;
+ property unshared type WindowProxy;
+ property unshared foo;
+ property shared type EventHandler;
+ property shared baz;
}
api mark %{
@@ -199,3 +201,7 @@ getter window %{
getter self %{
jsret = obj;
%}
+
+getter EventHandler %{
+ /* example shared property type handler */
+%}