Here is a patch that adds support for derived structs and fixes a bug that missed some nested structs. (#1493)
This commit is contained in:
parent
d11004fa3d
commit
9c2248254e
|
@ -6813,12 +6813,15 @@ void Tokenizer::simplifyStructDecl()
|
|||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
// check for named struct/union
|
||||
if (Token::Match(tok, "struct|union %type% {"))
|
||||
if (Token::Match(tok, "struct|union %type% :|{"))
|
||||
{
|
||||
Token *type = tok->next();
|
||||
Token *next = tok->tokAt(2);
|
||||
|
||||
tok = tok->tokAt(2)->link();
|
||||
while (next->str() != "{")
|
||||
next = next->next();
|
||||
|
||||
tok = next->link();
|
||||
|
||||
// check for named type
|
||||
if (Token::Match(tok->next(), "*|&| %type% ,|;|["))
|
||||
|
@ -6826,8 +6829,9 @@ void Tokenizer::simplifyStructDecl()
|
|||
tok->insertToken(";");
|
||||
tok = tok->next();
|
||||
tok->insertToken(type->str().c_str());
|
||||
tok = next;
|
||||
}
|
||||
|
||||
tok = next;
|
||||
}
|
||||
|
||||
// check for anonymous struct/union
|
||||
|
@ -6837,6 +6841,7 @@ void Tokenizer::simplifyStructDecl()
|
|||
|
||||
tok = tok->next()->link();
|
||||
|
||||
// check for named type
|
||||
if (Token::Match(tok->next(), "*|&| %type% ,|;|["))
|
||||
{
|
||||
std::string name;
|
||||
|
@ -6848,8 +6853,9 @@ void Tokenizer::simplifyStructDecl()
|
|||
tok->insertToken(";");
|
||||
tok = tok->next();
|
||||
tok->insertToken(name.c_str());
|
||||
tok = tok1->next();
|
||||
}
|
||||
|
||||
tok = tok1->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4221,6 +4221,18 @@ private:
|
|||
const char expected[] = "union ABC { int i ; float f ; } ; ABC abc ;";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "struct ABC { struct {} def; };";
|
||||
const char expected[] = "struct ABC { struct Anonymous0 { } ; Anonymous0 def ; } ;";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
|
||||
{
|
||||
const char code[] = "struct ABC : public XYZ { struct {} def; };";
|
||||
const char expected[] = "struct ABC : public XYZ { struct Anonymous0 { } ; Anonymous0 def ; } ;";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1514,19 +1514,37 @@ private:
|
|||
|
||||
void varid15()
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
"struct S {\n"
|
||||
" struct T {\n"
|
||||
" } t;\n"
|
||||
"} s;");
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
"struct S {\n"
|
||||
" struct T {\n"
|
||||
" } t;\n"
|
||||
"} s;");
|
||||
|
||||
const std::string expected("\n\n##file 0\n"
|
||||
"1: struct S {\n"
|
||||
"2: struct T {\n"
|
||||
"3: } ; T t@1 ;\n"
|
||||
"4: } ; S s@2 ;\n");
|
||||
const std::string expected("\n\n##file 0\n"
|
||||
"1: struct S {\n"
|
||||
"2: struct T {\n"
|
||||
"3: } ; T t@1 ;\n"
|
||||
"4: } ; S s@2 ;\n");
|
||||
|
||||
ASSERT_EQUALS(expected, actual);
|
||||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
|
||||
{
|
||||
const std::string actual = tokenizeDebugListing(
|
||||
"struct S {\n"
|
||||
" struct T {\n"
|
||||
" } t;\n"
|
||||
"};");
|
||||
|
||||
const std::string expected("\n\n##file 0\n"
|
||||
"1: struct S {\n"
|
||||
"2: struct T {\n"
|
||||
"3: } ; T t@1 ;\n"
|
||||
"4: } ;\n");
|
||||
|
||||
ASSERT_EQUALS(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
void varidStl()
|
||||
|
|
Loading…
Reference in New Issue