Index: test/Tooling/clang-diff-ast.cpp =================================================================== --- /dev/null +++ test/Tooling/clang-diff-ast.cpp @@ -0,0 +1,46 @@ +// RUN: clang-diff -no-compilation-database -ast-dump %s | FileCheck %s +// +// This tests the getNodeValue function from Tooling/ASTDiff/ASTDiff.h + +// CHECK: NamespaceDecl: test;( +namespace test { + +// CHECK: FunctionDecl: f( +void f() { + // CHECK: VarDecl: x(int)( + // CHECK: IntegerLiteral: 1 + int x = 1; + // CHECK: FloatingLiteral: 1.0( + x = 1; + // CHECK: CXXBoolLiteral: true( + x = true; + // CHECK: CallExpr( + // CHECK: DeclRefExpr: f( + f(); +} + +#if 0 +void main() { foo(); }; + +const char *a = "foo"; + +typedef unsigned int nat; + +int p = 1 * 2 * 3 * 4; +int squared = p * p; + +class X { + const char *foo(int i) { + if (i == 0) + return "foo"; + return 0; + } + +public: + X(){}; + + int id(int i) { return i; } +}; +#endif + +} Index: test/Tooling/clang-diff-basic.cpp =================================================================== --- test/Tooling/clang-diff-basic.cpp +++ test/Tooling/clang-diff-basic.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -E %s > %T/src.cpp // RUN: %clang_cc1 -E %s > %T/dst.cpp -DDEST -// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck %s +// RUN: clang-diff -m -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck %s #ifndef DEST namespace src { Index: tools/clang-diff/ClangDiff.cpp =================================================================== --- tools/clang-diff/ClangDiff.cpp +++ tools/clang-diff/ClangDiff.cpp @@ -33,6 +33,10 @@ cl::desc("Print the internal representation of the AST as JSON."), cl::init(false), cl::cat(ClangDiffCategory)); +static cl::opt<bool> + PrintMatches("m", cl::desc("Print the matched nodes (verbose)."), + cl::init(false), cl::cat(ClangDiffCategory)); + static cl::opt<bool> NoCompilationDatabase( "no-compilation-database", cl::desc( @@ -270,7 +274,7 @@ for (diff::NodeId Dst : DstTree) { diff::NodeId Src = Diff.getMapped(DstTree, Dst); - if (Src.isValid()) { + if (PrintMatches && Src.isValid()) { llvm::outs() << "Match "; printNode(llvm::outs(), SrcTree, Src); llvm::outs() << " to ";