From d5b56a8619bd0d8fee3ead9541e02cfe070e032d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 20 Aug 2017 10:22:32 +0000 Subject: [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 llvm-svn: 311280 --- clang/lib/Tooling/ASTDiff/ASTDiff.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'clang/lib/Tooling/ASTDiff/ASTDiff.cpp') diff --git a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp b/clang/lib/Tooling/ASTDiff/ASTDiff.cpp index 43c19a72260..ada7cbcfc55 100644 --- a/clang/lib/Tooling/ASTDiff/ASTDiff.cpp +++ b/clang/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 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 { 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 { return true; } bool TraverseStmt(Stmt *S) { + if (S) + S = S->IgnoreImplicit(); if (isNodeExcluded(Tree.AST.getSourceManager(), S)) return true; auto SavedState = PreTraverse(S); -- cgit v1.2.3