Fixed #1671 (simplifyTypedef: support for more typedefs)
This commit is contained in:
parent
3fb0260ef1
commit
1a25183e8f
|
@ -743,7 +743,8 @@ void Tokenizer::simplifyTypedef()
|
||||||
bool ptrToArray = false;
|
bool ptrToArray = false;
|
||||||
bool refToArray = false;
|
bool refToArray = false;
|
||||||
bool ptrMember = false;
|
bool ptrMember = false;
|
||||||
Token *functionNamespace = 0;
|
Token *namespaceStart = 0;
|
||||||
|
Token *namespaceEnd = 0;
|
||||||
|
|
||||||
if (Token::Match(tok->next(), "::") ||
|
if (Token::Match(tok->next(), "::") ||
|
||||||
Token::Match(tok->next(), "%type%"))
|
Token::Match(tok->next(), "%type%"))
|
||||||
|
@ -925,9 +926,12 @@ void Tokenizer::simplifyTypedef()
|
||||||
tok = specEnd->next();
|
tok = specEnd->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "( %var% :: *|&| const|volatile| const|volatile| %type% ) ("))
|
else if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "( ::| %var% :: *|&| const|volatile| const|volatile| %type% ) ("))
|
||||||
{
|
{
|
||||||
functionNamespace = tok->tokAt(offset + 1);
|
namespaceStart = tok->tokAt(offset + 1);
|
||||||
|
if (tok->tokAt(offset + 1)->str() == "::")
|
||||||
|
offset++;
|
||||||
|
namespaceEnd = tok->tokAt(offset + 2);
|
||||||
functionPtr = tok->tokAt(offset + 3)->str() == "*";
|
functionPtr = tok->tokAt(offset + 3)->str() == "*";
|
||||||
functionRef = tok->tokAt(offset + 3)->str() == "&";
|
functionRef = tok->tokAt(offset + 3)->str() == "&";
|
||||||
function = tok->tokAt(offset + 4)->str() == ")";
|
function = tok->tokAt(offset + 4)->str() == ")";
|
||||||
|
@ -1044,7 +1048,8 @@ void Tokenizer::simplifyTypedef()
|
||||||
// pointer to class member
|
// pointer to class member
|
||||||
else if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "( %type% :: * %type% ) ;"))
|
else if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset), "( %type% :: * %type% ) ;"))
|
||||||
{
|
{
|
||||||
functionNamespace = tok->tokAt(offset + 1);
|
namespaceStart = tok->tokAt(offset + 1);
|
||||||
|
namespaceEnd = tok->tokAt(offset + 2);
|
||||||
ptrMember = true;
|
ptrMember = true;
|
||||||
typeName = tok->tokAt(offset + 4);
|
typeName = tok->tokAt(offset + 4);
|
||||||
tok = tok->tokAt(offset + 6);
|
tok = tok->tokAt(offset + 6);
|
||||||
|
@ -1218,11 +1223,17 @@ void Tokenizer::simplifyTypedef()
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
Token *tok3 = tok2;
|
Token *tok3 = tok2;
|
||||||
if (functionNamespace)
|
if (namespaceStart)
|
||||||
{
|
{
|
||||||
tok2->insertToken(functionNamespace->str());
|
const Token *tok4 = namespaceStart;
|
||||||
tok2 = tok2->next();
|
|
||||||
tok2->insertToken("::");
|
while (tok4 != namespaceEnd)
|
||||||
|
{
|
||||||
|
tok2->insertToken(tok4->str());
|
||||||
|
tok2 = tok2->next();
|
||||||
|
tok4 = tok4->next();
|
||||||
|
}
|
||||||
|
tok2->insertToken(namespaceEnd->str());
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
}
|
}
|
||||||
if (functionPtr)
|
if (functionPtr)
|
||||||
|
@ -1428,10 +1439,15 @@ void Tokenizer::simplifyTypedef()
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
Token *tok3 = tok2;
|
Token *tok3 = tok2;
|
||||||
|
|
||||||
tok2->insertToken(functionNamespace->str());
|
const Token *tok4 = namespaceStart;
|
||||||
tok2 = tok2->next();
|
|
||||||
|
|
||||||
tok2->insertToken("::");
|
while (tok4 != namespaceEnd)
|
||||||
|
{
|
||||||
|
tok2->insertToken(tok4->str());
|
||||||
|
tok2 = tok2->next();
|
||||||
|
tok4 = tok4->next();
|
||||||
|
}
|
||||||
|
tok2->insertToken(namespaceEnd->str());
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
|
|
||||||
tok2->insertToken("*");
|
tok2->insertToken("*");
|
||||||
|
|
|
@ -4309,6 +4309,10 @@ private:
|
||||||
"typedef int ( C :: * const type6 ) ( float ) ;\n"
|
"typedef int ( C :: * const type6 ) ( float ) ;\n"
|
||||||
"typedef int ( C :: * volatile type7 ) ( float ) ;\n"
|
"typedef int ( C :: * volatile type7 ) ( float ) ;\n"
|
||||||
"typedef int ( C :: * const volatile type8 ) ( float ) ;\n"
|
"typedef int ( C :: * const volatile type8 ) ( float ) ;\n"
|
||||||
|
"typedef int ( :: C :: * type9 ) ( float ) ;\n"
|
||||||
|
"typedef int ( :: C :: * const type10 ) ( float ) ;\n"
|
||||||
|
"typedef int ( :: C :: * volatile type11 ) ( float ) ;\n"
|
||||||
|
"typedef int ( :: C :: * const volatile type12 ) ( float ) ;\n"
|
||||||
"type1 t1;\n"
|
"type1 t1;\n"
|
||||||
"type2 t2;\n"
|
"type2 t2;\n"
|
||||||
"type3 t3;\n"
|
"type3 t3;\n"
|
||||||
|
@ -4316,10 +4320,14 @@ private:
|
||||||
"type5 t5;\n"
|
"type5 t5;\n"
|
||||||
"type6 t6;\n"
|
"type6 t6;\n"
|
||||||
"type7 t7;\n"
|
"type7 t7;\n"
|
||||||
"type8 t8;";
|
"type8 t8;\n"
|
||||||
|
"type9 t9;\n"
|
||||||
|
"type10 t10;\n"
|
||||||
|
"type11 t11;\n"
|
||||||
|
"type12 t12;";
|
||||||
|
|
||||||
// The expected result..
|
// The expected result..
|
||||||
const std::string expected("; ; ; ; ; ; ; ; "
|
const std::string expected("; ; ; ; ; ; ; ; ; ; ; ; "
|
||||||
"int * t1 ; " // simplified to regular pointer
|
"int * t1 ; " // simplified to regular pointer
|
||||||
"int ( * const t2 ) ( float ) ; "
|
"int ( * const t2 ) ( float ) ; "
|
||||||
"int * t3 ; " // volatile removed, gets simplified to regular pointer
|
"int * t3 ; " // volatile removed, gets simplified to regular pointer
|
||||||
|
@ -4327,7 +4335,11 @@ private:
|
||||||
"int ( C :: * t5 ) ( float ) ; "
|
"int ( C :: * t5 ) ( float ) ; "
|
||||||
"int ( C :: * const t6 ) ( float ) ; "
|
"int ( C :: * const t6 ) ( float ) ; "
|
||||||
"int ( C :: * t7 ) ( float ) ; " // volatile removed
|
"int ( C :: * t7 ) ( float ) ; " // volatile removed
|
||||||
"int ( C :: * const t8 ) ( float ) ;"); // volatile removed
|
"int ( C :: * const t8 ) ( float ) ; " // volatile removed
|
||||||
|
"int ( :: C :: * t9 ) ( float ) ; "
|
||||||
|
"int ( :: C :: * const t10 ) ( float ) ; "
|
||||||
|
"int ( :: C :: * t11 ) ( float ) ; " // volatile removed
|
||||||
|
"int ( :: C :: * const t12 ) ( float ) ;"); // volatile removed
|
||||||
ASSERT_EQUALS(expected, tok(code, false));
|
ASSERT_EQUALS(expected, tok(code, false));
|
||||||
|
|
||||||
checkSimplifyTypedef(code);
|
checkSimplifyTypedef(code);
|
||||||
|
|
Loading…
Reference in New Issue