recognize a==0, a!=0, 0==a, 0!=a
| 7 | |
| 8 | // recognize a==0, a!=0, 0==a, 0!=a |
| 9 | bool matchEquNequZero ( ExpressionPtr expr, ExpressionPtr & zeroCond, bool & condIfZero ) { |
| 10 | if ( expr->rtti_isOp2() ) { |
| 11 | auto op2 = static_cast<ExprOp2*>(expr); |
| 12 | if ( op2->op=="==" || op2->op=="!=" ) { |
| 13 | condIfZero = op2->op == "=="; |
| 14 | if ( isZeroConst(op2->left) ) { |
| 15 | zeroCond = op2->right; |
| 16 | return true; |
| 17 | } else if ( isZeroConst(op2->right) ) { |
| 18 | zeroCond = op2->left; |
| 19 | return true; |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | bool isZeroConst ( ExpressionPtr expr ) { |
| 27 | return isFloatConst(expr, 0.0f) || isIntOrUIntConst(expr, 0) || isPtrZero(expr); |