From 8bc392a91daf4cc1a27a8e6777af1a29ed24e3c4 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 22 Jul 2015 13:13:41 +0100 Subject: chnage binding AST to put methds inside class nodes --- src/nsgenbind-parser.y | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src/nsgenbind-parser.y') 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 */ + } } -- cgit v1.2.3