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