fix #3093 (Simplify code (math expression) with keywords 'return' and 'case')
This commit is contained in:
parent
b0eab2587d
commit
08efad13b2
|
@ -7831,13 +7831,15 @@ bool Tokenizer::simplifyCalculations()
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok->previous(), "[=([,] 0 [+|]"))
|
else if (Token::Match(tok->previous(), "[=([,] 0 [+|]") ||
|
||||||
|
Token::Match(tok->previous(), "return|case 0 [+|]"))
|
||||||
{
|
{
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok->previous(), "[=[(,] 0 * %any% ,|]|)|;|%op%"))
|
else if (Token::Match(tok->previous(), "[=[(,] 0 * %any% ,|]|)|;|=|%op%") ||
|
||||||
|
Token::Match(tok->previous(), "return|case 0 * %any% ,|:|;|=|%op%"))
|
||||||
{
|
{
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
if (tok->next()->str() == "(")
|
if (tok->next()->str() == "(")
|
||||||
|
@ -7939,7 +7941,8 @@ bool Tokenizer::simplifyCalculations()
|
||||||
Token::Match(tok, "[[,(=<>+-*|&^] %num% [+-*/] %num% <<|>>") ||
|
Token::Match(tok, "[[,(=<>+-*|&^] %num% [+-*/] %num% <<|>>") ||
|
||||||
Token::Match(tok, "<< %num% [+-*/] %num% <<") ||
|
Token::Match(tok, "<< %num% [+-*/] %num% <<") ||
|
||||||
Token::Match(tok, "[(,[] %num% [|&^] %num% [];,);]") ||
|
Token::Match(tok, "[(,[] %num% [|&^] %num% [];,);]") ||
|
||||||
Token::Match(tok, "(|%op% %num% [+-*/] %num% )|%op%"))
|
Token::Match(tok, "(|%op% %num% [+-*/] %num% )|%op%") ||
|
||||||
|
Token::Match(tok,"return|case %num% [+-*/] %num% ;|,|=|:|%op%"))
|
||||||
{
|
{
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
|
|
|
@ -5679,6 +5679,19 @@ private:
|
||||||
tokenizeAndStringify("void foo ( int b ) { int a = b | 0 ; bar ( a ) ; }", true));
|
tokenizeAndStringify("void foo ( int b ) { int a = b | 0 ; bar ( a ) ; }", true));
|
||||||
ASSERT_EQUALS("void foo ( int b ) { int a ; a = b ; bar ( a ) ; }",
|
ASSERT_EQUALS("void foo ( int b ) { int a ; a = b ; bar ( a ) ; }",
|
||||||
tokenizeAndStringify("void foo ( int b ) { int a = 0 | b ; bar ( a ) ; }", true));
|
tokenizeAndStringify("void foo ( int b ) { int a = 0 | b ; bar ( a ) ; }", true));
|
||||||
|
|
||||||
|
// ticket #3093
|
||||||
|
ASSERT_EQUALS("int f ( ) { ; return 15 ; }",
|
||||||
|
tokenizeAndStringify("int f() { int a = 10; int b = 5; return a + b; }", true));
|
||||||
|
ASSERT_EQUALS("int f ( ) { return a ; }",
|
||||||
|
tokenizeAndStringify("int f() { return a * 1; }", true));
|
||||||
|
ASSERT_EQUALS("int f ( int a ) { return 0 ; }",
|
||||||
|
tokenizeAndStringify("int f(int a) { return 0 * a; }", true));
|
||||||
|
ASSERT_EQUALS("bool f ( int i ) { switch ( i ) { case 15 : ; return true ; } }",
|
||||||
|
tokenizeAndStringify("bool f(int i) { switch (i) { case 10 + 5: return true; } }", true));
|
||||||
|
TODO_ASSERT_EQUALS("bool f ( int i ) { ; switch ( i ) { case 15 : ; return true ; } }",
|
||||||
|
"bool f ( int i ) { int a ; a = 10 ; int b ; b = 5 ; switch ( i ) { case a + b : return true ; } }",
|
||||||
|
tokenizeAndStringify("bool f(int i) { int a = 10; int b = 5; switch (i) { case a + b: return true; } }", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplifyCompoundAssignment()
|
void simplifyCompoundAssignment()
|
||||||
|
|
Loading…
Reference in New Issue