Revert "Clarify expression with parentheses"

This reverts commit bbf0a81c2d.
This commit is contained in:
Dmitry-Me 2017-10-18 23:31:44 +03:00
parent bbf0a81c2d
commit e356ccca22
1 changed files with 20 additions and 13 deletions

View File

@ -481,9 +481,9 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (!f && !value1->isIntValue() && !value2->isIntValue()) if (!f && !value1->isIntValue() && !value2->isIntValue())
break; break;
if (parent->str() == ">") if (parent->str() == ">")
result.intvalue = f ? (floatValue1 > floatValue2) : (value1->intvalue > value2->intvalue); result.intvalue = f ? floatValue1 > floatValue2 : value1->intvalue > value2->intvalue;
else if (parent->str() == ">=") else if (parent->str() == ">=")
result.intvalue = f ? (floatValue1 >= floatValue2) : (value1->intvalue >= value2->intvalue); result.intvalue = f ? floatValue1 >= floatValue2 : value1->intvalue >= value2->intvalue;
else if (!f && parent->str() == ">>" && value1->intvalue >= 0 && value2->intvalue >= 0 && value2->intvalue < 64) else if (!f && parent->str() == ">>" && value1->intvalue >= 0 && value2->intvalue >= 0 && value2->intvalue < 64)
result.intvalue = value1->intvalue >> value2->intvalue; result.intvalue = value1->intvalue >> value2->intvalue;
else else
@ -496,9 +496,9 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (!f && !value1->isIntValue() && !value2->isIntValue()) if (!f && !value1->isIntValue() && !value2->isIntValue())
break; break;
if (parent->str() == "<") if (parent->str() == "<")
result.intvalue = f ? (floatValue1 < floatValue2) : (value1->intvalue < value2->intvalue); result.intvalue = f ? floatValue1 < floatValue2 : value1->intvalue < value2->intvalue;
else if (parent->str() == "<=") else if (parent->str() == "<=")
result.intvalue = f ? (floatValue1 <= floatValue2) : (value1->intvalue <= value2->intvalue); result.intvalue = f ? floatValue1 <= floatValue2 : value1->intvalue <= value2->intvalue;
else if (!f && parent->str() == "<<" && value1->intvalue >= 0 && value2->intvalue >= 0 && value2->intvalue < 64) else if (!f && parent->str() == "<<" && value1->intvalue >= 0 && value2->intvalue >= 0 && value2->intvalue < 64)
result.intvalue = value1->intvalue << value2->intvalue; result.intvalue = value1->intvalue << value2->intvalue;
else else
@ -1169,8 +1169,16 @@ static void valueFlowReverse(TokenList *tokenlist,
break; break;
} }
} }
}
if (Token::Match(tok2, "%name% (") && !Token::simpleMatch(tok2->linkAt(1), ") {")) {
// bailout: global non-const variables
if (!(var->isLocal() || var->isArgument()) && !var->isConst()) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok, "global variable " + var->name());
return;
}
}
}
} }
static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symboldatabase, ErrorLogger *errorLogger, const Settings *settings) static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
@ -1208,13 +1216,6 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, SymbolDatabase *symbo
if (varid == 0U || !var) if (varid == 0U || !var)
continue; continue;
// bailout: global non-const variables
if (!(var->isLocal() || var->isArgument()) && !var->isConst()) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok, "global variable " + var->name());
continue;
}
// bailout: for/while-condition, variable is changed in while loop // bailout: for/while-condition, variable is changed in while loop
for (const Token *tok2 = tok; tok2; tok2 = tok2->astParent()) { for (const Token *tok2 = tok; tok2; tok2 = tok2->astParent()) {
if (tok2->astParent() || tok2->str() != "(" || !Token::simpleMatch(tok2->link(), ") {")) if (tok2->astParent() || tok2->str() != "(" || !Token::simpleMatch(tok2->link(), ") {"))
@ -2885,12 +2886,18 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol
std::list<ValueFlow::Value> values; std::list<ValueFlow::Value> values;
values.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str()))); values.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str())));
values.back().condition = tok; values.back().condition = tok;
const std::string info("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
values.back().errorPath.push_back(ErrorPathItem(tok, info));
if ((Token::simpleMatch(tok->previous(), "{") || Token::simpleMatch(tok->tokAt(-2), "break ;")) && !Token::Match(tok->tokAt(3), ";| case"))
values.back().setKnown();
while (Token::Match(tok->tokAt(3), ";| case %num% :")) { while (Token::Match(tok->tokAt(3), ";| case %num% :")) {
tok = tok->tokAt(3); tok = tok->tokAt(3);
if (!tok->isName()) if (!tok->isName())
tok = tok->next(); tok = tok->next();
values.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str()))); values.push_back(ValueFlow::Value(MathLib::toLongNumber(tok->next()->str())));
values.back().condition = tok; values.back().condition = tok;
const std::string info2("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
values.back().errorPath.push_back(ErrorPathItem(tok, info2));
} }
for (std::list<ValueFlow::Value>::const_iterator val = values.begin(); val != values.end(); ++val) { for (std::list<ValueFlow::Value>::const_iterator val = values.begin(); val != values.end(); ++val) {
valueFlowReverse(tokenlist, valueFlowReverse(tokenlist,
@ -2902,7 +2909,7 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol
settings); settings);
} }
if (vartok->variable()->scope()) // #7257 if (vartok->variable()->scope()) // #7257
valueFlowForward(tok, vartok->variable()->scope()->classEnd, vartok->variable(), vartok->varId(), values, false, false, tokenlist, errorLogger, settings); valueFlowForward(tok->tokAt(3), vartok->variable()->scope()->classEnd, vartok->variable(), vartok->varId(), values, values.back().isKnown(), false, tokenlist, errorLogger, settings);
} }
} }
} }