Tokenizer: Use the %oror% in multiCompare patterns
This commit is contained in:
parent
747a2331c6
commit
4c753ca5ac
|
@ -5127,17 +5127,13 @@ bool Tokenizer::simplifyConditions()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change numeric constant in condition to "true" or "false"
|
// Change numeric constant in condition to "true" or "false"
|
||||||
if (Token::Match(tok, "if|while ( %num%") &&
|
if (Token::Match(tok, "if|while ( %num% )|%oror%|&&"))
|
||||||
(tok->tokAt(3)->str() == ")" || tok->tokAt(3)->str() == "||" || tok->tokAt(3)->str() == "&&"))
|
|
||||||
{
|
{
|
||||||
tok->tokAt(2)->str((tok->tokAt(2)->str() != "0") ? "true" : "false");
|
tok->tokAt(2)->str((tok->tokAt(2)->str() != "0") ? "true" : "false");
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
Token *tok2 = tok->tokAt(2);
|
Token *tok2 = tok->tokAt(2);
|
||||||
if (tok2 &&
|
if (Token::Match(tok2, "&&|%oror% %num% )|%oror%|&&"))
|
||||||
(tok->str() == "&&" || tok->str() == "||") &&
|
|
||||||
Token::Match(tok->next(), "%num%") &&
|
|
||||||
(tok2->str() == ")" || tok2->str() == "&&" || tok2->str() == "||"))
|
|
||||||
{
|
{
|
||||||
tok->next()->str((tok->next()->str() != "0") ? "true" : "false");
|
tok->next()->str((tok->next()->str() != "0") ? "true" : "false");
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -5147,10 +5143,10 @@ bool Tokenizer::simplifyConditions()
|
||||||
const Token *tok4 = tok->tokAt(4);
|
const Token *tok4 = tok->tokAt(4);
|
||||||
if (! tok4)
|
if (! tok4)
|
||||||
break;
|
break;
|
||||||
if ((tok->str() == "&&" || tok->str() == "||" || tok->str() == "(") &&
|
if (Token::Match(tok, "&&|%oror%|(") &&
|
||||||
(Token::Match(tok->tokAt(1), "%num% %any% %num%") ||
|
(Token::Match(tok->tokAt(1), "%num% %any% %num%") ||
|
||||||
Token::Match(tok->tokAt(1), "%bool% %any% %bool%")) &&
|
Token::Match(tok->tokAt(1), "%bool% %any% %bool%")) &&
|
||||||
(tok4->str() == "&&" || tok4->str() == "||" || tok4->str() == ")" || tok4->str() == "?"))
|
Token::Match(tok4, "&&|%oror%|)|?"))
|
||||||
{
|
{
|
||||||
std::string cmp = tok->strAt(2);
|
std::string cmp = tok->strAt(2);
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
@ -6739,9 +6735,7 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
|
|
||||||
// condition "(|&&|%OROR% %varid% )|&&|%OROR%
|
// condition "(|&&|%OROR% %varid% )|&&|%OROR%
|
||||||
if (!Token::Match(tok3->previous(), "( %var% )") &&
|
if (!Token::Match(tok3->previous(), "( %var% )") &&
|
||||||
(Token::Match(tok3->previous(), "&&|(") || tok3->strAt(-1) == "||") &&
|
Token::Match(tok3->previous(), "&&|(|%oror% %varid% &&|%oror%|)", varid))
|
||||||
tok3->varId() == varid &&
|
|
||||||
(Token::Match(tok3->next(), "&&|)") || tok3->strAt(1) == "||"))
|
|
||||||
{
|
{
|
||||||
tok3->str(value);
|
tok3->str(value);
|
||||||
ret = true;
|
ret = true;
|
||||||
|
@ -7309,9 +7303,7 @@ bool Tokenizer::simplifyCalculations()
|
||||||
MathLib::isInt(tok->str()) &&
|
MathLib::isInt(tok->str()) &&
|
||||||
MathLib::isInt(tok->tokAt(2)->str()))
|
MathLib::isInt(tok->tokAt(2)->str()))
|
||||||
{
|
{
|
||||||
const std::string prev(tok->previous() ? tok->strAt(-1).c_str() : "");
|
if (Token::Match(tok->previous(), "(|&&|%oror%") && Token::Match(tok->tokAt(3), ")|&&|%oror%"))
|
||||||
const std::string after(tok->tokAt(3) ? tok->strAt(3).c_str() : "");
|
|
||||||
if ((prev == "(" || prev == "&&" || prev == "||") && (after == ")" || after == "&&" || after == "||"))
|
|
||||||
{
|
{
|
||||||
const MathLib::bigint op1(MathLib::toLongNumber(tok->str()));
|
const MathLib::bigint op1(MathLib::toLongNumber(tok->str()));
|
||||||
const std::string &cmp(tok->next()->str());
|
const std::string &cmp(tok->next()->str());
|
||||||
|
|
Loading…
Reference in New Issue