Tokenizer: Improved simplification of 'a?(1):b'
This commit is contained in:
parent
2722f53edd
commit
a39b58046f
|
@ -6586,6 +6586,18 @@ bool Tokenizer::simplifyRedundantParenthesis()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Token::simpleMatch(tok->previous(), "? (") && Token::simpleMatch(tok->link(), ") :")) {
|
||||||
|
const Token *tok2 = tok->next();
|
||||||
|
while (tok2 && (tok2->isName() || tok2->isNumber() || tok2->isBoolean() || tok2->isArithmeticalOp()))
|
||||||
|
tok2 = tok2->next();
|
||||||
|
if (tok2 && tok2->str() == ")") {
|
||||||
|
tok->link()->deleteThis();
|
||||||
|
tok->deleteThis();
|
||||||
|
ret = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (Token::Match(tok->previous(), "[{([,:] ( !!{") && Token::Match(tok->link(), ") [;,])]")) {
|
while (Token::Match(tok->previous(), "[{([,:] ( !!{") && Token::Match(tok->link(), ") [;,])]")) {
|
||||||
// We have "( ... )", remove the parenthesis
|
// We have "( ... )", remove the parenthesis
|
||||||
tok->link()->deleteThis();
|
tok->link()->deleteThis();
|
||||||
|
|
|
@ -4574,6 +4574,7 @@ private:
|
||||||
void removeParentheses15() {
|
void removeParentheses15() {
|
||||||
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false));
|
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false));
|
||||||
ASSERT_EQUALS("a = b ? c : 579 ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
|
ASSERT_EQUALS("a = b ? c : 579 ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
|
||||||
|
ASSERT_EQUALS("a = b ? 123 : c ;", tokenizeAndStringify("a = b ? (123) : c;", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tokenize_double() {
|
void tokenize_double() {
|
||||||
|
|
Loading…
Reference in New Issue