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

Function dm_shared_rows

tests/test_doc_mentions.c:6684–6718  ·  view source on GitHub ↗

S4: tokens, resolutions and rows of a doc comment shared by the * declarators of one field declaration grow with its references, not with * references x declarators. Doubling both the declarators and the * references doubles the tokens and the rows, no more. */

Source from the content-addressed store, hash-verified

6682 * references x declarators. Doubling both the declarators and the
6683 * references doubles the tokens and the rows, no more. */
6684static int dm_shared_rows(int declarators, int refs, int *tokens) {
6685 size_t cap = (size_t)(declarators + refs) * 40 + 256;
6686 char *src = malloc(cap);
6687 if (!src) {
6688 return -1;
6689 }
6690 size_t w = (size_t)snprintf(src, cap, "namespace N\n{\n public class C\n {\n ///");
6691 for (int i = 0; i < refs; i++) {
6692 w += (size_t)snprintf(src + w, cap - w, " <see cref=\"Nowhere%d\"/>", i);
6693 }
6694 w += (size_t)snprintf(src + w, cap - w, "\n public int v0");
6695 for (int i = 1; i < declarators; i++) {
6696 w += (size_t)snprintf(src + w, cap - w, ", v%d", i);
6697 }
6698 snprintf(src + w, cap - w, ";\n }\n}\n");
6699 CBMFileResult *r = dm_extract(src, CBM_LANG_CSHARP, "Fields.cs");
6700 *tokens = r ? r->doc_links.count : -1;
6701 cbm_free_result(r);
6702 const dm_source_t files[] = {{"Fields.cs", src}};
6703 char tmp[256];
6704 snprintf(tmp, sizeof(tmp), "/tmp/cbm_dm_s4rows_XXXXXX");
6705 int rows = -1;
6706 if (cbm_mkdtemp(tmp)) {
6707 th_write_file(TH_PATH(tmp, files[0].path), files[0].text);
6708 char db[512];
6709 snprintf(db, sizeof(db), "%s/rows.db", tmp);
6710 if (dm_index(tmp, db, NULL) == 0) {
6711 rows = dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved");
6712 }
6713 dm_unlink_db(db);
6714 th_rmtree(tmp);
6715 }
6716 free(src);
6717 return rows;
6718}
6719
6720TEST(doc_mentions_cs_shared_doc_once) {
6721 int tokens_small = 0;

Callers 1

Calls 8

dm_extractFunction · 0.85
cbm_free_resultFunction · 0.85
cbm_mkdtempFunction · 0.85
th_write_fileFunction · 0.85
dm_indexFunction · 0.85
dm_countFunction · 0.85
dm_unlink_dbFunction · 0.85
th_rmtreeFunction · 0.85

Tested by

no test coverage detected