| 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 | { |
nothing calls this directly
no test coverage detected