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:
Robert Reif 2010-03-19 16:17:25 +01:00 committed by Daniel Marjamäki
parent d11004fa3d
commit 9c2248254e
3 changed files with 51 additions and 15 deletions

View File

@ -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();
}
}
}

View File

@ -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));
}
}
};

View File

@ -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()