simplify tokens: fixed bug when removing redundant parantheses around variable

This commit is contained in:
Daniel Marjamäki 2009-02-27 06:07:38 +00:00
parent 91011b8450
commit f4a8bc85f2
2 changed files with 10 additions and 5 deletions

View File

@ -926,7 +926,7 @@ void Tokenizer::simplifyTokenList()
// Remove parantheses around variable..
// keep parantheses here: dynamic_cast<Fred *>(p);
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% )"))
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% ) [;),+-*/><]]"))
{
tok->deleteNext();
tok = tok->next();

View File

@ -64,7 +64,7 @@ private:
TEST_CASE(double_plus);
TEST_CASE(redundant_plus);
TEST_CASE(parantheses1);
TEST_CASE(parantheses2);
TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )"
TEST_CASE(elseif1);
}
@ -313,10 +313,15 @@ private:
ASSERT_EQUALS("<= 110 ; ", tok(code1));
}
void parantheses2()
void paranthesesVar()
{
const char code1[] = "= (p);";
ASSERT_EQUALS("= p ; ", tok(code1));
// remove parantheses..
ASSERT_EQUALS("= p ; ", tok("= (p);"));
ASSERT_EQUALS("if ( a < p ) { ", tok("if(a<(p))"));
// keep parantheses..
ASSERT_EQUALS("= ( char ) a ; ", tok("= (char)a;"));
ASSERT_EQUALS("cast < char * > ( p ) ", tok("cast<char *>(p)"));
}