reverted 840b2fb0, it caused FN. tweaked the Tokenizer::simplifyAssignmentBlock to fix the FP it caused.

This commit is contained in:
Daniel Marjamäki 2015-01-07 06:38:42 +01:00
parent 840b2fb035
commit b0cc46e98b
1 changed files with 37 additions and 0 deletions

View File

@ -3544,6 +3544,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// f(x=g()) => x=g(); f(x) // f(x=g()) => x=g(); f(x)
simplifyAssignmentInFunctionCall(); simplifyAssignmentInFunctionCall();
// x = ({ 123; }); => { x = 123; }
simplifyAssignmentBlock();
// The simplifyTemplates have inner loops // The simplifyTemplates have inner loops
if (_settings->terminated()) if (_settings->terminated())
return false; 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.. // Remove __asm..
void Tokenizer::simplifyAsm() void Tokenizer::simplifyAsm()
{ {