diff options
-rw-r--r-- | src/analysis/statement.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/analysis/statement.cpp b/src/analysis/statement.cpp index 50c870a..a226483 100644 --- a/src/analysis/statement.cpp +++ b/src/analysis/statement.cpp @@ -28,6 +28,7 @@ #include "nodes/expr/eq_expr.h" #include "nodes/expr/indirect_ref.h" #include "nodes/expr/modify_expr.h" +#include "nodes/expr/ne_expr.h" #include "nodes/expr/pointerplus_expr.h" #include "nodes/stmt/if_stmt.h" @@ -46,7 +47,7 @@ WalkItem analyseIfStmt(IfStmtNode *node, WalkItem wi) return wi; if (node->condition->nodeType == EQ_EXPR) - { + { // if (... == ..) EqExprNode *eq = static_cast<EqExprNode*>(node->condition); // need atleast two operands for EQ_EXPR node if (eq->args.size() < 2) @@ -70,8 +71,36 @@ WalkItem analyseIfStmt(IfStmtNode *node, WalkItem wi) walkTree(node->elseNode, wi); wi.stopWalking = true; - // need aslo on parent remove variable too - // probably wi should have pointer to parent + // need check what return present + return wi; + } + } + else if (node->condition->nodeType == NE_EXPR) + { // if (... != ..) + NeExprNode *eq = static_cast<NeExprNode*>(node->condition); + // need atleast two operands for EQ_EXPR node + if (eq->args.size() < 2) + return wi; + + // PARM_DECL? + Node *node1 = eq->args[0]; + // INTEGER_CST? + Node *node2 = eq->args[1]; + // if (var != const) + if (node1->nodeType == PARM_DECL && + node2->nodeType == INTEGER_CST && + wi.checkNullVars.find(node1->label) != wi.checkNullVars.end() && + node2->label == "0") + { + // found check for parameter and 0. + // walking to then branch + WalkItem wi2 = wi; + wi2.checkNullVars.erase(node1->label); + // From then branch remove variable what we just found. + walkTree(node->thenNode, wi2); + // walking else node with all variables + walkTree(node->elseNode, wi); + wi.stopWalking = true; return wi; } } |