Refactorization: Removed some redundant conditions and an unused syntax check from tokenize.cpp
This commit is contained in:
parent
a720153e1e
commit
11be2f79a6
|
@ -2215,33 +2215,29 @@ static Token *skipTernaryOp(Token *tok)
|
||||||
|
|
||||||
Token * Tokenizer::startOfFunction(Token * tok) const
|
Token * Tokenizer::startOfFunction(Token * tok) const
|
||||||
{
|
{
|
||||||
if (tok && tok->str() == ")") {
|
tok = tok->next();
|
||||||
tok = tok->next();
|
while (tok && tok->str() != "{") {
|
||||||
while (tok && tok->str() != "{") {
|
if (isCPP() && Token::Match(tok, "const|volatile")) {
|
||||||
if (isCPP() && Token::Match(tok, "const|volatile")) {
|
tok = tok->next();
|
||||||
tok = tok->next();
|
} else if (isCPP() && tok->str() == "noexcept") {
|
||||||
} else if (isCPP() && tok->str() == "noexcept") {
|
tok = tok->next();
|
||||||
tok = tok->next();
|
if (tok && tok->str() == "(") {
|
||||||
if (tok && tok->str() == "(") {
|
tok = tok->link()->next();
|
||||||
tok = tok->link()->next();
|
|
||||||
}
|
|
||||||
} else if (isCPP() && tok->str() == "throw" && tok->next() && tok->next()->str() == "(") {
|
|
||||||
tok = tok->next()->link()->next();
|
|
||||||
}
|
}
|
||||||
// unknown macros ") MACRO {" and ") MACRO(...) {"
|
} else if (isCPP() && tok->str() == "throw" && tok->next() && tok->next()->str() == "(") {
|
||||||
else if (tok->isUpperCaseName()) {
|
tok = tok->next()->link()->next();
|
||||||
tok = tok->next();
|
|
||||||
if (tok && tok->str() == "(") {
|
|
||||||
tok = tok->link()->next();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
// unknown macros ") MACRO {" and ") MACRO(...) {"
|
||||||
return tok;
|
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)
|
const Token * Tokenizer::startOfExecutableScope(const Token * tok)
|
||||||
|
@ -2359,12 +2355,6 @@ void Tokenizer::simplifyTemplates()
|
||||||
if (isC())
|
if (isC())
|
||||||
return;
|
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()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
// #2648 - simple fix for sizeof used as template parameter
|
// #2648 - simple fix for sizeof used as template parameter
|
||||||
// TODO: this is a bit hardcoded. make a bit more generic
|
// TODO: this is a bit hardcoded. make a bit more generic
|
||||||
|
@ -3096,12 +3086,6 @@ bool Tokenizer::simplifySizeof()
|
||||||
if (tok->str() != "sizeof")
|
if (tok->str() != "sizeof")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!tok->next())
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (tok->strAt(1) == "sizeof")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (Token::simpleMatch(tok->next(), ". . .")) {
|
if (Token::simpleMatch(tok->next(), ". . .")) {
|
||||||
tok->deleteNext(3);
|
tok->deleteNext(3);
|
||||||
}
|
}
|
||||||
|
@ -4202,10 +4186,7 @@ bool Tokenizer::removeRedundantConditions()
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->str() != "if")
|
if (!Token::Match(tok, "if ( %bool% ) {"))
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!Token::Match(tok->next(), "( %bool% ) {"))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Find matching else
|
// Find matching else
|
||||||
|
|
Loading…
Reference in New Issue