15 #ifndef LLVM_CLANG_AST_CLONEDETECTION_H 16 #define LLVM_CLANG_AST_CLONEDETECTION_H 19 #include "llvm/Support/Regex.h" 77 iterator
begin()
const;
101 return EndIndex - StartIndex;
138 return std::tie(S, StartIndex, EndIndex) ==
139 std::tie(Other.S, Other.StartIndex, Other.EndIndex);
143 return std::tie(S, StartIndex, EndIndex) !=
144 std::tie(Other.S, Other.StartIndex, Other.EndIndex);
176 void analyzeCodeBody(
const Decl *D);
186 template <
typename T>
188 C.constrain(CloneGroups);
196 template <
typename T1,
typename... Ts>
198 Ts... ConstraintList) {
199 constrainClones(CloneGroups, C);
200 constrainClones(CloneGroups, ConstraintList...);
208 template <
typename... Ts>
213 CloneGroup AllClones;
214 AllClones.reserve(Sequences.size());
215 for (
const auto &
C : Sequences) {
216 AllClones.push_back(
C);
219 Result.push_back(AllClones);
221 constrainClones(Result, ConstraintList...);
225 CloneGroup Sequences;
238 std::vector<CloneDetector::CloneGroup> &CloneGroups,
241 std::remove_if(CloneGroups.begin(), CloneGroups.end(), Filter),
251 static void splitCloneGroups(
252 std::vector<CloneDetector::CloneGroup> &CloneGroups,
266 void constrain(std::vector<CloneDetector::CloneGroup> &Sequences);
277 void constrain(std::vector<CloneDetector::CloneGroup> &Sequences);
286 unsigned MinComplexity;
290 : MinComplexity(MinComplexity) {}
297 const std::string &ParentMacroStack =
"");
299 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
303 return calculateStmtComplexity(A.front(), MinComplexity) <
313 unsigned MinGroupSize;
317 : MinGroupSize(MinGroupSize) {}
319 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
322 return A.size() < MinGroupSize;
329 void constrain(std::vector<CloneDetector::CloneGroup> &
Result);
337 : IgnoredFilesPattern(IgnoredFilesPattern) {
338 IgnoredFilesRegex = std::make_shared<llvm::Regex>(
"^(" +
339 IgnoredFilesPattern.str() +
"$)");
344 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
347 return isAutoGenerated(Group);
356 struct VariableOccurence {
362 VariableOccurence(
size_t KindID,
const Stmt *Mention)
363 : KindID(KindID), Mention(Mention) {}
367 std::vector<VariableOccurence> Occurences;
370 std::vector<const VarDecl *> Variables;
378 void addVariables(
const Stmt *S);
384 for (
const Stmt *S : Sequence)
403 const VarDecl *Suggestion)
404 : Variable(Variable), Mention(Mention), Suggestion(Suggestion) {}
436 unsigned countPatternDifferences(
443 void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups);
448 #endif // LLVM_CLANG_AST_CLONEDETECTION_H FilenamePatternConstraint(StringRef IgnoredFilesPattern)
SourceLocation getStartLoc() const LLVM_READONLY
Returns the start sourcelocation of the first statement in this sequence.
SourceLocation getEndLoc() const
Returns the end sourcelocation of the last statement in this sequence.
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
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.
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
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.