diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7ed14f589..48329269b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3306,87 +3306,6 @@ bool Tokenizer::simplifyTokenList1() 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;