summaryrefslogtreecommitdiff
path: root/lib/Tooling/ASTDiff
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2017-08-20 10:22:32 +0000
committerJohannes Altmanninger <aclopte@gmail.com>2017-08-20 10:22:32 +0000
commit544626fd1a0364617e75c3511addbff936ce315a (patch)
tree9fc822dda95f710a2b3b8e4c462f2ee0a3e7c88f /lib/Tooling/ASTDiff
parent598a0a07067dc11b288c1f5da482003eb4439d68 (diff)
[clang-diff] Filter AST nodes
Summary: Ignore macros and implicit AST nodes, as well as anything outside of the main source file. Reviewers: arphaman Subscribers: klimek Differential Revision: https://reviews.llvm.org/D36184 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311280 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/ASTDiff')
-rw-r--r--lib/Tooling/ASTDiff/ASTDiff.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Tooling/ASTDiff/ASTDiff.cpp b/lib/Tooling/ASTDiff/ASTDiff.cpp
index 43c19a7226..ada7cbcfc5 100644
--- a/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ b/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -158,12 +158,23 @@ private:
void setLeftMostDescendants();
};
+static bool isSpecializedNodeExcluded(const Decl *D) { return D->isImplicit(); }
+static bool isSpecializedNodeExcluded(const Stmt *S) { return false; }
+
template <class T>
static bool isNodeExcluded(const SourceManager &SrcMgr, T *N) {
if (!N)
return true;
SourceLocation SLoc = N->getLocStart();
- return SLoc.isValid() && SrcMgr.isInSystemHeader(SLoc);
+ if (SLoc.isValid()) {
+ // Ignore everything from other files.
+ if (!SrcMgr.isInMainFile(SLoc))
+ return true;
+ // Ignore macros.
+ if (SLoc != SrcMgr.getSpellingLoc(SLoc))
+ return true;
+ }
+ return isSpecializedNodeExcluded(N);
}
namespace {
@@ -180,6 +191,8 @@ struct NodeCountVisitor : public RecursiveASTVisitor<NodeCountVisitor> {
return true;
}
bool TraverseStmt(Stmt *S) {
+ if (S)
+ S = S->IgnoreImplicit();
if (isNodeExcluded(Tree.AST.getSourceManager(), S))
return true;
++Count;
@@ -242,6 +255,8 @@ struct PreorderVisitor : public RecursiveASTVisitor<PreorderVisitor> {
return true;
}
bool TraverseStmt(Stmt *S) {
+ if (S)
+ S = S->IgnoreImplicit();
if (isNodeExcluded(Tree.AST.getSourceManager(), S))
return true;
auto SavedState = PreTraverse(S);