Support more patterns when replacing stuff like 'or' (#6201)

This commit is contained in:
PKEuS 2014-10-01 08:41:28 +02:00
parent f36aaae732
commit 14f15d65e7
2 changed files with 4 additions and 2 deletions

View File

@ -6257,14 +6257,14 @@ bool Tokenizer::simplifyCAlternativeTokens()
tok = start;
Token * const end = tok->link();
for (Token *tok2 = tok->next(); tok2 && tok2 != end; tok2 = tok2->next()) {
if (Token::Match(tok2, "%var%|%num%|)|] %any% %var%|%num%|(")) {
if (Token::Match(tok2, "%var%|%num%|)|]|> %any% %var%|%num%|(|%op%")) {
const std::map<std::string, std::string>::const_iterator cOpIt = cAlternativeTokens.find(tok2->next()->str());
if (cOpIt != cAlternativeTokens.end()) {
tok2->next()->str(cOpIt->second);
ret = true;
}
}
if (Token::Match(tok2, "not|compl %var%|(") &&
if (Token::Match(tok2, "not|compl %var%|(|%op%") &&
!Token::Match(tok2->previous(), "[;{}]")) { // Don't simplify 'not p;' (in case 'not' is a type)
tok2->str((tok2->str() == "not") ? "!" : "~");
ret = true;

View File

@ -5871,6 +5871,8 @@ private:
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }"));
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }"));
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }"));
// #6201
ASSERT_EQUALS("void f ( ) { if ( ! c || ! memcmp ( a , b , s ) ) { ; } }", tokenizeAndStringify("void f() { if (!c or !memcmp(a, b, s)); }"));
ASSERT_EQUALS("\n" // #6029
"\n"