johannes updated this revision to Diff 109423.
johannes added a comment.
tests
https://reviews.llvm.org/D36184
Files:
lib/Tooling/ASTDiff/ASTDiff.cpp
test/Tooling/clang-diff-ast.cpp
Index: test/Tooling/clang-diff-ast.cpp
===================================================================
--- test/Tooling/clang-diff-ast.cpp
+++ test/Tooling/clang-diff-ast.cpp
@@ -12,7 +12,8 @@
// CHECK: IntegerLiteral: 1
auto i = 1;
// CHECK: CallExpr(
- // CHECK: DeclRefExpr: f(
+ // CHECK-NOT: ImplicitCastExpr
+ // CHECK-NEXT: DeclRefExpr: f(
f();
// CHECK: BinaryOperator: =(
i = i;
@@ -37,6 +38,7 @@
if (i == 0)
// CHECK: StringLiteral: foo(
return "foo";
+ // CHECK-NOT: ImplicitCastExpr
return 0;
}
@@ -48,3 +50,22 @@
int x = m;
}
};
+
+#define M (void)1
+#define MA(a, b) (void)a, b
+// CHECK: FunctionDecl
+// CHECK-NEXT: CompoundStmt
+void macros() {
+ M;
+ MA(1, 2);
+}
+// CHECK-NEXT: NamespaceDecl
+
+#ifndef GUARD
+#define GUARD
+namespace world {
+// nodes from other files are excluded
+// CHECK-NOT {{.}}
+#include "clang-diff-ast.cpp"
+}
+#endif
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===================================================================
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -162,24 +162,37 @@
if (!N)
return true;
SourceLocation SLoc = N->getLocStart();
- return SLoc.isValid() && SrcMgr.isInSystemHeader(SLoc);
+ if (!SLoc.isValid())
+ return false;
+ // Ignore everything from other files.
+ if (!SrcMgr.isInMainFile(SLoc))
+ return true;
+ // Ignore macros.
+ if (N->getLocStart() != SrcMgr.getSpellingLoc(N->getLocStart()))
+ return true;
+ return false;
}
+static bool isDeclExcluded(const Decl *D) { return D->isImplicit(); }
+static bool isStmtExcluded(const Stmt *S) { return false; }
+
namespace {
/// Counts the number of nodes that will be compared.
struct NodeCountVisitor : public RecursiveASTVisitor<NodeCountVisitor> {
int Count = 0;
const SyntaxTree::Impl &Tree;
NodeCountVisitor(const SyntaxTree::Impl &Tree) : Tree(Tree) {}
bool TraverseDecl(Decl *D) {
- if (isNodeExcluded(Tree.AST.getSourceManager(), D))
+ if (isNodeExcluded(Tree.AST.getSourceManager(), D) || isDeclExcluded(D))
return true;
++Count;
RecursiveASTVisitor<NodeCountVisitor>::TraverseDecl(D);
return true;
}
bool TraverseStmt(Stmt *S) {
- if (isNodeExcluded(Tree.AST.getSourceManager(), S))
+ if (S)
+ S = S->IgnoreImplicit();
+ if (isNodeExcluded(Tree.AST.getSourceManager(), S) || isStmtExcluded(S))
return true;
++Count;
RecursiveASTVisitor<NodeCountVisitor>::TraverseStmt(S);
@@ -233,15 +246,17 @@
N.Height = std::max(N.Height, 1 + Tree.getNode(Child).Height);
}
bool TraverseDecl(Decl *D) {
- if (isNodeExcluded(Tree.AST.getSourceManager(), D))
+ if (isNodeExcluded(Tree.AST.getSourceManager(), D) || isDeclExcluded(D))
return true;
auto SavedState = PreTraverse(D);
RecursiveASTVisitor<PreorderVisitor>::TraverseDecl(D);
PostTraverse(SavedState);
return true;
}
bool TraverseStmt(Stmt *S) {
- if (isNodeExcluded(Tree.AST.getSourceManager(), S))
+ if (S)
+ S = S->IgnoreImplicit();
+ if (isNodeExcluded(Tree.AST.getSourceManager(), S) || isStmtExcluded(S))
return true;
auto SavedState = PreTraverse(S);
RecursiveASTVisitor<PreorderVisitor>::TraverseStmt(S);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits