diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5e64b2c2b..31f17facf 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1129,7 +1129,7 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) bool TemplateSimplifier::simplifyTemplateInstantiations( TokenList& tokenlist, - ErrorLogger& errorlogger, + ErrorLogger* errorlogger, const Settings *_settings, const Token *tok, std::list &templateInstantiations, @@ -1154,9 +1154,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( int namepos = TemplateSimplifier::getTemplateNamePosition(tok); if (namepos == -1) { // debug message that we bail out.. - if (_settings->debugwarnings) { + if (_settings->debugwarnings && errorlogger) { std::list callstack(1, tok); - errorlogger.reportErr(ErrorLogger::ErrorMessage(callstack, &tokenlist, Severity::debug, "debug", "simplifyTemplates: bailing out", false)); + errorlogger->reportErr(ErrorLogger::ErrorMessage(callstack, &tokenlist, Severity::debug, "debug", "simplifyTemplates: bailing out", false)); } return false; } @@ -1238,9 +1238,9 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( const std::string typeForNewName(typeForNewNameStr); if (typeForNewName.empty() || typeParametersInDeclaration.size() != typesUsedInTemplateInstantiation.size()) { - if (_settings->debugwarnings) { + if (_settings->debugwarnings && errorlogger) { std::list callstack(1, tok); - errorlogger.reportErr(ErrorLogger::ErrorMessage(callstack, &tokenlist, Severity::debug, "debug", + errorlogger->reportErr(ErrorLogger::ErrorMessage(callstack, &tokenlist, Severity::debug, "debug", "Failed to instantiate template. The checking continues anyway.", false)); } if (typeForNewName.empty()) @@ -1317,7 +1317,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( void TemplateSimplifier::simplifyTemplates( TokenList& tokenlist, - ErrorLogger& errorlogger, + ErrorLogger* errorlogger, const Settings *_settings, bool &_codeWithTemplates ) diff --git a/lib/templatesimplifier.h b/lib/templatesimplifier.h index bae7c7640..dfa10a0c2 100644 --- a/lib/templatesimplifier.h +++ b/lib/templatesimplifier.h @@ -130,7 +130,7 @@ public: */ static bool simplifyTemplateInstantiations( TokenList& tokenlist, - ErrorLogger& errorlogger, + ErrorLogger* errorlogger, const Settings *_settings, const Token *tok, std::list &templateInstantiations, @@ -145,7 +145,7 @@ public: */ static void simplifyTemplates( TokenList& tokenlist, - ErrorLogger& errorlogger, + ErrorLogger* errorlogger, const Settings *_settings, bool &_codeWithTemplates); diff --git a/lib/token.cpp b/lib/token.cpp index 43c00dddb..6562e2a84 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1285,3 +1285,12 @@ const ValueFlow::Value * Token::getValueGE(const MathLib::bigint val, const Sett return ret; } +void Token::assignProgressValues(Token *tok) +{ + unsigned int total_count = 0; + for (Token *tok2 = tok; tok2; tok2 = tok2->next()) + ++total_count; + unsigned int count = 0; + for (Token *tok2 = tok; tok2; tok2 = tok2->next()) + tok2->_progressValue = count++ * 100 / total_count; +} diff --git a/lib/token.h b/lib/token.h index 5a72a1f0c..003066edb 100644 --- a/lib/token.h +++ b/lib/token.h @@ -591,14 +591,7 @@ public: } /** Calculate progress values for all tokens */ - void assignProgressValues() { - unsigned int total_count = 0; - for (Token *tok = this; tok; tok = tok->next()) - ++total_count; - unsigned int count = 0; - for (Token *tok = this; tok; tok = tok->next()) - tok->_progressValue = count++ * 100 / total_count; - } + static void assignProgressValues(Token *tok); /** * @return the first token of the next argument. Does only work on argument diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1150b0d75..eea09b58d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1518,6 +1518,8 @@ void Tokenizer::simplifyTypedef() void Tokenizer::simplifyMulAndParens() { + if (!list.front()) + return; for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) { if (tok->isName()) { //fix ticket #2784 - improved by ticket #3184 @@ -2243,7 +2245,7 @@ void Tokenizer::simplifyTemplates() TemplateSimplifier::simplifyTemplates( list, - *_errorLogger, + _errorLogger, _settings, _codeWithTemplates); } @@ -3474,7 +3476,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) simplifyArrayAccessSyntax(); - list.front()->assignProgressValues(); + Token::assignProgressValues(list.front()); removeRedundantSemicolons(); @@ -3687,7 +3689,7 @@ bool Tokenizer::simplifyTokenList2() validate(); - list.front()->assignProgressValues(); + Token::assignProgressValues(list.front()); // Create symbol database and then remove const keywords createSymbolDatabase(); diff --git a/lib/tokenize.h b/lib/tokenize.h index bdf30352e..93f667132 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -800,7 +800,7 @@ private: const Settings * _settings; /** errorlogger */ - ErrorLogger * const _errorLogger; + ErrorLogger* const _errorLogger; /** Symbol database that all checks etc can use */ SymbolDatabase *_symbolDatabase; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index ce3981870..59c7ef884 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -360,7 +360,7 @@ bool TokenList::createTokens(std::istream &code, const std::string& file0) addtoken(CurrentToken, lineno, FileIndex, true); if (!CurrentToken.empty()) _back->isExpandedMacro(expandedMacro); - _front->assignProgressValues(); + Token::assignProgressValues(_front); for (unsigned int i = 1; i < _files.size(); i++) _files[i] = Path::getRelativePath(_files[i], _settings->_basePaths); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 458109af7..e66c76a6f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -25,6 +25,7 @@ #include "preprocessor.h" // usually tests here should not use preprocessor... #include #include +#include extern std::ostringstream errout; class TestTokenizer : public TestFixture { @@ -611,7 +612,10 @@ private: errout << line << "\n"; } - return tokenizer.tokens()->stringifyList(false, expand, false, true, false, 0, 0); + if (tokenizer.tokens()) + return tokenizer.tokens()->stringifyList(false, expand, false, true, false, 0, 0); + else + return ""; }