Fixed #10013 (Tokenizer: Code with 'not' is not handled)

This commit is contained in:
Daniel Marjamäki 2021-02-13 20:32:49 +01:00
parent edd10064d1
commit f08dde1140
2 changed files with 10 additions and 3 deletions

View File

@ -4701,6 +4701,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
removePragma();
// Simplify the C alternative tokens (and, or, etc.)
simplifyCAlternativeTokens();
reportUnknownMacros();
simplifyHeadersAndUnusedTemplates();
@ -4758,9 +4761,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// Combine tokens..
combineOperators();
// Simplify the C alternative tokens (and, or, etc.)
simplifyCAlternativeTokens();
// replace 'sin(0)' to '0' and other similar math expressions
simplifyMathExpressions();
@ -7628,6 +7628,11 @@ bool Tokenizer::simplifyCAlternativeTokens()
} else if (Token::Match(tok, "not|compl")) {
alt.push_back(tok);
if (Token::Match(tok->previous(), "%assign%") || Token::Match(tok->next(), "%number%")) {
replaceAll = true;
continue;
}
// Don't simplify 'not p;' (in case 'not' is a type)
if (!Token::Match(tok->next(), "%name%|(") ||
Token::Match(tok->previous(), "[;{}]") ||

View File

@ -6319,6 +6319,8 @@ private:
" char *or;\n"
" while ((*or != 0) && (*or != '|')) or++;\n"
"}", false, true, Settings::Native, "test.c"));
// #10013
ASSERT_EQUALS("void f ( ) { x = ! 123 ; }", tokenizeAndStringify("void f() { x = not 123; }", false, true, Settings::Native, "test.cpp"));
}
void simplifyCalculations() {