Tokenizer: Fixed goto problems
This commit is contained in:
parent
7f6a10599b
commit
47e1a571f7
|
@ -6697,14 +6697,12 @@ void Tokenizer::simplifyGoto()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok->str() == "}") {
|
else if (tok->str() == "}") {
|
||||||
if (!indentlevel) {
|
if (indentlevel == 0) {
|
||||||
if (indentspecial)
|
if (indentspecial)
|
||||||
--indentspecial;
|
--indentspecial;
|
||||||
else
|
|
||||||
break; // break out - it seems the code is wrong
|
|
||||||
} else {
|
} else {
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
if (!indentlevel) {
|
if (indentlevel == 0) {
|
||||||
gotos.clear();
|
gotos.clear();
|
||||||
beginfunction = 0;
|
beginfunction = 0;
|
||||||
}
|
}
|
||||||
|
@ -6839,6 +6837,9 @@ void Tokenizer::simplifyGoto()
|
||||||
}
|
}
|
||||||
|
|
||||||
// goto the end of the function
|
// goto the end of the function
|
||||||
|
if (tok->str() == "{")
|
||||||
|
tok = tok->link();
|
||||||
|
else {
|
||||||
while (tok) {
|
while (tok) {
|
||||||
if (tok->str() == "{")
|
if (tok->str() == "{")
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
|
@ -6846,6 +6847,7 @@ void Tokenizer::simplifyGoto()
|
||||||
break;
|
break;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!tok)
|
if (!tok)
|
||||||
break;
|
break;
|
||||||
gotos.clear();
|
gotos.clear();
|
||||||
|
|
|
@ -174,6 +174,7 @@ private:
|
||||||
TEST_CASE(goto3); // #3138
|
TEST_CASE(goto3); // #3138
|
||||||
TEST_CASE(goto4); // #3459
|
TEST_CASE(goto4); // #3459
|
||||||
TEST_CASE(goto5); // #3705 - return ({asm("");});
|
TEST_CASE(goto5); // #3705 - return ({asm("");});
|
||||||
|
TEST_CASE(goto6);
|
||||||
|
|
||||||
//remove dead code after flow control statements
|
//remove dead code after flow control statements
|
||||||
TEST_CASE(flowControl);
|
TEST_CASE(flowControl);
|
||||||
|
@ -3347,6 +3348,33 @@ private:
|
||||||
"}", tok(code));
|
"}", tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void goto6() { // from code in linux that wasn't handled well
|
||||||
|
const char code1[] = "static void a() {\n"
|
||||||
|
"unlock:\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"static void b() {\n"
|
||||||
|
" if (c)\n"
|
||||||
|
" goto defer;\n"
|
||||||
|
"defer:\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS("static void a ( ) { } "
|
||||||
|
"static void b ( ) { if ( c ) { return ; } }", tok(code1));
|
||||||
|
|
||||||
|
const char code2[] = "void a()\n"
|
||||||
|
"{\n"
|
||||||
|
" if (x) {}\n"
|
||||||
|
"unlock:\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void b()\n"
|
||||||
|
"{\n"
|
||||||
|
" { goto defer; }\n"
|
||||||
|
"defer:\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS("void a ( ) { if ( x ) { } } void b ( ) { return ; }", tok(code2));
|
||||||
|
}
|
||||||
|
|
||||||
void flowControl() {
|
void flowControl() {
|
||||||
std::list<std::string> beforedead;
|
std::list<std::string> beforedead;
|
||||||
//beforedead.push_back("return");
|
//beforedead.push_back("return");
|
||||||
|
|
Loading…
Reference in New Issue