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

Method fromValues

lib/infer.cpp:125–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124 template<class Predicate>
125 static Interval fromValues(const std::list<ValueFlow::Value>& values, Predicate predicate)
126 {
127 Interval result;
128 const ValueFlow::Value* minValue = getCompareValue(values, predicate, std::less<MathLib::bigint>{});
129 if (minValue) {
130 if (minValue->isImpossible() && minValue->bound == ValueFlow::Value::Bound::Upper)
131 result.setMinValue(minValue->intvalue + 1, minValue);
132 if (minValue->isPossible() && minValue->bound == ValueFlow::Value::Bound::Lower)
133 result.setMinValue(minValue->intvalue, minValue);
134 if (!minValue->isImpossible() && (minValue->bound == ValueFlow::Value::Bound::Point || minValue->isKnown()) &&
135 std::count_if(values.begin(), values.end(), predicate) == 1)
136 return Interval::fromInt(minValue->intvalue, minValue);
137 }
138 const ValueFlow::Value* maxValue = getCompareValue(values, predicate, std::greater<MathLib::bigint>{});
139 if (maxValue) {
140 if (maxValue->isImpossible() && maxValue->bound == ValueFlow::Value::Bound::Lower)
141 result.setMaxValue(maxValue->intvalue - 1, maxValue);
142 if (maxValue->isPossible() && maxValue->bound == ValueFlow::Value::Bound::Upper)
143 result.setMaxValue(maxValue->intvalue, maxValue);
144 assert(!maxValue->isKnown());
145 }
146 return result;
147 }
148
149 static Interval fromValues(const std::list<ValueFlow::Value>& values)
150 {

Callers

nothing calls this directly

Calls 8

isImpossibleMethod · 0.80
setMinValueMethod · 0.80
isPossibleMethod · 0.80
isKnownMethod · 0.80
setMaxValueMethod · 0.80
getCompareValueFunction · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected