llvm-project
83 строки · 1.8 Кб
1// RUN: %clang_cc1 -E %s > %t.src.cpp
2// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
3// RUN: clang-diff -dump-matches -stop-diff-after=topdown %t.src.cpp %t.dst.cpp -- -std=c++11 | FileCheck %s
4//
5// Test the top-down matching of identical subtrees only.
6
7#ifndef DEST8
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 multiple23// 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
30int x;31
32namespace src {33int x;34int x1 = x + 1;35int x2 = ::x + 1;36}
37
38class A { int x = 1 + 1; void f() { int x1 = x; } };39
40#else41
42
43void 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
59int x;60
61namespace dst {62int x;63// CHECK: Match DeclRefExpr: :x(17) to DeclRefExpr: :x(22)64int x1 = x + 1;65// CHECK: Match DeclRefExpr: x(21) to DeclRefExpr: x(26)66int 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)74int x = 1+1;75void f() {76// CHECK: Match MemberExpr: :x(32) to MemberExpr: :x(37)77// CHECK-NOT: Update MemberExpr: :x(32)78int x1 = B::x;79}80
81};82
83#endif84