[PATCH] D23418: [analyzer] Added a reusable constraint system to the CloneDetector
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 26 07:32:39 PDT 2016
NoQ added a comment.
Here's some pseudo-code of the way i see it.
// This interface mimics CloneDetector's interface, hence omnipotent but useless.
class BasicConstraint {
public:
virtual void add(const StmtSequence &S) = 0;
virtual vector<CloneGroup> findClones() = 0;
};
// This constraint separates statements by their hash values.
// Useful for the first pass, when we can't afford the number of sequences
// to slow us down.
class HashingConstraint: public BasicConstraint {
map<hash_t, CloneGroup> M;
public:
virtual hash_t hash(const StmtSequence &S) = 0;
virtual void add(const StmtSequence &S) override {
M[hash(S)].append(S);
}
virtual vector<CloneGroup> findClones() override {
vector<CloneGroup> V;
for (I in M)
V.append(I.second);
return V;
}
};
// This interface does pairwise comparisons via the provided compare() function.
// Quadratic but easy to use for later passes.
class ComparingConstraint {
vector<CloneGroup> V;
public:
virtual void compare(const StmtSequence &LHS, const StmtSequence &RHS) = 0;
virtual void add(const StmtSequence &S) override {
for (auto G in V) {
if (compare(G[0], S))
G.append(S);
else
V[V.length()].append(S);
}
}
vector<CloneGroup> findClones() override {
return V;
}
};
And inherit custom constraints from these building blocks, probably provide more building blocks.
https://reviews.llvm.org/D23418
More information about the cfe-commits
mailing list