Use functions instead of comparing with enum (#1471)

* Use isComparisonOp() instead of enum

* Use isAssignmentOp() instead of enum
This commit is contained in:
rikardfalkeborn 2018-11-09 06:30:41 +01:00 committed by Daniel Marjamäki
parent 67fe99fcd9
commit a3e717bea9
5 changed files with 8 additions and 8 deletions

View File

@ -64,7 +64,7 @@ void CheckAssert::assertWithSideEffects()
if (!scope) continue;
for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) {
if (tok2->tokType() != Token::eAssignmentOp && tok2->tokType() != Token::eIncDecOp)
if (!tok2->isAssignmentOp() && tok2->tokType() != Token::eIncDecOp)
continue;
const Variable* var = tok2->previous()->variable();

View File

@ -189,7 +189,7 @@ void CheckBool::checkComparisonOfFuncReturningBool()
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
if (!tok->isComparisonOp() || tok->str() == "==" || tok->str() == "!=")
continue;
const Token *firstToken = tok->previous();
if (tok->strAt(-1) == ")") {
@ -251,7 +251,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->tokType() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=")
if (!tok->isComparisonOp() || tok->str() == "==" || tok->str() == "!=")
continue;
bool firstTokenBool = false;

View File

@ -1988,7 +1988,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
const Token* lhs = tok1->previous();
if (lhs->str() == "&") {
lhs = lhs->previous();
if (lhs->tokType() == Token::eAssignmentOp && lhs->previous()->variable()) {
if (lhs->isAssignmentOp() && lhs->previous()->variable()) {
if (lhs->previous()->variable()->typeStartToken()->strAt(-1) != "const" && lhs->previous()->variable()->isPointer())
return false;
}
@ -1997,7 +1997,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
if (lhs->astParent()->strAt(1) != "const")
return false;
} else {
if (lhs->tokType() == Token::eAssignmentOp) {
if (lhs->isAssignmentOp()) {
const Variable* lhsVar = lhs->previous()->variable();
if (lhsVar && !lhsVar->isConst() && lhsVar->isReference() && lhs == lhsVar->nameToken()->next())
return false;
@ -2039,7 +2039,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
}
// Assignment
else if (end->next()->tokType() == Token::eAssignmentOp)
else if (end->next()->isAssignmentOp())
return false;
// Streaming

View File

@ -1194,7 +1194,7 @@ void CheckCondition::clarifyCondition()
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
if (tok2->str() == "(" || tok2->str() == "[")
tok2 = tok2->link();
else if (tok2->tokType() == Token::eComparisonOp) {
else if (tok2->isComparisonOp()) {
// This might be a template
if (!isC && tok2->link())
break;

View File

@ -169,7 +169,7 @@ void CheckString::checkSuspiciousStringCompare()
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (tok->tokType() != Token::eComparisonOp)
if (!tok->isComparisonOp())
continue;
const Token* varTok = tok->astOperand1();