Tokenizer: improved the simplifyInitVar

This commit is contained in:
Daniel Marjamäki 2010-01-30 14:25:11 +01:00
parent 3b08712930
commit 8716c771a4
2 changed files with 19 additions and 4 deletions

View File

@ -4126,9 +4126,12 @@ void Tokenizer::simplifyInitVar()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "[{};] %type% *| %var% ( %num% ) ;") &&
tok->next()->isStandardType())
if (Token::Match(tok, "[{};] %type% *| %var% ( %num% ) ;"))
{
// call constructor of class => no simplification
if (!tok->next()->isStandardType() && tok->tokAt(2)->str() != "*")
continue;
// goto variable name..
tok = tok->tokAt(2);
if (tok->str() == "*")

View File

@ -3237,8 +3237,20 @@ private:
void simplifyInitVar()
{
// ticket #1005 - int *p(0); => int *p = 0;
const char code[] = "void foo() { int *p(0); }";
ASSERT_EQUALS("void foo ( ) { int * p ; p = 0 ; }", tok(code));
{
const char code[] = "void foo() { int *p(0); }";
ASSERT_EQUALS("void foo ( ) { int * p ; p = 0 ; }", tok(code));
}
{
const char code[] = "void foo() { int p(0); }";
ASSERT_EQUALS("void foo ( ) { int p ; p = 0 ; }", tok(code));
}
{
const char code[] = "void a() { foo *p(0); }";
ASSERT_EQUALS("void a ( ) { foo * p ; p = 0 ; }", tok(code));
}
}
};