MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowInferCondition

Function valueFlowInferCondition

lib/valueflow.cpp:5064–5099  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5062}
5063
5064static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settings)
5065{
5066 for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
5067 if (!tok->astParent())
5068 continue;
5069 if (tok->hasKnownIntValue())
5070 continue;
5071 if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) {
5072 if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) {
5073 static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{},
5074 StartIteratorInferModel{}};
5075 for (const ValuePtr<InferModel>& model : iteratorModels) {
5076 std::vector<ValueFlow::Value> result =
5077 infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());
5078 for (ValueFlow::Value value : result) {
5079 value.valueType = ValueFlow::Value::ValueType::INT;
5080 setTokenValue(tok, std::move(value), settings);
5081 }
5082 }
5083 } else if (isIntegralOrPointer(tok->astOperand1()) && isIntegralOrPointer(tok->astOperand2())) {
5084 std::vector<ValueFlow::Value> result =
5085 infer(makeIntegralInferModel(), tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());
5086 for (ValueFlow::Value& value : result) {
5087 setTokenValue(tok, std::move(value), settings);
5088 }
5089 }
5090 } else if (Token::Match(tok->astParent(), "?|&&|!|%oror%") ||
5091 Token::Match(tok->astParent()->previous(), "if|while (") ||
5092 (astIsPointer(tok) && isUsedAsBool(tok, settings))) {
5093 std::vector<ValueFlow::Value> result = infer(makeIntegralInferModel(), "!=", tok->values(), 0);
5094 if (result.size() != 1)
5095 continue;
5096 setTokenValue(tok, std::move(result.front()), settings);
5097 }
5098 }
5099}
5100
5101struct SymbolicConditionHandler : SimpleConditionHandler {
5102

Callers 1

setValuesMethod · 0.85

Calls 15

astIsIteratorFunction · 0.85
inferFunction · 0.85
setTokenValueFunction · 0.85
isIntegralOrPointerFunction · 0.85
makeIntegralInferModelFunction · 0.85
astIsPointerFunction · 0.85
isUsedAsBoolFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
astParentMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80

Tested by

no test coverage detected