Johannes Altmanninger | d196930 | 2017-08-20 12:09:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -E %s > %t.src.cpp |
| 2 | // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST |
Jacob Gravelle | 46307d7 | 2017-08-22 17:42:44 +0000 | [diff] [blame] | 3 | // RUN: clang-diff -dump-matches -stop-diff-after=topdown %t.src.cpp %t.dst.cpp -- -std=c++11 | FileCheck %s |
Johannes Altmanninger | d196930 | 2017-08-20 12:09:07 +0000 | [diff] [blame] | 4 | // |
| 5 | // Test the top-down matching of identical subtrees only. |
| 6 | |
| 7 | #ifndef DEST |
| 8 | |
| 9 | void 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 Altmanninger | 2b955ff | 2017-08-22 08:56:26 +0000 | [diff] [blame] | 30 | int x; |
| 31 | |
| 32 | namespace src { |
| 33 | int x; |
| 34 | int x1 = x + 1; |
| 35 | int x2 = ::x + 1; |
| 36 | } |
| 37 | |
| 38 | class A { int x = 1 + 1; void f() { int x1 = x; } }; |
| 39 | |
Johannes Altmanninger | d196930 | 2017-08-20 12:09:07 +0000 | [diff] [blame] | 40 | #else |
| 41 | |
Johannes Altmanninger | 2b955ff | 2017-08-22 08:56:26 +0000 | [diff] [blame] | 42 | |
Johannes Altmanninger | d196930 | 2017-08-20 12:09:07 +0000 | [diff] [blame] | 43 | void 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 Altmanninger | 2b955ff | 2017-08-22 08:56:26 +0000 | [diff] [blame] | 59 | int x; |
| 60 | |
| 61 | namespace 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 | |
| 69 | class 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 Altmanninger | d196930 | 2017-08-20 12:09:07 +0000 | [diff] [blame] | 83 | #endif |