Tokenizer::simplifyLabelsCaseDefault(): Do not insert ; between two cases.

This commit is contained in:
PKEuS 2015-11-06 19:59:23 +01:00
parent 95a0c0f14c
commit 7a90b763f6
2 changed files with 8 additions and 6 deletions

View File

@ -2349,7 +2349,7 @@ void Tokenizer::simplifyLabelsCaseDefault()
} else if (Token::Match(tok, "(|[")) } else if (Token::Match(tok, "(|["))
tok = tok->link(); tok = tok->link();
if (Token::Match(tok, "[;{}] case")) { if (Token::Match(tok, "[;{}:] case")) {
while (nullptr != (tok = tok->next())) { while (nullptr != (tok = tok->next())) {
if (Token::Match(tok, "(|[")) { if (Token::Match(tok, "(|[")) {
tok = tok->link(); tok = tok->link();
@ -2367,8 +2367,10 @@ void Tokenizer::simplifyLabelsCaseDefault()
break; break;
if (tok->str() != "case" && tok->next() && tok->next()->str() == ":") { if (tok->str() != "case" && tok->next() && tok->next()->str() == ":") {
tok = tok->next(); tok = tok->next();
if (tok->next()->str() != ";") if (tok->next()->str() != ";" && tok->next()->str() != "case")
tok->insertToken(";"); tok->insertToken(";");
else
tok = tok->previous();
} else { } else {
syntaxError(tok); syntaxError(tok);
} }
@ -8064,7 +8066,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
else else
indentcase = switchindents[indentswitch-1]; indentcase = switchindents[indentswitch-1];
} }
} else if (Token::Match(tok, "[{};] case")) { } else if (Token::Match(tok, "[{};:] case")) {
const Token *tok2 = Token::findsimplematch(tok->next(), ": ;", end); const Token *tok2 = Token::findsimplematch(tok->next(), ": ;", end);
if (!tok2) { if (!tok2) {
tok->deleteNext(); tok->deleteNext();
@ -8106,7 +8108,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end)
while (tok2->next() && tok2->next() != end) { while (tok2->next() && tok2->next() != end) {
if (Token::Match(tok2->next(), "{|[|(")) { if (Token::Match(tok2->next(), "{|[|(")) {
tok2 = tok2->next()->link(); tok2 = tok2->next()->link();
} else if (Token::Match(tok2, "[{};] case")) { } else if (Token::Match(tok2, "[{};:] case")) {
const Token *tok3 = Token::findsimplematch(tok2->next(), ": ;", end); const Token *tok3 = Token::findsimplematch(tok2->next(), ": ;", end);
if (!tok3) { if (!tok3) {
tok2 = tok2->next(); tok2 = tok2->next();

View File

@ -7994,11 +7994,11 @@ private:
} }
void simplifyCaseRange() { void simplifyCaseRange() {
ASSERT_EQUALS("void f ( ) { case 1 : ; case 2 : ; case 3 : ; case 4 : ; }", tokenizeAndStringify("void f() { case 1 ... 4: }")); ASSERT_EQUALS("void f ( ) { case 1 : case 2 : case 3 : case 4 : ; }", tokenizeAndStringify("void f() { case 1 ... 4: }"));
ASSERT_EQUALS("void f ( ) { case 4 . . . 1 : ; }", tokenizeAndStringify("void f() { case 4 ... 1: }")); ASSERT_EQUALS("void f ( ) { case 4 . . . 1 : ; }", tokenizeAndStringify("void f() { case 4 ... 1: }"));
tokenizeAndStringify("void f() { case 1 ... 1000000: }"); // Do not run out of memory tokenizeAndStringify("void f() { case 1 ... 1000000: }"); // Do not run out of memory
ASSERT_EQUALS("void f ( ) { case 'a' : ; case 'b' : ; case 'c' : ; }", tokenizeAndStringify("void f() { case 'a' ... 'c': }")); ASSERT_EQUALS("void f ( ) { case 'a' : case 'b' : case 'c' : ; }", tokenizeAndStringify("void f() { case 'a' ... 'c': }"));
ASSERT_EQUALS("void f ( ) { case 'c' . . . 'a' : ; }", tokenizeAndStringify("void f() { case 'c' ... 'a': }")); ASSERT_EQUALS("void f ( ) { case 'c' . . . 'a' : ; }", tokenizeAndStringify("void f() { case 'c' ... 'a': }"));
} }