From 11be2f79a60704e16a1d0e7eee1130f1ce58c633 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 19 Aug 2015 19:29:32 +0200 Subject: [PATCH] Refactorization: Removed some redundant conditions and an unused syntax check from tokenize.cpp --- lib/tokenize.cpp | 59 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0ad6b001d..70cbf8d94 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2215,33 +2215,29 @@ static Token *skipTernaryOp(Token *tok) Token * Tokenizer::startOfFunction(Token * tok) const { - if (tok && tok->str() == ")") { - tok = tok->next(); - while (tok && tok->str() != "{") { - if (isCPP() && Token::Match(tok, "const|volatile")) { - tok = tok->next(); - } else if (isCPP() && tok->str() == "noexcept") { - tok = tok->next(); - if (tok && tok->str() == "(") { - tok = tok->link()->next(); - } - } else if (isCPP() && tok->str() == "throw" && tok->next() && tok->next()->str() == "(") { - tok = tok->next()->link()->next(); + tok = tok->next(); + while (tok && tok->str() != "{") { + if (isCPP() && Token::Match(tok, "const|volatile")) { + tok = tok->next(); + } else if (isCPP() && tok->str() == "noexcept") { + tok = tok->next(); + if (tok && tok->str() == "(") { + tok = tok->link()->next(); } - // unknown macros ") MACRO {" and ") MACRO(...) {" - else if (tok->isUpperCaseName()) { - tok = tok->next(); - if (tok && tok->str() == "(") { - tok = tok->link()->next(); - } - } else - return nullptr; + } else if (isCPP() && tok->str() == "throw" && tok->next() && tok->next()->str() == "(") { + tok = tok->next()->link()->next(); } - - return tok; + // unknown macros ") MACRO {" and ") MACRO(...) {" + else if (tok->isUpperCaseName()) { + tok = tok->next(); + if (tok && tok->str() == "(") { + tok = tok->link()->next(); + } + } else + return nullptr; } - return nullptr; + return tok; } const Token * Tokenizer::startOfExecutableScope(const Token * tok) @@ -2359,12 +2355,6 @@ void Tokenizer::simplifyTemplates() if (isC()) return; - for (const Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str()[0] == '=' && tok->str().length() > 2) { - std::cout << "BAD TOKEN" << std::endl; - } - } - for (Token *tok = list.front(); tok; tok = tok->next()) { // #2648 - simple fix for sizeof used as template parameter // TODO: this is a bit hardcoded. make a bit more generic @@ -3096,12 +3086,6 @@ bool Tokenizer::simplifySizeof() if (tok->str() != "sizeof") continue; - if (!tok->next()) - break; - - if (tok->strAt(1) == "sizeof") - continue; - if (Token::simpleMatch(tok->next(), ". . .")) { tok->deleteNext(3); } @@ -4202,10 +4186,7 @@ bool Tokenizer::removeRedundantConditions() bool ret = false; for (Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str() != "if") - continue; - - if (!Token::Match(tok->next(), "( %bool% ) {")) + if (!Token::Match(tok, "if ( %bool% ) {")) continue; // Find matching else