Fixed #1339 (add nested struct support to simplifyEnum and simplifyTypedef)

This commit is contained in:
Robert Reif 2010-02-01 19:59:24 +01:00 committed by Daniel Marjamäki
parent 1b9afc82a4
commit b704fc7bc7
2 changed files with 97 additions and 23 deletions

View File

@ -372,7 +372,7 @@ void Tokenizer::simplifyTypedef()
int classLevel = 0; int classLevel = 0;
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::Match(tok, "class|namespace %any%")) if (Token::Match(tok, "class|struct|namespace %any%"))
{ {
className = tok->next()->str(); className = tok->next()->str();
classLevel = 0; classLevel = 0;
@ -4925,7 +4925,7 @@ void Tokenizer::simplifyEnum()
int classLevel = 0; int classLevel = 0;
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::Match(tok, "class|namespace %any%")) if (Token::Match(tok, "class|struct|namespace %any%"))
{ {
className = tok->next()->str(); className = tok->next()->str();
classLevel = 0; classLevel = 0;

View File

@ -167,6 +167,7 @@ private:
TEST_CASE(simplifyTypedef28); TEST_CASE(simplifyTypedef28);
TEST_CASE(simplifyTypedef29); TEST_CASE(simplifyTypedef29);
TEST_CASE(simplifyTypedef30); TEST_CASE(simplifyTypedef30);
TEST_CASE(simplifyTypedef31);
TEST_CASE(reverseArraySyntax) TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition) TEST_CASE(simplify_numeric_condition)
@ -3022,6 +3023,55 @@ private:
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
} }
void simplifyTypedef31()
{
{
const char code[] = "class A {\n"
"public:\n"
" typedef int INT;\n"
" INT get() const;\n"
" void put(INT x) { a = x; }\n"
" INT a;\n"
"};\n"
"A::INT A::get() const { return a; }\n"
"A::INT i = A::a;";
const char expected[] = "class A { "
"public: "
"; "
"int get ( ) const ; "
"void put ( int x ) { a = x ; } "
"int a ; "
"} ; "
"int A :: get ( ) const { return a ; } "
"int i ; i = A :: a ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct A {\n"
" typedef int INT;\n"
" INT get() const;\n"
" void put(INT x) { a = x; }\n"
" INT a;\n"
"};\n"
"A::INT A::get() const { return a; }\n"
"A::INT i = A::a;";
const char expected[] = "struct A { "
"; "
"int get ( ) const ; "
"void put ( int x ) { a = x ; } "
"int a ; "
"} ; "
"int A :: get ( ) const { return a ; } "
"int i ; i = A :: a ;";
ASSERT_EQUALS(expected, tok(code, false));
}
}
void reverseArraySyntax() void reverseArraySyntax()
{ {
ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
@ -3268,29 +3318,53 @@ private:
void enum4() void enum4()
{ {
const char code[] = "class A {\n" {
"public:\n" const char code[] = "class A {\n"
" enum EA { a1, a2, a3 };\n" "public:\n"
" EA get() const;\n" " enum EA { a1, a2, a3 };\n"
" void put(EA a) { ea = a; ea = a1; }\n" " EA get() const;\n"
"private:\n" " void put(EA a) { ea = a; ea = a1; }\n"
" EA ea;\n" "private:\n"
"};\n" " EA ea;\n"
"A::EA A::get() const { return ea; }\n" "};\n"
"A::EA e = A::a1;"; "A::EA A::get() const { return ea; }\n"
"A::EA e = A::a1;";
const char expected[] = "class A { " const char expected[] = "class A { "
"public: " "public: "
"; " "; "
"int get ( ) const ; " "int get ( ) const ; "
"void put ( int a ) { ea = a ; ea = 0 ; } " "void put ( int a ) { ea = a ; ea = 0 ; } "
"private: " "private: "
"int ea ; " "int ea ; "
"} ; " "} ; "
"int A :: get ( ) const { return ea ; } " "int A :: get ( ) const { return ea ; } "
"int e ; e = 0 ;"; "int e ; e = 0 ;";
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "struct A {\n"
" enum EA { a1, a2, a3 };\n"
" EA get() const;\n"
" void put(EA a) { ea = a; ea = a1; }\n"
" EA ea;\n"
"};\n"
"A::EA A::get() const { return ea; }\n"
"A::EA e = A::a1;";
const char expected[] = "struct A { "
"; "
"int get ( ) const ; "
"void put ( int a ) { ea = a ; ea = 0 ; } "
"int ea ; "
"} ; "
"int A :: get ( ) const { return ea ; } "
"int e ; e = 0 ;";
ASSERT_EQUALS(expected, tok(code, false));
}
} }
void removestd() void removestd()