Extended Tokenizer::simplifyCaseRange() to support also ranges of chars.
This commit is contained in:
parent
41b1b9d850
commit
1fe1d7ea4a
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue