Made isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() pass.

And added isVariableDeclarationIdentifiesTemplatedArrayVariable() (passing) into the bargain.
This commit is contained in:
Pete Johns 2011-01-18 20:14:12 +11:00
parent 69d4db714e
commit abfd907763
2 changed files with 23 additions and 21 deletions

View File

@ -1236,24 +1236,21 @@ bool SymbolDatabase::SpaceInfo::isVariableDeclaration(const Token* tok, const To
if (Token::Match(localTypeTok, "%type% < ")) if (Token::Match(localTypeTok, "%type% < "))
{ {
const Token* closetok = NULL; const Token* closeTok = NULL;
bool found = findClosingBracket(localTypeTok->next(), closetok); bool found = findClosingBracket(localTypeTok->next(), closeTok);
if (found) if (found)
{ {
if (Token::Match(closetok, "> %var% ;")) const Token* localVarTok = skipPointers(closeTok->next());
if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok))
{ {
vartok = closetok->next(); vartok = localVarTok;
typetok = localTypeTok; typetok = localTypeTok;
} }
else if (Token::Match(closetok, "> * %var% ;")) else if (Token::Match(closeTok, "> :: %type% %var% ;"))
{ {
vartok = closetok->tokAt(2); vartok = closeTok->tokAt(3);
typetok = localTypeTok; typetok = closeTok->tokAt(2);
}
else if (Token::Match(closetok, "> :: %type% %var% ;"))
{
vartok = closetok->tokAt(3);
typetok = closetok->tokAt(2);
} }
} }
} }

View File

@ -64,6 +64,7 @@ private:
TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers); TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedArrayVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator); TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator);
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable); TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
@ -229,15 +230,19 @@ private:
reset(); reset();
givenACodeSampleToTokenize var("std::deque<int>*** ints;"); givenACodeSampleToTokenize var("std::deque<int>*** ints;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
TODO_ASSERT_EQUALS(true, result); ASSERT_EQUALS(true, result);
if (NULL != vartok) ASSERT_EQUALS("ints", vartok->str());
{ ASSERT_EQUALS("deque", typetok->str());
TODO_ASSERT_EQUALS("ints", vartok->str()); }
}
if (NULL != typetok) void isVariableDeclarationIdentifiesTemplatedArrayVariable()
{ {
TODO_ASSERT_EQUALS("deque", typetok->str()); reset();
} givenACodeSampleToTokenize var("std::deque<int> ints[3];");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("ints", vartok->str());
ASSERT_EQUALS("deque", typetok->str());
} }
void isVariableDeclarationIdentifiesTemplatedVariable() void isVariableDeclarationIdentifiesTemplatedVariable()