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;
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();
classLevel = 0;
@ -4925,7 +4925,7 @@ void Tokenizer::simplifyEnum()
int classLevel = 0;
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();
classLevel = 0;

View File

@ -167,6 +167,7 @@ private:
TEST_CASE(simplifyTypedef28);
TEST_CASE(simplifyTypedef29);
TEST_CASE(simplifyTypedef30);
TEST_CASE(simplifyTypedef31);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -3022,6 +3023,55 @@ private:
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()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));
@ -3267,6 +3317,7 @@ private:
}
void enum4()
{
{
const char code[] = "class A {\n"
"public:\n"
@ -3293,6 +3344,29 @@ private:
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()
{
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));