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

Function gc_eval

src/pipeline/pass_operator.c:1516–1619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1514}
1515
1516static void gc_eval(const gc_scope_t *sc, const char *s, size_t n, int depth, gc_val_t *out) {
1517 *out = (gc_val_t){.known = false};
1518 gc_trim(&s, &n);
1519 if (n == 0 || depth > GC_EVAL_DEPTH) {
1520 return;
1521 }
1522 /* a + b */
1523 int pd = 0;
1524 for (size_t i = 0; i < n; i++) {
1525 const char *q = gc_skip(s + i);
1526 if (q != s + i) {
1527 i = (size_t)(q - s) - SKIP_ONE;
1528 continue;
1529 }
1530 pd += strchr("([{", s[i]) != NULL;
1531 pd -= strchr(")]}", s[i]) != NULL;
1532 if (s[i] == '+' && pd == 0) {
1533 gc_val_t a;
1534 gc_val_t b;
1535 gc_eval(sc, s, i, depth + SKIP_ONE, &a);
1536 gc_eval(sc, s + i + SKIP_ONE, n - i - SKIP_ONE, depth + SKIP_ONE, &b);
1537 *out = a;
1538 if (!b.known || b.open_root) {
1539 out->known = false;
1540 } else if (out->known) {
1541 gc_join(out, &b, false);
1542 }
1543 return;
1544 }
1545 }
1546 if ((s[0] == '"' || s[0] == '`') && gc_skip(s) == s + n) {
1547 size_t w = 0;
1548 for (size_t i = SKIP_ONE; i + SKIP_ONE < n && w + SKIP_ONE < sizeof(out->s); i++) {
1549 if (s[0] == '"' && s[i] == '\\' && i + PAIR_LEN < n) {
1550 i++;
1551 }
1552 out->s[w++] = s[i];
1553 }
1554 out->s[w] = '\0';
1555 out->known = true;
1556 return;
1557 }
1558 bool fp = n > OP_SLEN("filepath.Join(") &&
1559 strncmp(s, "filepath.Join(", OP_SLEN("filepath.Join(")) == 0;
1560 bool pp = n > OP_SLEN("path.Join(") && strncmp(s, "path.Join(", OP_SLEN("path.Join(")) == 0;
1561 if ((fp || pp) && s[n - SKIP_ONE] == ')') {
1562 const char *open = s + (fp ? OP_SLEN("filepath.Join") : OP_SLEN("path.Join"));
1563 const char *starts[GC_ARGS_MAX];
1564 size_t lens[GC_ARGS_MAX];
1565 const char *end = NULL;
1566 int na = gc_args(open, starts, lens, GC_ARGS_MAX, &end);
1567 if (end != s + n - SKIP_ONE || na == 0 || na == GC_ARGS_MAX) {
1568 return;
1569 }
1570 *out = (gc_val_t){.known = true};
1571 for (int i = 0; i < na && out->known; i++) {
1572 gc_val_t part;
1573 gc_eval(sc, starts[i], lens[i], depth + SKIP_ONE, &part);

Callers 2

gc_const_valueFunction · 0.85
gc_link_callFunction · 0.85

Calls 9

gc_trimFunction · 0.85
gc_skipFunction · 0.85
gc_joinFunction · 0.85
gc_argsFunction · 0.85
gc_is_identFunction · 0.85
gc_localFunction · 0.85
gc_is_paramFunction · 0.85
gc_const_valueFunction · 0.85
gc_qual_dirFunction · 0.85

Tested by

no test coverage detected