Fixed ticket #377 (False positive with "char a[]")

Updated the tokenizer so "char a[]" is tokenized into "char *a"
This commit is contained in:
Daniel Marjamäki 2009-06-10 19:36:00 +02:00
parent db7b8fb3fd
commit d8f95f68c3
2 changed files with 20 additions and 0 deletions

View File

@ -476,11 +476,23 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
// replace "unsigned i" with "unsigned int i"
unsignedint();
// Split up variable declarations.
simplifyVarDecl();
// Handle templates..
simplifyTemplates();
// change array to pointer..
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%type% %var% [ ] [,;=]"))
{
tok->next()->deleteNext();
tok->next()->deleteNext();
tok->insertToken("*");
}
}
return true;
}
//---------------------------------------------------------------------------

View File

@ -66,6 +66,8 @@ private:
TEST_CASE(paranthesesVar); // Remove redundant parantheses around variable .. "( %var% )"
TEST_CASE(declareVar);
TEST_CASE(declareArray);
TEST_CASE(dontRemoveIncrement);
TEST_CASE(removePostIncrement);
TEST_CASE(removePreIncrement);
@ -385,6 +387,12 @@ private:
ASSERT_EQUALS(code, tok(code));
}
void declareArray()
{
const char code[] = "void f ( ) { char str [ ] = \"100\" ; } ";
const char expected[] = "void f ( ) { char * str ; str = \"100\" ; } ";
ASSERT_EQUALS(expected, tok(code));
}
void dontRemoveIncrement()
{