29 :
public Checker<check::ASTCodeBody, check::EndOfTranslationUnit> {
33 bool ReportNormalClones =
false;
34 StringRef IgnoredFilesPattern;
38 const BugType BT_Exact{
this,
"Exact code clone",
"Code clone"};
39 const BugType BT_Suspicious{
this,
"Suspicious code clone",
"Code clone"};
50 std::vector<CloneDetector::CloneGroup> &CloneGroups)
const;
54 void reportSuspiciousClones(
56 std::vector<CloneDetector::CloneGroup> &CloneGroups)
const;
64 Detector.analyzeCodeBody(
D);
76 std::vector<CloneDetector::CloneGroup> AllCloneGroups;
84 reportSuspiciousClones(BR, Mgr, AllCloneGroups);
88 if (!ReportNormalClones)
97 reportClones(BR, Mgr, AllCloneGroups);
108void CloneChecker::reportClones(
110 std::vector<CloneDetector::CloneGroup> &CloneGroups)
const {
114 auto R = std::make_unique<BasicBugReport>(
116 R->addRange(
Group.front().getSourceRange());
118 for (
unsigned i = 1; i <
Group.size(); ++i)
119 R->addNote(
"Similar code here",
makeLocation(Group[i], Mgr),
125void CloneChecker::reportSuspiciousClones(
127 std::vector<CloneDetector::CloneGroup> &CloneGroups)
const {
128 std::vector<VariablePattern::SuspiciousClonePair> Pairs;
131 for (
unsigned i = 0; i <
Group.size(); ++i) {
134 for (
unsigned j = i + 1; j <
Group.size(); ++j) {
146 if (PatternA.countPatternDifferences(PatternB, &ClonePair) == 1) {
147 Pairs.push_back(ClonePair);
165 auto R = std::make_unique<BasicBugReport>(
167 "Potential copy-paste error; did you really mean to use '" +
168 Pair.FirstCloneInfo.Variable->getNameAsString() +
"' here?",
171 R->addRange(Pair.FirstCloneInfo.Mention->getSourceRange());
173 R->addNote(
"Similar code using '" +
174 Pair.SecondCloneInfo.Variable->getNameAsString() +
"' here",
177 Pair.SecondCloneInfo.Mention->getSourceRange());
191 Checker,
"MinimumCloneComplexity");
193 if (
Checker->MinComplexity < 0)
195 Checker,
"MinimumCloneComplexity",
"a non-negative value");
198 Checker,
"ReportNormalClones");
Defines the Diagnostic-related interfaces.
static PathDiagnosticLocation makeLocation(const StmtSequence &S, AnalysisManager &Mgr)
This file defines classes for searching and analyzing source code clones.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
AnalysisDeclContext contains the context data for the function, method or block under analysis.
bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option's string value as a boolean.
int getCheckerIntegerOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option's string value as an integer value.
StringRef getCheckerStringOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Query an option's string value.
Searches for similar subtrees in the AST.
static void constrainClones(std::vector< CloneGroup > &CloneGroups, T C)
Constrains the given list of clone groups with the given constraint.
Decl - This represents one declaration (or definition), e.g.
Ensures that every clone has at least the given complexity.
Ensures that all clone groups contain at least the given amount of clones.
This constraint moves clones into clone groups of type II via hashing.
This constraint moves clones into clone groups of type II by comparing them.
This class handles loading and caching of source files into memory.
Identifies a list of statements.
The top declaration context.
Analyzes the pattern of the referenced variables in a statement.
ASTContext & getASTContext() override
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
BugReporter is a utility class for generating PathDiagnostics for analysis.
ASTContext & getContext()
virtual void emitReport(std::unique_ptr< BugReport > R)
Add the given report to the set of reports tracked by BugReporter.
const AnalyzerOptions & getAnalyzerOptions() const
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
void reportInvalidCheckerOptionValue(const CheckerBase *C, StringRef OptionName, StringRef ExpectedValueDesc) const
Emits an error through a DiagnosticsEngine about an invalid user supplied checker option value.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
The JSON file list parser is used to communicate input to InstallAPI.
Ensures that all clones reference variables in the same pattern.
Ensures that no clone group fully contains another clone group.
Describes two clones that reference their variables in a different pattern which could indicate a pro...