summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-06-21 15:41:34 +0300
committerAndrei Karas <akaras@inbox.ru>2015-06-21 15:41:34 +0300
commit2870e7cc31e23d5f3e7102e013b5c2151b2ca749 (patch)
treeb618b073fcf608e72892063279896dfaff3c2c48 /src/analysis
parenta1b06e57fd52926a41ae49711514e3116f6f079a (diff)
downloadparanucker-2870e7cc31e23d5f3e7102e013b5c2151b2ca749.tar.gz
paranucker-2870e7cc31e23d5f3e7102e013b5c2151b2ca749.tar.bz2
paranucker-2870e7cc31e23d5f3e7102e013b5c2151b2ca749.tar.xz
paranucker-2870e7cc31e23d5f3e7102e013b5c2151b2ca749.zip
Add basic analysis for node COMPOUND_EXPR.
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/analysis.cpp4
-rw-r--r--src/analysis/expression.cpp37
-rw-r--r--src/analysis/expression.h3
3 files changed, 44 insertions, 0 deletions
diff --git a/src/analysis/analysis.cpp b/src/analysis/analysis.cpp
index e31a393..47b6c6b 100644
--- a/src/analysis/analysis.cpp
+++ b/src/analysis/analysis.cpp
@@ -33,6 +33,7 @@
#include "nodes/decl/var_decl.h"
#include "nodes/expr/addr_expr.h"
+#include "nodes/expr/compound_expr.h"
#include "nodes/expr/cond_expr.h"
#include "nodes/expr/eq_expr.h"
#include "nodes/expr/modify_expr.h"
@@ -237,6 +238,9 @@ void analyseNode(Node *node, const WalkItem &wi, WalkItem &wo)
case COND_EXPR:
analyseCondExpr(static_cast<CondExprNode*>(node), wi2, wo);
break;
+ case COMPOUND_EXPR:
+ analyseCompoundExpr(static_cast<CompoundExprNode*>(node), wi2, wo);
+ break;
case TRUTH_ORIF_EXPR:
analyseTruthOrIfExpr(static_cast<TruthOrIfExprNode*>(node), wi2, wo);
break;
diff --git a/src/analysis/expression.cpp b/src/analysis/expression.cpp
index 5885d56..18d3bdd 100644
--- a/src/analysis/expression.cpp
+++ b/src/analysis/expression.cpp
@@ -26,6 +26,7 @@
#include "analysis/walkitem.h"
#include "nodes/expr/addr_expr.h"
+#include "nodes/expr/compound_expr.h"
#include "nodes/expr/cond_expr.h"
#include "nodes/expr/eq_expr.h"
#include "nodes/expr/modify_expr.h"
@@ -304,4 +305,40 @@ void analyseCondExpr(CondExprNode *node, const WalkItem &wi, WalkItem &wo)
Log::dumpWI(node, "wo out ", wo);
}
+// expression like this (expr1, expr2, ..., exprn). Only have sense exprn.
+void analyseCompoundExpr(CompoundExprNode *node, const WalkItem &wi, WalkItem &wo)
+{
+ // need one arg for check
+ if (node->args.size() < 1 || command == FindArgs)
+ return;
+
+ Log::dumpWI(node, "wo in ", wo);
+
+ const size_t sz = node->args.size();
+ // walking and ignoring results for all args except last
+ for (size_t f = 0; f < sz - 1; f ++)
+ {
+ WalkItem wo1 = wo;
+ walkTree(node->args[f], wi, wo1);
+ Log::dumpWI(node, "wo1 ", wo1);
+ }
+ WalkItem wo2 = wo;
+ walkTree(node->args[sz - 1], wi, wo2);
+ Log::dumpWI(node, "wo2 ", wo2);
+
+ // probably condition wrong
+ if (wo2.cleanExpr)
+ {
+ mergeNullChecked(wo, wo2);
+ mergeNonNullChecked(wo, wo2);
+ }
+
+ wo.removeNullVars.clear();
+
+ wo.cleanExpr = true;
+ wo.stopWalking = true;
+ wo.uselessExpr = false;
+ Log::dumpWI(node, "wo out ", wo);
+}
+
}
diff --git a/src/analysis/expression.h b/src/analysis/expression.h
index 8e64ec5..94dcd47 100644
--- a/src/analysis/expression.h
+++ b/src/analysis/expression.h
@@ -23,6 +23,7 @@
#include "includes.h"
struct AddrExprNode;
+struct CompoundExprNode;
struct CondExprNode;
struct EqExprNode;
struct ModifyExprNode;
@@ -52,6 +53,8 @@ namespace Analysis
void analyseTruthAndIfExpr(TruthAndIfExprNode *node, const WalkItem &wi, WalkItem &wo);
void analyseCondExpr(CondExprNode *node, const WalkItem &wi, WalkItem &wo);
+
+ void analyseCompoundExpr(CompoundExprNode *node, const WalkItem &wi, WalkItem &wo);
}
#endif // ANALYSIS_EXPRESSION_H