All named children of a node, read with one cursor walk (indexing them is * quadratic). */
| 432 | /* All named children of a node, read with one cursor walk (indexing them is |
| 433 | * quadratic). */ |
| 434 | static TSNode *php_children(php_walk_t *w, TSNode parent, int *count) { |
| 435 | *count = 0; |
| 436 | uint32_t nc = ts_node_named_child_count(parent); |
| 437 | if (nc == 0) { |
| 438 | return NULL; |
| 439 | } |
| 440 | TSNode *kids = (TSNode *)cbm_arena_alloc(w->sb->a, (size_t)nc * sizeof(TSNode)); |
| 441 | if (!kids) { |
| 442 | w->sb->oom = true; |
| 443 | return NULL; |
| 444 | } |
| 445 | TSTreeCursor cur = ts_tree_cursor_new(parent); |
| 446 | for (bool more = ts_tree_cursor_goto_first_child(&cur); more && *count < (int)nc; |
| 447 | more = ts_tree_cursor_goto_next_sibling(&cur)) { |
| 448 | TSNode c = ts_tree_cursor_current_node(&cur); |
| 449 | if (ts_node_is_named(c)) { |
| 450 | kids[(*count)++] = c; |
| 451 | } |
| 452 | } |
| 453 | ts_tree_cursor_delete(&cur); |
| 454 | return kids; |
| 455 | } |
| 456 | |
| 457 | /* `function` or `const` among a node's anonymous children: 'f', 'k', else |
| 458 | * `dflt`. */ |
no test coverage detected