From 4f0121ee2f38e712187ad8911c5aaef6f5c86c9d Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 30 Dec 2013 17:45:28 +0100 Subject: [PATCH] Splitted simplification out of tokenize() --- lib/cppcheck.cpp | 4 +- lib/tokenize.cpp | 1020 ++++++++++++++-------------- lib/tokenize.h | 20 +- test/testassignif.cpp | 2 +- test/testautovariables.cpp | 2 +- test/testbool.cpp | 2 +- test/testboost.cpp | 2 +- test/testbufferoverrun.cpp | 4 +- test/testclass.cpp | 24 +- test/testconstructors.cpp | 2 +- test/testincompletestatement.cpp | 2 +- test/testinternal.cpp | 2 +- test/testio.cpp | 2 +- test/testleakautovar.cpp | 2 +- test/testmemleak.cpp | 10 +- test/testnonreentrantfunctions.cpp | 2 +- test/testnullpointer.cpp | 2 +- test/testobsoletefunctions.cpp | 2 +- test/testother.cpp | 6 +- test/testpostfixoperator.cpp | 2 +- test/testsimplifytokens.cpp | 14 +- test/teststl.cpp | 2 +- test/testsymboldatabase.cpp | 2 +- test/testtokenize.cpp | 14 +- test/testuninitvar.cpp | 4 +- test/testunusedprivfunc.cpp | 2 +- 26 files changed, 583 insertions(+), 569 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index d0d46ad3f..d5a0aa914 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -305,7 +305,7 @@ void CppCheck::analyseFile(std::istream &fin, const std::string &filename) Tokenizer tokenizer(&_settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, filename.c_str(), ""); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Analyse the tokens.. std::set data; @@ -376,7 +376,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) return; Timer timer3("Tokenizer::simplifyTokenList", _settings._showtime, &S_timerResults); - result = _tokenizer.simplifyTokenList(); + result = _tokenizer.simplifyTokenList2(); timer3.Stop(); if (!result) return; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 60ca8afd0..672b726d9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1588,516 +1588,24 @@ bool Tokenizer::tokenize(std::istream &code, return false; } - if (_settings->terminated()) - return false; + if (simplifyTokenList1()) { - // if MACRO - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::Match(tok, "if|for|while|BOOST_FOREACH %var% (")) { - if (Token::simpleMatch(tok, "for each")) { - // 'for each ( )' -> 'asm ( )' - tok->str("asm"); - tok->deleteNext(); - } else { - syntaxError(tok); - return false; + createSymbolDatabase(); + + // Use symbol database to identify rvalue references. Split && to & &. This is safe, since it doesn't delete any tokens (which might be referenced by symbol database) + for (std::size_t i = 0; i < _symbolDatabase->getVariableListSize(); i++) { + const Variable* var = _symbolDatabase->getVariableFromVarId(i); + if (var && var->isRValueReference()) { + const_cast(var->typeEndToken())->str("&"); + const_cast(var->typeEndToken())->insertToken("&"); + const_cast(var->typeEndToken()->next())->scope(var->typeEndToken()->scope()); } } + + list.createAst(); + return true; } - - // remove MACRO in variable declaration: MACRO int x; - removeMacroInVarDecl(); - - // Combine strings - combineStrings(); - - // replace inline SQL with "asm()" (Oracle PRO*C). Ticket: #1959 - simplifySQL(); - - // replace __LINE__ macro with line number - simplifyFileAndLineMacro(); - - // Concatenate double sharp: 'a ## b' -> 'ab' - concatenateDoubleSharp(); - - if (!createLinks()) { - // Source has syntax errors, can't proceed - return false; - } - - // if (x) MACRO() .. - for (const Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "if (")) { - tok = tok->next()->link(); - if (Token::Match(tok, ") %var% (") && - tok->next()->isUpperCaseName() && - Token::Match(tok->linkAt(2), ") {|else")) { - syntaxError(tok->next()); - return false; - } - } - } - - if (_settings->terminated()) - return false; - - // replace 'NULL' and similar '0'-defined macros with '0' - simplifyNull(); - - // replace 'sin(0)' to '0' and other similar math expressions - simplifyMathExpressions(); - - // combine "- %num%" - concatenateNegativeNumberAndAnyPositive(); - - // simplify simple calculations - for (Token *tok = list.front() ? list.front()->next() : NULL; tok; tok = tok->next()) { - if (tok->isNumber()) - TemplateSimplifier::simplifyNumericCalculations(tok->previous()); - } - - // remove extern "C" and extern "C" {} - if (isCPP()) - simplifyExternC(); - - // simplify weird but legal code: "[;{}] ( { code; } ) ;"->"[;{}] code;" - simplifyRoundCurlyParentheses(); - - // check for simple syntax errors.. - for (const Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "> struct {") && - Token::simpleMatch(tok->linkAt(2), "} ;")) { - syntaxError(tok); - list.deallocateTokens(); - return false; - } - } - - if (!simplifyAddBraces()) - return false; - - sizeofAddParentheses(); - - // Combine tokens.. - combineOperators(); - - // Simplify: 0[foo] -> *(foo) - for (Token* tok = list.front(); tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "0 [") && tok->linkAt(1)) { - tok->str("*"); - tok->next()->str("("); - tok->linkAt(1)->str(")"); - } - } - - if (_settings->terminated()) - return false; - - // Remove "volatile", "inline", "register", and "restrict" - simplifyKeyword(); - - // Convert K&R function declarations to modern C - simplifyVarDecl(true); - if (!simplifyFunctionParameters()) - return false; - - // specify array size.. - arraySize(); - - // simplify labels and 'case|default'-like syntaxes - if (!simplifyLabelsCaseDefault()) - return false; - - // simplify '[;{}] * & ( %any% ) =' to '%any% =' - simplifyMulAndParens(); - - // ";a+=b;" => ";a=a+b;" - simplifyCompoundAssignment(); - - if (hasComplicatedSyntaxErrorsInTemplates()) { - list.deallocateTokens(); - return false; - } - - if (_settings->terminated()) - return false; - - // Remove __declspec() - simplifyDeclspec(); - - // remove some unhandled macros in global scope - removeMacrosInGlobalScope(); - - // remove calling conventions __cdecl, __stdcall.. - simplifyCallingConvention(); - - // remove __attribute__((?)) - simplifyAttribute(); - - // remove unnecessary member qualification.. - removeUnnecessaryQualification(); - - // remove Microsoft MFC.. - simplifyMicrosoftMFC(); - - // convert Microsoft memory functions - simplifyMicrosoftMemoryFunctions(); - - // convert Microsoft string functions - simplifyMicrosoftStringFunctions(); - - if (_settings->terminated()) - return false; - - // Remove Qt signals and slots - simplifyQtSignalsSlots(); - - // remove Borland stuff.. - simplifyBorland(); - - // Remove __builtin_expect, likely and unlikely - simplifyBuiltinExpect(); - - if (hasEnumsWithTypedef()) { - // #2449: syntax error: enum with typedef in it - list.deallocateTokens(); - return false; - } - - simplifyDebugNew(); - - // typedef.. - if (m_timerResults) { - Timer t("Tokenizer::tokenize::simplifyTypedef", _settings->_showtime, m_timerResults); - simplifyTypedef(); - } else { - simplifyTypedef(); - } - - for (Token* tok = list.front(); tok;) { - if (Token::Match(tok, "union|struct|class union|struct|class")) - tok->deleteNext(); - else - tok = tok->next(); - } - - // class x y { - if (_settings->isEnabled("information")) { - for (const Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::Match(tok, "class %type% %type% [:{]")) { - unhandled_macro_class_x_y(tok); - } - } - } - - // catch bad typedef canonicalization - // - // to reproduce bad typedef, download upx-ucl from: - // http://packages.debian.org/sid/upx-ucl - // analyse the file src/stub/src/i386-linux.elf.interp-main.c - if (!validate()) { - // Source has syntax errors, can't proceed - return false; - } - - // enum.. - simplifyEnum(); - - // The simplify enum have inner loops - if (_settings->terminated()) - return false; - - // Remove __asm.. - simplifyAsm(); - - // Put ^{} statements in asm() - for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "^ {")) { - Token * start = tok; - while (start && !Token::Match(start, "[;{}]")) - start = start->previous(); - if (start) - start = start->next(); - const Token *last = tok->next()->link(); - if (start != tok) { - last = last->next(); - while (last && !Token::Match(last->next(), "[;{}()]")) - last = last->next(); - } - if (start && last) { - std::string asmcode(start->str()); - while (start->next() != last) { - asmcode += start->next()->str(); - start->deleteNext(); - } - asmcode += last->str(); - start->deleteNext(); - start->insertToken(";"); - start->insertToken(")"); - start->insertToken("\"" + asmcode + "\""); - start->insertToken("("); - start->str("asm"); - start->link(NULL); - start->next()->link(start->tokAt(3)); - start->tokAt(3)->link(start->next()); - tok = start->tokAt(4); - } - } - } - - // When the assembly code has been cleaned up, no @ is allowed - for (const Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str() == "(") - tok = tok->link(); - else if (tok->str()[0] == '@') { - list.deallocateTokens(); - return false; - } - } - - // convert platform dependent types to standard types - // 32 bits: size_t -> unsigned long - // 64 bits: size_t -> unsigned long long - simplifyPlatformTypes(); - - // collapse compound standard types into a single token - // unsigned long long int => long _isUnsigned=true,_isLong=true - simplifyStdType(); - - // The simplifyTemplates have inner loops - if (_settings->terminated()) - return false; - - // simplify bit fields.. - simplifyBitfields(); - - // Use "<" comparison instead of ">" - simplifyComparisonOrder(); - - // Simplify '(p == 0)' to '(!p)' - simplifyIfNot(); - simplifyIfNotNull(); - - //simplify for: move out start-statement "for (a;b;c);" => "{ a; for(;b;c); }" - //not enabled because it fails many tests with testrunner. - //@todo fix these fails before enabling this simplification - /*for (Token* tok = list.front(); tok; tok = tok->next()) { - if (tok->str() == "(" && ( !tok->previous() || tok->previous()->str() != "for")) { - tok = tok->link(); - continue; - } - if (!Token::Match(tok->previous(),"[{};] for (")) - continue; - - //find the two needed semicolons inside the 'for' - const Token *firstsemicolon = Token::findsimplematch(tok->next(), ";", tok->next()->link()); - if (!firstsemicolon) - continue; - const Token *secondsemicolon = Token::findsimplematch(firstsemicolon->next(), ";", tok->next()->link()); - if (!secondsemicolon) - continue; - if (Token::findsimplematch(secondsemicolon->next(), ";", tok->next()->link())) - continue; //no more than two semicolons! - if (!tok->next()->link()->next()) - continue; //there should be always something after 'for (...)' - - Token *fortok = tok; - Token *begin = tok->tokAt(2); - Token *end = tok->next()->link(); - if ( begin->str() != ";" ) { - tok = tok->previous(); - tok->insertToken(";"); - tok->insertToken("{"); - tok = tok->next(); - if (end->next()->str() =="{") { - end = end->next()->link(); - end->insertToken("}"); - Token::createMutualLinks(tok, end->next()); - end = end->link()->previous(); - } else { - if (end->next()->str() != ";") - end->insertToken(";"); - end = end->next(); - end->insertToken("}"); - Token::createMutualLinks(tok, end->next()); - } - end = firstsemicolon->previous(); - Token::move(begin, end, tok); - tok = fortok; - end = fortok->next()->link(); - } - //every 'for' is changed to 'for(;b;c), now it's possible to convert the 'for' to a 'while'. - //precisely, 'for(;b;c){code}'-> 'while(b){code + c;}' - fortok->str("while"); - begin = firstsemicolon->previous(); - begin->deleteNext(); - begin = secondsemicolon->previous(); - begin->deleteNext(); - begin = begin->next(); - if (begin->str() == ")") { //'for(;b;)' -> 'while(b)' - if (begin->previous()->str() == "(") //'for(;;)' -> 'while(true)' - begin->previous()->insertToken("true"); - tok = fortok; - continue; - } - if (end->next()->str() =="{") { - tok = end->next()->link()->previous(); - tok->insertToken(";"); - } else { - tok = end; - if (end->next()->str() != ";") - tok->insertToken(";"); - tok->insertToken("{"); - tok = tok->tokAt(2); - tok->insertToken("}"); - Token::createMutualLinks(tok->previous(), tok->next()); - tok = tok->previous(); - } - end = end->previous(); - Token::move(begin, end, tok); - tok = fortok; - }*/ - - // The simplifyTemplates have inner loops - if (_settings->terminated()) - return false; - - simplifyConst(); - - // struct simplification "struct S {} s; => struct S { } ; S s ; - simplifyStructDecl(); - - // struct initialization (must be used before simplifyVarDecl) - simplifyStructInit(); - - // Change initialisation of variable to assignment - simplifyInitVar(); - - // The simplifyTemplates have inner loops - if (_settings->terminated()) - return false; - - // Split up variable declarations. - simplifyVarDecl(false); - - // specify array size.. needed when arrays are split - arraySize(); - - // f(x=g()) => x=g(); f(x) - simplifyAssignmentInFunctionCall(); - - // x = ({ 123; }); => { x = 123; } - simplifyAssignmentBlock(); - - // The simplifyTemplates have inner loops - if (_settings->terminated()) - return false; - - simplifyVariableMultipleAssign(); - - // Simplify float casts (float)1 => 1.0 - simplifyFloatCasts(); - - // Remove redundant parentheses - simplifyRedundantParentheses(); - for (Token *tok = list.front(); tok; tok = tok->next()) - while (TemplateSimplifier::simplifyNumericCalculations(tok)) - ; - - // Handle templates.. - simplifyTemplates(); - - // The simplifyTemplates have inner loops - if (_settings->terminated()) - return false; - - // Simplify templates.. sometimes the "simplifyTemplates" fail and - // then unsimplified function calls etc remain. These have the - // "wrong" syntax. So this function will just fix so that the - // syntax is corrected. - TemplateSimplifier::cleanupAfterSimplify(list.front()); - - // Simplify the operator "?:" - simplifyConditionOperator(); - - // remove exception specifications.. - removeExceptionSpecifications(); - - // Collapse operator name tokens into single token - // operator = => operator= - simplifyOperatorName(); - - // Simplify pointer to standard types (C only) - simplifyPointerToStandardType(); - - // simplify function pointers - simplifyFunctionPointers(); - - // "if (not p)" => "if (!p)" - // "if (p and q)" => "if (p && q)" - // "if (p or q)" => "if (p || q)" - while (simplifyLogicalOperators()) { } - - // Change initialisation of variable to assignment - simplifyInitVar(); - - // Split up variable declarations. - simplifyVarDecl(false); - - if (m_timerResults) { - Timer t("Tokenizer::tokenize::setVarId", _settings->_showtime, m_timerResults); - setVarId(); - } else { - setVarId(); - } - - // The simplify enum might have inner loops - if (_settings->terminated()) - return false; - - // Add std:: in front of std classes, when using namespace std; was given - simplifyNamespaceStd(); - - createLinks2(); - - // Change initialisation of variable to assignment - simplifyInitVar(); - - // Convert e.g. atol("0") into 0 - while (simplifyMathFunctions()) {}; - - simplifyDoublePlusAndDoubleMinus(); - - simplifyArrayAccessSyntax(); - - list.front()->assignProgressValues(); - - removeRedundantSemicolons(); - - simplifyParameterVoid(); - - simplifyRedundantConsecutiveBraces(); - - simplifyEmptyNamespaces(); - - if (!validate()) - return false; - - createSymbolDatabase(); - - // Use symbol database to identify rvalue references. Split && to & &. This is safe, since it doesn't delete any tokens (which might be referenced by symbol database) - for (std::size_t i = 0; i < _symbolDatabase->getVariableListSize(); i++) { - const Variable* var = _symbolDatabase->getVariableFromVarId(i); - if (var && var->isRValueReference()) { - const_cast(var->typeEndToken())->str("&"); - const_cast(var->typeEndToken())->insertToken("&"); - const_cast(var->typeEndToken()->next())->scope(var->typeEndToken()->scope()); - } - } - - list.createAst(); - - return true; + return false; } //--------------------------------------------------------------------------- @@ -3498,7 +3006,505 @@ bool Tokenizer::simplifySizeof() return ret; } -bool Tokenizer::simplifyTokenList() +bool Tokenizer::simplifyTokenList1() +{ + if (_settings->terminated()) + return false; + + // if MACRO + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::Match(tok, "if|for|while|BOOST_FOREACH %var% (")) { + if (Token::simpleMatch(tok, "for each")) { + // 'for each ( )' -> 'asm ( )' + tok->str("asm"); + tok->deleteNext(); + } else { + syntaxError(tok); + return false; + } + } + } + + // remove MACRO in variable declaration: MACRO int x; + removeMacroInVarDecl(); + + // Combine strings + combineStrings(); + + // replace inline SQL with "asm()" (Oracle PRO*C). Ticket: #1959 + simplifySQL(); + + // replace __LINE__ macro with line number + simplifyFileAndLineMacro(); + + // Concatenate double sharp: 'a ## b' -> 'ab' + concatenateDoubleSharp(); + + if (!createLinks()) { + // Source has syntax errors, can't proceed + return false; + } + + // if (x) MACRO() .. + for (const Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "if (")) { + tok = tok->next()->link(); + if (Token::Match(tok, ") %var% (") && + tok->next()->isUpperCaseName() && + Token::Match(tok->linkAt(2), ") {|else")) { + syntaxError(tok->next()); + return false; + } + } + } + + if (_settings->terminated()) + return false; + + // replace 'NULL' and similar '0'-defined macros with '0' + simplifyNull(); + + // replace 'sin(0)' to '0' and other similar math expressions + simplifyMathExpressions(); + + // combine "- %num%" + concatenateNegativeNumberAndAnyPositive(); + + // simplify simple calculations + for (Token *tok = list.front() ? list.front()->next() : NULL; tok; tok = tok->next()) { + if (tok->isNumber()) + TemplateSimplifier::simplifyNumericCalculations(tok->previous()); + } + + // remove extern "C" and extern "C" {} + if (isCPP()) + simplifyExternC(); + + // simplify weird but legal code: "[;{}] ( { code; } ) ;"->"[;{}] code;" + simplifyRoundCurlyParentheses(); + + // check for simple syntax errors.. + for (const Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "> struct {") && + Token::simpleMatch(tok->linkAt(2), "} ;")) { + syntaxError(tok); + list.deallocateTokens(); + return false; + } + } + + if (!simplifyAddBraces()) + return false; + + sizeofAddParentheses(); + + // Combine tokens.. + combineOperators(); + + // Simplify: 0[foo] -> *(foo) + for (Token* tok = list.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "0 [") && tok->linkAt(1)) { + tok->str("*"); + tok->next()->str("("); + tok->linkAt(1)->str(")"); + } + } + + if (_settings->terminated()) + return false; + + // Remove "volatile", "inline", "register", and "restrict" + simplifyKeyword(); + + // Convert K&R function declarations to modern C + simplifyVarDecl(true); + if (!simplifyFunctionParameters()) + return false; + + // specify array size.. + arraySize(); + + // simplify labels and 'case|default'-like syntaxes + if (!simplifyLabelsCaseDefault()) + return false; + + // simplify '[;{}] * & ( %any% ) =' to '%any% =' + simplifyMulAndParens(); + + // ";a+=b;" => ";a=a+b;" + simplifyCompoundAssignment(); + + if (hasComplicatedSyntaxErrorsInTemplates()) { + list.deallocateTokens(); + return false; + } + + if (_settings->terminated()) + return false; + + // Remove __declspec() + simplifyDeclspec(); + + // remove some unhandled macros in global scope + removeMacrosInGlobalScope(); + + // remove calling conventions __cdecl, __stdcall.. + simplifyCallingConvention(); + + // remove __attribute__((?)) + simplifyAttribute(); + + // remove unnecessary member qualification.. + removeUnnecessaryQualification(); + + // remove Microsoft MFC.. + simplifyMicrosoftMFC(); + + // convert Microsoft memory functions + simplifyMicrosoftMemoryFunctions(); + + // convert Microsoft string functions + simplifyMicrosoftStringFunctions(); + + if (_settings->terminated()) + return false; + + // Remove Qt signals and slots + simplifyQtSignalsSlots(); + + // remove Borland stuff.. + simplifyBorland(); + + // Remove __builtin_expect, likely and unlikely + simplifyBuiltinExpect(); + + if (hasEnumsWithTypedef()) { + // #2449: syntax error: enum with typedef in it + list.deallocateTokens(); + return false; + } + + simplifyDebugNew(); + + // typedef.. + if (m_timerResults) { + Timer t("Tokenizer::tokenize::simplifyTypedef", _settings->_showtime, m_timerResults); + simplifyTypedef(); + } else { + simplifyTypedef(); + } + + for (Token* tok = list.front(); tok;) { + if (Token::Match(tok, "union|struct|class union|struct|class")) + tok->deleteNext(); + else + tok = tok->next(); + } + + // class x y { + if (_settings->isEnabled("information")) { + for (const Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::Match(tok, "class %type% %type% [:{]")) { + unhandled_macro_class_x_y(tok); + } + } + } + + // catch bad typedef canonicalization + // + // to reproduce bad typedef, download upx-ucl from: + // http://packages.debian.org/sid/upx-ucl + // analyse the file src/stub/src/i386-linux.elf.interp-main.c + if (!validate()) { + // Source has syntax errors, can't proceed + return false; + } + + // enum.. + simplifyEnum(); + + // The simplify enum have inner loops + if (_settings->terminated()) + return false; + + // Remove __asm.. + simplifyAsm(); + + // Put ^{} statements in asm() + for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "^ {")) { + Token * start = tok; + while (start && !Token::Match(start, "[;{}]")) + start = start->previous(); + if (start) + start = start->next(); + const Token *last = tok->next()->link(); + if (start != tok) { + last = last->next(); + while (last && !Token::Match(last->next(), "[;{}()]")) + last = last->next(); + } + if (start && last) { + std::string asmcode(start->str()); + while (start->next() != last) { + asmcode += start->next()->str(); + start->deleteNext(); + } + asmcode += last->str(); + start->deleteNext(); + start->insertToken(";"); + start->insertToken(")"); + start->insertToken("\"" + asmcode + "\""); + start->insertToken("("); + start->str("asm"); + start->link(NULL); + start->next()->link(start->tokAt(3)); + start->tokAt(3)->link(start->next()); + tok = start->tokAt(4); + } + } + } + + // When the assembly code has been cleaned up, no @ is allowed + for (const Token *tok = list.front(); tok; tok = tok->next()) { + if (tok->str() == "(") + tok = tok->link(); + else if (tok->str()[0] == '@') { + list.deallocateTokens(); + return false; + } + } + + // convert platform dependent types to standard types + // 32 bits: size_t -> unsigned long + // 64 bits: size_t -> unsigned long long + simplifyPlatformTypes(); + + // collapse compound standard types into a single token + // unsigned long long int => long _isUnsigned=true,_isLong=true + simplifyStdType(); + + // The simplifyTemplates have inner loops + if (_settings->terminated()) + return false; + + // simplify bit fields.. + simplifyBitfields(); + + // Use "<" comparison instead of ">" + simplifyComparisonOrder(); + + // Simplify '(p == 0)' to '(!p)' + simplifyIfNot(); + simplifyIfNotNull(); + + + //simplify for: move out start-statement "for (a;b;c);" => "{ a; for(;b;c); }" + //not enabled because it fails many tests with testrunner. + //@todo fix these fails before enabling this simplification + /*for (Token* tok = list.front(); tok; tok = tok->next()) { + if (tok->str() == "(" && ( !tok->previous() || tok->previous()->str() != "for")) { + tok = tok->link(); + continue; + } + if (!Token::Match(tok->previous(),"[{};] for (")) + continue; + + //find the two needed semicolons inside the 'for' + const Token *firstsemicolon = Token::findsimplematch(tok->next(), ";", tok->next()->link()); + if (!firstsemicolon) + continue; + const Token *secondsemicolon = Token::findsimplematch(firstsemicolon->next(), ";", tok->next()->link()); + if (!secondsemicolon) + continue; + if (Token::findsimplematch(secondsemicolon->next(), ";", tok->next()->link())) + continue; //no more than two semicolons! + if (!tok->next()->link()->next()) + continue; //there should be always something after 'for (...)' + + Token *fortok = tok; + Token *begin = tok->tokAt(2); + Token *end = tok->next()->link(); + if ( begin->str() != ";" ) { + tok = tok->previous(); + tok->insertToken(";"); + tok->insertToken("{"); + tok = tok->next(); + if (end->next()->str() =="{") { + end = end->next()->link(); + end->insertToken("}"); + Token::createMutualLinks(tok, end->next()); + end = end->link()->previous(); + } else { + if (end->next()->str() != ";") + end->insertToken(";"); + end = end->next(); + end->insertToken("}"); + Token::createMutualLinks(tok, end->next()); + } + end = firstsemicolon->previous(); + Token::move(begin, end, tok); + tok = fortok; + end = fortok->next()->link(); + } + //every 'for' is changed to 'for(;b;c), now it's possible to convert the 'for' to a 'while'. + //precisely, 'for(;b;c){code}'-> 'while(b){code + c;}' + fortok->str("while"); + begin = firstsemicolon->previous(); + begin->deleteNext(); + begin = secondsemicolon->previous(); + begin->deleteNext(); + begin = begin->next(); + if (begin->str() == ")") { //'for(;b;)' -> 'while(b)' + if (begin->previous()->str() == "(") //'for(;;)' -> 'while(true)' + begin->previous()->insertToken("true"); + tok = fortok; + continue; + } + if (end->next()->str() =="{") { + tok = end->next()->link()->previous(); + tok->insertToken(";"); + } else { + tok = end; + if (end->next()->str() != ";") + tok->insertToken(";"); + tok->insertToken("{"); + tok = tok->tokAt(2); + tok->insertToken("}"); + Token::createMutualLinks(tok->previous(), tok->next()); + tok = tok->previous(); + } + end = end->previous(); + Token::move(begin, end, tok); + tok = fortok; + }*/ + + // The simplifyTemplates have inner loops + if (_settings->terminated()) + return false; + + simplifyConst(); + + // struct simplification "struct S {} s; => struct S { } ; S s ; + simplifyStructDecl(); + + // struct initialization (must be used before simplifyVarDecl) + simplifyStructInit(); + + // Change initialisation of variable to assignment + simplifyInitVar(); + + // The simplifyTemplates have inner loops + if (_settings->terminated()) + return false; + + // Split up variable declarations. + simplifyVarDecl(false); + + // specify array size.. needed when arrays are split + arraySize(); + + // f(x=g()) => x=g(); f(x) + simplifyAssignmentInFunctionCall(); + + // x = ({ 123; }); => { x = 123; } + simplifyAssignmentBlock(); + + // The simplifyTemplates have inner loops + if (_settings->terminated()) + return false; + + simplifyVariableMultipleAssign(); + + // Simplify float casts (float)1 => 1.0 + simplifyFloatCasts(); + + // Remove redundant parentheses + simplifyRedundantParentheses(); + for (Token *tok = list.front(); tok; tok = tok->next()) + while (TemplateSimplifier::simplifyNumericCalculations(tok)) + ; + + // Handle templates.. + simplifyTemplates(); + + // The simplifyTemplates have inner loops + if (_settings->terminated()) + return false; + + // Simplify templates.. sometimes the "simplifyTemplates" fail and + // then unsimplified function calls etc remain. These have the + // "wrong" syntax. So this function will just fix so that the + // syntax is corrected. + TemplateSimplifier::cleanupAfterSimplify(list.front()); + + // Simplify the operator "?:" + simplifyConditionOperator(); + + // remove exception specifications.. + removeExceptionSpecifications(); + + // Collapse operator name tokens into single token + // operator = => operator= + simplifyOperatorName(); + + // Simplify pointer to standard types (C only) + simplifyPointerToStandardType(); + + // simplify function pointers + simplifyFunctionPointers(); + + // "if (not p)" => "if (!p)" + // "if (p and q)" => "if (p && q)" + // "if (p or q)" => "if (p || q)" + while (simplifyLogicalOperators()) {} + + // Change initialisation of variable to assignment + simplifyInitVar(); + + // Split up variable declarations. + simplifyVarDecl(false); + + if (m_timerResults) { + Timer t("Tokenizer::tokenize::setVarId", _settings->_showtime, m_timerResults); + setVarId(); + } else { + setVarId(); + } + + // The simplify enum might have inner loops + if (_settings->terminated()) + return false; + + // Add std:: in front of std classes, when using namespace std; was given + simplifyNamespaceStd(); + + createLinks2(); + + // Change initialisation of variable to assignment + simplifyInitVar(); + + // Convert e.g. atol("0") into 0 + while (simplifyMathFunctions()) {}; + + simplifyDoublePlusAndDoubleMinus(); + + simplifyArrayAccessSyntax(); + + list.front()->assignProgressValues(); + + removeRedundantSemicolons(); + + simplifyParameterVoid(); + + simplifyRedundantConsecutiveBraces(); + + simplifyEmptyNamespaces(); + + return validate(); +} + +bool Tokenizer::simplifyTokenList2() { // clear the _functionList so it can't contain dead pointers deleteSymbolDatabase(); diff --git a/lib/tokenize.h b/lib/tokenize.h index 295d8ac06..1f1013775 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -101,12 +101,20 @@ public: void setVarId(); /** - * Simplify tokenlist - * - * @return false if there is an error that requires aborting - * the checking of this file. - */ - bool simplifyTokenList(); + * Basic simplification of tokenlist + * + * @return false if there is an error that requires aborting + * the checking of this file. + */ + bool simplifyTokenList1(); + + /** + * Most aggressive simplification of tokenlist + * + * @return false if there is an error that requires aborting + * the checking of this file. + */ + bool simplifyTokenList2(); /** * Deletes dead code between 'begin' and 'end'. diff --git a/test/testassignif.cpp b/test/testassignif.cpp index 16281485e..c53b23f4e 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -51,7 +51,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); // Ensure that the test case is not bad. diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 778a7b1f8..737ad774e 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -53,7 +53,7 @@ private: if (runSimpleChecks) { const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); if (str1 != str2) warn(("Unsimplified code in test case. It looks like this test " diff --git a/test/testbool.cpp b/test/testbool.cpp index 6d96396c6..2e832a6cb 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -79,7 +79,7 @@ private: // Check... CheckBool checkBool(&tokenizer, &settings, this); checkBool.runChecks(&tokenizer, &settings, this); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); checkBool.runSimplifiedChecks(&tokenizer, &settings, this); } diff --git a/test/testboost.cpp b/test/testboost.cpp index c5ee2fb74..3ccc1a6df 100644 --- a/test/testboost.cpp +++ b/test/testboost.cpp @@ -48,7 +48,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); if (str1 != str2) warn("Unsimplified code in test case"); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 0d0bef50d..96e1653ed 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -53,7 +53,7 @@ private: const std::string str1(tokenizer.tokens()->stringifyList(0,true)); // Assign variable ids - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); @@ -3649,7 +3649,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, filename); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for buffer overruns.. CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this); diff --git a/test/testclass.cpp b/test/testclass.cpp index f2026492f..ffb6d0233 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -191,7 +191,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -303,7 +303,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -541,7 +541,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -666,7 +666,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -900,7 +900,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -1722,7 +1722,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -1977,7 +1977,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -2536,7 +2536,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckClass checkClass(&tokenizer, &settings, this); @@ -2579,7 +2579,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); if (verify && str1 != str2) warn(("Unsimplified code in test case\nstr1="+str1+"\nstr2="+str2).c_str()); @@ -5480,7 +5480,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); CheckClass checkClass(&tokenizer, &settings, this); checkClass.initializerListOrder(); @@ -5508,7 +5508,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); CheckClass checkClass(&tokenizer, &settings, this); checkClass.initializationListUsage(); @@ -5661,7 +5661,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); CheckClass checkClass(&tokenizer, &settings, this); checkClass.checkPureVirtualFunctionCall(); diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 942a50e52..dd6887a20 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -46,7 +46,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check class constructors.. CheckClass checkClass(&tokenizer, &settings, this); diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 82dd8c3a5..f9af04ed5 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -46,7 +46,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for incomplete statements.. CheckOther checkOther(&tokenizer, &settings, this); diff --git a/test/testinternal.cpp b/test/testinternal.cpp index 9edf50e74..dcaafced4 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -53,7 +53,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckInternal checkInternal; diff --git a/test/testio.cpp b/test/testio.cpp index fb497af09..eafbdba73 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -82,7 +82,7 @@ private: checkIO.checkWrongPrintfScanfArguments(); // Simplify token list.. - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); checkIO.checkCoutCerrMisusage(); checkIO.checkFileUsage(); checkIO.invalidScanf(); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index c27b2f6c7..5d32348fe 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -122,7 +122,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.c"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for leaks.. CheckLeakAutoVar c; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index bb2487b34..d71540f8b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -136,7 +136,7 @@ private: Tokenizer tokenizer(settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for memory leaks.. CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, settings, this); @@ -378,7 +378,7 @@ private: std::istringstream istr(code); if (!tokenizer.tokenize(istr, "test.cpp")) return ""; - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const unsigned int varId(Token::findmatch(tokenizer.tokens(), varname)->varId()); @@ -4009,7 +4009,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for memory leaks.. CheckMemoryLeakInClass checkMemoryLeak(&tokenizer, &settings, this); @@ -5129,7 +5129,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, fname ? fname : "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for memory leaks.. CheckMemoryLeakStructMember checkMemoryLeakStructMember(&tokenizer, &settings, this); @@ -5499,7 +5499,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for memory leaks.. CheckMemoryLeakNoVar checkMemoryLeakNoVar(&tokenizer, &settings, this); diff --git a/test/testnonreentrantfunctions.cpp b/test/testnonreentrantfunctions.cpp index 49bd55d24..05437b1d1 100644 --- a/test/testnonreentrantfunctions.cpp +++ b/test/testnonreentrantfunctions.cpp @@ -49,7 +49,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for non reentrant functions.. CheckNonReentrantFunctions checkNonReentrantFunctions(&tokenizer, &settings, this); diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index de8d9440f..9a5124beb 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -98,7 +98,7 @@ private: checkNullPointer.nullPointer(); const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); if (verify && str1 != str2) warn(("Unsimplified code in test case. It looks like this test " diff --git a/test/testobsoletefunctions.cpp b/test/testobsoletefunctions.cpp index 06db77845..31fe66cbe 100644 --- a/test/testobsoletefunctions.cpp +++ b/test/testobsoletefunctions.cpp @@ -81,7 +81,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, filename); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for obsolete functions.. CheckObsoleteFunctions checkObsoleteFunctions(&tokenizer, &settings, this); diff --git a/test/testother.cpp b/test/testother.cpp index 6602cd4e0..916e9d198 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -231,7 +231,7 @@ private: if (runSimpleChecks) { const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); if (str1 != str2) warn(("Unsimplified code in test case\nstr1="+str1+"\nstr2="+str2).c_str()); @@ -567,7 +567,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr,"test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Assert that the symboldatabase is inconsistent.. const SymbolDatabase *symbolDatabase = tokenizer.getSymbolDatabase(); @@ -5933,7 +5933,7 @@ private: // Simplify token list.. CheckOther checkOther(&tokenizer, &settings, this); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); checkOther.checkRedundantCopy(); } void checkRedundantCopy() { diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index 77c098486..aa933ff85 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -46,7 +46,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for postfix operators.. CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9a91fc05e..d076cd44a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -470,7 +470,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); if (simplify) - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(0, !simplify); } @@ -485,7 +485,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, filename); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(0, false); } @@ -500,7 +500,7 @@ private: tokenizer.tokenize(istr, filename); if (simplify) - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // result.. return tokenizer.tokens()->stringifyList(true); @@ -3139,7 +3139,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const char expect[] = "\n\n##file 0\n" "1: void foo ( )\n" @@ -3173,7 +3173,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const char expect[] = "\n\n##file 0\n" "1: void foo ( )\n" @@ -4233,7 +4233,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS(true, tokenizer.validate()); } @@ -4296,7 +4296,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS(true, tokenizer.validate()); } diff --git a/test/teststl.cpp b/test/teststl.cpp index 232c23eb2..a1ab6dbbd 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -144,7 +144,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check.. CheckStl checkStl; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a322beb16..914e1c41b 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -1020,7 +1020,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // force symbol database creation tokenizer.getSymbolDatabase(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f118901ad..21c529a00 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -572,7 +572,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, filename); if (simplify) - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); return tokenizer.tokens()->stringifyList(false, expand, false, true, false, 0, 0); } @@ -888,7 +888,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.c"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS("[test.c:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str()); } @@ -3150,7 +3150,7 @@ private: tokenizer.tokenize(istr, filename); if (simplify) - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // result.. return tokenizer.tokens()->stringifyList(true); @@ -5422,7 +5422,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS("void f ( ) { const char * a ; a = { \"hello more world\" } ; }", tokenizer.tokens()->stringifyList(0, false)); } @@ -5449,7 +5449,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS("void f ( ) { } void g ( ) { }", tokenizer.tokens()->stringifyList(0, false)); } @@ -5472,7 +5472,7 @@ private: std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS("void f ( Foo & foo , Foo * foo2 ) { foo . a = 90 ; foo2 . a = 45 ; }", tokenizer.tokens()->stringifyList(0, false)); } @@ -6064,7 +6064,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index aa3f8a353..c21d82d50 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -79,7 +79,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, filename); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check code.. CheckUninitVar check(&tokenizer, &settings, this); @@ -2071,7 +2071,7 @@ private: tokenizer.tokenize(istr, fname); const std::string str1(tokenizer.tokens()->stringifyList(0,true)); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); const std::string str2(tokenizer.tokens()->stringifyList(0,true)); if (verify && str1 != str2) warn(("Unsimplified code in test case. It looks like this test " diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 4dae5cab2..6b463413b 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -85,7 +85,7 @@ private: Tokenizer tokenizer(&settings, this); std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); + tokenizer.simplifyTokenList2(); // Check for unused private functions.. CheckClass checkClass(&tokenizer, &settings, this);