From c8e40773f1ea150406349cb63754f3319ae4ba95 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 1 Aug 2012 12:04:47 -0700 Subject: [PATCH] Fixed cppcheck messagesa about functions that can be const/static: - Made Tokenizer::getErrorMessages static - Avoids creation of unnecessary instance of Tokenizer - Changed Tokenizer::removeExceptionSpecifications to common style for simplification functions. In contrast to the comment, this function doesn't call itself recursivly - fixed comment. - Made Tokenizer::IsScopeNoReturn static. --- lib/cppcheck.cpp | 4 +--- lib/tokenize.cpp | 12 +++++------- lib/tokenize.h | 9 ++++----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 344714032..867e0beda 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -543,8 +543,6 @@ void CppCheck::getErrorMessages() for (std::list::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) (*it)->getErrorMessages(this, &_settings); - Tokenizer tokenizer(&_settings, 0); - tokenizer.getErrorMessages(this, &_settings); - + Tokenizer::getErrorMessages(this, &_settings); Preprocessor::getErrorMessages(this, &_settings); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1d1011bcd..70cd4df77 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1930,7 +1930,7 @@ bool Tokenizer::tokenize(std::istream &code, simplifyConditionOperator(); // remove exception specifications.. - removeExceptionSpecifications(list.front()); + removeExceptionSpecifications(); // Collapse operator name tokens into single token // operator = => operator= @@ -7334,7 +7334,7 @@ void Tokenizer::simplifyStd() //--------------------------------------------------------------------------- -bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown) const +bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown) { if (unknown) *unknown = false; @@ -7834,9 +7834,9 @@ void Tokenizer::simplifyComma() } -void Tokenizer::removeExceptionSpecifications(Token *tok) const +void Tokenizer::removeExceptionSpecifications() { - while (tok) { + for(Token* tok = list.front(); tok; tok = tok->next()) { if (Token::Match(tok, ") const| throw (")) { if (tok->next()->str() == "const") { Token::eraseTokens(tok->next(), tok->linkAt(3)); @@ -7845,8 +7845,6 @@ void Tokenizer::removeExceptionSpecifications(Token *tok) const Token::eraseTokens(tok, tok->linkAt(2)); tok->deleteNext(); } - - tok = tok->next(); } } @@ -8065,7 +8063,7 @@ void Tokenizer::simplifyConst() } } -void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const +void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) { Tokenizer t(settings, errorLogger); t.syntaxError(0, ' '); diff --git a/lib/tokenize.h b/lib/tokenize.h index 2cb0bc424..dccaa7b4b 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -72,7 +72,7 @@ public: * \param unknown set to true if it's unknown if the scope is noreturn * \return true if scope ends with a function call that might be 'noreturn' */ - bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = 0) const; + static bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = 0); /** * Tokenize code @@ -171,7 +171,7 @@ public: /** * get error messages that the tokenizer generate */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const; + static void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings); /** Simplify assignment in function call "f(x=g());" => "x=g();f(x);" */ @@ -525,10 +525,9 @@ public: void simplifyFunctionPointers(); /** - * Remove exception specifications. This function calls itself recursively. - * @param tok First token in scope to cleanup + * Remove exception specifications. */ - void removeExceptionSpecifications(Token *tok) const; + void removeExceptionSpecifications(); /**