Same walk as eval_expr: recurses into NOT and into each operand, and follows * a chain of one operator (linked along the right child, see expr_chain_link) * in a loop, so a chain's length never becomes stack depth. This runs on every * seed row of execute_single, so it sees every WHERE chain the parser accepts. * The operands are read in the order of the nested form `a OP (b OP (c ...))`, * w
| 2934 | * with its short-circuits: AND stops at the first definite false, OR at the |
| 2935 | * first definite true, and XOR reads every operand. */ |
| 2936 | static cyp_partial_t eval_expr_partial(const cbm_expr_t *e, // NOLINT(misc-no-recursion) |
| 2937 | binding_t *b) { |
| 2938 | if (!e) { |
| 2939 | return CYP_PARTIAL_TRUE; |
| 2940 | } |
| 2941 | if (e->type == EXPR_CONDITION) { |
| 2942 | return eval_condition_partial(&e->cond, b); |
| 2943 | } |
| 2944 | if (e->type == EXPR_NOT) { |
| 2945 | cyp_partial_t child = eval_expr_partial(e->left, b); |
| 2946 | if (child == CYP_PARTIAL_UNKNOWN) { |
| 2947 | return CYP_PARTIAL_UNKNOWN; |
| 2948 | } |
| 2949 | return child == CYP_PARTIAL_TRUE ? CYP_PARTIAL_FALSE : CYP_PARTIAL_TRUE; |
| 2950 | } |
| 2951 | /* AND / OR / XOR. A right child that is not a link of the same operator is |
| 2952 | * the chain's last operand; one that is a parenthesised group of the same |
| 2953 | * operator is read as more links, which the operator's associativity |
| 2954 | * (three-valued as well) makes the same value. */ |
| 2955 | const cbm_expr_type_t type = e->type; |
| 2956 | cyp_partial_t acc = eval_expr_partial(e->left, b); |
| 2957 | const cbm_expr_t *rest = e->right; |
| 2958 | for (;;) { |
| 2959 | if ((type == EXPR_AND && acc == CYP_PARTIAL_FALSE) || |
| 2960 | (type == EXPR_OR && acc == CYP_PARTIAL_TRUE)) { |
| 2961 | return acc; |
| 2962 | } |
| 2963 | bool linked = rest && rest->type == type; |
| 2964 | cyp_partial_t v = eval_expr_partial(linked ? rest->left : rest, b); |
| 2965 | acc = partial_combine(type, acc, v); |
| 2966 | if (!linked) { |
| 2967 | return acc; |
| 2968 | } |
| 2969 | rest = rest->right; |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | static cyp_partial_t eval_where_partial(const cbm_where_clause_t *w, binding_t *b) { |
| 2974 | if (!w) { |
no test coverage detected