reverted 840b2fb0
, it caused FN. tweaked the Tokenizer::simplifyAssignmentBlock to fix the FP it caused.
This commit is contained in:
parent
840b2fb035
commit
b0cc46e98b
|
@ -3544,6 +3544,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
// f(x=g()) => x=g(); f(x)
|
||||
simplifyAssignmentInFunctionCall();
|
||||
|
||||
// x = ({ 123; }); => { x = 123; }
|
||||
simplifyAssignmentBlock();
|
||||
|
||||
// The simplifyTemplates have inner loops
|
||||
if (_settings->terminated())
|
||||
return false;
|
||||
|
@ -9407,6 +9410,40 @@ void Tokenizer::simplifyAssignmentInFunctionCall()
|
|||
}
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyAssignmentBlock()
|
||||
{
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "[;{}] %var% = ( {")) {
|
||||
const std::string &varname = tok->next()->str();
|
||||
|
||||
// goto the "} )"
|
||||
unsigned int indentlevel = 0;
|
||||
Token *tok2 = tok;
|
||||
while (nullptr != (tok2 = tok2->next())) {
|
||||
if (Token::Match(tok2, "(|{"))
|
||||
++indentlevel;
|
||||
else if (Token::Match(tok2, ")|}")) {
|
||||
if (indentlevel <= 2)
|
||||
break;
|
||||
--indentlevel;
|
||||
} else if (indentlevel == 2 && tok2->str() == varname && Token::Match(tok2->previous(), "%type%|*"))
|
||||
// declaring variable in inner scope with same name as lhs variable
|
||||
break;
|
||||
}
|
||||
if (indentlevel == 2 && Token::simpleMatch(tok2, "} )")) {
|
||||
tok2 = tok2->tokAt(-3);
|
||||
if (Token::Match(tok2, "[;{}] %num%|%var% ;")) {
|
||||
tok2->insertToken("=");
|
||||
tok2->insertToken(tok->next()->str());
|
||||
tok2->next()->varId(tok->next()->varId());
|
||||
tok->deleteNext(3);
|
||||
tok2->tokAt(5)->deleteNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove __asm..
|
||||
void Tokenizer::simplifyAsm()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue