Clang Project

clang_source_code/test/Tooling/clang-diff-basic.cpp
1// RUN: clang-diff -dump-matches %S/Inputs/clang-diff-basic-src.cpp %s -- | FileCheck %s
2
3// CHECK: Match TranslationUnitDecl{{.*}} to TranslationUnitDecl
4// CHECK: Match NamespaceDecl: src{{.*}} to NamespaceDecl: dst
5namespace dst {
6// CHECK-NOT: Match NamespaceDecl: src{{.*}} to NamespaceDecl: inner
7namespace inner {
8void foo() {
9  // CHECK: Match IntegerLiteral: 321{{.*}} to IntegerLiteral: 322
10  int x = 322;
11}
12}
13
14// CHECK: Match DeclRefExpr: :foo{{.*}} to DeclRefExpr: :inner::foo
15void main() { inner::foo(); }
16
17// CHECK: Match StringLiteral: foo{{.*}} to StringLiteral: foo
18const char *b = "f" "o" "o";
19
20// unsigned is canonicalized to unsigned int
21// CHECK: Match TypedefDecl: :nat;unsigned int;{{.*}} to TypedefDecl: :nat;unsigned int;
22typedef unsigned nat;
23
24// CHECK: Match VarDecl: :p(int){{.*}} to VarDecl: :prod(double)
25// CHECK: Update VarDecl: :p(int){{.*}} to :prod(double)
26// CHECK: Match BinaryOperator: *{{.*}} to BinaryOperator: *
27double prod = 1 * 2 * 10;
28// CHECK: Update DeclRefExpr
29int squared = prod * prod;
30
31class X {
32  const char *foo(int i) {
33    if (i == 0)
34      return "Bar";
35    // CHECK: Insert IfStmt{{.*}} into IfStmt
36    // CHECK: Insert BinaryOperator: =={{.*}} into IfStmt
37    else if (i == -1)
38      return "foo";
39    return 0;
40  }
41  X(){}
42};
43}
44
45// CHECK: Move CompoundStmt{{.*}} into CompoundStmt
46void m() { { int x = 0 + 0 + 0; } }
47// CHECK: Update and Move IntegerLiteral: 7{{.*}} into BinaryOperator: +({{.*}}) at 1
48int um = 1 + 7;
49
50namespace {
51// match with parents of different type
52// CHECK: Match FunctionDecl: f1{{.*}} to FunctionDecl: (anonymous namespace)::f1
53void f1() {{ (void) __func__;;; }}
54}
55
56// CHECK: Delete AccessSpecDecl: public
57// CHECK: Delete CXXMethodDecl
58