johannes created this revision.
Herald added a subscriber: klimek.

https://reviews.llvm.org/D39658

Files:
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-ast.cpp
  test/Tooling/clang-diff-basic.cpp
  test/Tooling/clang-diff-bottomup.cpp
  test/Tooling/clang-diff-heuristics.cpp
  test/Tooling/clang-diff-html.test
  test/Tooling/clang-diff-json.cpp
  test/Tooling/clang-diff-opt.cpp
  test/Tooling/clang-diff-topdown.cpp

Index: test/Tooling/clang-diff-topdown.cpp
===================================================================
--- test/Tooling/clang-diff-topdown.cpp
+++ test/Tooling/clang-diff-topdown.cpp
@@ -9,9 +9,10 @@
 void f1()
 {
   // Match some subtree of height greater than 2.
-  // CHECK: Match CompoundStmt(3) to CompoundStmt(3)
-  // CHECK: Match CompoundStmt(4) to CompoundStmt(4)
-  // CHECK: Match NullStmt(5) to NullStmt(5)
+  // CHECK: Match CompoundStmt(5) to CompoundStmt(5)
+  // CHECK-NEXT: Move CompoundStmt
+  // CHECK-NEXT: Match CompoundStmt
+  // CHECK-NEXT: Match NullStmt({{.*}}) to NullStmt({{.*}})
   {{;}}
 
   // Don't match subtrees that are smaller.
@@ -21,9 +22,10 @@
 
   // Greedy approach - use the first matching subtree when there are multiple
   // identical subtrees.
-  // CHECK: Match CompoundStmt(8) to CompoundStmt(8)
-  // CHECK: Match CompoundStmt(9) to CompoundStmt(9)
-  // CHECK: Match NullStmt(10) to NullStmt(10)
+  // CHECK: Match CompoundStmt(10) to CompoundStmt(10)
+  // CHECK-NEXT: Move CompoundStmt
+  // CHECK-NEXT: Match CompoundStmt({{.*}}) to CompoundStmt({{.*}})
+  // CHECK-NEXT: Match NullStmt({{.*}}) to NullStmt({{.*}})
   {{;;}}
 }
 
@@ -45,22 +47,22 @@
   {;}
 
   {{;;}}
-  // CHECK-NOT: Match {{.*}} to CompoundStmt(11)
-  // CHECK-NOT: Match {{.*}} to CompoundStmt(12)
-  // CHECK-NOT: Match {{.*}} to NullStmt(13)
+  // CHECK-NOT: Match {{.*}} to CompoundStmt(15)
+  // CHECK-NOT: Match {{.*}} to CompoundStmt(16)
+  // CHECK-NOT: Match {{.*}} to NullStmt(17)
   {{;;}}
 
-  // CHECK-NOT: Match {{.*}} to NullStmt(14)
+  // CHECK-NOT: Match {{.*}} to NullStmt(18)
   ;
 }
 
 int x;
 
 namespace dst {
   int x;
-  // CHECK: Match DeclRefExpr(17) to DeclRefExpr(22)
+  // CHECK: Match DeclRefExpr(22) to DeclRefExpr(27)
   int x1 = x + 1;
-  // CHECK: Match DeclRefExpr(21) to DeclRefExpr(26)
+  // CHECK: Match DeclRefExpr
   int x2 = ::x + 1;
 }
 
Index: test/Tooling/clang-diff-opt.cpp
===================================================================
--- test/Tooling/clang-diff-opt.cpp
+++ test/Tooling/clang-diff-opt.cpp
@@ -20,25 +20,25 @@
 void f1() {
 // Jaccard similarity = 3 / (5 + 4 - 3) = 3 / 6 >= 0.5
 // The optimal matching algorithm should move the ; into the outer block
-// CHECK: Match CompoundStmt(2) to CompoundStmt(2)
+// CHECK: Match CompoundStmt(4) to CompoundStmt(4)
 // CHECK-NOT: Match CompoundStmt(3)
-// CHECK-NEXT: Match NullStmt(4) to NullStmt(3)
+// CHECK-NEXT: Match NullStmt(6) to NullStmt(5)
   ; {{;}}
 }
 
 void f2() {
   // Jaccard similarity = 7 / (10 + 10 - 7) >= 0.5
   // As none of the subtrees is bigger than 10 nodes, the optimal algorithm
   // will be run.
-  // CHECK: Match NullStmt(11) to NullStmt(9)
+  // CHECK: Match NullStmt(15) to NullStmt(13)
   ;; {{;;;;;}}
 }
 
 void f3() {
   // Jaccard similarity = 8 / (11 + 11 - 8) >= 0.5
   // As the subtrees are bigger than 10 nodes, the optimal algorithm will not
   // be run.
-  // CHECK: Delete NullStmt(22)
+  // CHECK: Delete NullStmt(28)
   ;; {{;;;;;;}}
 }
  
Index: test/Tooling/clang-diff-json.cpp
===================================================================
--- test/Tooling/clang-diff-json.cpp
+++ test/Tooling/clang-diff-json.cpp
@@ -16,8 +16,8 @@
 // CHECK-NEXT: "children": []
 // CHECK-NEXT: "end":
 // CHECK-NEXT: "id":
-// CHECK-NEXT: "type": "CharacterLiteral"
-// CHECK-NEXT: }
+// CHECK-NEXT: "type": "TypeLoc"
+// CHECK: }
 // CHECK: ]
 // CHECK: "type": "VarDecl"
 char nl = '\n';
Index: test/Tooling/clang-diff-html.test
===================================================================
--- test/Tooling/clang-diff-html.test
+++ test/Tooling/clang-diff-html.test
@@ -1,4 +1,4 @@
-RUN: clang-diff -html %S/Inputs/clang-diff-basic-src.cpp %S/clang-diff-basic.cpp -- -std=c++11 | FileCheck %s
+RUN: clang-diff -html %S/Inputs/clang-diff-basic-src.cpp %S/clang-diff-basic.cpp -s=200 -- -std=c++11 | FileCheck %s
 
 CHECK: <pre><div id='L' class='code'><span id='L0' tid='R0' title='TranslationUnitDecl
 CHECK-NEXT: 0 -> 0' class='u'>
@@ -9,11 +9,15 @@
 
 match, move
 CHECK: <span id='L[[L:[0-9]+]]' tid='R[[R:[0-9]+]]' title='FunctionDecl
-CHECK-NEXT: [[L]] -> [[R]]' class='m'>void foo()
+CHECK-NEXT: [[L]] -> [[R]]' class='m'>{{.*}} title='TypeLoc
+CHECK-NEXT: TypeLoc
+CHECK-NEXT: void</span> foo()
 
 match
 CHECK: <span id='L[[L:[0-9]+]]' tid='R[[R:[0-9]+]]' title='FunctionDecl
-CHECK-NEXT: [[L]] -> [[R]]'>void main()
+CHECK-NEXT: TypeLoc
+CHECK-NEXT: TypeLoc
+CHECK-NEXT: void</span> main()
 
 deletion
 CHECK: <span id='L[[L:[0-9]+]]' tid='R-1' title='IntegerLiteral
Index: test/Tooling/clang-diff-heuristics.cpp
===================================================================
--- test/Tooling/clang-diff-heuristics.cpp
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -20,12 +20,12 @@
 void f1() {}
 
 // same parents, same identifier
-// CHECK: Match FunctionDecl(4) to FunctionDecl(3)
+// CHECK: Match FunctionDecl(6) to FunctionDecl(5)
 // CHECK: Match CompoundStmt
 void f2() {}
 
 // same parents, same identifier
-// CHECK: Match CXXConstructorDecl(9) to CXXConstructorDecl(6)
+// CHECK: Match CXXConstructorDecl(14) to CXXConstructorDecl(10)
 class C3 { C3(int); };
 
 #endif
Index: test/Tooling/clang-diff-bottomup.cpp
===================================================================
--- test/Tooling/clang-diff-bottomup.cpp
+++ test/Tooling/clang-diff-bottomup.cpp
@@ -6,33 +6,33 @@
 
 #ifndef DEST
 
-void f1() { ; {{;}} }
-void f2() { ;; {{;}} }
+void f1(int) { ; {{;}} }
+void f2(int) { ;; {{;}} }
 
 #else
 
 // Jaccard similarity threshold is 0.5.
 
 void f1() {
 // CompoundStmt: 3 matched descendants, subtree sizes 4 and 5
 // Jaccard similarity = 3 / (4 + 5 - 3) = 3 / 6 >= 0.5
-// CHECK: Match FunctionDecl(1) to FunctionDecl(1)
-// CHECK: Match CompoundStmt(2) to CompoundStmt(2)
-// CHECK: Match CompoundStmt(4) to CompoundStmt(3)
-// CHECK: Match CompoundStmt(5) to CompoundStmt(4)
-// CHECK: Match NullStmt(6) to NullStmt(5)
+// CHECK: Match CompoundStmt(6) to CompoundStmt(4)
+// CHECK-NEXT: Move CompoundStmt
+// CHECK-NEXT: Match CompoundStmt
+// CHECK-NEXT: Match CompoundStmt
+// CHECK-NEXT: Match NullStmt
   {{;}} ;;
 }
 
 void f2() {
 // CompoundStmt: 3 matched descendants, subtree sizes 4 and 5
 // Jaccard similarity = 3 / (5 + 6 - 3) = 3 / 8 < 0.5
-// CHECK-NOT: Match FunctionDecl(9)
-// CHECK-NOT: Match CompoundStmt(10)
-// CHECK: Match CompoundStmt(11) to CompoundStmt(10)
-// CHECK: Match CompoundStmt(12) to CompoundStmt(11)
-// CHECK: Match NullStmt(13) to NullStmt(12)
-// CHECK-NOT: Match NullStmt(13)
+// CHECK-NOT: Match CompoundStmt(16)
+// CHECK: Match CompoundStmt(19) to CompoundStmt(14)
+// CHECK-NEXT: Move CompoundStmt
+// CHECK-NEXT: Match CompoundStmt
+// CHECK-NEXT: Match NullStmt
+// CHECK-NOT: Match NullStmt({{.*}})
   {{;}} ;;;
 }
 
Index: test/Tooling/clang-diff-basic.cpp
===================================================================
--- test/Tooling/clang-diff-basic.cpp
+++ test/Tooling/clang-diff-basic.cpp
@@ -1,55 +1,57 @@
-// RUN: clang-diff -dump-matches %S/Inputs/clang-diff-basic-src.cpp %s -- -std=c++11 | FileCheck %s
+// RUN: clang-diff -dump-matches %S/Inputs/clang-diff-basic-src.cpp %s -s=200 -- -std=c++11 | FileCheck %s
 
 // CHECK: Match TranslationUnitDecl(0) to TranslationUnitDecl(0)
 // CHECK: Match NamespaceDecl(1) to NamespaceDecl(1)
 namespace dst {
 // CHECK-NOT: Match NamespaceDecl(1) to NamespaceDecl(2)
 namespace inner {
 void foo() {
-  // CHECK: Match IntegerLiteral(6) to IntegerLiteral(7)
+  // CHECK: Match IntegerLiteral(9) to IntegerLiteral(10)
   int x = 322;
 }
 }
 
-// CHECK: Match DeclRefExpr(10) to DeclRefExpr(11)
+// CHECK: Match DeclRefExpr(15) to DeclRefExpr(16)
 void main() { inner::foo(); }
 
-// CHECK: Match StringLiteral(13) to StringLiteral(13)
+// CHECK: Match StringLiteral(20) to StringLiteral(20)
 const char *b = "f" "o" "o";
 
 // unsigned is canonicalized to unsigned int
-// CHECK: Match TypedefDecl(14) to TypedefDecl(14)
+// CHECK: Match TypedefDecl
 typedef unsigned nat;
 
-// CHECK: Match VarDecl(15)
-// CHECK: Update VarDecl(15)
-// CHECK: Match BinaryOperator(17)
+// CHECK: Match VarDecl
+// CHECK-NEXT: Update VarDecl
+// CHECK-NEXT: Match TypeLoc
+// CHECK-NEXT: Update TypeLoc
+// CHECK-NEXT: Match BinaryOperator
 double prod = 1 * 2 * 10;
-// CHECK: Update DeclRefExpr(25)
+// CHECK: Update DeclRefExpr
 int squared = prod * prod;
 
 class X {
   const char *foo(int i) {
-    // CHECK: Insert IfStmt(29) into CompoundStmt(28)
+    // CHECK: Insert IfStmt(43) into CompoundStmt(42)
     if (i == 0)
       return "Bar";
-    // CHECK: Move IfStmt(35) into IfStmt
+    // CHECK: Move IfStmt(49) into IfStmt
     else if (i == -1)
       return "foo";
     return 0;
   }
   X(){}
 };
 }
 
-// CHECK: Move CompoundStmt(48) into CompoundStmt(47)
+// CHECK: Move CompoundStmt(66) into CompoundStmt(65)
 void m() { { int x = 0 + 0 + 0; } }
-// CHECK: Update and Move IntegerLiteral(59) into BinaryOperator(57) at 1
+// CHECK: Update and Move IntegerLiteral(79) into BinaryOperator(77) at 1
 int um = 1 + 7;
 
 namespace {
 // match with parents of different type
-// CHECK: Match FunctionDecl(70) to FunctionDecl(69)
+// CHECK: Match FunctionDecl(85) to FunctionDecl(81)
 void f1() {{ (void) __func__;;; }}
 }
 
@@ -60,26 +62,27 @@
 #define F(a, b) return a + b;
 
 int f2() {
-  // CHECK: Match Macro(72) to Macro(71)
+  // CHECK: Match Macro(100) to Macro(96)
   M1;
-  // CHECK: Update Macro(73)
+  // CHECK: Update Macro(101)
   M2;
-  // CHECK: Match Macro(74)
+  // CHECK: Match Macro(102)
   F(1, /*b=*/1);
 }
 
-// CHECK: Match TemplateTypeParmDecl(77)
+// CHECK: Match TemplateTypeParmDecl(105)
 template <class Type, class U = int>
 U visit(Type &t) {
   int x = t;
   return U();
 }
 
 void tmp() {
   long x;
-  // CHECK: Match TemplateArgument(93)
+  // CHECK: Match TemplateArgument(133)
+  // CHECK: Update TypeLoc
   visit<long>(x);
 }
 
-// CHECK: Delete AccessSpecDecl(39)
-// CHECK: Delete CXXMethodDecl(42)
+// CHECK: Delete AccessSpecDecl
+// CHECK: Delete CXXMethodDecl
Index: test/Tooling/clang-diff-ast.cpp
===================================================================
--- test/Tooling/clang-diff-ast.cpp
+++ test/Tooling/clang-diff-ast.cpp
@@ -6,103 +6,114 @@
 namespace test {
 
 // CHECK: {{^}} FunctionDecl(2)
-// CHECK: CompoundStmt(3)
 void f() {
-  // CHECK: DeclStmt(4)
-  // CHECK: VarDecl(5)
-  // CHECK: IntegerLiteral(6)
+  // CHECK: CompoundStmt(5)
+  // CHECK: DeclStmt(6)
+  // CHECK-NEXT: VarDecl
+  // CHECK-NEXT: TypeLoc
+  // CHECK-NEXT: QualType
+  // CHECK-NEXT: IntegerLiteral
   auto i = 1;
-  // CHECK: FloatingLiteral(9)
+  // CHECK: FloatingLiteral(15)
   auto r = 1.5;
-  // CHECK: CXXBoolLiteralExpr(12)
-  auto b = true;
-  // CHECK: CallExpr(13)
+  // CHECK: TypeLoc(18)
+  // CHECK-NEXT: CXXBoolLiteralExpr
+  bool b = true;
+  // CHECK: CallExpr(20)
   // CHECK-NOT: ImplicitCastExpr
-  // CHECK: DeclRefExpr(14)
+  // CHECK-NEXT: DeclRefExpr
   f();
-  // CHECK: UnaryOperator(15)
+  // CHECK: UnaryOperator(22)
   ++i;
-  // CHECK: BinaryOperator(17)
+  // CHECK: BinaryOperator(24)
   i = i;
 }
 
 } // end namespace test
 
-// CHECK: UsingDirectiveDecl(20)
+// CHECK: UsingDirectiveDecl(27)
 using namespace test;
 
-// CHECK: TypedefDecl(21)
+// CHECK: TypedefDecl(28)
 typedef unsigned nat;
-// CHECK: TypeAliasDecl(22)
+// CHECK: TypeAliasDecl(30)
 using real = double;
 
 class Base {
 };
 
