Extended Tokenizer::simplifyCaseRange() to support also ranges of chars.

This commit is contained in:
PKEuS 2015-11-06 18:46:43 +01:00
parent 41b1b9d850
commit 1fe1d7ea4a
2 changed files with 17 additions and 0 deletions

View File

@ -2397,6 +2397,20 @@ void Tokenizer::simplifyCaseRange()
tok->insertToken("case");
}
}
} else if (Token::Match(tok, "case %char% . . . %char% :")) {
char start = tok->strAt(1)[1];
char end = tok->strAt(5)[1];
if (start < end) {
tok = tok->tokAt(2);
tok->str(":");
tok->deleteNext();
tok->next()->str("case");
for (char i = end - 1; i > start; i--) {
tok->insertToken(":");
tok->insertToken(std::string(1, '\'') + i + '\'');
tok->insertToken("case");
}
}
}
}
}

View File

@ -7996,6 +7996,9 @@ private:
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 4 . . . 1 : ; }", tokenizeAndStringify("void f() { case 4 ... 1: }"));
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': }"));
}
void prepareTernaryOpForAST() {