From c1b0bfe4ee42d55e27ae800fbb19dd91aa36aac3 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 11 Sep 2014 16:55:00 +0200 Subject: [PATCH] Simplified code --- lib/checkbool.cpp | 19 ++++++++----------- lib/checkexceptionsafety.cpp | 4 ++-- lib/checkother.cpp | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index 4858cf678..245053e5c 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -46,13 +46,10 @@ void CheckBool::checkIncrementBoolean() for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { - if (Token::Match(tok, "%var% ++")) { - if (tok->varId()) { - const Variable *var = tok->variable(); - - if (var && var->typeEndToken()->str() == "bool") - incrementBooleanError(tok); - } + if (tok->variable() && Token::Match(tok, "%var% ++")) { + const Variable *var = tok->variable(); + if (var && var->typeEndToken()->str() == "bool") + incrementBooleanError(tok); } } } @@ -204,9 +201,9 @@ void CheckBool::comparisonOfBoolWithInvalidComparator(const Token *tok, const st static bool tokenIsFunctionReturningBool(const Token* tok) { - if (Token::Match(tok, "%var% (") && !Token::Match(tok->previous(), "::|.")) { - const Function* func = tok->function(); - if (func && func->tokenDef && func->tokenDef->strAt(-1) == "bool") { + const Function* func = tok->function(); + if (func && Token::Match(tok, "%var% (")) { + if (func->tokenDef && func->tokenDef->strAt(-1) == "bool") { return true; } } @@ -483,7 +480,7 @@ void CheckBool::checkAssignBoolToFloat() const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { if (Token::Match(tok, "%var% =")) { - const Variable * const var = symbolDatabase->getVariableFromVarId(tok->varId()); + const Variable * const var = tok->variable(); if (var && var->isFloatingType() && !var->isArrayOrPointer() && astIsBool(tok->next()->astOperand2())) assignBoolToFloatError(tok->next()); } diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 9f8fcc023..5ebfb38cb 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -53,13 +53,13 @@ void CheckExceptionSafety::destructors() } // Skip uncaught execptions - if (Token::simpleMatch(tok, "if ( ! std :: uncaught_exception ( ) ) {")) { + else if (Token::simpleMatch(tok, "if ( ! std :: uncaught_exception ( ) ) {")) { tok = tok->next()->link(); // end of if ( ... ) tok = tok->next()->link(); // end of { ... } } // throw found within a destructor - if (tok->str() == "throw") { + else if (tok->str() == "throw") { destructorsError(tok, scope->className); break; } diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 893e13420..27bd95e76 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1368,7 +1368,7 @@ void CheckOther::checkVariableScope() for (unsigned int i = 1; i < symbolDatabase->getVariableListSize(); i++) { const Variable* var = symbolDatabase->getVariableFromVarId(i); - if (!var || !var->isLocal() || (!var->isPointer() && !var->typeStartToken()->isStandardType() && !var->typeStartToken()->next()->isStandardType())) + if (!var || !var->isLocal() || (!var->isPointer() && !var->typeStartToken()->isStandardType())) continue; if (var->isConst())