Fixed #1671 (simplifyTypedef: support for more typedefs)
This commit is contained in:
parent
d0ca73c193
commit
963108d957
|
@ -732,6 +732,7 @@ void Tokenizer::simplifyTypedef()
|
|||
bool function = false;
|
||||
bool functionPtr = false;
|
||||
bool functionRef = false;
|
||||
Token *functionNamespace = 0;
|
||||
|
||||
if (Token::Match(tok->next(), "::") ||
|
||||
Token::Match(tok->next(), "%type%"))
|
||||
|
@ -794,6 +795,9 @@ void Tokenizer::simplifyTypedef()
|
|||
return;
|
||||
}
|
||||
|
||||
while (Token::Match(typeEnd->next(), "const|volatile"))
|
||||
typeEnd = typeEnd->next();
|
||||
|
||||
tok = typeEnd;
|
||||
offset = 1;
|
||||
}
|
||||
|
@ -878,6 +882,27 @@ void Tokenizer::simplifyTypedef()
|
|||
continue;
|
||||
}
|
||||
}
|
||||
else if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "( %var% :: *|&| %type% ) ("))
|
||||
{
|
||||
functionNamespace = tok->tokAt(offset + 1);
|
||||
functionPtr = tok->tokAt(offset + 3)->str() == "*";
|
||||
functionRef = tok->tokAt(offset + 3)->str() == "&";
|
||||
function = tok->tokAt(offset + 4)->str() == ")";
|
||||
if (!function)
|
||||
offset++;
|
||||
if (tok->tokAt(offset + 5)->link()->next())
|
||||
{
|
||||
typeName = tok->tokAt(offset + 3);
|
||||
argStart = tok->tokAt(offset + 5);
|
||||
argEnd = tok->tokAt(offset + 5)->link();
|
||||
tok = argEnd->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
// internal error
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "( %type% ("))
|
||||
{
|
||||
function = true;
|
||||
|
@ -1051,6 +1076,13 @@ void Tokenizer::simplifyTypedef()
|
|||
tok2->insertToken("(");
|
||||
tok2 = tok2->next();
|
||||
Token *tok3 = tok2;
|
||||
if (functionNamespace)
|
||||
{
|
||||
tok2->insertToken(functionNamespace->str());
|
||||
tok2 = tok2->next();
|
||||
tok2->insertToken("::");
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
if (functionPtr)
|
||||
tok2->insertToken("*");
|
||||
else if (functionRef)
|
||||
|
|
|
@ -185,6 +185,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef44);
|
||||
TEST_CASE(simplifyTypedef45); // ticket #1613
|
||||
TEST_CASE(simplifyTypedef46); // ticket #1615
|
||||
TEST_CASE(simplifyTypedef47);
|
||||
|
||||
TEST_CASE(simplifyTypedefFunction);
|
||||
|
||||
|
@ -3911,6 +3912,29 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyTypedef47()
|
||||
{
|
||||
{
|
||||
const char code[] = "typedef std::pair<int, int> const I;\n"
|
||||
"I i;";
|
||||
|
||||
// The expected result..
|
||||
const std::string expected("; "
|
||||
"std :: pair < int , int > const i ;");
|
||||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "typedef void (X:: *F)();\n"
|
||||
"F f;";
|
||||
|
||||
// The expected result..
|
||||
const std::string expected("; "
|
||||
"void ( X :: * f ) ( ) ;");
|
||||
ASSERT_EQUALS(expected, sizeof_(code));
|
||||
}
|
||||
}
|
||||
|
||||
void simplifyTypedefFunction()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue