summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-04 00:44:42 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-04 00:44:42 +0300
commit6e0b30c7d2febba72754838b4811dd31a90284f9 (patch)
treeaa31d85836b12745c8a2b9e54c736641cfd594f4 /src
parent4c0f6bc74b1cf798d28214544fb4b6517f741b8f (diff)
downloadparanucker-6e0b30c7d2febba72754838b4811dd31a90284f9.tar.gz
paranucker-6e0b30c7d2febba72754838b4811dd31a90284f9.tar.bz2
paranucker-6e0b30c7d2febba72754838b4811dd31a90284f9.tar.xz
paranucker-6e0b30c7d2febba72754838b4811dd31a90284f9.zip
Add numeric value in node calculation.
Use it in NE_EXPR and EQ_EXPR.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.files2
-rw-r--r--src/analysis/analysis.cpp4
-rw-r--r--src/analysis/cst.cpp49
-rw-r--r--src/analysis/cst.h33
-rw-r--r--src/analysis/expression.cpp25
-rw-r--r--src/analysis/walkitem.h6
6 files changed, 111 insertions, 8 deletions
diff --git a/src/Makefile.files b/src/Makefile.files
index 232b236..c6e126b 100644
--- a/src/Makefile.files
+++ b/src/Makefile.files
@@ -4,6 +4,8 @@ SRC = analysis/analysis.cpp \
analysis/checks.h \
analysis/collections.cpp \
analysis/collections.h \
+ analysis/cst.cpp \
+ analysis/cst.h \
analysis/declaration.cpp \
analysis/declaration.h \
analysis/expression.cpp \
diff --git a/src/analysis/analysis.cpp b/src/analysis/analysis.cpp
index 50f9211..6ccd658 100644
--- a/src/analysis/analysis.cpp
+++ b/src/analysis/analysis.cpp
@@ -23,6 +23,7 @@
#include "logger.h"
#include "analysis/collections.h"
+#include "analysis/cst.h"
#include "analysis/declaration.h"
#include "analysis/expression.h"
#include "analysis/function.h"
@@ -298,6 +299,9 @@ void analyseNode(Node *node, const WalkItem &wi, WalkItem &wo)
case COMPONENT_REF:
analyseComponentRef(static_cast<ComponentRefNode*>(node), wi2, wo);
break;
+ case INTEGER_CST:
+ analyseIntegerCst(static_cast<IntegerCstNode*>(node), wi2, wo);
+ break;
default:
break;
}
diff --git a/src/analysis/cst.cpp b/src/analysis/cst.cpp
new file mode 100644
index 0000000..c3cfda9
--- /dev/null
+++ b/src/analysis/cst.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015 Andrei Karas
+ *
+ * This file is part of Paranoid null checker.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "analysis/expression.h"
+
+#include "command.h"
+#include "logger.h"
+
+#include "analysis/analysis.h"
+#include "analysis/reports.h"
+#include "analysis/walkitem.h"
+
+#include "nodes/cst/integer_cst.h"
+
+#include <set>
+
+#include "localconsts.h"
+
+namespace Analysis
+{
+
+void analyseIntegerCst(IntegerCstNode *node,
+ const WalkItem &wi,
+ WalkItem &wo A_UNUSED)
+{
+ if (checkCommand(FindArgs))
+ return;
+
+ wo.isNum = true;
+ wo.num = atoi(node->label.c_str());
+}
+
+}
diff --git a/src/analysis/cst.h b/src/analysis/cst.h
new file mode 100644
index 0000000..064c9b4
--- /dev/null
+++ b/src/analysis/cst.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2015 Andrei Karas
+ *
+ * This file is part of Paranoid null checker.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ANALYSIS_CST_H
+#define ANALYSIS_CST_H
+
+#include "includes.h"
+
+struct IntegerCstNode;
+struct WalkItem;
+
+namespace Analysis
+{
+ void analyseIntegerCst(IntegerCstNode *node, const WalkItem &wi, WalkItem &wo);
+}
+
+#endif // ANALYSIS_CST_H
diff --git a/src/analysis/expression.cpp b/src/analysis/expression.cpp
index b2c250a..3add85a 100644
--- a/src/analysis/expression.cpp
+++ b/src/analysis/expression.cpp
@@ -408,17 +408,20 @@ void analyseNeExpr(NeExprNode *node, const WalkItem &wi, WalkItem &wo)
// PARM_DECL or VAR_DECL?
Node *node1 = skipNop(node->args[0]);
- // INTEGER_CST?
+ // integer 0?
Node *node2 = skipNop(node->args[1]);
reportParmDeclLeftNullPointer(node, node1, wi);
reportParmDeclLeftNullPointer(node, node2, wi);
+ WalkItem wo2 = wo;
+ walkTree(node2, wi, wo2);
+
std::string var = getVariableName(node1);
// if (var != 0)
if (!var.empty() &&
- node2 == INTEGER_CST &&
- node2->label == "0")
+ wo2.isNum &&
+ wo2.num == 0)
{
if (isIn(var, wi.needCheckNullVars) ||
isNotIn(var, wi.knownVars))
@@ -531,17 +534,20 @@ void analyseEqExpr(EqExprNode *node, const WalkItem &wi, WalkItem &wo)
// PARM_DECL or VAR_DECL ?
Node *node1 = skipNop(node->args[0]);
- // INTEGER_CST?
+ // integer 0?
Node *node2 = skipNop(node->args[1]);
reportParmDeclLeftNullPointer(node, node1, wi);
reportParmDeclLeftNullPointer(node, node2, wi);
+ WalkItem wo2 = wo;
+ walkTree(node2, wi, wo2);
+
std::string var = getVariableName(node1);
// if (var == 0)
if (!var.empty() &&
- node2 == INTEGER_CST &&
- node2->label == "0")
+ wo2.isNum &&
+ wo2.num == 0)
{
if (isIn(var, wi.needCheckNullVars) ||
isNotIn(var, wi.knownVars))
@@ -951,9 +957,12 @@ bool handleSetVarToFunctionBack(const std::string &var,
Node *node2,
WalkItem &wo)
{
- if (node2 == INTEGER_CST)
+ WalkItem wo2 = wo;
+ walkTree(node2, wo, wo2);
+
+ if (wo2.isNum)
{
- if (node2->label == "0")
+ if (wo2.num == 0)
addNullVar(wo, var);
else
addNonNullVar(wo, var);
diff --git a/src/analysis/walkitem.h b/src/analysis/walkitem.h
index aa5d579..c02b52e 100644
--- a/src/analysis/walkitem.h
+++ b/src/analysis/walkitem.h
@@ -44,6 +44,8 @@ struct WalkItem
checkedElseNonNullVars(),
linkedVars(),
linkedReverseVars(),
+ num(-1),
+ isNum(false),
stopWalking(false),
isReturned(false),
isContinued(false),
@@ -66,6 +68,8 @@ struct WalkItem
checkedElseNonNullVars(item.checkedElseNonNullVars),
linkedVars(item.linkedVars),
linkedReverseVars(item.linkedReverseVars),
+ num(item.num),
+ isNum(item.isNum),
stopWalking(item.stopWalking),
isReturned(item.isReturned),
isContinued(item.isContinued),
@@ -87,6 +91,8 @@ struct WalkItem
StringSet checkedElseNonNullVars; // vars checked for nonnull in expressions for else case
StringMapSet linkedVars; // linked vars. map <parent, set(vars)>
StringMap linkedReverseVars; // linked vars. map <child, parent>
+ int num; // numerical number stored in node
+ bool isNum; // true if number stored in node
bool stopWalking; // stop walking on tree after this node
bool isReturned; // set if return present in child nodes
bool isContinued; // set if continue present in child nodes