MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / build_using_index

Function build_using_index

src/pipeline/doc_links_cs.c:2690–2745  ·  view source on GitHub ↗

Build only after these directives have resolved. A static import is * associated with its own entity and its twin, without copying either * entity's declarations into every region that imports it. */

Source from the content-addressed store, hash-verified

2688 * associated with its own entity and its twin, without copying either
2689 * entity's declarations into every region that imports it. */
2690static bool build_using_index(cs_index_t *ix, const cs_using_t *us, int n,
2691 cs_using_index_t *index) {
2692 cs_using_index_t out = {0};
2693 for (int i = 0; i < n; i++) {
2694 cs_index_work(SKIP_ONE);
2695 const cs_using_t *u = &us[i];
2696 if (u->kind == 'a') {
2697 out.naliases++;
2698 } else if (u->kind == 'n' && u->ns >= 0) {
2699 out.nnamespaces++;
2700 } else if (u->kind == 's' && u->ent >= 0) {
2701 size_t extra = ix->ents[u->ent].twin >= 0 ? PAIR_LEN : SKIP_ONE;
2702 if (extra > SIZE_MAX - out.nentities) {
2703 ix->oom = true;
2704 return false;
2705 }
2706 out.nentities += extra;
2707 }
2708 }
2709 out.aliases = (cs_alias_id_t *)import_array(ix, out.naliases, sizeof(*out.aliases));
2710 out.namespaces = (cs_using_id_t *)import_array(ix, out.nnamespaces, sizeof(*out.namespaces));
2711 out.entities = (cs_using_id_t *)import_array(ix, out.nentities, sizeof(*out.entities));
2712 if (ix->oom) {
2713 return false;
2714 }
2715 size_t a = 0;
2716 size_t ns = 0;
2717 size_t e = 0;
2718 for (int i = 0; i < n; i++) {
2719 cs_index_work(SKIP_ONE);
2720 const cs_using_t *u = &us[i];
2721 if (u->kind == 'a') {
2722 out.aliases[a++] = (cs_alias_id_t){.name = u->alias, .id = i};
2723 } else if (u->kind == 'n' && u->ns >= 0) {
2724 out.namespaces[ns++] = (cs_using_id_t){.scope = u->ns, .id = i};
2725 } else if (u->kind == 's' && u->ent >= 0) {
2726 out.entities[e++] = (cs_using_id_t){.scope = u->ent, .id = i};
2727 int twin = ix->ents[u->ent].twin;
2728 if (twin >= 0) {
2729 out.entities[e++] = (cs_using_id_t){.scope = twin, .id = i};
2730 }
2731 }
2732 }
2733 if (a > 1) {
2734 qsort(out.aliases, a, sizeof(*out.aliases), alias_id_cmp);
2735 }
2736 if (ns > 1) {
2737 qsort(out.namespaces, ns, sizeof(*out.namespaces), using_id_cmp);
2738 }
2739 if (e > 1) {
2740 qsort(out.entities, e, sizeof(*out.entities), using_id_cmp);
2741 }
2742 out.ready = true;
2743 *index = out;
2744 return true;
2745}
2746
2747/* ── Choosing the declaration a reference binds ──────────────────── */

Callers 1

resolve_usingsFunction · 0.85

Calls 2

cs_index_workFunction · 0.85
import_arrayFunction · 0.85

Tested by

no test coverage detected