From fe1101771a59a3dc982325f05dd38533af86e5d8 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 29 Aug 2009 16:08:11 +0700 Subject: [PATCH] Tokenizer: call createLinks() only once. Fixed simplifyIfAssign() and simplifyIfNot() to link() just inseted tokens. No functional change. --- src/tokenize.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index fee82d34f..d4e4d14e3 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2616,11 +2616,12 @@ bool Tokenizer::simplifyIfAssign() if (isNot) tok->next()->deleteNext(); - // Delete paranthesis.. and remember how many there are. - unsigned int numpar = 0; + // Delete paranthesis.. and remember how many there are with + // their links. + std::list braces; while (tok->next()->str() == "(") { - ++numpar; + braces.push_back(tok->next()->link()); tok->deleteNext(); } @@ -2647,8 +2648,14 @@ bool Tokenizer::simplifyIfAssign() tok2->insertToken(tok->strAt(2)); } tok2->insertToken(tok->strAt(1)); - for (unsigned int p = 0; p < numpar; ++p) + + while (! braces.empty()) + { tok2->insertToken("("); + Token::createMutualLinks(tok2->next(), braces.back()); + braces.pop_back(); + } + if (isNot) tok2->next()->insertToken("!"); tok2->insertToken(iswhile ? "while" : "if"); @@ -2743,6 +2750,7 @@ bool Tokenizer::simplifyIfNot() // if( (x) == 0 ) tok->link()->insertToken("("); tok->link()->str("!"); + Token::createMutualLinks(tok->link()->next(), tok); } ret = true; @@ -3011,9 +3019,6 @@ bool Tokenizer::elseif() bool Tokenizer::simplifyRedundantParanthesis() { - if (!createLinks()) - return false; - bool ret = false; for (Token *tok = _tokens; tok; tok = tok->next()) {