varid: Set variable id for stl containers and iterators

This commit is contained in:
Daniel Marjamäki 2009-04-25 16:55:00 +02:00
parent ef54e446db
commit 49430afabe
2 changed files with 36 additions and 0 deletions

View File

@ -631,6 +631,21 @@ void Tokenizer::setVarId()
if (Token::simpleMatch(tok, "std ::"))
tok = tok->tokAt(2);
// Skip template arguments..
if (Token::Match(tok, "%type% <"))
{
Token *tok2 = tok->tokAt(2);
while (tok2 && (tok2->isName() || tok2->str() == "*"))
tok2 = tok2->next();
if (Token::Match(tok2, "> %var%"))
tok = tok2;
else if (Token::Match(tok2, "> :: %var%"))
tok = tok2->next();
else
continue; // Not code that I understand / not a variable declaration
}
// Determine name of declared variable..
const char *varname = 0;
Token *tok2 = tok->tokAt(1);

View File

@ -107,6 +107,7 @@ private:
TEST_CASE(varidReturn);
TEST_CASE(varid8);
TEST_CASE(varid9);
TEST_CASE(varidStl);
TEST_CASE(file1);
TEST_CASE(file2);
@ -1049,6 +1050,26 @@ private:
ASSERT_EQUALS(expected, actual);
}
void varidStl()
{
const std::string code("list<int> ints;\n"
"list<int>::iterator it;\n");
// tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId();
// result..
const std::string actual(tokenizer.tokens()->stringifyList(true));
const std::string expected("\n\n##file 0\n"
"1: list < int > ints@1 ;\n"
"2: list < int > :: iterator it@2 ;\n");
ASSERT_EQUALS(expected, actual);
}