tokenizer: fixed TestTokenizer::sizeof1

This commit is contained in:
Daniel Marjamäki 2009-01-28 17:38:32 +00:00
parent dd9cd9ce82
commit b7b055e885
2 changed files with 14 additions and 2 deletions

View File

@ -675,7 +675,19 @@ void Tokenizer::simplifyTokenList()
else if (Token::Match(tok, "sizeof ( * %var% )")) else if (Token::Match(tok, "sizeof ( * %var% )"))
{ {
tok->str("100"); // Some default value..
int sz = 100;
// Try to locate variable declaration..
const Token *decltok = Token::findmatch(_tokens, (std::string("%type% ") + tok->strAt(3) + " [").c_str());
if (decltok)
{
sz = SizeOfType(decltok->strAt(0));
}
std::ostringstream ostr;
ostr << sz;
tok->str(ostr.str().c_str());
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
tok->deleteNext(); tok->deleteNext();
} }

View File

@ -67,7 +67,7 @@ private:
TEST_CASE(noerr2); TEST_CASE(noerr2);
TEST_CASE(noerr3); TEST_CASE(noerr3);
TEST_CASE(noerr4); TEST_CASE(noerr4);
TEST_CASE(sizeof1); TEST_CASE(sizeof1);
TEST_CASE(array_index_1); TEST_CASE(array_index_1);