1)Remove newly copy of 'eraseTokens' and replace every occurrence with 'deleteNext' with right parameter.
2)General improvements to code.
This commit is contained in:
parent
76972e8dd3
commit
4de5d87078
|
@ -1551,7 +1551,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
--innerIndentlevel;
|
--innerIndentlevel;
|
||||||
}
|
}
|
||||||
while (innerIndentlevel == 0 && Token::Match(tok3, "[{};] if|ifv|else { continue ; }")) {
|
while (innerIndentlevel == 0 && Token::Match(tok3, "[{};] if|ifv|else { continue ; }")) {
|
||||||
Token::eraseTokens(tok3, 5);
|
tok3->deleteNext(5);
|
||||||
if (Token::simpleMatch(tok3->next(), "else"))
|
if (Token::simpleMatch(tok3->next(), "else"))
|
||||||
tok3->deleteNext();
|
tok3->deleteNext();
|
||||||
}
|
}
|
||||||
|
@ -1559,8 +1559,8 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
if (Token::simpleMatch(tok2, "while1 { if { dealloc ; return ; } }")) {
|
if (Token::simpleMatch(tok2, "while1 { if { dealloc ; return ; } }")) {
|
||||||
tok2->str(";");
|
tok2->str(";");
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
Token::eraseTokens(tok2->tokAt(4), 2);
|
tok2->tokAt(4)->deleteNext(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1575,7 +1575,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// Replace "{ }" with ";"
|
// Replace "{ }" with ";"
|
||||||
if (Token::simpleMatch(tok2->next(), "{ }")) {
|
if (Token::simpleMatch(tok2->next(), "{ }")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
tok2->insertToken(";");
|
tok2->insertToken(";");
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
@ -1600,7 +1600,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// outer/inner if blocks. Remove outer condition..
|
// outer/inner if blocks. Remove outer condition..
|
||||||
else if (Token::Match(tok2->next(), "if|if(var) { if return use ; }")) {
|
else if (Token::Match(tok2->next(), "if|if(var) { if return use ; }")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
tok2->tokAt(4)->deleteNext();
|
tok2->tokAt(4)->deleteNext();
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
@ -1615,19 +1615,19 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// Reduce "if X ; else X ;" => "X ;"
|
// Reduce "if X ; else X ;" => "X ;"
|
||||||
else if (Token::Match(tok2->next(), "if %var% ; else %var% ;") &&
|
else if (Token::Match(tok2->next(), "if %var% ; else %var% ;") &&
|
||||||
tok2->strAt(2) == tok2->strAt(5)) {
|
tok2->strAt(2) == tok2->strAt(5)) {
|
||||||
Token::eraseTokens(tok2, 4);
|
tok2->deleteNext(4);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "if continue ; if continue ;" => "if continue ;"
|
// Reduce "if continue ; if continue ;" => "if continue ;"
|
||||||
else if (Token::simpleMatch(tok2->next(), "if continue ; if continue ;")) {
|
else if (Token::simpleMatch(tok2->next(), "if continue ; if continue ;")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "if return ; alloc ;" => "alloc ;"
|
// Reduce "if return ; alloc ;" => "alloc ;"
|
||||||
else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;")) {
|
else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1636,31 +1636,31 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// Remove "if"
|
// Remove "if"
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
// Remove "; else return"
|
// Remove "; else return"
|
||||||
Token::eraseTokens(tok2->next(), 3);
|
tok2->next()->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "if ; else %var% ;" => "if %var% ;"
|
// Reduce "if ; else %var% ;" => "if %var% ;"
|
||||||
else if (Token::Match(tok2->next(), "if ; else %var% ;")) {
|
else if (Token::Match(tok2->next(), "if ; else %var% ;")) {
|
||||||
Token::eraseTokens(tok2->next(), 2);
|
tok2->next()->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "if ; else" => "if"
|
// Reduce "if ; else" => "if"
|
||||||
else if (Token::simpleMatch(tok2->next(), "if ; else")) {
|
else if (Token::simpleMatch(tok2->next(), "if ; else")) {
|
||||||
Token::eraseTokens(tok2->next(), 2);
|
tok2->next()->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "if return ; else|if return|continue ;" => "if return ;"
|
// Reduce "if return ; else|if return|continue ;" => "if return ;"
|
||||||
else if (Token::Match(tok2->next(), "if return ; else|if return|continue|break ;")) {
|
else if (Token::Match(tok2->next(), "if return ; else|if return|continue|break ;")) {
|
||||||
Token::eraseTokens(tok2->tokAt(3), 3);
|
tok2->tokAt(3)->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "if continue|break ; else|if return ;" => "if return ;"
|
// Reduce "if continue|break ; else|if return ;" => "if return ;"
|
||||||
else if (Token::Match(tok2->next(), "if continue|break ; if|else return ;")) {
|
else if (Token::Match(tok2->next(), "if continue|break ; if|else return ;")) {
|
||||||
Token::eraseTokens(tok2->next(), 3);
|
tok2->next()->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1673,7 +1673,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// Delete "if { dealloc|assign|use ; return ; }"
|
// Delete "if { dealloc|assign|use ; return ; }"
|
||||||
else if (Token::Match(tok2, "[;{}] if { dealloc|assign|use ; return ; }") &&
|
else if (Token::Match(tok2, "[;{}] if { dealloc|assign|use ; return ; }") &&
|
||||||
!Token::findmatch(tok, "if {| alloc ;")) {
|
!Token::findmatch(tok, "if {| alloc ;")) {
|
||||||
Token::eraseTokens(tok2, 7);
|
tok2->deleteNext(7);
|
||||||
if (Token::simpleMatch(tok2->next(), "else"))
|
if (Token::simpleMatch(tok2->next(), "else"))
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
done = false;
|
done = false;
|
||||||
|
@ -1682,7 +1682,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// Remove "if { dealloc ; callfunc ; } !!else|return"
|
// Remove "if { dealloc ; callfunc ; } !!else|return"
|
||||||
else if (Token::Match(tok2->next(), "if { dealloc|assign ; callfunc ; }") &&
|
else if (Token::Match(tok2->next(), "if { dealloc|assign ; callfunc ; }") &&
|
||||||
!Token::Match(tok2->tokAt(8), "else|return")) {
|
!Token::Match(tok2->tokAt(8), "else|return")) {
|
||||||
Token::eraseTokens(tok2, 7);
|
tok2->deleteNext(7);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1691,7 +1691,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// Reduce "alloc while(!var) alloc ;" => "alloc ;"
|
// Reduce "alloc while(!var) alloc ;" => "alloc ;"
|
||||||
if (Token::Match(tok2, "[;{}] alloc ; while(!var) alloc ;")) {
|
if (Token::Match(tok2, "[;{}] alloc ; while(!var) alloc ;")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1722,7 +1722,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// Reduce "if(!var) exit ;" => ";"
|
// Reduce "if(!var) exit ;" => ";"
|
||||||
if (Token::simpleMatch(tok2, "; if(!var) exit ;")) {
|
if (Token::simpleMatch(tok2, "; if(!var) exit ;")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1737,7 +1737,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
tok2->str("if(var)");
|
tok2->str("if(var)");
|
||||||
|
|
||||||
// remove the "; else"
|
// remove the "; else"
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
} else {
|
} else {
|
||||||
// remove the "if*"
|
// remove the "if*"
|
||||||
tok2->deleteNext();
|
tok2->deleteNext();
|
||||||
|
@ -1762,13 +1762,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// Reduce "while1 if break ;" => ";"
|
// Reduce "while1 if break ;" => ";"
|
||||||
if (Token::simpleMatch(tok2, "while1 if break ;")) {
|
if (Token::simpleMatch(tok2, "while1 if break ;")) {
|
||||||
tok2->str(";");
|
tok2->str(";");
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete if block: "alloc; if return use ;"
|
// Delete if block: "alloc; if return use ;"
|
||||||
if (Token::Match(tok2, "alloc ; if return use ; !!else")) {
|
if (Token::Match(tok2, "alloc ; if return use ; !!else")) {
|
||||||
Token::eraseTokens(tok2, 4);
|
tok2->deleteNext(4);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1793,33 +1793,33 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// Remove the "if break|continue ;" that follows "dealloc ; alloc ;"
|
// Remove the "if break|continue ;" that follows "dealloc ; alloc ;"
|
||||||
if (! _settings->experimental && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;")) {
|
if (! _settings->experimental && Token::Match(tok2, "dealloc ; alloc ; if break|continue ;")) {
|
||||||
Token::eraseTokens(tok2->tokAt(3), 2);
|
tok2->tokAt(3)->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if break ; break ; => break ;
|
// if break ; break ; => break ;
|
||||||
if (Token::Match(tok2->previous(), "[;{}] if break ; break ;")) {
|
if (Token::Match(tok2->previous(), "[;{}] if break ; break ;")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "do { dealloc ; alloc ; } while(var) ;" => ";"
|
// Reduce "do { dealloc ; alloc ; } while(var) ;" => ";"
|
||||||
if (Token::simpleMatch(tok2->next(), "do { dealloc ; alloc ; } while(var) ;")) {
|
if (Token::simpleMatch(tok2->next(), "do { dealloc ; alloc ; } while(var) ;")) {
|
||||||
Token::eraseTokens(tok2, 8);
|
tok2->deleteNext(8);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "do { alloc ; } " => "alloc ;"
|
// Reduce "do { alloc ; } " => "alloc ;"
|
||||||
/** @todo If the loop "do { alloc ; }" can be executed twice, reduce it to "loop alloc ;" */
|
/** @todo If the loop "do { alloc ; }" can be executed twice, reduce it to "loop alloc ;" */
|
||||||
if (Token::simpleMatch(tok2->next(), "do { alloc ; }")) {
|
if (Token::simpleMatch(tok2->next(), "do { alloc ; }")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
tok2->tokAt(2)->deleteNext();
|
tok2->tokAt(2)->deleteNext();
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "loop break ; => ";"
|
// Reduce "loop break ; => ";"
|
||||||
if (Token::Match(tok2->next(), "loop break|continue ;")) {
|
if (Token::Match(tok2->next(), "loop break|continue ;")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1831,19 +1831,19 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// Reduce "loop if break|continue ; !!else" => ";"
|
// Reduce "loop if break|continue ; !!else" => ";"
|
||||||
if (Token::Match(tok2->next(), "loop if break|continue ; !!else")) {
|
if (Token::Match(tok2->next(), "loop if break|continue ; !!else")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce "loop { if break|continue ; !!else" => "loop {"
|
// Reduce "loop { if break|continue ; !!else" => "loop {"
|
||||||
if (Token::Match(tok2, "loop { if break|continue ; !!else")) {
|
if (Token::Match(tok2, "loop { if break|continue ; !!else")) {
|
||||||
Token::eraseTokens(tok2->next(), 3);
|
tok2->next()->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace "do ; loop ;" with ";"
|
// Replace "do ; loop ;" with ";"
|
||||||
if (Token::simpleMatch(tok2, "; loop ;")) {
|
if (Token::simpleMatch(tok2, "; loop ;")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1875,7 +1875,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// loop { use ; callfunc ; } => use ;
|
// loop { use ; callfunc ; } => use ;
|
||||||
// assume that the "callfunc" is not noreturn
|
// assume that the "callfunc" is not noreturn
|
||||||
if (Token::simpleMatch(tok2, "loop { use ; callfunc ; }")) {
|
if (Token::simpleMatch(tok2, "loop { use ; callfunc ; }")) {
|
||||||
Token::eraseTokens(tok2, 6);
|
tok2->deleteNext(6);
|
||||||
tok2->str("use");
|
tok2->str("use");
|
||||||
tok2->insertToken(";");
|
tok2->insertToken(";");
|
||||||
done = false;
|
done = false;
|
||||||
|
@ -1883,7 +1883,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
|
|
||||||
// Delete if block in "alloc ; if(!var) return ;"
|
// Delete if block in "alloc ; if(!var) return ;"
|
||||||
if (Token::simpleMatch(tok2, "alloc ; if(!var) return ;")) {
|
if (Token::simpleMatch(tok2, "alloc ; if(!var) return ;")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1902,13 +1902,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// malloc - realloc => alloc ; dealloc ; alloc ;
|
// malloc - realloc => alloc ; dealloc ; alloc ;
|
||||||
// Reduce "[;{}] alloc ; dealloc ; alloc ;" => "[;{}] alloc ;"
|
// Reduce "[;{}] alloc ; dealloc ; alloc ;" => "[;{}] alloc ;"
|
||||||
if (Token::Match(tok2, "[;{}] alloc ; dealloc ; alloc ;")) {
|
if (Token::Match(tok2, "[;{}] alloc ; dealloc ; alloc ;")) {
|
||||||
Token::eraseTokens(tok2, 4);
|
tok2->deleteNext(4);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use; dealloc; => dealloc;
|
// use; dealloc; => dealloc;
|
||||||
if (Token::Match(tok2, "[;{}] use ; dealloc ;")) {
|
if (Token::Match(tok2, "[;{}] use ; dealloc ;")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1921,28 +1921,26 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
// use; if| use; => use;
|
// use; if| use; => use;
|
||||||
while (Token::Match(tok2, "[;{}] use ; if| use ;")) {
|
while (Token::Match(tok2, "[;{}] use ; if| use ;")) {
|
||||||
Token *t = tok2->tokAt(2);
|
Token *t = tok2->tokAt(2);
|
||||||
Token::eraseTokens(t, 2);
|
t->deleteNext(2+(t->str()=="if"));
|
||||||
if (t->next() && t->next()->str() == ";")
|
|
||||||
t->deleteNext();
|
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete first part in "use ; return use ;"
|
// Delete first part in "use ; return use ;"
|
||||||
if (Token::Match(tok2, "[;{}] use ; return use ;")) {
|
if (Token::Match(tok2, "[;{}] use ; return use ;")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try/catch
|
// try/catch
|
||||||
if (Token::simpleMatch(tok2, "try ; catch exit ;")) {
|
if (Token::simpleMatch(tok2, "try ; catch exit ;")) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
tok2->deleteThis();
|
tok2->deleteThis();
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete second case in "case ; case ;"
|
// Delete second case in "case ; case ;"
|
||||||
while (Token::simpleMatch(tok2, "case ; case ;")) {
|
while (Token::simpleMatch(tok2, "case ; case ;")) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1341,7 +1341,7 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &c
|
||||||
tok->str("0");
|
tok->str("0");
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1414,7 +1414,7 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &c
|
||||||
|
|
||||||
for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next()) {
|
for (Token *tok = const_cast<Token *>(tokenizer.tokens()); tok; tok = tok->next()) {
|
||||||
while (Token::Match(tok, "(|%oror% %any% %oror% 1")) {
|
while (Token::Match(tok, "(|%oror% %any% %oror% 1")) {
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
if (tok->tokAt(-3))
|
if (tok->tokAt(-3))
|
||||||
tok = tok->tokAt(-3);
|
tok = tok->tokAt(-3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ std::string Token::strValue() const
|
||||||
|
|
||||||
void Token::deleteNext(unsigned long index)
|
void Token::deleteNext(unsigned long index)
|
||||||
{
|
{
|
||||||
while(_next && index--) {
|
while (_next && index--) {
|
||||||
Token *n = _next;
|
Token *n = _next;
|
||||||
_next = n->next();
|
_next = n->next();
|
||||||
delete n;
|
delete n;
|
||||||
|
@ -869,16 +869,6 @@ void Token::eraseTokens(Token *begin, const Token *end)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Token::eraseTokens(Token *tok, unsigned long index)
|
|
||||||
{
|
|
||||||
if (!tok)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (tok->next() && index--) {
|
|
||||||
tok->deleteNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Token::createMutualLinks(Token *begin, Token *end)
|
void Token::createMutualLinks(Token *begin, Token *end)
|
||||||
{
|
{
|
||||||
assert(begin != NULL);
|
assert(begin != NULL);
|
||||||
|
|
10
lib/token.h
10
lib/token.h
|
@ -279,16 +279,6 @@ public:
|
||||||
*/
|
*/
|
||||||
static void eraseTokens(Token *begin, const Token *end);
|
static void eraseTokens(Token *begin, const Token *end);
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete tokens after tok 'index' times. It's a replacement
|
|
||||||
* of the consecutive calls to 'deleteNext', more efficient
|
|
||||||
* than calling 'Token::eraseTokens(tok, tok->tokAt(index+1))'.
|
|
||||||
*
|
|
||||||
* @param tok Tokens after this will be erased.
|
|
||||||
* @param index How many times it should remove the next token.
|
|
||||||
*/
|
|
||||||
static void eraseTokens(Token *tok, unsigned long index);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert new token after this token. This function will handle
|
* Insert new token after this token. This function will handle
|
||||||
* relations between next and previous token also.
|
* relations between next and previous token also.
|
||||||
|
|
147
lib/tokenize.cpp
147
lib/tokenize.cpp
|
@ -936,7 +936,7 @@ 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") {
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
if (tok->next())
|
if (tok->next())
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
@ -1429,7 +1429,7 @@ void Tokenizer::simplifyTypedef()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t i = classLevel; i < spaceInfo.size(); ++i) {
|
for (std::size_t i = classLevel; i < spaceInfo.size(); ++i) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
}
|
}
|
||||||
simplifyType = true;
|
simplifyType = true;
|
||||||
} else if ((inScope && !exitThisScope) || inMemberFunc) {
|
} else if ((inScope && !exitThisScope) || inMemberFunc) {
|
||||||
|
@ -1437,7 +1437,7 @@ void Tokenizer::simplifyTypedef()
|
||||||
// Don't replace this typename if it's preceded by "::" unless it's a namespace
|
// Don't replace this typename if it's preceded by "::" unless it's a namespace
|
||||||
if (!spaceInfo.empty() && (tok2->strAt(-2) == spaceInfo[0].className) && spaceInfo[0].isNamespace) {
|
if (!spaceInfo.empty() && (tok2->strAt(-2) == spaceInfo[0].className) && spaceInfo[0].isNamespace) {
|
||||||
tok2 = tok2->tokAt(-3);
|
tok2 = tok2->tokAt(-3);
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
simplifyType = true;
|
simplifyType = true;
|
||||||
}
|
}
|
||||||
|
@ -1910,7 +1910,7 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
(tok->isName() || tok->isNumber()) &&
|
(tok->isName() || tok->isNumber()) &&
|
||||||
(tok->tokAt(2)->isName() || tok->tokAt(2)->isNumber())) {
|
(tok->tokAt(2)->isName() || tok->tokAt(2)->isNumber())) {
|
||||||
tok->str(tok->str() + tok->strAt(2));
|
tok->str(tok->str() + tok->strAt(2));
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
if (tok->previous())
|
if (tok->previous())
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
}
|
}
|
||||||
|
@ -1943,7 +1943,7 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
const bool isJava(_files[0].find(".java") != std::string::npos);
|
const bool isJava(_files[0].find(".java") != std::string::npos);
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (isJava && Token::Match(tok, ") throws %var% {")) {
|
if (isJava && Token::Match(tok, ") throws %var% {")) {
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
} else if (tok->str() == "private")
|
} else if (tok->str() == "private")
|
||||||
tok->str("private:");
|
tok->str("private:");
|
||||||
else if (tok->str() == "protected")
|
else if (tok->str() == "protected")
|
||||||
|
@ -2791,7 +2791,7 @@ std::set<std::string> Tokenizer::simplifyTemplatesExpandSpecialized()
|
||||||
tok2->str(name);
|
tok2->str(name);
|
||||||
|
|
||||||
// delete the "template < >"
|
// delete the "template < >"
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
|
|
||||||
// Use this special template in the code..
|
// Use this special template in the code..
|
||||||
|
@ -3101,7 +3101,7 @@ void Tokenizer::simplifyTemplatesInstantiate(const Token *tok,
|
||||||
if (Token::Match(tok2, "%var% < sizeof ( %type% ) >") && tok2->tokAt(4)->isStandardType()) {
|
if (Token::Match(tok2, "%var% < sizeof ( %type% ) >") && tok2->tokAt(4)->isStandardType()) {
|
||||||
Token * const tok3 = tok2->next();
|
Token * const tok3 = tok2->next();
|
||||||
const unsigned int sz = sizeOfType(tok3->tokAt(3));
|
const unsigned int sz = sizeOfType(tok3->tokAt(3));
|
||||||
Token::eraseTokens(tok3, 4);
|
tok3->deleteNext(4);
|
||||||
tok3->insertToken(MathLib::toString<unsigned int>(sz));
|
tok3->insertToken(MathLib::toString<unsigned int>(sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4047,7 +4047,7 @@ void Tokenizer::simplifySizeof()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Token::simpleMatch(tok->next(), ". . .")) {
|
if (Token::simpleMatch(tok->next(), ". . .")) {
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sizeof 'x'
|
// sizeof 'x'
|
||||||
|
@ -4162,7 +4162,7 @@ void Tokenizer::simplifySizeof()
|
||||||
|
|
||||||
if (Token::simpleMatch(tok->next(), "( * )")) {
|
if (Token::simpleMatch(tok->next(), "( * )")) {
|
||||||
tok->str(MathLib::toString<unsigned long>(sizeOfType(tok->tokAt(2))));
|
tok->str(MathLib::toString<unsigned long>(sizeOfType(tok->tokAt(2))));
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sizeof( a )
|
// sizeof( a )
|
||||||
|
@ -4182,7 +4182,7 @@ void Tokenizer::simplifySizeof()
|
||||||
unsigned int size = sizeOfType(tok->tokAt(2));
|
unsigned int size = sizeOfType(tok->tokAt(2));
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
tok->str(MathLib::toString<unsigned int>(size));
|
tok->str(MathLib::toString<unsigned int>(size));
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4264,7 +4264,7 @@ bool Tokenizer::simplifyTokenList()
|
||||||
// change array to pointer..
|
// change array to pointer..
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "%type% %var% [ ] [,;=]")) {
|
if (Token::Match(tok, "%type% %var% [ ] [,;=]")) {
|
||||||
Token::eraseTokens(tok->next(), 2);
|
tok->next()->deleteNext(2);
|
||||||
tok->insertToken("*");
|
tok->insertToken("*");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4309,7 +4309,7 @@ bool Tokenizer::simplifyTokenList()
|
||||||
&& (Token::Match(tok->next(), "* ( %var% + %num% )") ||
|
&& (Token::Match(tok->next(), "* ( %var% + %num% )") ||
|
||||||
Token::Match(tok->next(), "* ( %var% + %var% )"))) {
|
Token::Match(tok->next(), "* ( %var% + %var% )"))) {
|
||||||
// remove '* ('
|
// remove '* ('
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
// '+'->'['
|
// '+'->'['
|
||||||
|
@ -4358,14 +4358,14 @@ bool Tokenizer::simplifyTokenList()
|
||||||
const unsigned int varid(tok->next()->varId());
|
const unsigned int varid(tok->next()->varId());
|
||||||
|
|
||||||
// Delete the "%var% ="
|
// Delete the "%var% ="
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
// Change function name "realloc" to "free"
|
// Change function name "realloc" to "free"
|
||||||
tok->next()->str("free");
|
tok->next()->str("free");
|
||||||
|
|
||||||
// delete the ", 0"
|
// delete the ", 0"
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
// goto the ";"
|
// goto the ";"
|
||||||
tok = tok->tokAt(2);
|
tok = tok->tokAt(2);
|
||||||
|
@ -4384,7 +4384,7 @@ bool Tokenizer::simplifyTokenList()
|
||||||
tok->str("malloc");
|
tok->str("malloc");
|
||||||
|
|
||||||
// delete "0 ,"
|
// delete "0 ,"
|
||||||
Token::eraseTokens(tok->next(), 2);
|
tok->next()->deleteNext(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4429,7 +4429,7 @@ bool Tokenizer::simplifyTokenList()
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << Token::getStrLength(tok->tokAt(2));
|
ostr << Token::getStrLength(tok->tokAt(2));
|
||||||
tok->str(ostr.str());
|
tok->str(ostr.str());
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4542,11 +4542,12 @@ void Tokenizer::removeRedundantAssignment()
|
||||||
if (!localvars.empty()) {
|
if (!localvars.empty()) {
|
||||||
for (Token *tok2 = tok->next(); tok2 && tok2 != end;) {
|
for (Token *tok2 = tok->next(); tok2 && tok2 != end;) {
|
||||||
if (Token::Match(tok2, "[;{}] %type% %var% ;") && localvars.find(tok2->tokAt(2)->varId()) != localvars.end()) {
|
if (Token::Match(tok2, "[;{}] %type% %var% ;") && localvars.find(tok2->tokAt(2)->varId()) != localvars.end()) {
|
||||||
Token::eraseTokens(tok2, 3);
|
tok2->deleteNext(3);
|
||||||
} else if (Token::Match(tok2, "[;{}] %type% * %var% ;") && localvars.find(tok2->tokAt(3)->varId()) != localvars.end()) {
|
} else if ((Token::Match(tok2, "[;{}] %type% * %var% ;") &&
|
||||||
Token::eraseTokens(tok2, 4);
|
localvars.find(tok2->tokAt(3)->varId()) != localvars.end()) ||
|
||||||
} else if (Token::Match(tok2, "[;{}] %var% = %any% ;") && localvars.find(tok2->next()->varId()) != localvars.end()) {
|
(Token::Match(tok2, "[;{}] %var% = %any% ;") &&
|
||||||
Token::eraseTokens(tok2, 4);
|
localvars.find(tok2->next()->varId()) != localvars.end())) {
|
||||||
|
tok2->deleteNext(4);
|
||||||
} else
|
} else
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
|
@ -4677,7 +4678,7 @@ bool Tokenizer::removeRedundantConditions()
|
||||||
else
|
else
|
||||||
tok->str(";");
|
tok->str(";");
|
||||||
|
|
||||||
Token::eraseTokens(tok, 4);
|
tok->deleteNext(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -4701,7 +4702,7 @@ bool Tokenizer::removeRedundantConditions()
|
||||||
else
|
else
|
||||||
tok->str(";");
|
tok->str(";");
|
||||||
|
|
||||||
Token::eraseTokens(tok, 4);
|
tok->deleteNext(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -4760,7 +4761,7 @@ void Tokenizer::removeRedundantFor()
|
||||||
// Simplify loop if loop variable isn't written
|
// Simplify loop if loop variable isn't written
|
||||||
if (!write) {
|
if (!write) {
|
||||||
// remove "for ("
|
// remove "for ("
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
// If loop variable is read then keep assignment before
|
// If loop variable is read then keep assignment before
|
||||||
// loop body..
|
// loop body..
|
||||||
|
@ -4769,11 +4770,11 @@ void Tokenizer::removeRedundantFor()
|
||||||
tok = tok->tokAt(4);
|
tok = tok->tokAt(4);
|
||||||
} else {
|
} else {
|
||||||
// remove "x = 0 ;"
|
// remove "x = 0 ;"
|
||||||
Token::eraseTokens(tok, 4);
|
tok->deleteNext(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove "x < 1 ; x ++ )"
|
// remove "x < 1 ; x ++ )"
|
||||||
Token::eraseTokens(tok, 7);
|
tok->deleteNext(7);
|
||||||
|
|
||||||
// Add assignment after the loop body so the loop variable
|
// Add assignment after the loop body so the loop variable
|
||||||
// get the correct end value
|
// get the correct end value
|
||||||
|
@ -4799,7 +4800,7 @@ void Tokenizer::removeRedundantSemicolons()
|
||||||
if (Token::simpleMatch(tok, "; ;")) {
|
if (Token::simpleMatch(tok, "; ;")) {
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
} else if (Token::simpleMatch(tok, "; { ; }")) {
|
} else if (Token::simpleMatch(tok, "; { ; }")) {
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -5129,11 +5130,11 @@ void Tokenizer::simplifyConditionOperator()
|
||||||
|
|
||||||
if (isPointer) {
|
if (isPointer) {
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
Token::eraseTokens(tok, tok->tokAt(10));
|
tok->deleteNext(9);
|
||||||
} else if (isReturn)
|
} else if (isReturn)
|
||||||
Token::eraseTokens(tok, tok->tokAt(7));
|
tok->deleteNext(6);
|
||||||
else
|
else
|
||||||
Token::eraseTokens(tok, tok->tokAt(9));
|
tok->deleteNext(8);
|
||||||
|
|
||||||
Token *starttok = 0;
|
Token *starttok = 0;
|
||||||
|
|
||||||
|
@ -5192,14 +5193,14 @@ bool Tokenizer::simplifyConditions()
|
||||||
if (Token::simpleMatch(tok, "( true &&") ||
|
if (Token::simpleMatch(tok, "( true &&") ||
|
||||||
Token::simpleMatch(tok, "&& true &&") ||
|
Token::simpleMatch(tok, "&& true &&") ||
|
||||||
Token::simpleMatch(tok->next(), "&& true )")) {
|
Token::simpleMatch(tok->next(), "&& true )")) {
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok, "( false ||") ||
|
else if (Token::simpleMatch(tok, "( false ||") ||
|
||||||
Token::simpleMatch(tok, "|| false ||") ||
|
Token::simpleMatch(tok, "|| false ||") ||
|
||||||
Token::simpleMatch(tok->next(), "|| false )")) {
|
Token::simpleMatch(tok->next(), "|| false )")) {
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5287,7 +5288,7 @@ bool Tokenizer::simplifyConditions()
|
||||||
|
|
||||||
if (! cmp.empty()) {
|
if (! cmp.empty()) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
tok->str(result ? "true" : "false");
|
tok->str(result ? "true" : "false");
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -5359,7 +5360,7 @@ bool Tokenizer::simplifyQuestionMark()
|
||||||
|
|
||||||
// delete the condition token and the "?"
|
// delete the condition token and the "?"
|
||||||
tok = tok->tokAt(-2);
|
tok = tok->tokAt(-2);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
|
|
||||||
// delete operator after the :
|
// delete operator after the :
|
||||||
if (end) {
|
if (end) {
|
||||||
|
@ -5606,8 +5607,7 @@ void Tokenizer:: simplifyFunctionPointers()
|
||||||
// ok simplify this function pointer cast to an ordinary pointer cast
|
// ok simplify this function pointer cast to an ordinary pointer cast
|
||||||
tok1->deleteNext();
|
tok1->deleteNext();
|
||||||
tok1->next()->deleteNext();
|
tok1->next()->deleteNext();
|
||||||
const Token *tok2 = tok1->linkAt(2);
|
Token::eraseTokens(tok1->next(), tok1->linkAt(2)->next());
|
||||||
Token::eraseTokens(tok1->next(), tok2 ? tok2->next() : 0);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5632,8 +5632,7 @@ void Tokenizer:: simplifyFunctionPointers()
|
||||||
// ok simplify this function pointer to an ordinary pointer
|
// ok simplify this function pointer to an ordinary pointer
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->tokAt(2)->deleteNext();
|
tok->tokAt(2)->deleteNext();
|
||||||
const Token *tok2 = tok->linkAt(3);
|
Token::eraseTokens(tok->tokAt(2), tok->linkAt(3)->next());
|
||||||
Token::eraseTokens(tok->tokAt(2), tok2 ? tok2->next() : 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5655,7 +5654,7 @@ bool Tokenizer::simplifyFunctionReturn()
|
||||||
if (Token::Match(tok2, pattern.c_str())) {
|
if (Token::Match(tok2, pattern.c_str())) {
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
tok2->str(tok->strAt(5));
|
tok2->str(tok->strAt(5));
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6304,28 +6303,28 @@ void Tokenizer::simplifyIfNot()
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
tok->insertToken("!");
|
tok->insertToken("!");
|
||||||
tok = tok->tokAt(4);
|
tok = tok->tokAt(4);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::Match(tok, "* %var% == 0|false")) {
|
else if (Token::Match(tok, "* %var% == 0|false")) {
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
tok->insertToken("!");
|
tok->insertToken("!");
|
||||||
tok = tok->tokAt(3);
|
tok = tok->tokAt(3);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->link() && Token::Match(tok, ") == 0|false")) {
|
else if (tok->link() && Token::Match(tok, ") == 0|false")) {
|
||||||
// if( foo(x) == 0 )
|
// if( foo(x) == 0 )
|
||||||
if (Token::Match(tok->link()->tokAt(-2), "( %var%")) {
|
if (Token::Match(tok->link()->tokAt(-2), "( %var%")) {
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
tok->link()->previous()->insertToken(tok->link()->previous()->str().c_str());
|
tok->link()->previous()->insertToken(tok->link()->previous()->str().c_str());
|
||||||
tok->link()->tokAt(-2)->str("!");
|
tok->link()->tokAt(-2)->str("!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if( (x) == 0 )
|
// if( (x) == 0 )
|
||||||
else if (Token::simpleMatch(tok->link()->previous(), "(")) {
|
else if (Token::simpleMatch(tok->link()->previous(), "(")) {
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
tok->link()->insertToken("(");
|
tok->link()->insertToken("(");
|
||||||
tok->link()->str("!");
|
tok->link()->str("!");
|
||||||
Token *temp = tok->link();
|
Token *temp = tok->link();
|
||||||
|
@ -6350,7 +6349,7 @@ void Tokenizer::simplifyIfNotNull()
|
||||||
if (Token::simpleMatch(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) ||
|
if (Token::simpleMatch(tok->tokAt(2), (varname + " != 0 ) ;").c_str()) ||
|
||||||
Token::simpleMatch(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str())) {
|
Token::simpleMatch(tok->tokAt(2), ("0 != " + varname + " ) ;").c_str())) {
|
||||||
tok = tok->tokAt(-2);
|
tok = tok->tokAt(-2);
|
||||||
Token::eraseTokens(tok, tok->tokAt(9));
|
tok->deleteNext(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -6979,7 +6978,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!structname.empty()) {
|
if (!structname.empty()) {
|
||||||
Token::eraseTokens(tok3, 2);
|
tok3->deleteNext(2);
|
||||||
}
|
}
|
||||||
if (Token::Match(valueToken, "& %var% ;")) {
|
if (Token::Match(valueToken, "& %var% ;")) {
|
||||||
tok3->insertToken("&");
|
tok3->insertToken("&");
|
||||||
|
@ -7044,7 +7043,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
// array usage
|
// array usage
|
||||||
if (Token::Match(tok3, ("[(,] " + structname + " %varid% [|%op%").c_str(), varid)) {
|
if (Token::Match(tok3, ("[(,] " + structname + " %varid% [|%op%").c_str(), varid)) {
|
||||||
if (!structname.empty()) {
|
if (!structname.empty()) {
|
||||||
Token::eraseTokens(tok3, 2);
|
tok3->deleteNext(2);
|
||||||
}
|
}
|
||||||
tok3 = tok3->next();
|
tok3 = tok3->next();
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
|
@ -7061,7 +7060,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
if (value[0] == '\"')
|
if (value[0] == '\"')
|
||||||
break;
|
break;
|
||||||
if (!structname.empty()) {
|
if (!structname.empty()) {
|
||||||
Token::eraseTokens(tok3, 2);
|
tok3->deleteNext(2);
|
||||||
}
|
}
|
||||||
tok3 = tok3->next();
|
tok3 = tok3->next();
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
|
@ -7122,7 +7121,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
if (indentlevel == indentlevel3 && Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value)) {
|
if (indentlevel == indentlevel3 && Token::Match(tok3->next(), "%varid% ++|--", varid) && MathLib::isInt(value)) {
|
||||||
const std::string op(tok3->strAt(2));
|
const std::string op(tok3->strAt(2));
|
||||||
if (Token::Match(tok3, "[{};] %any% %any% ;")) {
|
if (Token::Match(tok3, "[{};] %any% %any% ;")) {
|
||||||
Token::eraseTokens(tok3, 3);
|
tok3->deleteNext(3);
|
||||||
} else {
|
} else {
|
||||||
tok3 = tok3->next();
|
tok3 = tok3->next();
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
|
@ -7143,7 +7142,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
(*tok2)->tokAt(2)->str(value);
|
(*tok2)->tokAt(2)->str(value);
|
||||||
(*tok2)->tokAt(2)->varId(valueVarId);
|
(*tok2)->tokAt(2)->varId(valueVarId);
|
||||||
if (Token::Match(tok3, "[;{}] %any% %any% ;")) {
|
if (Token::Match(tok3, "[;{}] %any% %any% ;")) {
|
||||||
Token::eraseTokens(tok3, 3);
|
tok3->deleteNext(3);
|
||||||
} else {
|
} else {
|
||||||
tok3->deleteNext();
|
tok3->deleteNext();
|
||||||
tok3->next()->str(value);
|
tok3->next()->str(value);
|
||||||
|
@ -7324,7 +7323,7 @@ void Tokenizer::simplifyReference()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Token::eraseTokens(tok2, tok2->tokAt(7+(tok->strAt(6)==")")));
|
tok2->deleteNext(6+(tok->strAt(6)==")"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7372,7 +7371,7 @@ 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);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
}
|
}
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
@ -7446,7 +7445,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
result = (op1 > op2) ? "1" : "0";
|
result = (op1 > op2) ? "1" : "0";
|
||||||
|
|
||||||
tok->str(result);
|
tok->str(result);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7465,7 +7464,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
ss << result;
|
ss << result;
|
||||||
|
|
||||||
tok->str(ss.str());
|
tok->str(ss.str());
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7500,7 +7499,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
if (!result.empty()) {
|
if (!result.empty()) {
|
||||||
ret = true;
|
ret = true;
|
||||||
tok->str(result);
|
tok->str(result);
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7525,7 +7524,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
else
|
else
|
||||||
tok->str(MathLib::calculate(tok->str(), tok->strAt(2), tok->next()->str()[0], this));
|
tok->str(MathLib::calculate(tok->str(), tok->strAt(2), tok->next()->str()[0], this));
|
||||||
|
|
||||||
Token::eraseTokens(tok, tok->tokAt(3));
|
tok->deleteNext(2);
|
||||||
|
|
||||||
// evaluate "2 + 2 - 2 - 2"
|
// evaluate "2 + 2 - 2 - 2"
|
||||||
// as (((2 + 2) - 2) - 2) = 0
|
// as (((2 + 2) - 2) - 2) = 0
|
||||||
|
@ -7617,7 +7616,7 @@ void Tokenizer::simplifyGoto()
|
||||||
|
|
||||||
const std::string name(tok->str());
|
const std::string name(tok->str());
|
||||||
|
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
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..
|
||||||
|
@ -7626,7 +7625,7 @@ void Tokenizer::simplifyGoto()
|
||||||
if (token->next()->str() == name) {
|
if (token->next()->str() == name) {
|
||||||
// Delete the "goto name;"
|
// Delete the "goto name;"
|
||||||
token = token->previous();
|
token = token->previous();
|
||||||
Token::eraseTokens(token, 3);
|
token->deleteNext(3);
|
||||||
|
|
||||||
// Insert the statements..
|
// Insert the statements..
|
||||||
bool ret = false; // is there return
|
bool ret = false; // is there return
|
||||||
|
@ -8116,7 +8115,7 @@ void Tokenizer::simplifyEnum()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasClass) {
|
if (hasClass) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
simplify = false;
|
simplify = false;
|
||||||
|
@ -8202,7 +8201,7 @@ void Tokenizer::simplifyEnum()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasClass) {
|
if (hasClass) {
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
simplify = false;
|
simplify = false;
|
||||||
|
@ -8406,9 +8405,9 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (indentlevel == indentcase)
|
if (indentlevel == indentcase)
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
if (!checklabel || !indentswitch) {
|
if (!checklabel || !indentswitch) {
|
||||||
Token::eraseTokens(tok, 3 + (tok->next()->str() == "case"));
|
tok->deleteNext(3+(tok->next()->str()=="case"));
|
||||||
} else {
|
} else {
|
||||||
tok = tok->tokAt(3 + (tok->next()->str() == "case"));
|
tok = tok->tokAt(3+(tok->next()->str()=="case"));
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "[{};] %var% : ;") && tok->next()->str() != "default") {
|
} else if (Token::Match(tok, "[{};] %var% : ;") && tok->next()->str() != "default") {
|
||||||
if (checklabel) {
|
if (checklabel) {
|
||||||
|
@ -8428,7 +8427,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
|
||||||
if (Token::Match(tok2->next(), "{|[|(")) {
|
if (Token::Match(tok2->next(), "{|[|(")) {
|
||||||
tok2 = tok2->next()->link();
|
tok2 = tok2->next()->link();
|
||||||
} else if (Token::Match(tok2, "[{};] case %any% : ;") || Token::Match(tok2, "[{};] default : ;")) {
|
} else if (Token::Match(tok2, "[{};] case %any% : ;") || Token::Match(tok2, "[{};] default : ;")) {
|
||||||
Token::eraseTokens(tok2, 3 + (tok2->next()->str() == "case"));
|
tok2->deleteNext(3+(tok2->next()->str()=="case"));
|
||||||
} else if (tok2->next()->str() == "}") {
|
} else if (tok2->next()->str() == "}") {
|
||||||
--indentlevel2;
|
--indentlevel2;
|
||||||
if (indentlevel2 <= indentcase)
|
if (indentlevel2 <= indentcase)
|
||||||
|
@ -9004,7 +9003,7 @@ void Tokenizer::simplifyWhile0()
|
||||||
|
|
||||||
// delete "(}) while ( 0 ) (;)"
|
// delete "(}) while ( 0 ) (;)"
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
Token::eraseTokens(tok, 4); // while ( 0 )
|
tok->deleteNext(4); // while ( 0 )
|
||||||
if (tok->next() && tok->next()->str() == ";")
|
if (tok->next() && tok->next()->str() == ";")
|
||||||
tok->deleteNext(); // ;
|
tok->deleteNext(); // ;
|
||||||
if (!flowmatch)
|
if (!flowmatch)
|
||||||
|
@ -9044,7 +9043,8 @@ void Tokenizer::simplifyErrNoInWhile()
|
||||||
tok1 = tok1->previous();
|
tok1 = tok1->previous();
|
||||||
|
|
||||||
// erase "&& errno == EINTR"
|
// erase "&& errno == EINTR"
|
||||||
Token::eraseTokens(tok1->previous(), endpar);
|
Token::eraseTokens(tok1, endpar);
|
||||||
|
tok1->deleteThis();
|
||||||
|
|
||||||
// tok is invalid.. move to endpar
|
// tok is invalid.. move to endpar
|
||||||
tok = endpar;
|
tok = endpar;
|
||||||
|
@ -9321,7 +9321,7 @@ void Tokenizer::simplifyAsm()
|
||||||
Token *partok = tok->tokAt(2);
|
Token *partok = tok->tokAt(2);
|
||||||
if (partok->str() != "(")
|
if (partok->str() != "(")
|
||||||
partok = partok->next();
|
partok = partok->next();
|
||||||
Token::eraseTokens(tok, partok->link() ? partok->link()->next() : NULL);
|
Token::eraseTokens(tok, partok->link()->next());
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (Token::simpleMatch(tok->next(), "__asm")) {
|
else if (Token::simpleMatch(tok->next(), "__asm")) {
|
||||||
|
@ -9366,10 +9366,10 @@ void Tokenizer::simplifyBitfields()
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") &&
|
} else if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% : %any% ;") &&
|
||||||
tok->next()->str() != "default") {
|
tok->next()->str() != "default") {
|
||||||
bool offset = (tok->next()->str() == "const");
|
unsigned char offset = (tok->next()->str() == "const") ? 1 : 0;
|
||||||
|
|
||||||
if (tok->strAt(3 + offset) != "{") {
|
if (tok->strAt(3 + offset) != "{") {
|
||||||
Token::eraseTokens(tok, 4+offset);
|
tok->deleteNext(4+offset);
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9407,7 +9407,8 @@ void Tokenizer::simplifyBuiltinExpect()
|
||||||
if (parlevel == 1 && tok2->str() == ",") {
|
if (parlevel == 1 && tok2->str() == ",") {
|
||||||
if (Token::Match(tok2, ", %num% )")) {
|
if (Token::Match(tok2, ", %num% )")) {
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
Token::eraseTokens(tok2->previous(), tok2->tokAt(2));
|
tok2->deleteNext();
|
||||||
|
tok2->deleteThis();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -9417,7 +9418,7 @@ void Tokenizer::simplifyBuiltinExpect()
|
||||||
tok->linkAt(2)->deleteThis();
|
tok->linkAt(2)->deleteThis();
|
||||||
|
|
||||||
// remove "likely|unlikely ("
|
// remove "likely|unlikely ("
|
||||||
Token::eraseTokens(tok, 2);
|
tok->deleteNext(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9434,9 +9435,9 @@ void Tokenizer::simplifyMicrosoftMFC()
|
||||||
|
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (Token::simpleMatch(tok->next(), "DECLARE_MESSAGE_MAP ( )")) {
|
if (Token::simpleMatch(tok->next(), "DECLARE_MESSAGE_MAP ( )")) {
|
||||||
Token::eraseTokens(tok, 3);
|
tok->deleteNext(3);
|
||||||
} else if (Token::Match(tok->next(), "DECLARE_DYNAMIC|DECLARE_DYNAMIC_CLASS|DECLARE_DYNCREATE ( %any% )")) {
|
} else if (Token::Match(tok->next(), "DECLARE_DYNAMIC|DECLARE_DYNAMIC_CLASS|DECLARE_DYNCREATE ( %any% )")) {
|
||||||
Token::eraseTokens(tok, 4);
|
tok->deleteNext(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9673,7 +9674,7 @@ void Tokenizer::simplifyQtSignalsSlots()
|
||||||
} else if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) {
|
} else if (Token::Match(tok2->next(), "public|protected|private slots|Q_SLOTS :")) {
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
tok2->str(tok2->str() + ":");
|
tok2->str(tok2->str() + ":");
|
||||||
Token::eraseTokens(tok2, 2);
|
tok2->deleteNext(2);
|
||||||
tok2 = tok2->previous();
|
tok2 = tok2->previous();
|
||||||
} else if (Token::Match(tok2->next(), "signals|Q_SIGNALS :")) {
|
} else if (Token::Match(tok2->next(), "signals|Q_SIGNALS :")) {
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
|
@ -9742,7 +9743,7 @@ void Tokenizer::simplifyOperatorName()
|
||||||
|
|
||||||
if (par && Token::Match(par->link(), ") const| [=;{),]")) {
|
if (par && Token::Match(par->link(), ") const| [=;{),]")) {
|
||||||
tok->str("operator" + op);
|
tok->str("operator" + op);
|
||||||
Token::eraseTokens(tok,par);
|
Token::eraseTokens(tok, par);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue