summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-10 18:39:14 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-10 18:39:14 +0300
commitd83c46b507c0fc75bcf1255036e31d87cd89de7e (patch)
tree06dc95839580900752321b2ca516cae996dc6b06 /src/analysis
parent226880f239ece548b6dd85b629d7b5b92851e08a (diff)
downloadparanucker-d83c46b507c0fc75bcf1255036e31d87cd89de7e.tar.gz
paranucker-d83c46b507c0fc75bcf1255036e31d87cd89de7e.tar.bz2
paranucker-d83c46b507c0fc75bcf1255036e31d87cd89de7e.tar.xz
paranucker-d83c46b507c0fc75bcf1255036e31d87cd89de7e.zip
Add into IF_STMT node analysis check for if(var).
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/statement.cpp35
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;
}
}