From 82fe6193fa6a36e5411208550b42cd9d278f7a25 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Thu, 9 Jul 2020 23:08:04 +0200 Subject: [PATCH] Refactor: Use visitAstNodes in checkstring --- lib/checkstring.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/checkstring.cpp b/lib/checkstring.cpp index a87d5cd0c..576be7a1b 100644 --- a/lib/checkstring.cpp +++ b/lib/checkstring.cpp @@ -355,37 +355,32 @@ void CheckString::overlappingStrcmp() continue; std::list equals0; std::list notEquals0; - std::stack tokens; - tokens.push(tok); - while (!tokens.empty()) { - const Token * const t = tokens.top(); - tokens.pop(); + visitAstNodes(tok, [&](const Token * t) { if (!t) - continue; + return ChildrenToVisit::none; if (t->str() == "||") { - tokens.push(t->astOperand1()); - tokens.push(t->astOperand2()); - continue; + return ChildrenToVisit::op1_and_op2; } if (t->str() == "==") { if (Token::simpleMatch(t->astOperand1(), "(") && Token::simpleMatch(t->astOperand2(), "0")) equals0.push_back(t->astOperand1()); else if (Token::simpleMatch(t->astOperand2(), "(") && Token::simpleMatch(t->astOperand1(), "0")) equals0.push_back(t->astOperand2()); - continue; + return ChildrenToVisit::none; } if (t->str() == "!=") { if (Token::simpleMatch(t->astOperand1(), "(") && Token::simpleMatch(t->astOperand2(), "0")) notEquals0.push_back(t->astOperand1()); else if (Token::simpleMatch(t->astOperand2(), "(") && Token::simpleMatch(t->astOperand1(), "0")) notEquals0.push_back(t->astOperand2()); - continue; + return ChildrenToVisit::none; } if (t->str() == "!" && Token::simpleMatch(t->astOperand1(), "(")) equals0.push_back(t->astOperand1()); else if (t->str() == "(") notEquals0.push_back(t); - } + return ChildrenToVisit::none; + }); for (const Token *eq0 : equals0) { for (const Token * ne0 : notEquals0) {