TemplateSimplifier::simplifyCalculations: Add some more tests and make sure they pass

This commit is contained in:
Daniel Marjamäki 2017-06-08 08:15:05 +02:00
parent cb48e63f92
commit c1ea873e1c
2 changed files with 15 additions and 3 deletions

View File

@ -1152,10 +1152,10 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
ret = true;
}
if (Token::simpleMatch(tok->previous(), "( 0 |") ||
Token::simpleMatch(tok->previous(), "| 0 )")) {
if (Token::Match(tok->previous(), "( 0 [|+]") ||
Token::Match(tok->previous(), "[|+-] 0 )")) {
tok = tok->previous();
if (tok->str() == "|")
if (Token::Match(tok, "[|+-]"))
tok = tok->previous();
tok->deleteNext(2);
ret = true;

View File

@ -5753,6 +5753,18 @@ private:
void simplifyCalculations() {
ASSERT_EQUALS("void foo ( char str [ ] ) { char x ; x = * str ; }",
tokenizeAndStringify("void foo ( char str [ ] ) { char x = 0 | ( * str ) ; }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
tokenizeAndStringify("void foo ( ) { if (b + 0) { } }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
tokenizeAndStringify("void foo ( ) { if (0 + b) { } }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
tokenizeAndStringify("void foo ( ) { if (b - 0) { } }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
tokenizeAndStringify("void foo ( ) { if (b * 1) { } }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
tokenizeAndStringify("void foo ( ) { if (1 * b) { } }", true));
//ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
// tokenizeAndStringify("void foo ( ) { if (b / 1) { } }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",
tokenizeAndStringify("void foo ( ) { if (b | 0) { } }", true));
ASSERT_EQUALS("void foo ( ) { if ( b ) { } }",