* find the "key" variable of an expression. * return NULL if expression is a function call, constant, or a binary * operation involves at least two variables */
| 99 | * operation involves at least two variables |
| 100 | */ |
| 101 | static const Variable* find_expr_key_var(const Expression* e) |
| 102 | { |
| 103 | if (e->term_type == eVariable) { |
| 104 | return ((const ExpressionVariable*)e)->get_var(); |
| 105 | } |
| 106 | else if (e->term_type == eFunction) { |
| 107 | const ExpressionFuncall* ef = dynamic_cast<const ExpressionFuncall*>(e); |
| 108 | assert(ef); |
| 109 | const FunctionInvocation& fi = *(ef->get_invoke()); |
| 110 | if (fi.invoke_type == eBinaryPrim || fi.invoke_type == eUnaryPrim) { |
| 111 | if (fi.param_value.size()==1) { |
| 112 | return find_expr_key_var(fi.param_value[0]); |
| 113 | } |
| 114 | assert(fi.param_value.size() == 2); |
| 115 | const Variable* v0 = find_expr_key_var(fi.param_value[0]); |
| 116 | const Variable* v1 = find_expr_key_var(fi.param_value[1]); |
| 117 | if (v0 == NULL && v1 != NULL) return v1; |
| 118 | if (v0 != NULL && v1 == NULL) return v0; |
| 119 | } |
| 120 | } |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | //======================================================================================= |
| 125 | ArrayVariable * |
no test coverage detected