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

Function gc_const_line

src/pipeline/pass_operator.c:1323–1354  ·  view source on GitHub ↗

One `NAME [TYPE] = expr` of a const declaration, line [ls, le). */

Source from the content-addressed store, hash-verified

1321
1322/* One `NAME [TYPE] = expr` of a const declaration, line [ls, le). */
1323static void gc_const_line(CBMHashTable *t, const char *ls, const char *le) {
1324 while (ls < le && (*ls == ' ' || *ls == '\t')) {
1325 ls++;
1326 }
1327 const char *ne = ls;
1328 while (ne < le && op_ident_char(*ne)) {
1329 ne++;
1330 }
1331 const char *eq = memchr(ne, '=', (size_t)(le - ne));
1332 if (ne == ls || !eq || (eq + SKIP_ONE < le && eq[SKIP_ONE] == '=')) {
1333 return;
1334 }
1335 const char *ve = op_comment_start(eq + SKIP_ONE, le);
1336 const char *vs = eq + SKIP_ONE;
1337 size_t vl = (size_t)(ve - vs);
1338 gc_trim(&vs, &vl);
1339 char name[OP_IDENT_MAX];
1340 snprintf(name, sizeof(name), "%.*s", (int)(ne - ls), ls);
1341 if (vl == 0 || cbm_ht_get(t, name)) {
1342 return;
1343 }
1344 char *key = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, name);
1345 char *val = cbm_alloc(CBM_MEM_CLASS_OTHER, vl + SKIP_ONE);
1346 if (!key || !val) {
1347 cbm_free(CBM_MEM_CLASS_OTHER, key);
1348 cbm_free(CBM_MEM_CLASS_OTHER, val);
1349 return;
1350 }
1351 memcpy(val, vs, vl);
1352 val[vl] = '\0';
1353 cbm_ht_set(t, key, val);
1354}
1355
1356static void gc_scan_consts(CBMHashTable *t, const char *text) {
1357 for (const char *p = strstr(text, "const"); p; p = strstr(p + SKIP_ONE, "const")) {

Callers 1

gc_scan_constsFunction · 0.85

Calls 8

op_ident_charFunction · 0.85
op_comment_startFunction · 0.85
gc_trimFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_mem_strdupFunction · 0.85
cbm_allocFunction · 0.85
cbm_freeFunction · 0.85
cbm_ht_setFunction · 0.85

Tested by

no test coverage detected