HANDLES from `fn` to the Go type `type` resolved as Go resolves it: the * package the file imports as `qual`, or (unqualified) the file's own -- one * directory, looked up in the type index. Only an import no module of the * repository has falls back to the same-named types whose directory ends * the import path. */
| 508 | * repository has falls back to the same-named types whose directory ends |
| 509 | * the import path. */ |
| 510 | static int op_handle(cbm_gbuf_t *gb, const op_index_t *ix, const cbm_gbuf_node_t *fn, |
| 511 | const char *file, const char *text, const char *qual, const char *type, |
| 512 | const char *role) { |
| 513 | char import[CBM_SZ_1K] = ""; |
| 514 | char pkg_dir[CBM_SZ_1K] = ""; |
| 515 | bool in_repo = false; |
| 516 | if (qual[0]) { |
| 517 | op_import_path(text, qual, import, sizeof(import)); |
| 518 | if (!import[0]) { |
| 519 | return 0; |
| 520 | } |
| 521 | in_repo = op_import_dir(ix->mods, import, pkg_dir, sizeof(pkg_dir)); |
| 522 | } else { |
| 523 | op_dirname(file, pkg_dir, sizeof(pkg_dir)); |
| 524 | } |
| 525 | char props[CBM_SZ_128]; |
| 526 | snprintf(props, sizeof(props), "{\"via\":\"controller\",\"role\":\"%s\"}", role); |
| 527 | int linked = 0; |
| 528 | if (!qual[0] || in_repo) { |
| 529 | char key[PAIR_LEN * CBM_SZ_1K]; |
| 530 | op_key(key, sizeof(key), pkg_dir, type); |
| 531 | const op_nodes_t *v = cbm_ht_get(ix->dir_types, key); |
| 532 | atomic_fetch_add_explicit(&g_op_candidates, (uint64_t)(v ? v->count : 0), |
| 533 | memory_order_relaxed); |
| 534 | for (int i = 0; v && i < v->count; i++) { |
| 535 | cbm_gbuf_insert_edge(gb, fn->id, v->items[i]->id, "HANDLES", props); |
| 536 | linked++; |
| 537 | } |
| 538 | return linked; |
| 539 | } |
| 540 | const cbm_gbuf_node_t **types = NULL; |
| 541 | int tn = 0; |
| 542 | if (cbm_gbuf_find_by_name(gb, type, &types, &tn) != 0) { |
| 543 | return 0; |
| 544 | } |
| 545 | atomic_fetch_add_explicit(&g_op_candidates, (uint64_t)(tn), memory_order_relaxed); |
| 546 | for (int i = 0; i < tn; i++) { |
| 547 | const cbm_gbuf_node_t *t = types[i]; |
| 548 | if (!t->label || !t->file_path || |
| 549 | (strcmp(t->label, "Struct") != 0 && strcmp(t->label, "Class") != 0 && |
| 550 | strcmp(t->label, "Type") != 0)) { |
| 551 | continue; |
| 552 | } |
| 553 | char dir[CBM_SZ_1K]; |
| 554 | op_dirname(t->file_path, dir, sizeof(dir)); |
| 555 | if (op_dir_is_import(dir, import)) { |
| 556 | cbm_gbuf_insert_edge(gb, fn->id, t->id, "HANDLES", props); |
| 557 | linked++; |
| 558 | } |
| 559 | } |
| 560 | return linked; |
| 561 | } |
| 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, |
no test coverage detected