Refactorizations:

- Removed some duplicate nullpointer checks
- Simplified tok->link() on '<' usage.
This commit is contained in:
PKEuS 2014-05-18 17:04:52 +02:00
parent 65916e027c
commit b162560755
1 changed files with 23 additions and 28 deletions

View File

@ -8613,11 +8613,8 @@ void Tokenizer::simplifyComma()
} }
// Skip unhandled template specifiers.. // Skip unhandled template specifiers..
if (Token::Match(tok, "%var% <")) { if (tok->link() && tok->str() == "<")
Token* tok2 = tok->next()->link(); tok = tok->link();
if (tok2)
tok = tok2;
}
if (!tok->next() || tok->str() != ",") if (!tok->next() || tok->str() != ",")
continue; continue;
@ -8629,27 +8626,25 @@ void Tokenizer::simplifyComma()
tok->str(";"); tok->str(";");
} }
if (tok->previous() && tok->tokAt(-2)) { if (Token::Match(tok->tokAt(-2), "delete %var% , %var% ;") &&
if (Token::Match(tok->tokAt(-2), "delete %var% , %var% ;") && tok->next()->varId() != 0) {
tok->next()->varId() != 0) { // Handle "delete a, b;"
// Handle "delete a, b;" tok->str(";");
tok->str(";"); tok->insertToken("delete");
tok->insertToken("delete"); } else if (tok->tokAt(-2)) {
} else { bool replace = false;
bool replace = false; for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) {
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) { if (tok2->str() == "=") {
if (tok2->str() == "=") { // Handle "a = 0, b = 0;"
// Handle "a = 0, b = 0;" replace = true;
replace = true; } else if (Token::Match(tok2, "delete %var%") ||
} else if (Token::Match(tok2, "delete %var%") || Token::Match(tok2, "delete [ ] %var%")) {
Token::Match(tok2, "delete [ ] %var%")) { // Handle "delete a, a = 0;"
// Handle "delete a, a = 0;" replace = true;
replace = true; } else if (Token::Match(tok2, "[?:;,{}()]")) {
} else if (Token::Match(tok2, "[?:;,{}()]")) { if (replace && Token::Match(tok2, "[;{}]"))
if (replace && Token::Match(tok2, "[;{}]")) tok->str(";");
tok->str(";"); break;
break;
}
} }
} }
} }
@ -9773,7 +9768,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
tok->deleteNext(); tok->deleteNext();
tok->deleteThis(); tok->deleteThis();
tok->deleteNext(); tok->deleteNext();
while (tok->next() && Token::Match(tok->next(), "_T ( %char%|%str% )")) { while (Token::Match(tok->next(), "_T ( %char%|%str% )")) {
tok->next()->deleteNext(); tok->next()->deleteNext();
tok->next()->deleteThis(); tok->next()->deleteThis();
tok->next()->deleteNext(); tok->next()->deleteNext();
@ -9886,7 +9881,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
tok->deleteThis(); tok->deleteThis();
tok->deleteNext(); tok->deleteNext();
tok->isLong(true); tok->isLong(true);
while (tok->next() && Token::Match(tok->next(), "_T ( %char%|%str% )")) { while (Token::Match(tok->next(), "_T ( %char%|%str% )")) {
tok->next()->deleteNext(); tok->next()->deleteNext();
tok->next()->deleteThis(); tok->next()->deleteThis();
tok->next()->deleteNext(); tok->next()->deleteNext();