diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-07-22 13:13:41 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-07-22 13:13:41 +0100 |
commit | 8bc392a91daf4cc1a27a8e6777af1a29ed24e3c4 (patch) | |
tree | 2d6b837bc51caf015a58b785ce276f024f65f3b0 /src/nsgenbind-parser.y | |
parent | 1288d8c535edd2ce29eebdc4acca6b2beab89841 (diff) | |
download | nsgenbind-8bc392a91daf4cc1a27a8e6777af1a29ed24e3c4.tar.gz nsgenbind-8bc392a91daf4cc1a27a8e6777af1a29ed24e3c4.tar.bz2 |
chnage binding AST to put methds inside class nodes
Diffstat (limited to 'src/nsgenbind-parser.y')
-rw-r--r-- | src/nsgenbind-parser.y | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/nsgenbind-parser.y b/src/nsgenbind-parser.y index c8e5154..454fb56 100644 --- a/src/nsgenbind-parser.y +++ b/src/nsgenbind-parser.y @@ -128,7 +128,7 @@ Statements | Statements Statement { - $$ = genbind_node_link($2, $1); + $$ = *genbind_ast = genbind_node_prepend($2, $1); } | error ';' @@ -330,11 +330,52 @@ Method : MethodType MethodDeclarator CBlock { - $$ = genbind_new_node(GENBIND_NODE_TYPE_METHOD, NULL, + struct genbind_node *declarator; + struct genbind_node *method_node; + struct genbind_node *class_node; + char *class_name; + + declarator = $2; + + /* extract the class name from the declarator */ + class_name = genbind_node_gettext( + genbind_node_find_type( + genbind_node_getnode( + genbind_node_find_type( + declarator, + NULL, + GENBIND_NODE_TYPE_CLASS)), + NULL, + GENBIND_NODE_TYPE_IDENT)); + + /* generate method node */ + method_node = genbind_new_node(GENBIND_NODE_TYPE_METHOD, NULL, genbind_new_node(GENBIND_NODE_TYPE_METHOD_TYPE, genbind_new_node(GENBIND_NODE_TYPE_CDATA, - $2, $3), + declarator, $3), (void *)$1)); + + + + class_node = genbind_node_find_type_ident(*genbind_ast, + NULL, + GENBIND_NODE_TYPE_CLASS, + class_name); + if (class_node == NULL) { + /* no existing class so manufacture one and attach method */ + $$ = genbind_new_node(GENBIND_NODE_TYPE_CLASS, NULL, + genbind_new_node(GENBIND_NODE_TYPE_IDENT, + method_node, + class_name)); + + } else { + /* update the existing class */ + + /* link member node into class_node */ + genbind_node_add(class_node, method_node); + + $$ = NULL; /* updating so no need to add a new node */ + } } |