Move simplification of realloc after simplification of math ops
This commit is contained in:
parent
d2714fefda
commit
e75a81669e
|
@ -4076,36 +4076,6 @@ bool Tokenizer::simplifyTokenList()
|
||||||
|
|
||||||
simplifyCasts();
|
simplifyCasts();
|
||||||
|
|
||||||
// simplify "x=realloc(y,0);" => "free(y); x=0;"..
|
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
|
||||||
{
|
|
||||||
if (Token::Match(tok, "; %var% = realloc ( %var% , 0 ) ;"))
|
|
||||||
{
|
|
||||||
const std::string varname(tok->next()->str());
|
|
||||||
const unsigned int varid(tok->next()->varId());
|
|
||||||
|
|
||||||
// Delete the "%var% ="
|
|
||||||
tok->deleteNext();
|
|
||||||
tok->deleteNext();
|
|
||||||
|
|
||||||
// Change function name "realloc" to "free"
|
|
||||||
tok->next()->str("free");
|
|
||||||
|
|
||||||
// delete the ", 0"
|
|
||||||
Token::eraseTokens(tok->tokAt(3), tok->tokAt(6));
|
|
||||||
|
|
||||||
// goto the ";"
|
|
||||||
tok = tok->tokAt(5);
|
|
||||||
|
|
||||||
// insert "var=0;"
|
|
||||||
tok->insertToken(";");
|
|
||||||
tok->insertToken("0");
|
|
||||||
tok->insertToken("=");
|
|
||||||
tok->insertToken(varname);
|
|
||||||
tok->next()->varId(varid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simplify simple calculations..
|
// Simplify simple calculations..
|
||||||
simplifyCalculations();
|
simplifyCalculations();
|
||||||
|
|
||||||
|
@ -4145,6 +4115,36 @@ bool Tokenizer::simplifyTokenList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simplify "x=realloc(y,0);" => "free(y); x=0;"..
|
||||||
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
|
{
|
||||||
|
if (Token::Match(tok, "; %var% = realloc ( %var% , 0 ) ;"))
|
||||||
|
{
|
||||||
|
const std::string varname(tok->next()->str());
|
||||||
|
const unsigned int varid(tok->next()->varId());
|
||||||
|
|
||||||
|
// Delete the "%var% ="
|
||||||
|
tok->deleteNext();
|
||||||
|
tok->deleteNext();
|
||||||
|
|
||||||
|
// Change function name "realloc" to "free"
|
||||||
|
tok->next()->str("free");
|
||||||
|
|
||||||
|
// delete the ", 0"
|
||||||
|
Token::eraseTokens(tok->tokAt(3), tok->tokAt(6));
|
||||||
|
|
||||||
|
// goto the ";"
|
||||||
|
tok = tok->tokAt(5);
|
||||||
|
|
||||||
|
// insert "var=0;"
|
||||||
|
tok->insertToken(";");
|
||||||
|
tok->insertToken("0");
|
||||||
|
tok->insertToken("=");
|
||||||
|
tok->insertToken(varname);
|
||||||
|
tok->next()->varId(varid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Change initialisation of variable to assignment
|
// Change initialisation of variable to assignment
|
||||||
simplifyInitVar();
|
simplifyInitVar();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue