blob: d6c1d770333babd79711ddd42d7e81cefbbff1d3 [file] [log] [blame]
Johannes Altmanningerd1969302017-08-20 12:09:07 +00001// RUN: %clang_cc1 -E %s > %t.src.cpp
2// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
Jacob Gravelle46307d72017-08-22 17:42:44 +00003// RUN: clang-diff -dump-matches -stop-diff-after=topdown %t.src.cpp %t.dst.cpp -- -std=c++11 | FileCheck %s
Johannes Altmanningerd1969302017-08-20 12:09:07 +00004//
5// Test the top-down matching of identical subtrees only.
6
7#ifndef DEST
8
9void f1()
10{
11 // Match some subtree of height greater than 2.
12 // CHECK: Match CompoundStmt(3) to CompoundStmt(3)
13 // CHECK: Match CompoundStmt(4) to CompoundStmt(4)
14 // CHECK: Match NullStmt(5) to NullStmt(5)
15 {{;}}
16
17 // Don't match subtrees that are smaller.
18 // CHECK-NOT: Match CompoundStmt(6)
19 // CHECK-NOT: Match NullStmt(7)
20 {;}
21
22 // Greedy approach - use the first matching subtree when there are multiple
23 // identical subtrees.
24 // CHECK: Match CompoundStmt(8) to CompoundStmt(8)
25 // CHECK: Match CompoundStmt(9) to CompoundStmt(9)
26 // CHECK: Match NullStmt(10) to NullStmt(10)
27 {{;;}}
28}
29
Johannes Altmanninger2b955ff2017-08-22 08:56:26 +000030int x;
31
32namespace src {
33 int x;
34 int x1 = x + 1;
35 int x2 = ::x + 1;
36}
37
38class A { int x = 1 + 1; void f() { int x1 = x; } };
39
Johannes Altmanningerd1969302017-08-20 12:09:07 +000040#else
41
Johannes Altmanninger2b955ff2017-08-22 08:56:26 +000042
Johannes Altmanningerd1969302017-08-20 12:09:07 +000043void f1() {
44
45 {{;}}
46
47 {;}
48
49 {{;;}}
50 // CHECK-NOT: Match {{.*}} to CompoundStmt(11)
51 // CHECK-NOT: Match {{.*}} to CompoundStmt(12)
52 // CHECK-NOT: Match {{.*}} to NullStmt(13)
53 {{;;}}
54
55 // CHECK-NOT: Match {{.*}} to NullStmt(14)
56 ;
57}
58
Johannes Altmanninger2b955ff2017-08-22 08:56:26 +000059int x;
60
61namespace dst {
62 int x;
63 // CHECK: Match DeclRefExpr: :x(17) to DeclRefExpr: :x(22)
64 int x1 = x + 1;
65 // CHECK: Match DeclRefExpr: x(21) to DeclRefExpr: x(26)
66 int x2 = ::x + 1;
67}
68
69class B {
70 // Only the class name changed; it is not included in the field value,
71 // therefore there is no update.
72 // CHECK: Match FieldDecl: :x(int)(24) to FieldDecl: :x(int)(29)
73 // CHECK-NOT: Update FieldDecl: :x(int)(24)
74 int x = 1+1;
75 void f() {
76 // CHECK: Match MemberExpr: :x(32) to MemberExpr: :x(37)
77 // CHECK-NOT: Update MemberExpr: :x(32)
78 int x1 = B::x;
79 }
80
81};
82
Johannes Altmanningerd1969302017-08-20 12:09:07 +000083#endif