Clang Project

clang_source_code/test/Tooling/clang-diff-opt.cpp
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 -s=10 %t.src.cpp %t.dst.cpp -- | FileCheck %s
4//
5// Test the behaviour of the matching according to the optimal tree edit
6// distance, implemented with Zhang and Shasha's algorithm.
7// Just for testing we use a tiny value of 10 for maxsize. Subtrees bigger than
8// this size will not be processed by the optimal algorithm.
9
10#ifndef DEST
11
12void f1() { {;} {{;}} }
13
14void f2() { {;} {{;;;;;}} }
15
16void f3() { {;} {{;;;;;;}} }
17
18#else
19
20void f1() {
21// Jaccard similarity = 3 / (5 + 4 - 3) = 3 / 6 >= 0.5
22// The optimal matching algorithm should move the ; into the outer block
23// CHECK: Match CompoundStmt(2) to CompoundStmt(2)
24// CHECK-NOT: Match CompoundStmt(3)
25// CHECK-NEXT: Match NullStmt(4) to NullStmt(3)
26  ; {{;}}
27}
28
29void f2() {
30  // Jaccard similarity = 7 / (10 + 10 - 7) >= 0.5
31  // As none of the subtrees is bigger than 10 nodes, the optimal algorithm
32  // will be run.
33  // CHECK: Match NullStmt(11) to NullStmt(9)
34  ;; {{;;;;;}}
35}
36
37void f3() {
38  // Jaccard similarity = 8 / (11 + 11 - 8) >= 0.5
39  // As the subtrees are bigger than 10 nodes, the optimal algorithm will not
40  // be run.
41  // CHECK: Delete NullStmt(22)
42  ;; {{;;;;;;}}
43}
44 
45#endif
46