Fixed #6207 ('not' misinterpreted as alternative C token)
This commit is contained in:
parent
684966f674
commit
06a594a9e0
|
@ -6044,6 +6044,9 @@ namespace {
|
|||
// xor_eq => ^=
|
||||
bool Tokenizer::simplifyCAlternativeTokens()
|
||||
{
|
||||
if (!isC())
|
||||
return false;
|
||||
|
||||
/* For C code: executable scope level */
|
||||
unsigned int executableScopeLevel = 0;
|
||||
|
||||
|
@ -6066,17 +6069,16 @@ bool Tokenizer::simplifyCAlternativeTokens()
|
|||
|
||||
const std::map<std::string, std::string>::const_iterator cOpIt = cAlternativeTokens.find(tok->str());
|
||||
if (cOpIt != cAlternativeTokens.end()) {
|
||||
if (isC() && !Token::Match(tok->previous(), "%name%|%num%|%char%|)|]|> %name% %name%|%num%|%char%|%op%|("))
|
||||
if (!Token::Match(tok->previous(), "%name%|%num%|%char%|)|]|> %name% %name%|%num%|%char%|%op%|("))
|
||||
continue;
|
||||
tok->str(cOpIt->second);
|
||||
ret = true;
|
||||
} else if (Token::Match(tok, "not|compl")) {
|
||||
// Don't simplify 'not p;' (in case 'not' is a type)
|
||||
if (isC() && (!Token::Match(tok->next(), "%name%|%op%|(") ||
|
||||
if (!Token::Match(tok->next(), "%name%|(") ||
|
||||
Token::Match(tok->previous(), "[;{}]") ||
|
||||
(executableScopeLevel == 0U && tok->strAt(-1) == "(")))
|
||||
(executableScopeLevel == 0U && tok->strAt(-1) == "("))
|
||||
continue;
|
||||
|
||||
tok->str((tok->str() == "not") ? "!" : "~");
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -5662,22 +5662,20 @@ private:
|
|||
}
|
||||
|
||||
void simplifyCAlternativeTokens() {
|
||||
ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a | b ) { ; } }", tokenizeAndStringify("void f() { if (a bitor b); }"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a ^ b ) { ; } }", tokenizeAndStringify("void f() { if (a xor b); }"));
|
||||
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); }"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a | b ) { ; } }", tokenizeAndStringify("void f() { if (a bitor b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a ^ b ) { ; } }", tokenizeAndStringify("void f() { if (a xor b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", false, true, Settings::Native, "test.c"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", false, true, Settings::Native, "test.c"));
|
||||
// #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"
|
||||
"##file 0\n"
|
||||
"1: void f ( bool b@1 ) { if ( ! b@1 ) { ; } }\n",
|
||||
tokenizeDebugListing("void f(bool b) { if (not b); }"));
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! c || ! memcmp ( a , b , s ) ) { ; } }", tokenizeAndStringify("void f() { if (!c or !memcmp(a, b, s)); }", false, true, Settings::Native, "test.c"));
|
||||
// #6029
|
||||
ASSERT_EQUALS("void f ( ) { if ( ! b ) { } }", tokenizeAndStringify("void f() { if (not b){} }", false, true, Settings::Native, "test.c"));
|
||||
// #6207
|
||||
ASSERT_EQUALS("void f ( ) { if ( not = x ) { } }", tokenizeAndStringify("void f() { if (not=x){} }", false, true, Settings::Native, "test.c"));
|
||||
}
|
||||
|
||||
void simplifyCalculations() {
|
||||
|
|
Loading…
Reference in New Issue