tokenizer: improved the Tokenizer::simplifyIfNot
This commit is contained in:
parent
b4c3ed78b4
commit
2ccc01f5ed
|
@ -2434,7 +2434,9 @@ bool Tokenizer::simplifyIfNot()
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
if (tok->str() == "(" || tok->str() == "||" || tok->str() == "&&")
|
||||||
|
{
|
||||||
|
tok = tok->next();
|
||||||
if (Token::simpleMatch(tok, "0 == (") ||
|
if (Token::simpleMatch(tok, "0 == (") ||
|
||||||
Token::Match(tok, "0 == %var%"))
|
Token::Match(tok, "0 == %var%"))
|
||||||
{
|
{
|
||||||
|
@ -2443,7 +2445,7 @@ bool Tokenizer::simplifyIfNot()
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "%var% == 0"))
|
else if (Token::Match(tok, "%var% == 0"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->next()->str(tok->str());
|
tok->next()->str(tok->str());
|
||||||
|
@ -2451,7 +2453,18 @@ bool Tokenizer::simplifyIfNot()
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->link() && Token::simpleMatch(tok, ") == 0"))
|
else if (Token::Match(tok, "%var% . %var% == 0"))
|
||||||
|
{
|
||||||
|
tok = tok->previous();
|
||||||
|
tok->insertToken("!");
|
||||||
|
tok = tok->tokAt(4);
|
||||||
|
tok->deleteNext();
|
||||||
|
tok->deleteNext();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (tok->link() && Token::simpleMatch(tok, ") == 0"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
|
|
@ -971,11 +971,13 @@ private:
|
||||||
void ifnot()
|
void ifnot()
|
||||||
{
|
{
|
||||||
ASSERT_EQUALS("if ( ! x )", simplifyIfNot("if(0==x)"));
|
ASSERT_EQUALS("if ( ! x )", simplifyIfNot("if(0==x)"));
|
||||||
|
ASSERT_EQUALS("if ( ! x )", simplifyIfNot("if(x==0)"));
|
||||||
ASSERT_EQUALS("if ( ! ( a = b ) )", simplifyIfNot("if(0==(a=b))"));
|
ASSERT_EQUALS("if ( ! ( a = b ) )", simplifyIfNot("if(0==(a=b))"));
|
||||||
ASSERT_EQUALS("if ( ! x )", simplifyIfNot("if(x==0)"));
|
ASSERT_EQUALS("if ( ! x )", simplifyIfNot("if(x==0)"));
|
||||||
ASSERT_EQUALS("if ( ! a && b ( ) )", simplifyIfNot("if( 0 == a && b() )"));
|
ASSERT_EQUALS("if ( ! a && b ( ) )", simplifyIfNot("if( 0 == a && b() )"));
|
||||||
ASSERT_EQUALS("if ( b ( ) && ! a )", simplifyIfNot("if( b() && 0 == a )"));
|
ASSERT_EQUALS("if ( b ( ) && ! a )", simplifyIfNot("if( b() && 0 == a )"));
|
||||||
ASSERT_EQUALS("if ( ! ( a = b ) )", simplifyIfNot("if((a=b)==0)"));
|
ASSERT_EQUALS("if ( ! ( a = b ) )", simplifyIfNot("if((a=b)==0)"));
|
||||||
|
ASSERT_EQUALS("if ( ! x . y )", simplifyIfNot("if(x.y==0)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue