diff options
author | Vincent Sanders <vincent.sanders@collabora.co.uk> | 2013-01-28 16:27:37 +0000 |
---|---|---|
committer | Vincent Sanders <vincent.sanders@collabora.co.uk> | 2013-01-28 16:27:37 +0000 |
commit | 6f13eb3a9984d00c2b803b9b435a911c0081d84f (patch) | |
tree | 7413f0a8ced8c8da9b8c1397190009c1ffd08765 /src | |
parent | 515dc7e649e1276c131b9ef4e0e1c7ff4e19a69f (diff) | |
download | nsgenbind-6f13eb3a9984d00c2b803b9b435a911c0081d84f.tar.gz nsgenbind-6f13eb3a9984d00c2b803b9b435a911c0081d84f.tar.bz2 |
annotate the webIDL AST with extended attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/webidl-ast.c | 30 | ||||
-rw-r--r-- | src/webidl-ast.h | 2 | ||||
-rw-r--r-- | src/webidl-parser.y | 199 |
3 files changed, 217 insertions, 14 deletions
diff --git a/src/webidl-ast.c b/src/webidl-ast.c index 7957f02..d75a186 100644 --- a/src/webidl-ast.c +++ b/src/webidl-ast.c @@ -78,15 +78,33 @@ webidl_node_append(struct webidl_node *list, struct webidl_node *node) struct webidl_node * webidl_node_add(struct webidl_node *node, struct webidl_node *list) { - struct webidl_node *node_list; + if (node == NULL) { + return list; + } - node_list = webidl_node_getnode(node); - if (node_list == NULL) { + /* this does not use webidl_node_getnode() as it cannot + * determine between an empty node and a node which is not a + * list type + */ + switch (node->type) { + case WEBIDL_NODE_TYPE_ROOT: + case WEBIDL_NODE_TYPE_INTERFACE: + case WEBIDL_NODE_TYPE_LIST: + case WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE: + case WEBIDL_NODE_TYPE_ATTRIBUTE: + case WEBIDL_NODE_TYPE_OPERATION: + case WEBIDL_NODE_TYPE_OPTIONAL_ARGUMENT: + case WEBIDL_NODE_TYPE_ARGUMENT: + case WEBIDL_NODE_TYPE_TYPE: + case WEBIDL_NODE_TYPE_CONST: + break; + + default: /* not a node type node */ return list; } - node->r.node = webidl_node_prepend(node_list, list); + node->r.node = webidl_node_prepend(node->r.node, list); return node; } @@ -260,6 +278,7 @@ struct webidl_node *webidl_node_getnode(struct webidl_node *node) case WEBIDL_NODE_TYPE_ROOT: case WEBIDL_NODE_TYPE_INTERFACE: case WEBIDL_NODE_TYPE_LIST: + case WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE: case WEBIDL_NODE_TYPE_ATTRIBUTE: case WEBIDL_NODE_TYPE_OPERATION: case WEBIDL_NODE_TYPE_OPTIONAL_ARGUMENT: @@ -332,6 +351,9 @@ static const char *webidl_node_type_to_str(enum webidl_node_type type) case WEBIDL_NODE_TYPE_LITERAL_INT: return "Literal (int)"; + case WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE: + return "Extended Attribute"; + default: return "Unknown"; } diff --git a/src/webidl-ast.h b/src/webidl-ast.h index aa791ca..70518fd 100644 --- a/src/webidl-ast.h +++ b/src/webidl-ast.h @@ -40,6 +40,8 @@ enum webidl_node_type { WEBIDL_NODE_TYPE_LITERAL_BOOL, WEBIDL_NODE_TYPE_LITERAL_FLOAT, + WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE, + }; enum webidl_type { diff --git a/src/webidl-parser.y b/src/webidl-parser.y index bf79e8f..8e0db72 100644 --- a/src/webidl-parser.y +++ b/src/webidl-parser.y @@ -174,6 +174,14 @@ webidl_error(YYLTYPE *locp, struct webidl_node **winbind_ast, const char *str) %type <isit> OptionalLong %type <isit> Inherit +%type <node> ExtendedAttributeList +%type <node> ExtendedAttributes +%type <node> ExtendedAttributeRest +%type <node> ExtendedAttributeInner +%type <node> ExtendedAttribute +%type <text> Other +%type <text> OtherOrComma + %% /* [1] default rule to add built AST to passed in one, altered from @@ -187,7 +195,8 @@ Definitions: | Definitions ExtendedAttributeList Definition { - $$ = *webidl_ast = webidl_node_prepend(*webidl_ast, $3); + webidl_node_add($3, $2); + $$ = *webidl_ast = webidl_node_prepend(*webidl_ast, $3); } | error @@ -334,25 +343,34 @@ InterfaceMembers: struct webidl_node *ident_node; struct webidl_node *list_node; - ident_node = webidl_node_find(webidl_node_getnode($3), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_IDENT); + ident_node = webidl_node_find_type(webidl_node_getnode($3), + NULL, + WEBIDL_NODE_TYPE_IDENT); - list_node = webidl_node_find(webidl_node_getnode($3), - NULL, - webidl_cmp_node_type, - (void *)WEBIDL_NODE_TYPE_LIST); + list_node = webidl_node_find_type(webidl_node_getnode($3), + NULL, + WEBIDL_NODE_TYPE_LIST); if (ident_node == NULL) { /* something with no ident - possibly constructors? */ /* @todo understand this abtter */ $$ = webidl_node_prepend($1, $3); + } else if (list_node == NULL) { - /* something with no argument list - cannot be polymorphic */ + /* member with no argument list, usually an attribute, cannot + * be polymorphic + */ + + /* add extended attributes to parameter list */ + webidl_node_add($3, $2); + $$ = webidl_node_prepend($1, $3); + } else { + /* add extended attributes to parameter list */ + webidl_node_add(list_node, $2); + /* has an arguemnt list so can be polymorphic */ member_node = webidl_node_find_type_ident($1, webidl_node_gettype($3), @@ -829,121 +847,276 @@ ExceptionField: /* [49] extended attribute list inside square brackets */ ExtendedAttributeList: /* empty */ + { + $$ = NULL; + } | '[' ExtendedAttribute ExtendedAttributes ']' + { + $$ = webidl_node_new(WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE, $3, $2); + } ; /* [50] extended attributes are separated with a comma */ ExtendedAttributes: /* empty */ + { + $$ = NULL; + } | ',' ExtendedAttribute ExtendedAttributes + { + $$ = webidl_node_new(WEBIDL_NODE_TYPE_EXTENDED_ATTRIBUTE, $3, $2); + } ; /* [51] extended attributes are nested with normal, square and curly braces */ ExtendedAttribute: '(' ExtendedAttributeInner ')' ExtendedAttributeRest + { + $$ = webidl_node_prepend($2, $4); + } | '[' ExtendedAttributeInner ']' ExtendedAttributeRest + { + $$ = webidl_node_prepend($2, $4); + } | '{' ExtendedAttributeInner '}' ExtendedAttributeRest + { + $$ = webidl_node_prepend($2, $4); + } | Other ExtendedAttributeRest + { + $$ = webidl_node_new(WEBIDL_NODE_TYPE_IDENT, $2, $1); + } ; /* [52] extended attributes can be space separated too */ ExtendedAttributeRest: /* empty */ + { + $$ = NULL; + } | ExtendedAttribute + { + $$ = $1; + } ; /* [53] extended attributes are nested with normal, square and curly braces */ ExtendedAttributeInner: /* empty */ + { + $$ = NULL; + } | '(' ExtendedAttributeInner ')' ExtendedAttributeInner + { + $$ = webidl_node_prepend($2, $4); + } | '[' ExtendedAttributeInner ']' ExtendedAttributeInner + { + $$ = webidl_node_prepend($2, $4); + } | '{' ExtendedAttributeInner '}' ExtendedAttributeInner + { + $$ = webidl_node_prepend($2, $4); + } | OtherOrComma ExtendedAttributeInner + { + $$ = webidl_node_new(WEBIDL_NODE_TYPE_IDENT, $2, $1); + } ; /* [54] */ Other: TOK_INT_LITERAL + { + /* @todo loosing base info here might break the attribute */ + $$ = calloc(1, 32); + snprintf($$, 32, "%ld", $1); + } | TOK_FLOAT_LITERAL + { + $$ = $1; + } | TOK_IDENTIFIER + { + $$ = $1; + } | TOK_STRING_LITERAL + { + $$ = $1; + } | TOK_OTHER_LITERAL + { + $$ = $1; + } | '-' + { + $$ = strdup("-"); + } | '.' + { + $$ = strdup("."); + } | TOK_ELLIPSIS + { + $$ = strdup("..."); + } | ':' + { + $$ = strdup(":"); + } | ';' + { + $$ = strdup(";"); + } | '<' + { + $$ = strdup("<"); + } | '=' + { + $$ = strdup("="); + } | '>' + { + $$ = strdup(">"); + } | '?' + { + $$ = strdup("?"); + } | TOK_DATE + { + $$ = strdup("Date"); + } | TOK_STRING + { + $$ = strdup("DOMString"); + } | TOK_INFINITY + { + $$ = strdup("Infinity"); + } | TOK_NAN + { + $$ = strdup("NaN"); + } | TOK_ANY + { + $$ = strdup("any"); + } | TOK_BOOLEAN + { + $$ = strdup("boolean"); + } | TOK_BYTE + { + $$ = strdup("byte"); + } | TOK_DOUBLE + { + $$ = strdup("double"); + } | TOK_FALSE + { + $$ = strdup("false"); + } | TOK_FLOAT + { + $$ = strdup("float"); + } | TOK_LONG + { + $$ = strdup("long"); + } | TOK_NULL_LITERAL + { + $$ = strdup("null"); + } | TOK_OBJECT + { + $$ = strdup("object"); + } | TOK_OCTET + { + $$ = strdup("octet"); + } | TOK_OR + { + $$ = strdup("or"); + } | TOK_OPTIONAL + { + $$ = strdup("optional"); + } | TOK_SEQUENCE + { + $$ = strdup("sequence"); + } | TOK_SHORT + { + $$ = strdup("short"); + } | TOK_TRUE + { + $$ = strdup("true"); + } | TOK_UNSIGNED + { + $$ = strdup("unsigned"); + } | TOK_VOID + { + $$ = strdup("void"); + } | ArgumentNameKeyword + { + $$ = $1; + } ; /* [55] */ @@ -1047,8 +1220,14 @@ ArgumentNameKeyword: /* [56] as it says an other element or a comma */ OtherOrComma: Other + { + $$ = $1; + } | ',' + { + $$ = strdup(","); + } ; /* [57] */ |