clang  6.0.0svn
Public Types | Public Member Functions | Static Public Member Functions | List of all members
clang::CloneDetector Class Reference

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. More...
 

Public Member Functions

void analyzeCodeBody (const Decl *D)
 Generates and stores search data for all statements in the body of the given Decl. More...
 
template<typename... Ts>
void findClones (std::vector< CloneGroup > &Result, Ts... ConstraintList)
 Searches for clones in all previously passed statements. More...
 

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. More...
 
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. More...
 

Detailed Description

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 exectuable source code (e.g. function bodies). Other clones (e.g. cloned comments or declarations) are not supported.

Definition at line 167 of file CloneDetection.h.

Member Typedef Documentation

◆ CloneGroup

A collection of StmtSequences that share an arbitrary property.

Definition at line 171 of file CloneDetection.h.

Member Function Documentation

◆ analyzeCodeBody()

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 clang::Decl::getBody(), clang::Decl::hasBody(), and clang::StmtSequence::StmtSequence().

◆ constrainClones() [1/2]

template<typename T >
static void clang::CloneDetector::constrainClones ( std::vector< CloneGroup > &  CloneGroups,
T  C 
)
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 186 of file CloneDetection.h.

◆ constrainClones() [2/2]

template<typename T1 , typename... Ts>
static void clang::CloneDetector::constrainClones ( std::vector< CloneGroup > &  CloneGroups,
T1  C,
Ts...  ConstraintList 
)
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 196 of file CloneDetection.h.

◆ findClones()

template<typename... Ts>
void clang::CloneDetector::findClones ( std::vector< CloneGroup > &  Result,
Ts...  ConstraintList 
)
inline

Searches for clones in all previously passed statements.

Parameters
ResultOutput parameter to which all created clone groups are added.
ConstraintListThe constraints that should be applied to the

Definition at line 208 of file CloneDetection.h.

References clang::C.


The documentation for this class was generated from the following files: