clang  14.0.0git
CloneDetection.h
Go to the documentation of this file.
1 //===--- CloneDetection.h - Finds code clones in an AST ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines classes for searching and analyzing source code clones.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_AST_CLONEDETECTION_H
15 #define LLVM_CLANG_AST_CLONEDETECTION_H
16 
17 #include "clang/AST/StmtVisitor.h"
18 #include "llvm/Support/Regex.h"
19 #include <vector>
20 
21 namespace clang {
22 
23 class Stmt;
24 class Decl;
25 class VarDecl;
26 class ASTContext;
27 class CompoundStmt;
28 
29 /// Identifies a list of statements.
30 ///
31 /// Can either identify a single arbitrary Stmt object, a continuous sequence of
32 /// child statements inside a CompoundStmt or no statements at all.
33 class StmtSequence {
34  /// If this object identifies a sequence of statements inside a CompoundStmt,
35  /// S points to this CompoundStmt. If this object only identifies a single
36  /// Stmt, then S is a pointer to this Stmt.
37  const Stmt *S;
38 
39  /// The declaration that contains the statements.
40  const Decl *D;
41 
42  /// If EndIndex is non-zero, then S is a CompoundStmt and this StmtSequence
43  /// instance is representing the CompoundStmt children inside the array
44  /// [StartIndex, EndIndex).
45  unsigned StartIndex;
46  unsigned EndIndex;
47 
48 public:
49  /// Constructs a StmtSequence holding multiple statements.
50  ///
51  /// The resulting StmtSequence identifies a continuous sequence of statements
52  /// in the body of the given CompoundStmt. Which statements of the body should
53  /// be identified needs to be specified by providing a start and end index
54  /// that describe a non-empty sub-array in the body of the given CompoundStmt.
55  ///
56  /// \param Stmt A CompoundStmt that contains all statements in its body.
57  /// \param D The Decl containing this Stmt.
58  /// \param StartIndex The inclusive start index in the children array of
59  /// \p Stmt
60  /// \param EndIndex The exclusive end index in the children array of \p Stmt.
61  StmtSequence(const CompoundStmt *Stmt, const Decl *D, unsigned StartIndex,
62  unsigned EndIndex);
63 
64  /// Constructs a StmtSequence holding a single statement.
65  ///
66  /// \param Stmt An arbitrary Stmt.
67  /// \param D The Decl containing this Stmt.
68  StmtSequence(const Stmt *Stmt, const Decl *D);
69 
70  /// Constructs an empty StmtSequence.
71  StmtSequence();
72 
73  typedef const Stmt *const *iterator;
74 
75  /// Returns an iterator pointing to the first statement in this sequence.
76  iterator begin() const;
77 
78  /// Returns an iterator pointing behind the last statement in this sequence.
79  iterator end() const;
80 
81  /// Returns the first statement in this sequence.
82  ///
83  /// This method should only be called on a non-empty StmtSequence object.
84  const Stmt *front() const {
85  assert(!empty());
86  return begin()[0];
87  }
88 
89  /// Returns the last statement in this sequence.
90  ///
91  /// This method should only be called on a non-empty StmtSequence object.
92  const Stmt *back() const {
93  assert(!empty());
94  return begin()[size() - 1];
95  }
96 
97  /// Returns the number of statements this object holds.
98  unsigned size() const {
99  if (holdsSequence())
100  return EndIndex - StartIndex;
101  if (S == nullptr)
102  return 0;
103  return 1;
104  }
105 
106  /// Returns true if and only if this StmtSequence contains no statements.
107  bool empty() const { return size() == 0; }
108 
109  /// Returns the related ASTContext for the stored Stmts.
110  ASTContext &getASTContext() const;
111 
112  /// Returns the declaration that contains the stored Stmts.
113  const Decl *getContainingDecl() const {
114  assert(D);
115  return D;
116  }
117 
118  /// Returns true if this objects holds a list of statements.
119  bool holdsSequence() const { return EndIndex != 0; }
120 
121  /// Returns the start sourcelocation of the first statement in this sequence.
122  ///
123  /// This method should only be called on a non-empty StmtSequence object.
124  SourceLocation getBeginLoc() const;
125 
126  /// Returns the end sourcelocation of the last statement in this sequence.
127  ///
128  /// This method should only be called on a non-empty StmtSequence object.
129  SourceLocation getEndLoc() const;
130 
131  /// Returns the source range of the whole sequence - from the beginning
132  /// of the first statement to the end of the last statement.
133  SourceRange getSourceRange() const;
134 
135  bool operator==(const StmtSequence &Other) const {
136  return std::tie(S, StartIndex, EndIndex) ==
137  std::tie(Other.S, Other.StartIndex, Other.EndIndex);
138  }
139 
140  bool operator!=(const StmtSequence &Other) const {
141  return std::tie(S, StartIndex, EndIndex) !=
142  std::tie(Other.S, Other.StartIndex, Other.EndIndex);
143  }
144 
145  /// Returns true if and only if this sequence covers a source range that
146  /// contains the source range of the given sequence \p Other.
147  ///
148  /// This method should only be called on a non-empty StmtSequence object
149  /// and passed a non-empty StmtSequence object.
150  bool contains(const StmtSequence &Other) const;
151 };
152 
153 /// Searches for similar subtrees in the AST.
154 ///
155 /// First, this class needs several declarations with statement bodies which
156 /// can be passed via analyzeCodeBody. Afterwards all statements can be
157 /// searched for clones by calling findClones with a given list of constraints
158 /// that should specify the wanted properties of the clones.
159 ///
160 /// The result of findClones can be further constrained with the constrainClones
161 /// method.
162 ///
163 /// This class only searches for clones in executable source code
164 /// (e.g. function bodies). Other clones (e.g. cloned comments or declarations)
165 /// are not supported.
167 
168 public:
169  /// A collection of StmtSequences that share an arbitrary property.
171 
172  /// Generates and stores search data for all statements in the body of
173  /// the given Decl.
174  void analyzeCodeBody(const Decl *D);
175 
176  /// Constrains the given list of clone groups with the given constraint.
177  ///
178  /// The constraint is expected to have a method with the signature
179  /// `void constrain(std::vector<CloneDetector::CloneGroup> &Sequences)`
180  /// as this is the interface that the CloneDetector uses for applying the
181  /// constraint. The constraint is supposed to directly modify the passed list
182  /// so that all clones in the list fulfill the specific property this
183  /// constraint ensures.
184  template <typename T>
185  static void constrainClones(std::vector<CloneGroup> &CloneGroups, T C) {
186  C.constrain(CloneGroups);
187  }
188 
189  /// Constrains the given list of clone groups with the given list of
190  /// constraints.
191  ///
192  /// The constraints are applied in sequence in the order in which they are
193  /// passed to this function.
194  template <typename T1, typename... Ts>
195  static void constrainClones(std::vector<CloneGroup> &CloneGroups, T1 C,
196  Ts... ConstraintList) {
197  constrainClones(CloneGroups, C);
198  constrainClones(CloneGroups, ConstraintList...);
199  }
200 
201  /// Searches for clones in all previously passed statements.
202  /// \param Result Output parameter to which all created clone groups are
203  /// added.
204  /// \param ConstraintList The constraints that should be applied to the
205  // result.
206  template <typename... Ts>
207  void findClones(std::vector<CloneGroup> &Result, Ts... ConstraintList) {
208  // The initial assumption is that there is only one clone group and every
209  // statement is a clone of the others. This clone group will then be
210  // split up with the help of the constraints.
211  CloneGroup AllClones;
212  AllClones.reserve(Sequences.size());
213  for (const auto &C : Sequences) {
214  AllClones.push_back(C);
215  }
216 
217  Result.push_back(AllClones);
218 
219  constrainClones(Result, ConstraintList...);
220  }
221 
222 private:
223  CloneGroup Sequences;
224 };
225 
226 /// This class is a utility class that contains utility functions for building
227 /// custom constraints.
229 public:
230  /// Removes all groups by using a filter function.
231  /// \param CloneGroups The list of CloneGroups that is supposed to be
232  /// filtered.
233  /// \param Filter The filter function that should return true for all groups
234  /// that should be removed from the list.
235  static void filterGroups(
236  std::vector<CloneDetector::CloneGroup> &CloneGroups,
237  llvm::function_ref<bool(const CloneDetector::CloneGroup &)> Filter) {
238  llvm::erase_if(CloneGroups, Filter);
239  }
240 
241  /// Splits the given CloneGroups until the given Compare function returns true
242  /// for all clones in a single group.
243  /// \param CloneGroups A list of CloneGroups that should be modified.
244  /// \param Compare The comparison function that all clones are supposed to
245  /// pass. Should return true if and only if two clones belong
246  /// to the same CloneGroup.
247  static void splitCloneGroups(
248  std::vector<CloneDetector::CloneGroup> &CloneGroups,
249  llvm::function_ref<bool(const StmtSequence &, const StmtSequence &)>
250  Compare);
251 };
252 
253 /// This constraint moves clones into clone groups of type II via hashing.
254 ///
255 /// Clones with different hash values are moved into separate clone groups.
256 /// Collisions are possible, and this constraint does nothing to address this
257 /// them. Add the slower RecursiveCloneTypeIIVerifyConstraint later in the
258 /// constraint chain, not necessarily immediately, to eliminate hash collisions
259 /// through a more detailed analysis.
261 public:
262  void constrain(std::vector<CloneDetector::CloneGroup> &Sequences);
263 };
264 
265 /// This constraint moves clones into clone groups of type II by comparing them.
266 ///
267 /// Clones that aren't type II clones are moved into separate clone groups.
268 /// In contrast to the RecursiveCloneTypeIIHashConstraint, all clones in a clone
269 /// group are guaranteed to be be type II clones of each other, but it is too
270 /// slow to efficiently handle large amounts of clones.
272 public:
273  void constrain(std::vector<CloneDetector::CloneGroup> &Sequences);
274 };
275 
276 /// Ensures that every clone has at least the given complexity.
277 ///
278 /// Complexity is here defined as the total amount of children of a statement.
279 /// This constraint assumes the first statement in the group is representative
280 /// for all other statements in the group in terms of complexity.
282  unsigned MinComplexity;
283 
284 public:
285  MinComplexityConstraint(unsigned MinComplexity)
286  : MinComplexity(MinComplexity) {}
287 
288  /// Calculates the complexity of the given StmtSequence.
289  /// \param Limit The limit of complexity we probe for. After reaching
290  /// this limit during calculation, this method is exiting
291  /// early to improve performance and returns this limit.
292  size_t calculateStmtComplexity(const StmtSequence &Seq, std::size_t Limit,
293  const std::string &ParentMacroStack = "");
294 
295  void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
297  CloneGroups, [this](const CloneDetector::CloneGroup &A) {
298  if (!A.empty())
299  return calculateStmtComplexity(A.front(), MinComplexity) <
300  MinComplexity;
301  else
302  return false;
303  });
304  }
305 };
306 
307 /// Ensures that all clone groups contain at least the given amount of clones.
309  unsigned MinGroupSize;
310 
311 public:
312  MinGroupSizeConstraint(unsigned MinGroupSize = 2)
313  : MinGroupSize(MinGroupSize) {}
314 
315  void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
316  CloneConstraint::filterGroups(CloneGroups,
317  [this](const CloneDetector::CloneGroup &A) {
318  return A.size() < MinGroupSize;
319  });
320  }
321 };
322 
323 /// Ensures that no clone group fully contains another clone group.
325  void constrain(std::vector<CloneDetector::CloneGroup> &Result);
326 };
327 
330  std::shared_ptr<llvm::Regex> IgnoredFilesRegex;
331 
334  IgnoredFilesRegex = std::make_shared<llvm::Regex>("^(" +
335  IgnoredFilesPattern.str() + "$)");
336  }
337 
339 
340  void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
342  CloneGroups, [this](const CloneDetector::CloneGroup &Group) {
343  return isAutoGenerated(Group);
344  });
345  }
346 };
347 
348 /// Analyzes the pattern of the referenced variables in a statement.
350 
351  /// Describes an occurrence of a variable reference in a statement.
352  struct VariableOccurence {
353  /// The index of the associated VarDecl in the Variables vector.
354  size_t KindID;
355  /// The statement in the code where the variable was referenced.
356  const Stmt *Mention;
357 
358  VariableOccurence(size_t KindID, const Stmt *Mention)
359  : KindID(KindID), Mention(Mention) {}
360  };
361 
362  /// All occurrences of referenced variables in the order of appearance.
363  std::vector<VariableOccurence> Occurences;
364  /// List of referenced variables in the order of appearance.
365  /// Every item in this list is unique.
366  std::vector<const VarDecl *> Variables;
367 
368  /// Adds a new variable referenced to this pattern.
369  /// \param VarDecl The declaration of the variable that is referenced.
370  /// \param Mention The SourceRange where this variable is referenced.
371  void addVariableOccurence(const VarDecl *VarDecl, const Stmt *Mention);
372 
373  /// Adds each referenced variable from the given statement.
374  void addVariables(const Stmt *S);
375 
376 public:
377  /// Creates an VariablePattern object with information about the given
378  /// StmtSequence.
379  VariablePattern(const StmtSequence &Sequence) {
380  for (const Stmt *S : Sequence)
381  addVariables(S);
382  }
383 
384  /// Describes two clones that reference their variables in a different pattern
385  /// which could indicate a programming error.
387  /// Utility class holding the relevant information about a single
388  /// clone in this pair.
390  /// The variable which referencing in this clone was against the pattern.
392  /// Where the variable was referenced.
393  const Stmt *Mention;
394  /// The variable that should have been referenced to follow the pattern.
395  /// If Suggestion is a nullptr then it's not possible to fix the pattern
396  /// by referencing a different variable in this clone.
399  const VarDecl *Suggestion)
402  };
403  /// The first clone in the pair which always has a suggested variable.
405  /// This other clone in the pair which can have a suggested variable.
407  };
408 
409  /// Counts the differences between this pattern and the given one.
410  /// \param Other The given VariablePattern to compare with.
411  /// \param FirstMismatch Output parameter that will be filled with information
412  /// about the first difference between the two patterns. This parameter
413  /// can be a nullptr, in which case it will be ignored.
414  /// \return Returns the number of differences between the pattern this object
415  /// is following and the given VariablePattern.
416  ///
417  /// For example, the following statements all have the same pattern and this
418  /// function would return zero:
419  ///
420  /// if (a < b) return a; return b;
421  /// if (x < y) return x; return y;
422  /// if (u2 < u1) return u2; return u1;
423  ///
424  /// But the following statement has a different pattern (note the changed
425  /// variables in the return statements) and would have two differences when
426  /// compared with one of the statements above.
427  ///
428  /// if (a < b) return b; return a;
429  ///
430  /// This function should only be called if the related statements of the given
431  /// pattern and the statements of this objects are clones of each other.
432  unsigned countPatternDifferences(
433  const VariablePattern &Other,
434  VariablePattern::SuspiciousClonePair *FirstMismatch = nullptr);
435 };
436 
437 /// Ensures that all clones reference variables in the same pattern.
439  void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups);
440 };
441 
442 } // end namespace clang
443 
444 #endif // LLVM_CLANG_AST_CLONEDETECTION_H
clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo::SuspiciousCloneInfo
SuspiciousCloneInfo()
Definition: CloneDetection.h:401
clang::MinComplexityConstraint::MinComplexityConstraint
MinComplexityConstraint(unsigned MinComplexity)
Definition: CloneDetection.h:285
clang::StmtSequence::empty
bool empty() const
Returns true if and only if this StmtSequence contains no statements.
Definition: CloneDetection.h:107
clang::StmtSequence::getEndLoc
SourceLocation getEndLoc() const
Returns the end sourcelocation of the last statement in this sequence.
Definition: CloneDetection.cpp:84
clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo
Utility class holding the relevant information about a single clone in this pair.
Definition: CloneDetection.h:389
clang::FilenamePatternConstraint::isAutoGenerated
bool isAutoGenerated(const CloneDetector::CloneGroup &Group)
Definition: CloneDetection.cpp:155
clang::CloneConstraint::filterGroups
static void filterGroups(std::vector< CloneDetector::CloneGroup > &CloneGroups, llvm::function_ref< bool(const CloneDetector::CloneGroup &)> Filter)
Removes all groups by using a filter function.
Definition: CloneDetection.h:235
clang::FilenamePatternConstraint::FilenamePatternConstraint
FilenamePatternConstraint(StringRef IgnoredFilesPattern)
Definition: CloneDetection.h:332
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::StmtSequence::holdsSequence
bool holdsSequence() const
Returns true if this objects holds a list of statements.
Definition: CloneDetection.h:119
clang::StmtSequence::front
const Stmt * front() const
Returns the first statement in this sequence.
Definition: CloneDetection.h:84
llvm::SmallVector< StmtSequence, 8 >
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::CloneDetector::constrainClones
static void constrainClones(std::vector< CloneGroup > &CloneGroups, T C)
Constrains the given list of clone groups with the given constraint.
Definition: CloneDetection.h:185
clang::tooling::Filter
llvm::cl::opt< std::string > Filter
clang::OnlyLargestCloneConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &Result)
Definition: CloneDetection.cpp:126
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::MatchingVariablePatternConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
Definition: CloneDetection.cpp:465
clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo::Variable
const VarDecl * Variable
The variable which referencing in this clone was against the pattern.
Definition: CloneDetection.h:391
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:102
clang::FilenamePatternConstraint
Definition: CloneDetection.h:328
clang::interp::Compare
ComparisonCategoryResult Compare(const T &X, const T &Y)
Helper to compare two comparable types.
Definition: Integral.h:32
clang::CloneDetector::analyzeCodeBody
void analyzeCodeBody(const Decl *D)
Generates and stores search data for all statements in the body of the given Decl.
Definition: CloneDetection.cpp:90
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1399
clang::CloneDetector::constrainClones
static void constrainClones(std::vector< CloneGroup > &CloneGroups, T1 C, Ts... ConstraintList)
Constrains the given list of clone groups with the given list of constraints.
Definition: CloneDetection.h:195
clang::StmtSequence
Identifies a list of statements.
Definition: CloneDetection.h:33
clang::StmtSequence::operator==
bool operator==(const StmtSequence &Other) const
Definition: CloneDetection.h:135
clang::CloneDetector::CloneGroup
llvm::SmallVector< StmtSequence, 8 > CloneGroup
A collection of StmtSequences that share an arbitrary property.
Definition: CloneDetection.h:170
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
clang::CloneDetector::findClones
void findClones(std::vector< CloneGroup > &Result, Ts... ConstraintList)
Searches for clones in all previously passed statements.
Definition: CloneDetection.h:207
clang::StmtSequence::getASTContext
ASTContext & getASTContext() const
Returns the related ASTContext for the stored Stmts.
Definition: CloneDetection.cpp:75
clang::FilenamePatternConstraint::IgnoredFilesPattern
StringRef IgnoredFilesPattern
Definition: CloneDetection.h:329
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::StmtSequence::getBeginLoc
SourceLocation getBeginLoc() const
Returns the start sourcelocation of the first statement in this sequence.
Definition: CloneDetection.cpp:80
clang::MinGroupSizeConstraint::MinGroupSizeConstraint
MinGroupSizeConstraint(unsigned MinGroupSize=2)
Definition: CloneDetection.h:312
clang::FilenamePatternConstraint::IgnoredFilesRegex
std::shared_ptr< llvm::Regex > IgnoredFilesRegex
Definition: CloneDetection.h:330
clang::StmtSequence::operator!=
bool operator!=(const StmtSequence &Other) const
Definition: CloneDetection.h:140
clang::MinGroupSizeConstraint
Ensures that all clone groups contain at least the given amount of clones.
Definition: CloneDetection.h:308
clang::VariablePattern::SuspiciousClonePair
Describes two clones that reference their variables in a different pattern which could indicate a pro...
Definition: CloneDetection.h:386
clang::RecursiveCloneTypeIIVerifyConstraint
This constraint moves clones into clone groups of type II by comparing them.
Definition: CloneDetection.h:271
clang::RecursiveCloneTypeIIHashConstraint
This constraint moves clones into clone groups of type II via hashing.
Definition: CloneDetection.h:260
clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo::Suggestion
const VarDecl * Suggestion
The variable that should have been referenced to follow the pattern.
Definition: CloneDetection.h:397
clang::StmtSequence::end
iterator end() const
Returns an iterator pointing behind the last statement in this sequence.
Definition: CloneDetection.cpp:67
clang::MatchingVariablePatternConstraint
Ensures that all clones reference variables in the same pattern.
Definition: CloneDetection.h:438
clang::FilenamePatternConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
Definition: CloneDetection.h:340
clang::RecursiveCloneTypeIIVerifyConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &Sequences)
Definition: CloneDetection.cpp:411
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::StmtSequence::getSourceRange
SourceRange getSourceRange() const
Returns the source range of the whole sequence - from the beginning of the first statement to the end...
Definition: CloneDetection.cpp:86
clang::OnlyLargestCloneConstraint
Ensures that no clone group fully contains another clone group.
Definition: CloneDetection.h:324
clang::StmtSequence::contains
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...
Definition: CloneDetection.cpp:37
StmtVisitor.h
clang::StmtSequence::back
const Stmt * back() const
Returns the last statement in this sequence.
Definition: CloneDetection.h:92
clang::VariablePattern::SuspiciousClonePair::SecondCloneInfo
SuspiciousCloneInfo SecondCloneInfo
This other clone in the pair which can have a suggested variable.
Definition: CloneDetection.h:406
clang::CloneConstraint
This class is a utility class that contains utility functions for building custom constraints.
Definition: CloneDetection.h:228
clang::VariablePattern::SuspiciousClonePair::FirstCloneInfo
SuspiciousCloneInfo FirstCloneInfo
The first clone in the pair which always has a suggested variable.
Definition: CloneDetection.h:404
clang::StmtSequence::getContainingDecl
const Decl * getContainingDecl() const
Returns the declaration that contains the stored Stmts.
Definition: CloneDetection.h:113
clang::MinComplexityConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
Definition: CloneDetection.h:295
clang
Definition: CalledOnceCheck.h:17
clang::MinComplexityConstraint::calculateStmtComplexity
size_t calculateStmtComplexity(const StmtSequence &Seq, std::size_t Limit, const std::string &ParentMacroStack="")
Calculates the complexity of the given StmtSequence.
Definition: CloneDetection.cpp:419
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::VariablePattern
Analyzes the pattern of the referenced variables in a statement.
Definition: CloneDetection.h:349
clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo::Mention
const Stmt * Mention
Where the variable was referenced.
Definition: CloneDetection.h:393
clang::CloneConstraint::splitCloneGroups
static void splitCloneGroups(std::vector< CloneDetector::CloneGroup > &CloneGroups, llvm::function_ref< bool(const StmtSequence &, const StmtSequence &)> Compare)
Splits the given CloneGroups until the given Compare function returns true for all clones in a single...
Definition: CloneDetection.cpp:475
clang::StmtSequence::iterator
const typedef Stmt *const * iterator
Definition: CloneDetection.h:73
clang::MinComplexityConstraint
Ensures that every clone has at least the given complexity.
Definition: CloneDetection.h:281
clang::CloneDetector
Searches for similar subtrees in the AST.
Definition: CloneDetection.h:166
clang::StmtSequence::begin
iterator begin() const
Returns an iterator pointing to the first statement in this sequence.
Definition: CloneDetection.cpp:59
clang::RecursiveCloneTypeIIHashConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &Sequences)
Definition: CloneDetection.cpp:351
clang::StmtSequence::size
unsigned size() const
Returns the number of statements this object holds.
Definition: CloneDetection.h:98
clang::VariablePattern::SuspiciousClonePair::SuspiciousCloneInfo::SuspiciousCloneInfo
SuspiciousCloneInfo(const VarDecl *Variable, const Stmt *Mention, const VarDecl *Suggestion)
Definition: CloneDetection.h:398
clang::MinGroupSizeConstraint::constrain
void constrain(std::vector< CloneDetector::CloneGroup > &CloneGroups)
Definition: CloneDetection.h:315
clang::VariablePattern::countPatternDifferences
unsigned countPatternDifferences(const VariablePattern &Other, VariablePattern::SuspiciousClonePair *FirstMismatch=nullptr)
Counts the differences between this pattern and the given one.
Definition: CloneDetection.cpp:562
clang::StmtSequence::StmtSequence
StmtSequence()
Constructs an empty StmtSequence.
Definition: CloneDetection.cpp:34
clang::VariablePattern::VariablePattern
VariablePattern(const StmtSequence &Sequence)
Creates an VariablePattern object with information about the given StmtSequence.
Definition: CloneDetection.h:379