Tokenizer: use 'deleteNext()' or, even better, 'eraseTokens' instead of 'deleteThis()' where possible.
This commit is contained in:
parent
e9546c5042
commit
65213772df
|
@ -744,7 +744,7 @@ static Token *splitDefinitionFromTypedef(Token *tok)
|
||||||
bool isConst = false;
|
bool isConst = false;
|
||||||
|
|
||||||
if (tok->next()->str() == "const") {
|
if (tok->next()->str() == "const") {
|
||||||
tok->next()->deleteThis();
|
tok->deleteNext();
|
||||||
isConst = true;
|
isConst = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,10 +936,10 @@ void Tokenizer::simplifyTypedef()
|
||||||
bool undefinedStruct = false;
|
bool undefinedStruct = false;
|
||||||
if (Token::Match(tok, "typedef enum|struct %type% %type% ;") && tok->strAt(2) == tok->strAt(3)) {
|
if (Token::Match(tok, "typedef enum|struct %type% %type% ;") && tok->strAt(2) == tok->strAt(3)) {
|
||||||
if (tok->next()->str() == "enum") {
|
if (tok->next()->str() == "enum") {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
if (tok->next())
|
if (tok->next())
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
//now the next token to process is 'tok', not 'tok->next()';
|
//now the next token to process is 'tok', not 'tok->next()';
|
||||||
|
@ -2551,8 +2551,8 @@ void Tokenizer::arraySize()
|
||||||
{
|
{
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "%var% [ ] = { %str% }")) {
|
if (Token::Match(tok, "%var% [ ] = { %str% }")) {
|
||||||
tok->tokAt(4)->deleteThis();
|
tok->tokAt(3)->deleteNext();
|
||||||
tok->tokAt(5)->deleteThis();
|
tok->tokAt(4)->deleteNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "%var% [ ] = {")) {
|
if (Token::Match(tok, "%var% [ ] = {")) {
|
||||||
|
@ -2780,8 +2780,8 @@ std::set<std::string> Tokenizer::simplifyTemplatesExpandSpecialized()
|
||||||
tok2->str(name);
|
tok2->str(name);
|
||||||
|
|
||||||
// delete the "template < >"
|
// delete the "template < >"
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
|
||||||
// Use this special template in the code..
|
// Use this special template in the code..
|
||||||
|
@ -2978,7 +2978,7 @@ void Tokenizer::simplifyTemplatesUseDefaultArgumentValues(const std::list<Token
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::list<Token *>::iterator it = eq.begin(); it != eq.end(); ++it) {
|
for (std::list<Token *>::iterator it = eq.begin(); it != eq.end(); ++it) {
|
||||||
(*it)->deleteThis();
|
(*it)->deleteNext();
|
||||||
(*it)->deleteThis();
|
(*it)->deleteThis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4044,7 +4044,7 @@ void Tokenizer::simplifySizeof()
|
||||||
|
|
||||||
// sizeof('x')
|
// sizeof('x')
|
||||||
if (Token::Match(tok, "sizeof ( %any% )") && tok->strAt(2)[0] == '\'') {
|
if (Token::Match(tok, "sizeof ( %any% )") && tok->strAt(2)[0] == '\'') {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
std::ostringstream sz;
|
std::ostringstream sz;
|
||||||
|
@ -4064,7 +4064,7 @@ void Tokenizer::simplifySizeof()
|
||||||
|
|
||||||
// sizeof ("text")
|
// sizeof ("text")
|
||||||
if (Token::Match(tok->next(), "( %str% )")) {
|
if (Token::Match(tok->next(), "( %str% )")) {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
|
@ -4151,7 +4151,7 @@ void Tokenizer::simplifySizeof()
|
||||||
// sizeof( a )
|
// sizeof( a )
|
||||||
else if (Token::Match(tok->next(), "( %var% )") && tok->tokAt(2)->varId() != 0) {
|
else if (Token::Match(tok->next(), "( %var% )") && tok->tokAt(2)->varId() != 0) {
|
||||||
if (sizeOfVar.find(tok->tokAt(2)->varId()) != sizeOfVar.end()) {
|
if (sizeOfVar.find(tok->tokAt(2)->varId()) != sizeOfVar.end()) {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->str(sizeOfVar[tok->varId()]);
|
tok->str(sizeOfVar[tok->varId()]);
|
||||||
|
@ -7013,7 +7013,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
if (tok3->str() == functionName[i]) {
|
if (tok3->str() == functionName[i]) {
|
||||||
Token *par1 = tok3->tokAt(2);
|
Token *par1 = tok3->tokAt(2);
|
||||||
if (!structname.empty()) {
|
if (!structname.empty()) {
|
||||||
par1->deleteThis();
|
par1->deleteNext();
|
||||||
par1->deleteThis();
|
par1->deleteThis();
|
||||||
}
|
}
|
||||||
par1->str(value);
|
par1->str(value);
|
||||||
|
@ -7033,7 +7033,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
if (tok3->str() == functionName[i]) {
|
if (tok3->str() == functionName[i]) {
|
||||||
Token *par = tok3->tokAt(4);
|
Token *par = tok3->tokAt(4);
|
||||||
if (!structname.empty()) {
|
if (!structname.empty()) {
|
||||||
par->deleteThis();
|
par->deleteNext();
|
||||||
par->deleteThis();
|
par->deleteThis();
|
||||||
}
|
}
|
||||||
par->str(value);
|
par->str(value);
|
||||||
|
@ -7376,16 +7376,16 @@ bool Tokenizer::simplifyCalculations()
|
||||||
if (Token::Match(tok->tokAt(-4), "[;{}] %var% = %var% [+-|] 0 ;") &&
|
if (Token::Match(tok->tokAt(-4), "[;{}] %var% = %var% [+-|] 0 ;") &&
|
||||||
tok->strAt(-3) == tok->previous()->str()) {
|
tok->strAt(-3) == tok->previous()->str()) {
|
||||||
tok = tok->tokAt(-3);
|
tok = tok->tokAt(-3);
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
}
|
}
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if (Token::Match(tok->previous(), "[=([,] 0 [+|]") ||
|
} else if (Token::Match(tok->previous(), "[=([,] 0 [+|]") ||
|
||||||
Token::Match(tok->previous(), "return|case 0 [+|]")) {
|
Token::Match(tok->previous(), "return|case 0 [+|]")) {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if (Token::Match(tok->previous(), "[=[(,] 0 * %any% ,|]|)|;|=|%op%") ||
|
} else if (Token::Match(tok->previous(), "[=[(,] 0 * %any% ,|]|)|;|=|%op%") ||
|
||||||
|
@ -7401,7 +7401,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
if (Token::simpleMatch(tok->previous(), "* 1") || Token::simpleMatch(tok, "1 *")) {
|
if (Token::simpleMatch(tok->previous(), "* 1") || Token::simpleMatch(tok, "1 *")) {
|
||||||
if (tok->previous()->isOp())
|
if (tok->previous()->isOp())
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
@ -7422,7 +7422,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
Token::simpleMatch(tok->previous(), "&& 1 )")) {
|
Token::simpleMatch(tok->previous(), "&& 1 )")) {
|
||||||
if (tok->previous()->isOp())
|
if (tok->previous()->isOp())
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
@ -7624,8 +7624,8 @@ void Tokenizer::simplifyGoto()
|
||||||
|
|
||||||
const std::string name(tok->str());
|
const std::string name(tok->str());
|
||||||
|
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
|
||||||
// This label is at the end of the function.. replace all matching goto statements..
|
// This label is at the end of the function.. replace all matching goto statements..
|
||||||
|
@ -7958,8 +7958,7 @@ void Tokenizer::simplifyEnum()
|
||||||
|
|
||||||
/** @todo start substitution check at forward declaration */
|
/** @todo start substitution check at forward declaration */
|
||||||
// delete forward declaration
|
// delete forward declaration
|
||||||
while (start->next() != tok)
|
Token::eraseTokens(start, tok);
|
||||||
start->deleteThis();
|
|
||||||
start->deleteThis();
|
start->deleteThis();
|
||||||
tok = start;
|
tok = start;
|
||||||
continue;
|
continue;
|
||||||
|
@ -9584,11 +9583,11 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
|
||||||
} else if (Token::simpleMatch(tok, "_stscanf (")) {
|
} else if (Token::simpleMatch(tok, "_stscanf (")) {
|
||||||
tok->str("sscanf");
|
tok->str("sscanf");
|
||||||
} else if (Token::Match(tok, "_T ( %str% )")) {
|
} else if (Token::Match(tok, "_T ( %str% )")) {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
} else if (Token::Match(tok, "_T ( %any% )") && tok->strAt(2)[0] == '\'') {
|
} else if (Token::Match(tok, "_T ( %any% )") && tok->strAt(2)[0] == '\'') {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
}
|
}
|
||||||
|
@ -9631,11 +9630,11 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
|
||||||
} else if (Token::simpleMatch(tok, "_stscanf (")) {
|
} else if (Token::simpleMatch(tok, "_stscanf (")) {
|
||||||
tok->str("swscanf");
|
tok->str("swscanf");
|
||||||
} else if (Token::Match(tok, "_T ( %str% )")) {
|
} else if (Token::Match(tok, "_T ( %str% )")) {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
} else if (Token::Match(tok, "_T ( %any% )") && tok->strAt(2)[0] == '\'') {
|
} else if (Token::Match(tok, "_T ( %any% )") && tok->strAt(2)[0] == '\'') {
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
}
|
}
|
||||||
|
@ -9678,7 +9677,7 @@ void Tokenizer::simplifyBorland()
|
||||||
tok2->deleteThis();
|
tok2->deleteThis();
|
||||||
if (Token::simpleMatch(tok2, "{")) {
|
if (Token::simpleMatch(tok2, "{")) {
|
||||||
Token::eraseTokens(tok2, tok2->link());
|
Token::eraseTokens(tok2, tok2->link());
|
||||||
tok2->deleteThis();
|
tok2->deleteNext();
|
||||||
tok2->deleteThis();
|
tok2->deleteThis();
|
||||||
|
|
||||||
// insert "; __property ;"
|
// insert "; __property ;"
|
||||||
|
@ -9868,7 +9867,7 @@ void Tokenizer::removeUnnecessaryQualification()
|
||||||
if (_settings && _settings->isEnabled("portability"))
|
if (_settings && _settings->isEnabled("portability"))
|
||||||
unnecessaryQualificationError(tok, qualification);
|
unnecessaryQualificationError(tok, qualification);
|
||||||
|
|
||||||
tok->deleteThis();
|
tok->deleteNext();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue