Tokenizer: fixed typedef issues

This commit is contained in:
Robert Reif 2010-01-13 07:59:47 +01:00 committed by Daniel Marjamäki
parent 1aac8f3e52
commit 0212225859
2 changed files with 11 additions and 4 deletions

View File

@ -455,8 +455,8 @@ void Tokenizer::simplifyTypedef()
Token::Match(tok->next(), "%type% :: %type% <") ||
Token::Match(tok->next(), "%type% *| %type% ;") ||
Token::Match(tok->next(), "%type% %type% *| %type% ;") ||
Token::Match(tok->next(), "%type% *| %type% [ %num% ]") ||
Token::Match(tok->next(), "%type% %type% *| %type% [ %num% ]"))
Token::Match(tok->next(), "%type% *| %type% [ %num% ] ;") ||
Token::Match(tok->next(), "%type% %type% *| %type% [ %num% ] ;"))
{
if ((tok->tokAt(2)->str() == "<") ||
(tok->tokAt(4) && (tok->tokAt(4)->str() == "<")))
@ -482,6 +482,9 @@ void Tokenizer::simplifyTypedef()
level++;
}
while (end && end->next() && Token::Match(end->next(), ":: %type%"))
end = end->tokAt(2);
if (end && end->next() && Token::Match(end->next(), "%type% ;"))
{
typeName = end->strAt(1);

View File

@ -2408,17 +2408,21 @@ private:
const char code[] = "typedef vector<int> V1;\n"
"typedef std::vector<int> V2;\n"
"typedef std::vector<std::vector<int> > V3;\n"
"typedef std::list<int>::iterator IntListIterator;\n"
"V1 v1;\n"
"V2 v2;\n"
"V3 v3;";
"V3 v3;\n"
"IntListIterator iter;";
const char expected[] =
"typedef vector < int > V1 ; "
"typedef std :: vector < int > V2 ; "
"typedef std :: vector < std :: vector < int > > V3 ; "
"typedef std :: list < int > :: iterator IntListIterator ; "
"vector < int > v1 ; "
"std :: vector < int > v2 ; "
"std :: vector < std :: vector < int > > v3 ;";
"std :: vector < std :: vector < int > > v3 ; "
"std :: list < int > :: iterator iter ;";
ASSERT_EQUALS(expected, tok(code, false));
}