diff --git a/src/VlcSource.h b/src/VlcSource.h index 3781727c86..57c1697367 100644 --- a/src/VlcSource.h +++ b/src/VlcSource.h @@ -36,17 +36,35 @@ class VlcPoint; class VlcSourceCount final { // TYPES struct PointCmp { + static int getIndexLength(const std::string& s) { + int indexLength = 0; + while (std::isdigit(s[s.size() - 1 - indexLength])) { indexLength++; } + return indexLength; + } bool operator()(const VlcPoint* a, const VlcPoint* b) const { if (a->comment().rfind("toggle", 0) != 0) { // not toggle coverage, compare pointers return a < b; - } else { - const std::string aStripped = a->commentStripped(); - const std::string bStripped = b->commentStripped(); - const int aIndex = std::stoi(aStripped.substr(aStripped.rfind("_") + 1)); - const int bIndex = std::stoi(bStripped.substr(bStripped.rfind("_") + 1)); - return aIndex < bIndex; } + const std::string aStripped = a->commentStripped(); + const std::string bStripped = b->commentStripped(); + int aIndexLength = getIndexLength(aStripped); + int bIndexLength = getIndexLength(bStripped); + const std::string aWithoutIndex = aStripped.substr(0, aStripped.size() - aIndexLength); + const std::string bWithoutIndex = bStripped.substr(0, bStripped.size() - bIndexLength); + if (aWithoutIndex != bWithoutIndex) { + // different variables, compare names + return aWithoutIndex < bWithoutIndex; + } + if (aIndexLength == 0 || bIndexLength == 0) { + // probably a case like: + // reg clk, clk2; + // compare pointers, as done in old way + return a < b; + } + const int aIndex = std::stoi(aStripped.substr(aStripped.size() - aIndexLength)); + const int bIndex = std::stoi(bStripped.substr(bStripped.size() - bIndexLength)); + return aIndex < bIndex; } }; using PointsSet = std::set;