Refactoring; Use Token::isBinaryOp() to clarify code, use early continue in loop

This commit is contained in:
Daniel Marjamäki 2018-07-13 23:06:45 +02:00
parent a4fdef8d9e
commit 2c90a83695
1 changed files with 10 additions and 11 deletions

View File

@ -135,9 +135,10 @@ void CheckBool::checkComparisonOfBoolWithInt()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (!tok->isComparisonOp() || !tok->isBinaryOp())
continue;
const Token* const left = tok->astOperand1();
const Token* const right = tok->astOperand2();
if (left && right && tok->isComparisonOp()) {
if (left->isBoolean() && right->varId()) { // Comparing boolean constant with variable
if (tok->str() != "==" && tok->str() != "!=") {
comparisonOfBoolWithInvalidComparator(right, left->str());
@ -150,7 +151,6 @@ void CheckBool::checkComparisonOfBoolWithInt()
}
}
}
}
void CheckBool::comparisonOfBoolWithInvalidComparator(const Token *tok, const std::string &expression)
{
@ -409,8 +409,7 @@ void CheckBool::pointerArithBoolCond(const Token *tok)
if (tok->str() != "+" && tok->str() != "-")
return;
if (tok->astOperand1() &&
tok->astOperand2() &&
if (tok->isBinaryOp() &&
tok->astOperand1()->isName() &&
tok->astOperand1()->variable() &&
tok->astOperand1()->variable()->isPointer() &&