File: clang-diff-topdown.cpp

package info (click to toggle)
llvm-toolchain-6.0 1%3A6.0.1-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 598,080 kB
  • sloc: cpp: 3,046,253; ansic: 595,057; asm: 271,965; python: 128,926; objc: 106,554; sh: 21,906; lisp: 10,191; pascal: 6,094; ml: 5,544; perl: 5,265; makefile: 2,227; cs: 2,027; xml: 686; php: 212; csh: 117
file content (83 lines) | stat: -rw-r--r-- 1,853 bytes parent folder | download | duplicates (28)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// RUN: %clang_cc1 -E %s > %t.src.cpp
// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
// RUN: clang-diff -dump-matches -stop-diff-after=topdown %t.src.cpp %t.dst.cpp -- -std=c++11 | FileCheck %s
//
// Test the top-down matching of identical subtrees only.

#ifndef DEST

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)
  {{;}}

  // Don't match subtrees that are smaller.
  // CHECK-NOT: Match CompoundStmt(6)
  // CHECK-NOT: Match NullStmt(7)
  {;}

  // 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)
  {{;;}}
}

int x;

namespace src {
  int x;
  int x1 = x + 1;
  int x2 = ::x + 1;
}

class A { int x = 1 + 1; void f() { int x1 = x; } };

#else


void f1() {

  {{;}}

  {;}

  {{;;}}
  // CHECK-NOT: Match {{.*}} to CompoundStmt(11)
  // CHECK-NOT: Match {{.*}} to CompoundStmt(12)
  // CHECK-NOT: Match {{.*}} to NullStmt(13)
  {{;;}}

  // CHECK-NOT: Match {{.*}} to NullStmt(14)
  ;
}

int x;

namespace dst {
  int x;
  // CHECK: Match DeclRefExpr: :x(17) to DeclRefExpr: :x(22)
  int x1 = x + 1;
  // CHECK: Match DeclRefExpr: x(21) to DeclRefExpr: x(26)
  int x2 = ::x + 1;
}

class B {
  // Only the class name changed; it is not included in the field value,
  // therefore there is no update.
  // CHECK: Match FieldDecl: :x(int)(24) to FieldDecl: :x(int)(29)
  // CHECK-NOT: Update FieldDecl: :x(int)(24)
  int x = 1+1;
  void f() {
    // CHECK: Match MemberExpr: :x(32) to MemberExpr: :x(37)
    // CHECK-NOT: Update MemberExpr: :x(32)
    int x1 = B::x;
  }

};

#endif