From b6b359d1c6b71f8b2382ddd7192e3ad7bbd2b2d6 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sun, 4 Nov 2012 19:54:50 +0100 Subject: [PATCH] Tokenizer::simplifyRedundantParenthesis refactor: Change useless 'while' to 'if' where possible; unify duplicate 'delete [| ]| var' handling code. --- lib/tokenize.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5841d556d..e662757fa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6511,7 +6511,7 @@ bool Tokenizer::simplifyRedundantParenthesis() ret = true; } - while (Token::Match(tok->previous(), "[,;{}(] ( %var% (") && + if (Token::Match(tok->previous(), "[(,;{}] ( %var% (") && tok->link()->previous() == tok->linkAt(2)) { // We have "( func ( *something* ))", remove the outer // parenthesis @@ -6520,18 +6520,10 @@ bool Tokenizer::simplifyRedundantParenthesis() ret = true; } - while (Token::Match(tok->previous(), "[;{] ( delete %var% ) ;")) { - // We have "( delete var )", remove the outer + if (Token::Match(tok->previous(), "[,;{}] ( delete [| ]| %var% ) ;")) { + // We have "( delete [| ]| var )", remove the outer // parenthesis - tok->tokAt(3)->deleteThis(); - tok->deleteThis(); - ret = true; - } - - while (Token::Match(tok->previous(), "[;{] ( delete [ ] %var% ) ;")) { - // We have "( delete [] var )", remove the outer - // parenthesis - tok->tokAt(5)->deleteThis(); + tok->link()->deleteThis(); tok->deleteThis(); ret = true; } @@ -6550,7 +6542,6 @@ bool Tokenizer::simplifyRedundantParenthesis() tok->deleteThis(); tok->deleteNext(); ret = true; - continue; } if (Token::Match(tok->previous(), "[(,!] ( %var% . %var% )")) {