blob: 4d8c40099801cf4fda14ad7938e45f1f6cd5af46 [file] [log] [blame]
struct AClass {
void constMethod() const;
void method();
};
struct AWrapper {
const AClass &object(int x) const;
AClass &object(int x);
};
void takesClass(AWrapper &ref) {
int x = 0;
ref.object(x).constMethod();
int y = 0;
ref.object(x).method();
}
// CHECK1: "AClass &object = ref.object(x);\nobject" [[@LINE-4]]:3 -> [[@LINE-4]]:16
// CHECK1-NEXT: "object" [[@LINE-4]]:3 -> [[@LINE-4]]:16
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:14:3 %s | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:16:3 %s | FileCheck --check-prefix=CHECK1 %s
void variableNameSuggested(AWrapper &object) {
#ifdef IN_COMPOUND
{
#endif
object.object(21).constMethod();
object.object(21).method();
#ifdef IN_COMPOUND
}
#endif
}
// CHECK2: "AClass &object = object.object(21);\nobject" [[@LINE-6]]:3 -> [[@LINE-6]]:20
// CHECK2-NEXT: "object" [[@LINE-7]]:3 -> [[@LINE-7]]:20
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:29:3 %s | FileCheck --check-prefix=CHECK2 %s
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:29:3 %s -D IN_COMPOUND | FileCheck --check-prefix=CHECK2 %s
void takesClass2(AWrapper &ref) {
int x = 0;
if (x)
ref.object(x).constMethod();
ref.object(x).method();
}
// CHECK3: "AClass &object = ref.object(x);\n" [[@LINE-4]]:3 -> [[@LINE-4]]:3
// CHECK3-NEXT: "object" [[@LINE-4]]:5 -> [[@LINE-4]]:18
// CHECK3-NEXT: "object" [[@LINE-4]]:3 -> [[@LINE-4]]:16
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:45:5 %s | FileCheck --check-prefix=CHECK3 %s
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:46:3 %s | FileCheck --check-prefix=CHECK3 %s
void takesClass4(AWrapper &ref) {
int x = 0;
if (x) {
ref.object(x).constMethod();
ref.object(x).method();
}
}
// CHECK4: "AClass &object = ref.object(x);\nobject" [[@LINE-4]]:5 -> [[@LINE-4]]:18
// CHECK4-NEXT: "object" [[@LINE-5]]:5 -> [[@LINE-5]]:18
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:58:5 %s | FileCheck --check-prefix=CHECK4 %s
void insertIntoCommonCompound1(AWrapper &ref) {
#ifdef EMBED
int x = 0;
while (true) {
#endif
int x = 0;
if (x) {
if (true) {
int y = x;
ref.object(x).constMethod();
}
} else {
ref.object(x).method();
}
// CHECK5: "AClass &object = ref.object(x);\n" [[@LINE-8]]:3 -> [[@LINE-8]]:3
// CHECK5-NEXT: "object" [[@LINE-6]]:7 -> [[@LINE-6]]:20
// CHECK5-NEXT: "object" [[@LINE-4]]:5 -> [[@LINE-4]]:18
#ifdef EMBED
}
#endif
}
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:77:7 %s | FileCheck --check-prefix=CHECK5 %s
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:80:5 %s -DEMBED | FileCheck --check-prefix=CHECK5 %s
void checkFirstStmtInCompoundPlacement(AWrapper &ref) {
while (true) {
ref.object(20);
ref.object(20).method();
// CHECK6: "AClass &object = ref.object(20);\nobject" [[@LINE-2]]:5 -> [[@LINE-2]]:19
}
}
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:94:5 %s | FileCheck --check-prefix=CHECK6 %s