known variables: better handling of ++ and --
This commit is contained in:
parent
832275bc37
commit
547f120ee9
|
@ -1713,20 +1713,32 @@ bool Tokenizer::simplifyKnownVariables()
|
||||||
|
|
||||||
if (Token::Match(tok3->next(), "%varid% ++|--", varid))
|
if (Token::Match(tok3->next(), "%varid% ++|--", varid))
|
||||||
{
|
{
|
||||||
tok3 = tok3->next();
|
const std::string op(tok3->strAt(2));
|
||||||
const std::string op(tok3->strAt(1));
|
if (Token::Match(tok3, "; %any% %any% ;"))
|
||||||
if (!Token::Match(tok3->previous(), "; %any% %any% ;"))
|
|
||||||
{
|
{
|
||||||
|
tok3->deleteNext();
|
||||||
|
tok3->deleteNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tok3 = tok3->next();
|
||||||
tok3->str(value.c_str());
|
tok3->str(value.c_str());
|
||||||
tok3->deleteNext();
|
tok3->deleteNext();
|
||||||
}
|
}
|
||||||
incdec(value, op);
|
incdec(value, op);
|
||||||
|
tok2->tokAt(2)->str(value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok3->next(), "++|-- %varid%", varid))
|
if (Token::Match(tok3->next(), "++|-- %varid%", varid))
|
||||||
{
|
{
|
||||||
incdec(value, tok3->strAt(1));
|
incdec(value, tok3->strAt(1));
|
||||||
if (!Token::Match(tok3, "; %any% %any% ;"))
|
tok2->tokAt(2)->str(value.c_str());
|
||||||
|
if (Token::Match(tok3, "; %any% %any% ;"))
|
||||||
|
{
|
||||||
|
tok3->deleteNext();
|
||||||
|
tok3->deleteNext();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
tok3->deleteNext();
|
tok3->deleteNext();
|
||||||
tok3->next()->str(value.c_str());
|
tok3->next()->str(value.c_str());
|
||||||
|
|
|
@ -552,7 +552,7 @@ private:
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||||
ostr << " " << tok->str();
|
ostr << " " << tok->str();
|
||||||
ASSERT_EQUALS(std::string(" void foo ( ) { int i = 22 ; abc [ 22 ] = 1 ; abc [ 24 ] = 2 ; }"), ostr.str());
|
ASSERT_EQUALS(std::string(" void foo ( ) { int i = 24 ; abc [ 22 ] = 1 ; abc [ 24 ] = 2 ; }"), ostr.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyKnownVariables8()
|
void simplifyKnownVariables8()
|
||||||
|
@ -574,7 +574,7 @@ private:
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
|
||||||
ostr << " " << tok->str();
|
ostr << " " << tok->str();
|
||||||
ASSERT_EQUALS(std::string(" void foo ( ) { int i = 22 ; i ++ ; abc [ 23 ] = 0 ; }"), ostr.str());
|
ASSERT_EQUALS(std::string(" void foo ( ) { int i = 23 ; ; abc [ 23 ] = 0 ; }"), ostr.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue