| 410 | /* ── Call depth via BFS ───────────────────────────────────────── */ |
| 411 | |
| 412 | static void compute_call_depth(int n, const int *es, const int *ed, int ne, const char **labels, |
| 413 | int *depth) { |
| 414 | for (int i = 0; i < n; i++) |
| 415 | depth[i] = -1; |
| 416 | int *q = malloc((size_t)n * sizeof(int)); |
| 417 | int head = 0, tail = 0; |
| 418 | if (!q) |
| 419 | return; |
| 420 | |
| 421 | /* Entry points at depth 0 */ |
| 422 | for (int i = 0; i < n; i++) { |
| 423 | if (labels[i] && (strcmp(labels[i], "Route") == 0 || strcmp(labels[i], "File") == 0 || |
| 424 | strcmp(labels[i], "Module") == 0 || strcmp(labels[i], "Package") == 0)) { |
| 425 | depth[i] = 0; |
| 426 | q[tail++] = i; |
| 427 | } |
| 428 | } |
| 429 | if (tail == 0) { |
| 430 | int *in_d = calloc((size_t)n, sizeof(int)); |
| 431 | if (in_d) { |
| 432 | for (int e = 0; e < ne; e++) { |
| 433 | int t = ed[e]; |
| 434 | if (t >= 0 && t < n) |
| 435 | in_d[t]++; |
| 436 | } |
| 437 | for (int i = 0; i < n; i++) |
| 438 | if (in_d[i] == 0) { |
| 439 | depth[i] = 0; |
| 440 | q[tail++] = i; |
| 441 | } |
| 442 | free(in_d); |
| 443 | } |
| 444 | } |
| 445 | while (head < tail) { |
| 446 | int c = q[head++], cd = depth[c]; |
| 447 | for (int e = 0; e < ne; e++) |
| 448 | if (es[e] == c) { |
| 449 | int t = ed[e]; |
| 450 | if (t >= 0 && t < n && depth[t] == -1) { |
| 451 | depth[t] = cd + SKIP_ONE; |
| 452 | q[tail++] = t; |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | for (int i = 0; i < n; i++) |
| 457 | if (depth[i] == -1) |
| 458 | depth[i] = 0; |
| 459 | free(q); |
| 460 | } |
| 461 | |
| 462 | /* ── Helpers ──────────────────────────────────────────────────── */ |
| 463 |
no outgoing calls
no test coverage detected