From 3d2e26daebc87970a3376153feef94d4b15ff2b4 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 11 Mar 2015 20:52:54 +0100 Subject: [PATCH] Small Refactorizations: - Removed #include "symboldatabase.h" from library.h - Moved variable to inner scope in tokenize.cpp - Removed unnecessary variable in tokenize.cpp --- lib/library.cpp | 20 ++++++++++++++++++++ lib/library.h | 20 ++------------------ lib/tokenize.cpp | 15 +++++++-------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 33d721424..7d91cdca9 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -713,3 +713,23 @@ bool Library::isNotLibraryFunction(const Token *ftok) const } return args != callargs; } + +bool Library::isnoreturn(const Token *ftok) const +{ + if (ftok->function() && ftok->function()->isAttributeNoreturn()) + return true; + if (isNotLibraryFunction(ftok)) + return false; + std::map::const_iterator it = _noreturn.find(ftok->str()); + return (it != _noreturn.end() && it->second); +} + +bool Library::isnotnoreturn(const Token *ftok) const +{ + if (ftok->function() && ftok->function()->isAttributeNoreturn()) + return false; + if (isNotLibraryFunction(ftok)) + return false; + std::map::const_iterator it = _noreturn.find(ftok->str()); + return (it != _noreturn.end() && !it->second); +} diff --git a/lib/library.h b/lib/library.h index 25245d823..5571a9810 100644 --- a/lib/library.h +++ b/lib/library.h @@ -25,7 +25,6 @@ #include "path.h" #include "mathlib.h" #include "token.h" -#include "symboldatabase.h" #include #include @@ -129,23 +128,8 @@ public: // returns true if ftok is not a library function bool isNotLibraryFunction(const Token *ftok) const; - bool isnoreturn(const Token *ftok) const { - if (ftok->function() && ftok->function()->isAttributeNoreturn()) - return true; - if (isNotLibraryFunction(ftok)) - return false; - std::map::const_iterator it = _noreturn.find(ftok->str()); - return (it != _noreturn.end() && it->second); - } - - bool isnotnoreturn(const Token *ftok) const { - if (ftok->function() && ftok->function()->isAttributeNoreturn()) - return false; - if (isNotLibraryFunction(ftok)) - return false; - std::map::const_iterator it = _noreturn.find(ftok->str()); - return (it != _noreturn.end() && !it->second); - } + bool isnoreturn(const Token *ftok) const; + bool isnotnoreturn(const Token *ftok) const; bool isScopeNoReturn(const Token *end, std::string *unknownFunc) const; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2ca2785ee..37e448aaf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6572,7 +6572,6 @@ bool Tokenizer::simplifyKnownVariables() if (varid == 0) continue; - const std::string structname; const Token * const valueToken = tok2->tokAt(4); std::string value(valueToken->str()); if (tok2->str() == "sprintf") { @@ -6584,7 +6583,7 @@ bool Tokenizer::simplifyKnownVariables() const unsigned int valueVarId(0); const bool valueIsPointer(false); Token *tok3 = tok2->tokAt(6); - ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, structname, value, valueVarId, valueIsPointer, valueToken, indentlevel); + ret |= simplifyKnownVariablesSimplify(&tok2, tok3, varid, emptyString, value, valueVarId, valueIsPointer, valueToken, indentlevel); // there could be a hang here if tok2 was moved back by the function call above for some reason if (_settings->terminated()) @@ -8508,8 +8507,8 @@ bool Tokenizer::isTwoNumber(const std::string &s) void Tokenizer::simplifyMathFunctions() { for (Token *tok = list.front(); tok; tok = tok->next()) { - bool simplifcationMade = false; if (tok->isName() && tok->strAt(1) == "(") { // precondition for function + bool simplifcationMade = false; if (Token::Match(tok, "atol ( %str% )")) { //@todo Add support for atoll() if (tok->previous() && Token::simpleMatch(tok->tokAt(-2), "std ::")) { @@ -8739,11 +8738,11 @@ void Tokenizer::simplifyMathFunctions() } } } - } - // Jump back to begin of statement if a simplification was performed - if (simplifcationMade) { - while (tok->previous() && tok->str() != ";") { - tok = tok->previous(); + // Jump back to begin of statement if a simplification was performed + if (simplifcationMade) { + while (tok->previous() && tok->str() != ";") { + tok = tok->previous(); + } } } }