diff options
-rw-r--r-- | src/analysis/analysis.cpp | 4 | ||||
-rw-r--r-- | src/analysis/expression.cpp | 37 | ||||
-rw-r--r-- | src/analysis/expression.h | 3 | ||||
-rw-r--r-- | src/logger.cpp | 2 |
4 files changed, 45 insertions, 1 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 diff --git a/src/logger.cpp b/src/logger.cpp index ff58714..5d45821 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -196,7 +196,7 @@ void dumpWI(Node *const node, const std::string &name, WalkItem &wi) { - return; + //return; Log::log("%s%s %s", name.c_str(), node->nodeTypeName.c_str(), |