Merge branch 'multi_indirection_templates'

This commit is contained in:
Pete Johns 2011-01-18 21:08:04 +11:00
commit 0e1bab6dc3
2 changed files with 36 additions and 21 deletions

View File

@ -1233,40 +1233,33 @@ const Token* skipPointers(const Token* tok)
bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const
{
const Token* localTypeTok = skipScopeIdentifiers(tok);
const Token* localVarTok = NULL;
if (Token::Match(localTypeTok, "%type% < "))
{
const Token* closetok = NULL;
bool found = findClosingBracket(localTypeTok->next(), closetok);
const Token* closeTok = NULL;
bool found = findClosingBracket(localTypeTok->next(), closeTok);
if (found)
{
if (Token::Match(closetok, "> %var% ;"))
localVarTok = skipPointers(closeTok->next());
if (Token::Match(localVarTok, ":: %type% %var% ;"))
{
vartok = closetok->next();
typetok = localTypeTok;
}
else if (Token::Match(closetok, "> * %var% ;"))
{
vartok = closetok->tokAt(2);
typetok = localTypeTok;
}
else if (Token::Match(closetok, "> :: %type% %var% ;"))
{
vartok = closetok->tokAt(3);
typetok = closetok->tokAt(2);
localTypeTok = localVarTok->next();
localVarTok = localVarTok->tokAt(2);
}
}
}
else if (Token::Match(localTypeTok, "%type%"))
{
const Token* localVarTok = skipPointers(localTypeTok->next());
localVarTok = skipPointers(localTypeTok->next());
}
if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok))
{
vartok = localVarTok;
typetok = localTypeTok;
}
}
return NULL != vartok;
}

View File

@ -62,6 +62,8 @@ private:
TEST_CASE(test_isVariableDeclarationIdentifiesArray);
TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedArrayVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable);
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator);
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
@ -222,6 +224,26 @@ private:
ASSERT_EQUALS("set", typetok->str());
}
void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable()
{
reset();
givenACodeSampleToTokenize var("std::deque<int>*** ints;");
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
ASSERT_EQUALS(true, result);
ASSERT_EQUALS("ints", vartok->str());
ASSERT_EQUALS("deque", typetok->str());
}
void isVariableDeclarationIdentifiesTemplatedArrayVariable()
{
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()
{
reset();