Merge branch 'multi_indirection_templates'
This commit is contained in:
commit
0e1bab6dc3
|
@ -1233,40 +1233,33 @@ const Token* skipPointers(const Token* tok)
|
||||||
bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const
|
bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const
|
||||||
{
|
{
|
||||||
const Token* localTypeTok = skipScopeIdentifiers(tok);
|
const Token* localTypeTok = skipScopeIdentifiers(tok);
|
||||||
|
const Token* localVarTok = NULL;
|
||||||
|
|
||||||
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% ;"))
|
localVarTok = skipPointers(closeTok->next());
|
||||||
|
|
||||||
|
if (Token::Match(localVarTok, ":: %type% %var% ;"))
|
||||||
{
|
{
|
||||||
vartok = closetok->next();
|
localTypeTok = localVarTok->next();
|
||||||
typetok = localTypeTok;
|
localVarTok = localVarTok->tokAt(2);
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Token::Match(localTypeTok, "%type%"))
|
else if (Token::Match(localTypeTok, "%type%"))
|
||||||
{
|
{
|
||||||
const Token* localVarTok = skipPointers(localTypeTok->next());
|
localVarTok = skipPointers(localTypeTok->next());
|
||||||
|
}
|
||||||
|
|
||||||
if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok))
|
if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok))
|
||||||
{
|
{
|
||||||
vartok = localVarTok;
|
vartok = localVarTok;
|
||||||
typetok = localTypeTok;
|
typetok = localTypeTok;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return NULL != vartok;
|
return NULL != vartok;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ private:
|
||||||
TEST_CASE(test_isVariableDeclarationIdentifiesArray);
|
TEST_CASE(test_isVariableDeclarationIdentifiesArray);
|
||||||
TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers);
|
TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers);
|
||||||
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable);
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable);
|
||||||
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable);
|
||||||
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedArrayVariable);
|
||||||
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable);
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable);
|
||||||
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator);
|
TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator);
|
||||||
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
|
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
|
||||||
|
@ -222,6 +224,26 @@ private:
|
||||||
ASSERT_EQUALS("set", typetok->str());
|
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()
|
void isVariableDeclarationIdentifiesTemplatedVariable()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
|
|
Loading…
Reference in New Issue