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:
parent
6b56b4a9d3
commit
2ce5cb3075
|
@ -6591,15 +6591,21 @@ bool Tokenizer::simplifyRedundantParenthesis()
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(tok, "( ( %bool% )") ||
|
if (Token::simpleMatch(tok->previous(), ", (") &&
|
||||||
Token::Match(tok, "( ( %num% )")) {
|
Token::simpleMatch(tok->link(), ") =")) {
|
||||||
tok->deleteNext();
|
tok->link()->deleteThis();
|
||||||
tok->next()->deleteNext();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::simpleMatch(tok->previous(), ", (") &&
|
// Simplify "!!operator !!(%var%|)) ( %num%|%bool% ) %op%|;|,|)"
|
||||||
Token::simpleMatch(tok->link(), ") =")) {
|
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->link()->deleteThis();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
|
@ -4573,6 +4573,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 : 123 + 456 ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tokenize_double() {
|
void tokenize_double() {
|
||||||
|
@ -4805,7 +4806,7 @@ private:
|
||||||
void vardecl_template_1() {
|
void vardecl_template_1() {
|
||||||
// ticket #1046
|
// ticket #1046
|
||||||
const char code1[] = "b<(1<<24),10,24> u, v;";
|
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));
|
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
|
||||||
// ticket #3571 (segmentation fault)
|
// ticket #3571 (segmentation fault)
|
||||||
tokenizeAndStringify("template <int i = (3>4) > class X4 {};");
|
tokenizeAndStringify("template <int i = (3>4) > class X4 {};");
|
||||||
|
|
Loading…
Reference in New Issue