Fixed #9739 (Tokenizer: simplifyTypedef: wrong simplification in using)
This commit is contained in:
parent
7ff692341e
commit
67115491ea
|
@ -546,6 +546,23 @@ Token *Tokenizer::processFunc(Token *tok2, bool inOperator) const
|
||||||
return tok2;
|
return tok2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tokenizer::simplifyUsingToTypedef()
|
||||||
|
{
|
||||||
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
// using a::b; => typedef a::b b;
|
||||||
|
if (Token::Match(tok, "[;{}] using %name% :: %name% ::|;") && !tok->tokAt(2)->isKeyword()) {
|
||||||
|
Token *endtok = tok->tokAt(5);
|
||||||
|
while (Token::Match(endtok, ":: %name%"))
|
||||||
|
endtok = endtok->tokAt(2);
|
||||||
|
if (endtok && endtok->str() == ";") {
|
||||||
|
tok->next()->str("typedef");
|
||||||
|
endtok = endtok->previous();
|
||||||
|
endtok->insertToken(endtok->str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Tokenizer::simplifyTypedef()
|
void Tokenizer::simplifyTypedef()
|
||||||
{
|
{
|
||||||
std::vector<Space> spaceInfo;
|
std::vector<Space> spaceInfo;
|
||||||
|
@ -553,6 +570,10 @@ void Tokenizer::simplifyTypedef()
|
||||||
std::string className;
|
std::string className;
|
||||||
bool hasClass = false;
|
bool hasClass = false;
|
||||||
bool goback = false;
|
bool goback = false;
|
||||||
|
|
||||||
|
// Convert "using a::b;" to corresponding typedef statements
|
||||||
|
simplifyUsingToTypedef();
|
||||||
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (mErrorLogger && !list.getFiles().empty())
|
if (mErrorLogger && !list.getFiles().empty())
|
||||||
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());
|
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());
|
||||||
|
|
|
@ -367,6 +367,9 @@ public:
|
||||||
*/
|
*/
|
||||||
Token * simplifyAddBracesPair(Token *tok, bool commandWithCondition);
|
Token * simplifyAddBracesPair(Token *tok, bool commandWithCondition);
|
||||||
|
|
||||||
|
// Convert "using ...;" to corresponding typedef
|
||||||
|
void simplifyUsingToTypedef();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* typedef A mytype;
|
* typedef A mytype;
|
||||||
* mytype c;
|
* mytype c;
|
||||||
|
|
|
@ -167,6 +167,7 @@ private:
|
||||||
TEST_CASE(simplifyTypedef129);
|
TEST_CASE(simplifyTypedef129);
|
||||||
TEST_CASE(simplifyTypedef130); // ticket #9446
|
TEST_CASE(simplifyTypedef130); // ticket #9446
|
||||||
TEST_CASE(simplifyTypedef131); // ticket #9446
|
TEST_CASE(simplifyTypedef131); // ticket #9446
|
||||||
|
TEST_CASE(simplifyTypedef132); // ticket #9739 - using
|
||||||
|
|
||||||
TEST_CASE(simplifyTypedefFunction1);
|
TEST_CASE(simplifyTypedefFunction1);
|
||||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||||
|
@ -2630,6 +2631,27 @@ private:
|
||||||
ASSERT_EQUALS(exp, tok(code, false));
|
ASSERT_EQUALS(exp, tok(code, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void simplifyTypedef132() {
|
||||||
|
const char code[] = "namespace NamespaceA {\n"
|
||||||
|
" typedef int MySpecialType;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"class A {\n"
|
||||||
|
" void DoSomething( NamespaceA::MySpecialType special );\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"using NamespaceA::MySpecialType;\n"
|
||||||
|
"\n"
|
||||||
|
"void A::DoSomething( MySpecialType wrongName ) {}";
|
||||||
|
|
||||||
|
const char exp [] = "class A { "
|
||||||
|
"void DoSomething ( int special ) ; "
|
||||||
|
"} ; "
|
||||||
|
"void A :: DoSomething ( int wrongName ) { }";
|
||||||
|
|
||||||
|
ASSERT_EQUALS(exp, tok(code, false));
|
||||||
|
}
|
||||||
|
|
||||||
void simplifyTypedefFunction1() {
|
void simplifyTypedefFunction1() {
|
||||||
{
|
{
|
||||||
const char code[] = "typedef void (*my_func)();\n"
|
const char code[] = "typedef void (*my_func)();\n"
|
||||||
|
|
Loading…
Reference in New Issue