Tokenizer: Simplify 'false ==' to '!'
This commit is contained in:
parent
e95bc41e59
commit
80edb4d8f4
|
@ -4527,21 +4527,21 @@ void Tokenizer::simplifyIfNot()
|
|||
if (!tok)
|
||||
break;
|
||||
|
||||
if (Token::simpleMatch(tok, "0 == (") ||
|
||||
Token::Match(tok, "0 == %var%"))
|
||||
if (Token::Match(tok, "0|false == (") ||
|
||||
Token::Match(tok, "0|false == %var%"))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok->str("!");
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "%var% == 0"))
|
||||
else if (Token::Match(tok, "%var% == 0|false"))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok->next()->str(tok->str());
|
||||
tok->str("!");
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "%var% .|:: %var% == 0"))
|
||||
else if (Token::Match(tok, "%var% .|:: %var% == 0|false"))
|
||||
{
|
||||
tok = tok->previous();
|
||||
tok->insertToken("!");
|
||||
|
@ -4549,7 +4549,7 @@ void Tokenizer::simplifyIfNot()
|
|||
Token::eraseTokens(tok, tok->tokAt(3));
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "* %var% == 0"))
|
||||
else if (Token::Match(tok, "* %var% == 0|false"))
|
||||
{
|
||||
tok = tok->previous();
|
||||
tok->insertToken("!");
|
||||
|
@ -4558,7 +4558,7 @@ void Tokenizer::simplifyIfNot()
|
|||
}
|
||||
}
|
||||
|
||||
else if (tok->link() && Token::simpleMatch(tok, ") == 0"))
|
||||
else if (tok->link() && Token::Match(tok, ") == 0|false"))
|
||||
{
|
||||
Token::eraseTokens(tok, tok->tokAt(3));
|
||||
if (Token::Match(tok->link()->previous(), "%var%"))
|
||||
|
|
|
@ -448,77 +448,41 @@ private:
|
|||
|
||||
void pointers_condition()
|
||||
{
|
||||
const char code[] = "void f()\n"
|
||||
"{\n"
|
||||
" if (p != NULL);\n"
|
||||
" if (NULL != p);\n"
|
||||
" if (this->p != NULL);\n"
|
||||
" if (NULL != this->p);\n"
|
||||
" if (Foo::p != NULL);\n"
|
||||
" if (NULL != Foo::p);\n"
|
||||
" while (p != NULL);\n"
|
||||
" while (NULL != p);\n"
|
||||
" while (this->p != NULL);\n"
|
||||
" while (NULL != this->p);\n"
|
||||
" while (Foo::p != NULL);\n"
|
||||
" while (NULL != Foo::p);\n"
|
||||
" if (p == NULL);\n"
|
||||
" if (NULL == p);\n"
|
||||
" if (this->p == NULL);\n"
|
||||
" if (NULL == this->p);\n"
|
||||
" if (Foo::p == NULL);\n"
|
||||
" if (NULL == Foo::p);\n"
|
||||
" while (p == NULL);\n"
|
||||
" while (NULL == p);\n"
|
||||
" while (this->p == NULL);\n"
|
||||
" while (NULL == this->p);\n"
|
||||
" while (Foo::p == NULL);\n"
|
||||
" while (NULL == Foo::p);\n"
|
||||
" if (p1 != NULL || p2 == NULL) { ; }\n"
|
||||
" if (p1 != NULL && p2 == NULL) { ; }\n"
|
||||
" if (p == '\\0');\n"
|
||||
" if (p == 0L);\n"
|
||||
" if (p == 0UL);\n"
|
||||
" if (p == 0ul);\n"
|
||||
" if (p == 0l);\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("( p )", tokenizeAndStringify("( p != NULL )", true));
|
||||
ASSERT_EQUALS("( p )", tokenizeAndStringify("( NULL != p )", true));
|
||||
ASSERT_EQUALS("( this . p )", tokenizeAndStringify("( this->p != NULL )", true));
|
||||
ASSERT_EQUALS("( this . p )", tokenizeAndStringify("( NULL != this->p )", true));
|
||||
ASSERT_EQUALS("( Foo :: p )", tokenizeAndStringify("( Foo::p != NULL )", true));
|
||||
ASSERT_EQUALS("( Foo :: p )", tokenizeAndStringify("( NULL != Foo::p )", true));
|
||||
|
||||
ASSERT_EQUALS("void f ( )\n"
|
||||
"{\n"
|
||||
"if ( p ) { ; }\n"
|
||||
"if ( p ) { ; }\n"
|
||||
"if ( this . p ) { ; }\n"
|
||||
"if ( this . p ) { ; }\n"
|
||||
"if ( Foo :: p ) { ; }\n"
|
||||
"if ( Foo :: p ) { ; }\n"
|
||||
"while ( p ) { ; }\n"
|
||||
"while ( p ) { ; }\n"
|
||||
"while ( this . p ) { ; }\n"
|
||||
"while ( this . p ) { ; }\n"
|
||||
"while ( Foo :: p ) { ; }\n"
|
||||
"while ( Foo :: p ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"if ( ! this . p ) { ; }\n"
|
||||
"if ( ! this . p ) { ; }\n"
|
||||
"if ( ! Foo :: p ) { ; }\n"
|
||||
"if ( ! Foo :: p ) { ; }\n"
|
||||
"while ( ! p ) { ; }\n"
|
||||
"while ( ! p ) { ; }\n"
|
||||
"while ( ! this . p ) { ; }\n"
|
||||
"while ( ! this . p ) { ; }\n"
|
||||
"while ( ! Foo :: p ) { ; }\n"
|
||||
"while ( ! Foo :: p ) { ; }\n"
|
||||
"if ( p1 || ! p2 ) { ; }\n"
|
||||
"if ( p1 && ! p2 ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"if ( ! p ) { ; }\n"
|
||||
"}", tokenizeAndStringify(code, true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == NULL )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( NULL == p )", true));
|
||||
ASSERT_EQUALS("( ! this . p )", tokenizeAndStringify("( this->p == NULL )", true));
|
||||
ASSERT_EQUALS("( ! this . p )", tokenizeAndStringify("( NULL == this->p )", true));
|
||||
ASSERT_EQUALS("( ! Foo :: p )", tokenizeAndStringify("( Foo::p == NULL )", true));
|
||||
ASSERT_EQUALS("( ! Foo :: p )", tokenizeAndStringify("( NULL == Foo::p )", true));
|
||||
|
||||
ASSERT_EQUALS("( p1 || ! p2 )", tokenizeAndStringify("( p1 != NULL || p2 == NULL )", true));
|
||||
ASSERT_EQUALS("( p1 && ! p2 )", tokenizeAndStringify("( p1 != NULL && p2 == NULL )", true));
|
||||
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == false )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == 0 )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == '\\0' )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == 0L )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == 0UL )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == 0ul )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( p == 0l )", true));
|
||||
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( false == p )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( 0 == p )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( '\\0' == p )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( 0L == p )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( 0UL == p )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( 0ul == p )", true));
|
||||
ASSERT_EQUALS("( ! p )", tokenizeAndStringify("( 0l == p )", true));
|
||||
}
|
||||
|
||||
|
||||
void ifAddBraces1()
|
||||
{
|
||||
const char code[] = "void f()\n"
|
||||
|
|
Loading…
Reference in New Issue