* count the "key" variable of an binary/unary operation. * return 0 for constants, 2 for function calls */
| 65 | * return 0 for constants, 2 for function calls |
| 66 | */ |
| 67 | static int count_expr_key_var(const Expression* e) |
| 68 | { |
| 69 | if (e->term_type == eVariable) { |
| 70 | return 1; |
| 71 | } |
| 72 | else if (e->term_type == eConstant) { |
| 73 | return 0; |
| 74 | } |
| 75 | else if (e->term_type == eFunction) { |
| 76 | const ExpressionFuncall* ef = dynamic_cast<const ExpressionFuncall*>(e); |
| 77 | assert(ef); |
| 78 | const FunctionInvocation* fi = ef->get_invoke(); |
| 79 | // for calls |
| 80 | if (fi->invoke_type == eFuncCall) { |
| 81 | return 2; |
| 82 | } |
| 83 | // for unary operations |
| 84 | if (fi->param_value.size()==1) { |
| 85 | return count_expr_key_var(fi->param_value[0]); |
| 86 | } |
| 87 | // for binary operations |
| 88 | assert(fi->param_value.size() == 2); |
| 89 | return count_expr_key_var(fi->param_value[0]) + count_expr_key_var(fi->param_value[1]); |
| 90 | } |
| 91 | // shouldn't be here |
| 92 | assert(0); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * find the "key" variable of an expression. |
no test coverage detected