6 void node_walk(struct node
*node
,
7 int (*callback
) (struct node
*, void *),
11 if (callback(node
, data
))
12 for (i
= 0; i
< node
->count
; i
++)
13 node_walk(node
->children
[i
], callback
, data
);
21 static int search_node(struct node
*node
, void *data
)
23 struct node_search
*search
= data
;
24 long offset
= search
->offset
;
25 if (node
->start
<= offset
&& offset
< node
->end
) {
26 search
->result
= node
;
32 struct node
*node_find(struct node
*node
, long offset
)
34 struct node_search search
;
35 search
.offset
= offset
;
37 node_walk(node
, search_node
, &search
);
41 int node_cmp(struct node
*n1
, struct node
*n2
)
44 if (n1
->type
!= n2
->type
|| n1
->count
!= n2
->count
)
46 /* node->data should be compared based on node->type */
47 if (n1
->type
== AST_IDENTIFIER
|| n1
->type
== AST_TYPENAME
)
48 if (strcmp(n1
->data
, n2
->data
))
50 for (i
= 0; i
< n1
->count
; i
++)
51 if (node_cmp(n1
->children
[i
], n2
->children
[i
]))
56 struct node
*declarator_name(struct node
*node
)
58 struct node
*cur
= node
;
60 if (cur
->type
== AST_DECL
)
61 cur
= cur
->children
[cur
->count
- 1];
63 cur
= cur
->children
[0];
65 if (cur
->type
== AST_IDENTIFIER
)