From f08dde1140f6f73369c80e3bd95683f146304f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 13 Feb 2021 20:32:49 +0100 Subject: [PATCH] Fixed #10013 (Tokenizer: Code with 'not' is not handled) --- lib/tokenize.cpp | 11 ++++++++--- test/testtokenize.cpp | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9d371c9c0..d052c7b97 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(), "[;{}]") || diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index cca6c3231..96a9df28a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() {