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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
typedef struct {
int width, height;
} Rectangle;
#ifdef ADD
#define MUT(x, y) x += y
#endif
#ifdef MUL
#define MUT(x, y) x *= y
#endif
#ifdef BIT
#define MUT(x, y) x |= y
#endif
#ifdef SHIFT
#define MUT(x, y) x >>= y
#endif
#ifdef INC1
#define MUT(x, y) ++x
#endif
#ifdef INC2
#define MUT(x, y) x++
#endif
#ifdef DEC1
#define MUT(x, y) --x
#endif
#ifdef DEC2
#define MUT(x, y) x--
#endif
#ifndef MUT
#define MUT(x, y) x = y
#endif
#ifdef FIELD
class MutatePrivateInstanceVariables {
int x;
int y;
Rectangle r;
#endif
void mutateVariableOrField
#ifndef FIELD
(int x, int y, Rectangle r)
#else
()
#endif
{
(MUT(x, 1));
// CHECK1: (int &x) {\nreturn (MUT(x, 1));\n}
(MUT((x), 1));
// CHECK1: (int &x) {\nreturn (MUT((x), 1));\n}
(MUT(r.width, 1));
// CHECK1: (Rectangle &r) {\nreturn (MUT(r.width, 1));\n}
(MUT((x, r.height), 1));
// CHECK1: (Rectangle &r, int x) {\nreturn (MUT((x, r.height), 1));\n}
(MUT((x == 0 ? x : y), 1));
// CHECK1: (int &x, int &y) {\nreturn (MUT((x == 0 ? x : y), 1));\n}
Rectangle a, b;
(x == 0 ? (r) : b) = a;
// CHECK2: (const Rectangle &a, Rectangle &b, Rectangle &r, int x) {\nreturn (x == 0 ? (r) : b) = a;\n}
}
#ifdef FIELD
};
#endif
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DFIELD | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:73:3-73:25 %s | FileCheck --check-prefix=CHECK2 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:73:3-73:25 %s -DFIELD | FileCheck --check-prefix=CHECK2 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DADD | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DMUL -DFIELD | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DBIT | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DSHIFT -DFIELD | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DINC1 | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DINC2 -DFIELD | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DDEC1 | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:57:3-57:14 -selected=%s:60:3-60:16 -selected=%s:63:3-63:20 -selected=%s:66:3-66:26 -selected=%s:69:3-69:29 %s -DDEC2 -DFIELD | FileCheck --check-prefix=CHECK1 %s
void dontMutateVariable(int *array, int x) {
array[x] = 0;
// CHECK3: (int *array, int x) {\narray[x] = 0;\n}
*array = 0;
// CHECK3: (int *array) {\n*array = 0;\n}
array = 0;
// CHECK3: extracted(int *&array) {\narray = 0;\n}
}
// RUN: clang-refactor-test perform -action extract -selected=%s:101:3-101:15 -selected=%s:103:3-103:13 -selected=%s:105:3-105:12 %s | FileCheck --check-prefix=CHECK3 %s
#ifdef __cplusplus
int &returnsRef(int x) {
static int result = 0;
return result;
}
void dontMutateCallArguments(int x) {
returnsRef(x) = 0;
// CHECK4: extracted(int x) {\nreturnsRef(x) = 0;\n}
}
void mutateRefVar(int &x) {
x = 0;
// CHECK4: extracted(int &x) {\nx = 0;\n}
}
// RUN: clang-refactor-test perform -action extract -selected=%s:119:3-119:20 -selected=%s:124:3-124:8 %s | FileCheck --check-prefix=CHECK4 %s
#endif
|