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

Function eval_expr

src/cypher/cypher.c:2818–2849  ·  view source on GitHub ↗

Expression tree evaluator. Recurses into NOT and into the left operand of a * binary node; a chain of one operator is linked along the right child (see * expr_chain_link) and is walked here in a loop. */

Source from the content-addressed store, hash-verified

2816 * binary node; a chain of one operator is linked along the right child (see
2817 * expr_chain_link) and is walked here in a loop. */
2818static bool eval_expr(const cbm_expr_t *e, binding_t *b) { // NOLINT(misc-no-recursion)
2819 if (!e) {
2820 return true;
2821 }
2822 if (e->type == EXPR_CONDITION) {
2823 return eval_condition(&e->cond, b);
2824 }
2825 if (e->type == EXPR_NOT) {
2826 return (!eval_expr(e->left, b)) != 0;
2827 }
2828 /* AND / OR / XOR. The nested form `a OP (b OP (c ...))` evaluates a, then
2829 * b, then c, and AND/OR stop at the first operand that decides the result;
2830 * the loop does exactly that, one link per iteration. A right child that
2831 * is not a link of the same operator is the chain's last operand. */
2832 const cbm_expr_type_t type = e->type;
2833 bool acc = eval_expr(e->left, b);
2834 const cbm_expr_t *rest = e->right;
2835 for (;;) {
2836 if ((type == EXPR_AND && !acc) || (type == EXPR_OR && acc)) {
2837 return acc;
2838 }
2839 bool linked = rest && rest->type == type;
2840 bool v = eval_expr(linked ? rest->left : rest, b);
2841 /* AND reaches here only with acc true, OR only with acc false, so the
2842 * combined value is v itself; XOR keeps the running parity. */
2843 acc = (type == EXPR_XOR) ? (acc != v) : v;
2844 if (!linked) {
2845 return acc;
2846 }
2847 rest = rest->right;
2848 }
2849}
2850
2851/* Evaluate WHERE clause — uses expression tree if available, falls back to legacy */
2852static bool eval_where(const cbm_where_clause_t *w, binding_t *b) {

Callers 2

eval_whereFunction · 0.85
eval_case_exprFunction · 0.85

Calls 1

eval_conditionFunction · 0.85

Tested by

no test coverage detected