clang 20.0.0git
|
Searches for similar subtrees in the AST. More...
#include "clang/Analysis/CloneDetection.h"
Public Types | |
typedef llvm::SmallVector< StmtSequence, 8 > | CloneGroup |
A collection of StmtSequences that share an arbitrary property. | |
Public Member Functions | |
void | analyzeCodeBody (const Decl *D) |
Generates and stores search data for all statements in the body of the given Decl. | |
template<typename... Ts> | |
void | findClones (std::vector< CloneGroup > &Result, Ts... ConstraintList) |
Searches for clones in all previously passed statements. | |
Static Public Member Functions | |
template<typename T > | |
static void | constrainClones (std::vector< CloneGroup > &CloneGroups, T C) |
Constrains the given list of clone groups with the given constraint. | |
template<typename T1 , typename... Ts> | |
static void | constrainClones (std::vector< CloneGroup > &CloneGroups, T1 C, Ts... ConstraintList) |
Constrains the given list of clone groups with the given list of constraints. | |
Searches for similar subtrees in the AST.
First, this class needs several declarations with statement bodies which can be passed via analyzeCodeBody. Afterwards all statements can be searched for clones by calling findClones with a given list of constraints that should specify the wanted properties of the clones.
The result of findClones can be further constrained with the constrainClones method.
This class only searches for clones in executable source code (e.g. function bodies). Other clones (e.g. cloned comments or declarations) are not supported.
Definition at line 166 of file CloneDetection.h.
A collection of StmtSequences that share an arbitrary property.
Definition at line 170 of file CloneDetection.h.
void CloneDetector::analyzeCodeBody | ( | const Decl * | D | ) |
Generates and stores search data for all statements in the body of the given Decl.
Definition at line 90 of file CloneDetection.cpp.
References D, clang::Decl::getBody(), and clang::Decl::hasBody().
|
inlinestatic |
Constrains the given list of clone groups with the given constraint.
The constraint is expected to have a method with the signature void constrain(std::vector<CloneDetector::CloneGroup> &Sequences)
as this is the interface that the CloneDetector uses for applying the constraint. The constraint is supposed to directly modify the passed list so that all clones in the list fulfill the specific property this constraint ensures.
Definition at line 185 of file CloneDetection.h.
References clang::C.
Referenced by constrainClones(), and findClones().
|
inlinestatic |
Constrains the given list of clone groups with the given list of constraints.
The constraints are applied in sequence in the order in which they are passed to this function.
Definition at line 195 of file CloneDetection.h.
References clang::C, and constrainClones().
|
inline |
Searches for clones in all previously passed statements.
Result | Output parameter to which all created clone groups are added. |
ConstraintList | The constraints that should be applied to the |
Definition at line 207 of file CloneDetection.h.
References constrainClones(), and clang::Result.