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

Function mergeAdjacent

lib/token.cpp:2118–2172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2116}
2117
2118static void mergeAdjacent(std::list<ValueFlow::Value>& values)
2119{
2120 for (auto x = values.begin(); x != values.end();) {
2121 if (x->isNonValue()) {
2122 x++;
2123 continue;
2124 }
2125 if (x->bound == ValueFlow::Value::Bound::Point) {
2126 x++;
2127 continue;
2128 }
2129 std::vector<ValueIterator> adjValues;
2130 for (auto y = values.begin(); y != values.end(); y++) {
2131 if (x == y)
2132 continue;
2133 if (y->isNonValue())
2134 continue;
2135 if (x->valueType != y->valueType)
2136 continue;
2137 if (x->valueKind != y->valueKind)
2138 continue;
2139 if (x->isSymbolicValue() && !ValueFlow::Value::sameToken(x->tokvalue, y->tokvalue))
2140 continue;
2141 if (x->bound != y->bound) {
2142 if (y->bound != ValueFlow::Value::Bound::Point && isAdjacent(*x, *y)) {
2143 adjValues.clear();
2144 break;
2145 }
2146 // No adjacent points for floating points
2147 if (x->valueType == ValueFlow::Value::ValueType::FLOAT)
2148 continue;
2149 if (y->bound != ValueFlow::Value::Bound::Point)
2150 continue;
2151 }
2152 if (x->bound == ValueFlow::Value::Bound::Lower && !y->compareValue(*x, less{}))
2153 continue;
2154 if (x->bound == ValueFlow::Value::Bound::Upper && !x->compareValue(*y, less{}))
2155 continue;
2156 adjValues.push_back(y);
2157 }
2158 if (adjValues.empty()) {
2159 x++;
2160 continue;
2161 }
2162 std::sort(adjValues.begin(), adjValues.end(), [&values](ValueIterator xx, ValueIterator yy) {
2163 (void)values;
2164 assert(xx != values.end() && yy != values.end());
2165 return xx->compareValue(*yy, less{});
2166 });
2167 if (x->bound == ValueFlow::Value::Bound::Lower)
2168 x = removeAdjacentValues(values, x, adjValues.rbegin(), adjValues.rend());
2169 else if (x->bound == ValueFlow::Value::Bound::Upper)
2170 x = removeAdjacentValues(values, x, adjValues.begin(), adjValues.end());
2171 }
2172}
2173
2174static void removeOverlaps(std::list<ValueFlow::Value>& values)
2175{

Callers 1

removeOverlapsFunction · 0.85

Calls 7

isAdjacentFunction · 0.85
removeAdjacentValuesFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected