Every `&[pkg.]Type{` in the arguments of a controller builder call. */
| 562 | |
| 563 | /* Every `&[pkg.]Type{` in the arguments of a controller builder call. */ |
| 564 | static int op_controller_calls(cbm_gbuf_t *gb, CBMHashTable *by_file, const op_index_t *ix, |
| 565 | const char *file, const char *text) { |
| 566 | /* method name + "(", called on a receiver outside a comment: the previous |
| 567 | * code char is '.', and Kind's receiver is the `source` package. */ |
| 568 | static const struct { |
| 569 | const char *name; |
| 570 | const char *recv; |
| 571 | const char *role; |
| 572 | } calls[] = {{"For(", NULL, "for"}, |
| 573 | {"Owns(", NULL, "owns"}, |
| 574 | {"Watches(", NULL, "watches"}, |
| 575 | {"Kind(", "source", "watches"}}; |
| 576 | int linked = 0; |
| 577 | for (size_t c = 0; c < sizeof(calls) / sizeof(calls[0]); c++) { |
| 578 | for (const char *p = strstr(text, calls[c].name); p; |
| 579 | p = strstr(p + SKIP_ONE, calls[c].name)) { |
| 580 | if (p > text && op_ident_char(p[-SKIP_ONE])) { |
| 581 | continue; /* part of a longer name */ |
| 582 | } |
| 583 | if (op_comment_start(op_line_start(text, p), p) < p) { |
| 584 | continue; |
| 585 | } |
| 586 | const char *dot = op_prev_code(text, p); |
| 587 | if (!dot || *dot != '.') { |
| 588 | continue; |
| 589 | } |
| 590 | if (calls[c].recv) { |
| 591 | size_t rl = strlen(calls[c].recv); |
| 592 | const char *r = dot - rl; |
| 593 | if (r < text || strncmp(r, calls[c].recv, rl) != 0 || |
| 594 | (r > text && op_ident_char(r[-SKIP_ONE]))) { |
| 595 | continue; |
| 596 | } |
| 597 | } |
| 598 | const char *open = p + strlen(calls[c].name) - SKIP_ONE; |
| 599 | const char *end = op_args_end(open); |
| 600 | const cbm_gbuf_node_t *fn = op_enclosing(by_file, file, op_line_of(text, p)); |
| 601 | if (!fn) { |
| 602 | continue; |
| 603 | } |
| 604 | for (const char *a = open; a < end; a++) { |
| 605 | if (*a == '/' && a[SKIP_ONE] == '/') { |
| 606 | const char *nl = strchr(a, '\n'); |
| 607 | a = nl && nl < end ? nl : end; |
| 608 | continue; |
| 609 | } |
| 610 | if (*a != '&') { |
| 611 | continue; |
| 612 | } |
| 613 | const char *q = a + SKIP_ONE; |
| 614 | const char *first = q; |
| 615 | const char *last = q; |
| 616 | while (q < end && (op_ident_char(*q) || *q == '.')) { |
| 617 | if (*q == '.') { |
| 618 | last = q + SKIP_ONE; |
| 619 | } |
| 620 | q++; |
| 621 | } |
no test coverage detected