Tokenizer: alternative tokens for and,or,etc. context sensitive for both c and c++.
This commit is contained in:
parent
920ac5a3f6
commit
b8ca9fc844
|
@ -6049,9 +6049,6 @@ static const std::map<std::string, std::string> cAlternativeTokens = make_contai
|
||||||
// xor_eq => ^=
|
// xor_eq => ^=
|
||||||
bool Tokenizer::simplifyCAlternativeTokens()
|
bool Tokenizer::simplifyCAlternativeTokens()
|
||||||
{
|
{
|
||||||
// In C these are optional macros (iso646.h). In C++ these are builtin keywords.
|
|
||||||
bool cpp = isCPP();
|
|
||||||
|
|
||||||
/* executable scope level */
|
/* executable scope level */
|
||||||
unsigned int executableScopeLevel = 0;
|
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());
|
const std::map<std::string, std::string>::const_iterator cOpIt = cAlternativeTokens.find(tok->str());
|
||||||
if (cOpIt != cAlternativeTokens.end()) {
|
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;
|
continue;
|
||||||
tok->str(cOpIt->second);
|
tok->str(cOpIt->second);
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if (Token::Match(tok, "not|compl")) {
|
} else if (Token::Match(tok, "not|compl")) {
|
||||||
// Don't simplify 'not p;' (in case 'not' is a type)
|
// 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(), "[;{}]") ||
|
Token::Match(tok->previous(), "[;{}]") ||
|
||||||
(executableScopeLevel == 0U && tok->strAt(-1) == "(")))
|
(executableScopeLevel == 0U && tok->strAt(-1) == "("))
|
||||||
continue;
|
continue;
|
||||||
tok->str((tok->str() == "not") ? "!" : "~");
|
tok->str((tok->str() == "not") ? "!" : "~");
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
Loading…
Reference in New Issue