-// CHECK: CXXRecordDecl(23)
+// CHECK: CXXRecordDecl(33)
 class X : Base {
   int m;
-  // CHECK: CXXMethodDecl(26)
-  // CHECK: ParmVarDecl(27)
+  // CHECK: CXXMethodDecl(37)
+  // CHECK: ParmVarDecl(41)
   const char *foo(int i) {
     if (i == 0)
-      // CHECK: StringLiteral(34)
+      // CHECK: StringLiteral(49)
       return "foo";
     // CHECK-NOT: ImplicitCastExpr
     return 0;
   }
 
-  // CHECK: AccessSpecDecl(37)
+  // CHECK: AccessSpecDecl(52)
 public:
   int not_initialized;
-  // CHECK: CXXConstructorDecl(39)
-  // CHECK-NEXT: ParmVarDecl(40)
-  // CHECK-NEXT: ParmVarDecl(41)
-  // CHECK-NEXT: CXXCtorInitializer(42)
-  // CHECK-NEXT: CXXConstructExpr(43)
-  // CHECK-NEXT: CXXCtorInitializer(44)
-  // CHECK-NEXT: IntegerLiteral(45)
+  // CHECK: CXXConstructorDecl(55)
+  // CHECK-NEXT: TypeLoc
+  // CHECK-NEXT: TypeLoc
+  // CHECK-NEXT: ParmVarDecl
+  // CHECK-NEXT: TypeLoc
+  // CHECK-NEXT: ParmVarDecl
+  // CHECK-NEXT: TypeLoc
+  // CHECK-NEXT: CXXCtorInitializer
+  // CHECK-NEXT: TypeLoc
+  // CHECK-NEXT: CXXConstructExpr
+  // CHECK-NEXT: CXXCtorInitializer
+  // CHECK-NEXT: IntegerLiteral
   X(char s, int) : Base(), m(0) {
-    // CHECK-NEXT: CompoundStmt(46)
-    // CHECK: MemberExpr(49)
+    // CHECK-NEXT: CompoundStmt(67)
+    // CHECK: MemberExpr(71)
     int x = m;
   }
-  // CHECK: CXXConstructorDecl(51)
-  // CHECK: CXXCtorInitializer(53)
+  // CHECK: CXXConstructorDecl(73)
+  // CHECK: CXXCtorInitializer(78)
   X(char s) : X(s, 4) {}
 };
 
 #define M (void)1
 #define F(a, b) (void)a, b
 void macros() {
-  // CHECK: Macro(60)
+  // CHECK: Macro(90)
   M;
   // two expressions, therefore it occurs twice
-  // CHECK-NEXT: Macro(61)
-  // CHECK-NEXT: Macro(62)
+  // CHECK-NEXT: Macro(91)
+  // CHECK-NEXT: Macro(92)
   F(1, 2);
 }
 
 #ifndef GUARD
 #define GUARD
-// CHECK-NEXT: NamespaceDecl(63)
+// CHECK-NEXT: NamespaceDecl(93)
 namespace world {
 // nodes from other files are excluded, there should be no output here
 #include "clang-diff-ast.cpp"
 }
-// CHECK-NEXT: FunctionDecl(64)
+// CHECK-NEXT: FunctionDecl(94)
 void sentinel();
 #endif
 
-// CHECK-NEXT: ClassTemplateDecl(65)
-// CHECK-NEXT: TemplateTypeParmDecl(66)
-// CHECK-NEXT: CXXRecordDecl(67)
+// CHECK: ClassTemplateDecl(97)
+// CHECK-NEXT: TemplateTypeParmDecl
+// CHECK-NEXT: QualType
+// CHECK-NEXT: CXXRecordDecl
 template <class T> class C {
-  // CHECK-NEXT: FieldDecl(68)
+  // CHECK-NEXT: FieldDecl
+  // CHECK-NEXT: TypeLoc
   T t;
 };
 
-// CHECK-NEXT: CXXRecordDecl(69)
-// CHECK-NEXT: TemplateName(70)
-// CHECK-NEXT: TemplateArgument(71)
+// CHECK-NEXT: CXXRecordDecl
+// CHECK-NEXT: TypeLoc
+// CHECK-NEXT: TemplateName
+// CHECK-NEXT: TemplateArgument
 class I : C<int> {};
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===================================================================
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -179,6 +179,7 @@
 static bool isSpecializedNodeExcluded(const TemplateArgumentLoc *S) {
   return false;
 }
+static bool isNodeExcluded(ASTUnit &AST, QualType QT) { return false; }
 
 static bool isNodeExcluded(ASTUnit &AST, TemplateName *Template) {
   return false;
@@ -266,7 +267,20 @@
     PostTraverse(SavedState);
     return true;
   }
-  bool TraverseType(QualType T) { return true; }
+  bool TraverseTypeLoc(TypeLoc TL) {
+    auto SavedState = PreTraverse(TL);
+    BaseType::TraverseTypeLoc(TL);
+    PostTraverse(SavedState);
+    return true;
+  }
+  bool TraverseType(QualType QT) {
+    if (isNodeExcluded(Tree.AST, QT))
+      return true;
+    auto SavedState = PreTraverse(QT);
+    BaseType::TraverseType(QT);
+    PostTraverse(SavedState);
+    return true;
+  }
   bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
     if (isNodeExcluded(Tree.AST, Init))
       return true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to