Tokenizer: alternative tokens for and,or,etc. context sensitive for both c and c++.

This commit is contained in:
Daniel Marjamäki 2016-07-16 21:29:56 +02:00
parent 920ac5a3f6
commit b8ca9fc844
1 changed files with 4 additions and 7 deletions

View File

@ -6049,9 +6049,6 @@ static const std::map<std::string, std::string> cAlternativeTokens = make_contai
// xor_eq => ^=
bool Tokenizer::simplifyCAlternativeTokens()
{
// In C these are optional macros (iso646.h). In C++ these are builtin keywords.
bool cpp = isCPP();
/* executable scope level */
unsigned int executableScopeLevel = 0;
@ -6074,15 +6071,15 @@ bool Tokenizer::simplifyCAlternativeTokens()
const std::map<std::string, std::string>::const_iterator cOpIt = cAlternativeTokens.find(tok->str());
if (cOpIt != cAlternativeTokens.end()) {
if (!cpp && !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 (!cpp && (!Token::Match(tok->next(), "%name%|(") ||
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;