summaryrefslogtreecommitdiffstats
path: root/lib/Analysis/CloneDetection.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2016-10-04 02:40:35 +0000
committerVitaly Buka <vitalybuka@google.com>2016-10-04 02:40:35 +0000
commitb01e9e02909532ea411a3134fffa666b84a95398 (patch)
tree533bd4580389d67728077ef0ed2caeb8fe889b86 /lib/Analysis/CloneDetection.cpp
parentb89ba4ae947835a21e443d78c8cfaf7db595fc0b (diff)
Revert "[analyzer] Improve CloneChecker diagnostics" as its depends on reverted r283092
This reverts commit r283094. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283182 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CloneDetection.cpp')
-rw-r--r--lib/Analysis/CloneDetection.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/Analysis/CloneDetection.cpp b/lib/Analysis/CloneDetection.cpp
index 4fdac5abbd..1b43cfb274 100644
--- a/lib/Analysis/CloneDetection.cpp
+++ b/lib/Analysis/CloneDetection.cpp
@@ -82,10 +82,6 @@ SourceLocation StmtSequence::getStartLoc() const {
SourceLocation StmtSequence::getEndLoc() const { return back()->getLocEnd(); }
-SourceRange StmtSequence::getSourceRange() const {
- return SourceRange(getStartLoc(), getEndLoc());
-}
-
namespace {
/// \brief Analyzes the pattern of the referenced variables in a statement.
@@ -95,11 +91,11 @@ class VariablePattern {
struct VariableOccurence {
/// The index of the associated VarDecl in the Variables vector.
size_t KindID;
- /// The statement in the code where the variable was referenced.
- const Stmt *Mention;
+ /// The source range in the code where the variable was referenced.
+ SourceRange Range;
- VariableOccurence(size_t KindID, const Stmt *Mention)
- : KindID(KindID), Mention(Mention) {}
+ VariableOccurence(size_t KindID, SourceRange Range)
+ : KindID(KindID), Range(Range) {}
};
/// All occurences of referenced variables in the order of appearance.
@@ -111,19 +107,19 @@ class VariablePattern {
/// \brief Adds a new variable referenced to this pattern.
/// \param VarDecl The declaration of the variable that is referenced.
/// \param Mention The statement in the code where the variable was referenced.
- void addVariableOccurence(const VarDecl *VarDecl, const Stmt *Mention) {
+ void addVariableOccurence(const VarDecl *VarDecl, SourceRange Range) {
// First check if we already reference this variable
for (size_t KindIndex = 0; KindIndex < Variables.size(); ++KindIndex) {
if (Variables[KindIndex] == VarDecl) {
// If yes, add a new occurence that points to the existing entry in
// the Variables vector.
- Occurences.emplace_back(KindIndex, Mention);
+ Occurences.emplace_back(KindIndex, Range);
return;
}
}
// If this variable wasn't already referenced, add it to the list of
// referenced variables and add a occurence that points to this new entry.
- Occurences.emplace_back(Variables.size(), Mention);
+ Occurences.emplace_back(Variables.size(), Range);
Variables.push_back(VarDecl);
}
@@ -138,7 +134,7 @@ class VariablePattern {
// Check if S is a reference to a variable. If yes, add it to the pattern.
if (auto D = dyn_cast<DeclRefExpr>(S)) {
if (auto VD = dyn_cast<VarDecl>(D->getDecl()->getCanonicalDecl()))
- addVariableOccurence(VD, D);
+ addVariableOccurence(VD, D->getSourceRange());
}
// Recursively check all children of the given statement.
@@ -212,7 +208,7 @@ public:
// Store information about the first clone.
FirstMismatch->FirstCloneInfo =
CloneDetector::SuspiciousClonePair::SuspiciousCloneInfo(
- Variables[ThisOccurence.KindID], ThisOccurence.Mention,
+ Variables[ThisOccurence.KindID], ThisOccurence.Range,
FirstSuggestion);
// Same as above but with the other clone. We do this for both clones as
@@ -225,7 +221,7 @@ public:
// Store information about the second clone.
FirstMismatch->SecondCloneInfo =
CloneDetector::SuspiciousClonePair::SuspiciousCloneInfo(
- Other.Variables[OtherOccurence.KindID], OtherOccurence.Mention,
+ Variables[ThisOccurence.KindID], OtherOccurence.Range,
SecondSuggestion);
// SuspiciousClonePair guarantees that the first clone always has a