14 #ifndef LLVM_CLANG_AST_CLONEDETECTION_H 15 #define LLVM_CLANG_AST_CLONEDETECTION_H 18 #include "llvm/Support/Regex.h" 76 iterator
begin()
const;
100 return EndIndex - StartIndex;
136 return std::tie(S, StartIndex, EndIndex) ==
137 std::tie(Other.S, Other.StartIndex, Other.EndIndex);
141 return std::tie(S, StartIndex, EndIndex) !=
142 std::tie(Other.S, Other.StartIndex, Other.EndIndex);
174 void analyzeCodeBody(
const Decl *D);
184 template <
typename T>
186 C.constrain(CloneGroups);
194 template <
typename T1,
typename... Ts>
196 Ts... ConstraintList) {
197 constrainClones(CloneGroups, C);
198 constrainClones(CloneGroups, ConstraintList...);
206 template <
typename... Ts>
211 CloneGroup AllClones;
212 AllClones.reserve(Sequences.size());
213 for (
const auto &
C : Sequences) {
214 AllClones.push_back(
C);
217 Result.push_back(AllClones);
219 constrainClones(Result, ConstraintList...);
223 CloneGroup Sequences;
236 std::vector<CloneDetector::CloneGroup> &CloneGroups,
239 std::remove_if(CloneGroups.begin(), CloneGroups.end(),
Filter),
249 static void splitCloneGroups(
250 std::vector<CloneDetector::CloneGroup> &CloneGroups,
264 void constrain(std::vector<CloneDetector::CloneGroup> &Sequences);
275 void constrain(std::vector<CloneDetector::CloneGroup> &Sequences);
284 unsigned MinComplexity;
288 : MinComplexity(MinComplexity) {}
295 const std::string &ParentMacroStack =
"");
297 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
301 return calculateStmtComplexity(A.front(), MinComplexity) <
311 unsigned MinGroupSize;
315 : MinGroupSize(MinGroupSize) {}
317 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
320 return A.size() < MinGroupSize;
327 void constrain(std::vector<CloneDetector::CloneGroup> &
Result);
335 : IgnoredFilesPattern(IgnoredFilesPattern) {
336 IgnoredFilesRegex = std::make_shared<llvm::Regex>(
"^(" +
337 IgnoredFilesPattern.str() +
"$)");
342 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
345 return isAutoGenerated(Group);
354 struct VariableOccurence {
360 VariableOccurence(
size_t KindID,
const Stmt *Mention)
361 : KindID(KindID), Mention(Mention) {}
365 std::vector<VariableOccurence> Occurences;
368 std::vector<const VarDecl *> Variables;
376 void addVariables(
const Stmt *S);
382 for (
const Stmt *S : Sequence)
401 const VarDecl *Suggestion)
402 : Variable(Variable), Mention(Mention), Suggestion(Suggestion) {}
434 unsigned countPatternDifferences(
441 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups);
446 #endif // LLVM_CLANG_AST_CLONEDETECTION_H FilenamePatternConstraint(StringRef IgnoredFilesPattern)
SourceLocation getEndLoc() const
Returns the end sourcelocation of the last statement in this sequence.
Stmt - This represents one statement.
ASTContext & getASTContext() const
Returns the related ASTContext for the stored Stmts.
SourceRange getSourceRange() const
Returns the source range of the whole sequence - from the beginning of the first statement to the end...
Analyzes the pattern of the referenced variables in a statement.
Decl - This represents one declaration (or definition), e.g.
const Stmt * front() const
Returns the first statement in this sequence.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool operator!=(const StmtSequence &Other) const
bool operator==(const StmtSequence &Other) const
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
Represents a variable declaration or definition.
StmtSequence()
Constructs an empty StmtSequence.
SuspiciousCloneInfo(const VarDecl *Variable, const Stmt *Mention, const VarDecl *Suggestion)
iterator begin() const
Returns an iterator pointing to the first statement in this sequence.
Identifies a list of statements.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
This class is a utility class that contains utility functions for building custom constraints...
Ensures that all clones reference variables in the same pattern.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Ensures that all clone groups contain at least the given amount of clones.
static void constrainClones(std::vector< CloneGroup > &CloneGroups, T C)
Constrains the given list of clone groups with the given constraint.
VariablePattern(const StmtSequence &Sequence)
Creates an VariablePattern object with information about the given StmtSequence.
void findClones(std::vector< CloneGroup > &Result, Ts... ConstraintList)
Searches for clones in all previously passed statements.
iterator end() const
Returns an iterator pointing behind the last statement in this sequence.
Searches for similar subtrees in the AST.
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
bool empty() const
Returns true if and only if this StmtSequence contains no statements.
Describes two clones that reference their variables in a different pattern which could indicate a pro...
CompoundStmt - This represents a group of statements like { stmt stmt }.
llvm::SmallVector< StmtSequence, 8 > CloneGroup
A collection of StmtSequences that share an arbitrary property.
This constraint moves clones into clone groups of type II via hashing.
SuspiciousCloneInfo SecondCloneInfo
This other clone in the pair which can have a suggested variable.
const Decl * getContainingDecl() const
Returns the declaration that contains the stored Stmts.
This constraint moves clones into clone groups of type II by comparing them.
StringRef IgnoredFilesPattern
Ensures that every clone has at least the given complexity.
const VarDecl * Suggestion
The variable that should have been referenced to follow the pattern.
The result type of a method or function.
std::shared_ptr< llvm::Regex > IgnoredFilesRegex
Utility class holding the relevant information about a single clone in this pair. ...
const Stmt * Mention
Where the variable was referenced.
unsigned size() const
Returns the number of statements this object holds.
static void constrainClones(std::vector< CloneGroup > &CloneGroups, T1 C, Ts... ConstraintList)
Constrains the given list of clone groups with the given list of constraints.
MinComplexityConstraint(unsigned MinComplexity)
Encodes a location in the source.
const Stmt *const * iterator
bool holdsSequence() const
Returns true if this objects holds a list of statements.
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
Dataflow Directional Tag Classes.
const Stmt * back() const
Returns the last statement in this sequence.
SourceLocation getBeginLoc() const
Returns the start sourcelocation of the first statement in this sequence.
MinGroupSizeConstraint(unsigned MinGroupSize=2)
bool contains(const StmtSequence &Other) const
Returns true if and only if this sequence covers a source range that contains the source range of the...
static void filterGroups(std::vector< CloneDetector::CloneGroup > &CloneGroups, llvm::function_ref< bool(const CloneDetector::CloneGroup &)> Filter)
Removes all groups by using a filter function.
SuspiciousCloneInfo FirstCloneInfo
The first clone in the pair which always has a suggested variable.
A trivial tuple used to represent a source range.
const VarDecl * Variable
The variable which referencing in this clone was against the pattern.
Ensures that no clone group fully contains another clone group.