Use functions instead of comparing with enum (#1471)
* Use isComparisonOp() instead of enum * Use isAssignmentOp() instead of enum
This commit is contained in:
parent
67fe99fcd9
commit
a3e717bea9
|
@ -64,7 +64,7 @@ void CheckAssert::assertWithSideEffects()
|
||||||
if (!scope) continue;
|
if (!scope) continue;
|
||||||
|
|
||||||
for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) {
|
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;
|
continue;
|
||||||
|
|
||||||
const Variable* var = tok2->previous()->variable();
|
const Variable* var = tok2->previous()->variable();
|
||||||
|
|
|
@ -189,7 +189,7 @@ void CheckBool::checkComparisonOfFuncReturningBool()
|
||||||
|
|
||||||
for (const Scope * scope : symbolDatabase->functionScopes) {
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
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;
|
continue;
|
||||||
const Token *firstToken = tok->previous();
|
const Token *firstToken = tok->previous();
|
||||||
if (tok->strAt(-1) == ")") {
|
if (tok->strAt(-1) == ")") {
|
||||||
|
@ -251,7 +251,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
|
||||||
|
|
||||||
for (const Scope * scope : symbolDatabase->functionScopes) {
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
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;
|
continue;
|
||||||
bool firstTokenBool = false;
|
bool firstTokenBool = false;
|
||||||
|
|
||||||
|
|
|
@ -1988,7 +1988,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
const Token* lhs = tok1->previous();
|
const Token* lhs = tok1->previous();
|
||||||
if (lhs->str() == "&") {
|
if (lhs->str() == "&") {
|
||||||
lhs = lhs->previous();
|
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())
|
if (lhs->previous()->variable()->typeStartToken()->strAt(-1) != "const" && lhs->previous()->variable()->isPointer())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1997,7 +1997,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
if (lhs->astParent()->strAt(1) != "const")
|
if (lhs->astParent()->strAt(1) != "const")
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (lhs->tokType() == Token::eAssignmentOp) {
|
if (lhs->isAssignmentOp()) {
|
||||||
const Variable* lhsVar = lhs->previous()->variable();
|
const Variable* lhsVar = lhs->previous()->variable();
|
||||||
if (lhsVar && !lhsVar->isConst() && lhsVar->isReference() && lhs == lhsVar->nameToken()->next())
|
if (lhsVar && !lhsVar->isConst() && lhsVar->isReference() && lhs == lhsVar->nameToken()->next())
|
||||||
return false;
|
return false;
|
||||||
|
@ -2039,7 +2039,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
else if (end->next()->tokType() == Token::eAssignmentOp)
|
else if (end->next()->isAssignmentOp())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Streaming
|
// Streaming
|
||||||
|
|
|
@ -1194,7 +1194,7 @@ void CheckCondition::clarifyCondition()
|
||||||
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "(" || tok2->str() == "[")
|
if (tok2->str() == "(" || tok2->str() == "[")
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
else if (tok2->tokType() == Token::eComparisonOp) {
|
else if (tok2->isComparisonOp()) {
|
||||||
// This might be a template
|
// This might be a template
|
||||||
if (!isC && tok2->link())
|
if (!isC && tok2->link())
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -169,7 +169,7 @@ void CheckString::checkSuspiciousStringCompare()
|
||||||
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
|
const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||||
for (const Scope * scope : symbolDatabase->functionScopes) {
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
if (tok->tokType() != Token::eComparisonOp)
|
if (!tok->isComparisonOp())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Token* varTok = tok->astOperand1();
|
const Token* varTok = tok->astOperand1();
|
||||||
|
|
Loading…
Reference in New Issue