Tokenizer::simplifyGoto: process also derived class/structs.

This commit is contained in:
Edoardo Prezioso 2012-01-04 16:50:38 +01:00
parent b0e4dc3ab8
commit a7029291fd
2 changed files with 67 additions and 5 deletions

View File

@ -7181,11 +7181,25 @@ void Tokenizer::simplifyGoto()
if (tok->str() == "(" || tok->str() == "[")
tok = tok->link();
else if (tok->str() == "{") {
if (Token::Match(tok->tokAt(-2),"class|namespace|struct|union %var% {") ||
Token::Match(tok->previous(),"namespace|struct|union {"))
else if (Token::Match(tok, "class|namespace|struct|union %type% :|{")) {
tok = tok->tokAt(2);
while (tok && !Token::Match(tok, "[;{=]"))
tok = tok->next();
if (tok && tok->str() == "{")
++indentspecial;
else if ((!beginfunction && !indentlevel) ||
else if (!tok)
break;
else
continue;
}
else if (Token::Match(tok, "namespace|struct|union {")) {
tok = tok->next();
++indentspecial;
}
else if (tok->str() == "{") {
if ((!beginfunction && !indentlevel) ||
(tok->previous() && tok->previous()->str() == "="))
tok = tok->link();
else

View File

@ -3130,6 +3130,54 @@ private:
"}";
ASSERT_EQUALS(expected, tok(code));
}
{
const char code[] = "class A"
"{"
" int a; "
" double b; "
" A() : b(3.22)"
" {"
" goto source ;"
" bleeh;"
" source:"
" a = 322;"
" }"
"}"
"class A1 : public A"
"{"
" int a1; "
" double b1; "
" A1() : b1(3.22)"
" {"
" goto source1 ;"
" bleeh1;"
" source1:"
" a = 322;"
" }"
"}";
const char expected[] = "class A "
"{"
" int a ;"
" double b ;"
" A ( ) : b ( 3.22 )"
" {"
" a = 322 ;"
" return ;"
" } "
"} "
"class A1 : public A "
"{"
" int a1 ;"
" double b1 ;"
" A1 ( ) : b1 ( 3.22 )"
" {"
" a = 322 ;"
" return ;"
" } "
"}";
ASSERT_EQUALS(expected, tok(code));
}
}
void flowControl() {