Skip to content

Commit

Permalink
Handle conrner cases
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Jan 21, 2025
1 parent 75a7f45 commit 9a0ce2a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/VlcSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VlcPoint*, PointCmp>;
Expand Down

0 comments on commit 9a0ce2a

Please sign in to comment.