One clause of a use declaration; `prefix` is a group's common prefix. */
| 506 | |
| 507 | /* One clause of a use declaration; `prefix` is a group's common prefix. */ |
| 508 | static void php_use_clause(php_walk_t *w, TSNode clause, char kind, const char *prefix, |
| 509 | size_t prefix_len) { |
| 510 | TSNode alias = ts_node_child_by_field_name(clause, TS_FIELD("alias")); |
| 511 | TSNode name = ts_node_named_child(clause, 0); |
| 512 | if (!php_kind(name, "name") && !php_kind(name, "qualified_name")) { |
| 513 | return; |
| 514 | } |
| 515 | size_t nl = 0; |
| 516 | const char *nt = php_name_text(w, name, &nl); |
| 517 | const char *full = nt; |
| 518 | size_t fl = nl; |
| 519 | if (prefix_len) { |
| 520 | char *joined = |
| 521 | cbm_arena_sprintf(w->sb->a, "%.*s\\%.*s", (int)prefix_len, prefix, (int)nl, nt); |
| 522 | if (!joined) { |
| 523 | w->sb->oom = true; |
| 524 | return; |
| 525 | } |
| 526 | full = joined; |
| 527 | fl = strlen(joined); |
| 528 | } |
| 529 | const char *al = NULL; |
| 530 | size_t all = 0; |
| 531 | if (!ts_node_is_null(alias)) { |
| 532 | al = php_name_text(w, alias, &all); |
| 533 | } else { |
| 534 | const char *bs = full + fl; |
| 535 | while (bs > full && bs[-SKIP_ONE] != '\\') { |
| 536 | bs--; |
| 537 | } |
| 538 | al = bs; |
| 539 | all = (size_t)(full + fl - bs); |
| 540 | } |
| 541 | php_add_use(w, php_use_kind(clause, kind), al, all, full, fl); |
| 542 | } |
| 543 | |
| 544 | static void php_use_decl(php_walk_t *w, TSNode decl) { |
| 545 | char kind = php_use_kind(decl, 'c'); |
no test coverage detected