Tokenizer: Simplified parentheses better in such pattern: 'git merge --squash 4142 operator git merge --squash 4142 (%var%|)) ( %num%|%bool% ) %op%|;|,|)'

This commit is contained in:
Daniel Marjamäki 2012-09-08 07:01:35 +02:00
parent 6b56b4a9d3
commit 2ce5cb3075
2 changed files with 14 additions and 7 deletions

View File

@ -6591,15 +6591,21 @@ bool Tokenizer::simplifyRedundantParenthesis()
ret = true;
}
if (Token::Match(tok, "( ( %bool% )") ||
Token::Match(tok, "( ( %num% )")) {
tok->deleteNext();
tok->next()->deleteNext();
if (Token::simpleMatch(tok->previous(), ", (") &&
Token::simpleMatch(tok->link(), ") =")) {
tok->link()->deleteThis();
tok->deleteThis();
ret = true;
}
if (Token::simpleMatch(tok->previous(), ", (") &&
Token::simpleMatch(tok->link(), ") =")) {
// Simplify "!!operator !!(%var%|)) ( %num%|%bool% ) %op%|;|,|)"
if (Token::Match(tok, "( !!) ) %op%|;|,|)") &&
!Token::simpleMatch(tok->tokAt(-2), "operator") &&
tok->previous() &&
!tok->previous()->isName() &&
tok->previous()->str() != ")" &&
(!isCPP() || tok->previous()->str() != ">") &&
(tok->next()->isNumber() || tok->next()->isBoolean())) {
tok->link()->deleteThis();
tok->deleteThis();
ret = true;

View File

@ -4573,6 +4573,7 @@ private:
void removeParentheses15() {
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false));
ASSERT_EQUALS("a = b ? c : 123 + 456 ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
}
void tokenize_double() {
@ -4805,7 +4806,7 @@ private:
void vardecl_template_1() {
// ticket #1046
const char code1[] = "b<(1<<24),10,24> u, v;";
const char res1[] = "b < ( 16777216 ) , 10 , 24 > u ; b < ( 16777216 ) , 10 , 24 > v ;";
const char res1[] = "b < 16777216 , 10 , 24 > u ; b < 16777216 , 10 , 24 > v ;";
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
// ticket #3571 (segmentation fault)
tokenizeAndStringify("template <int i = (3>4) > class X4 {};");