1 // RUN: %clang_cc1 -E %s > %t.src.cpp
2 // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
3 // RUN: clang-diff %t.src.cpp %t.dst.cpp -- | FileCheck %s
4 
5 #ifndef DEST
6 namespace src {
7 
8 void foo() {
9   int x = 321;
10 }
11 
12 void main() { foo(); };
13 
14 const char *a = "foo";
15 
16 typedef unsigned int nat;
17 
18 int p = 1 * 2 * 3 * 4;
19 int squared = p * p;
20 
21 class X {
22   const char *foo(int i) {
23     if (i == 0)
24       return "foo";
25     return 0;
26   }
27 
28 public:
29   X(){};
30 
31   int id(int i) { return i; }
32 };
33 }
34 
35 void m() { int x = 0 + 0 + 0; }
36 int um = 1 + 2 + 3;
37 
38 #else
39 // CHECK: Match TranslationUnitDecl{{.*}} to TranslationUnitDecl
40 // CHECK: Match NamespaceDecl: src{{.*}} to NamespaceDecl: dst
41 namespace dst {
42 // CHECK-NOT: Match NamespaceDecl: src{{.*}} to NamespaceDecl: inner
43 namespace inner {
44 void foo() {
45   // CHECK: Match IntegerLiteral: 321{{.*}} to IntegerLiteral: 322
46   int x = 322;
47 }
48 }
49 
50 // CHECK: Match DeclRefExpr: foo{{.*}} to DeclRefExpr: inner::foo
51 void main() { inner::foo(); }
52 
53 // CHECK: Match StringLiteral: foo{{.*}} to StringLiteral: foo
54 const char *b = "f" "o" "o";
55 
56 // unsigned is canonicalized to unsigned int
57 // CHECK: Match TypedefDecl: nat;unsigned int;{{.*}} to TypedefDecl: nat;unsigned int;
58 typedef unsigned nat;
59 
60 // CHECK: Match VarDecl: p(int){{.*}} to VarDecl: prod(double)
61 // CHECK: Update VarDecl: p(int){{.*}} to prod(double)
62 // CHECK: Match BinaryOperator: *{{.*}} to BinaryOperator: *
63 double prod = 1 * 2 * 10;
64 // CHECK: Update DeclRefExpr
65 int squared = prod * prod;
66 
67 class X {
68   const char *foo(int i) {
69     if (i == 0)
70       return "Bar";
71     // CHECK: Insert IfStmt{{.*}} into IfStmt
72     // CHECK: Insert BinaryOperator: =={{.*}} into IfStmt
73     else if (i == -1)
74       return "foo";
75     return 0;
76   }
77   X(){}
78 };
79 }
80 
81 // CHECK: Move DeclStmt{{.*}} into CompoundStmt
82 void m() { { int x = 0 + 0 + 0; } }
83 // CHECK: Update and Move IntegerLiteral: 7{{.*}} into BinaryOperator: +({{.*}}) at 1
84 int um = 1 + 7;
85 #endif
86 
87 // CHECK: Delete AccessSpecDecl: public
88 // CHECK: Delete CXXMethodDecl
89