File: extract-capture-this.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (66 lines) | stat: -rw-r--r-- 2,894 bytes parent folder | download
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

class AClassWithMethods {
  void method() {
  }
  void constMethod() const {
  }
  int operator << (int x) const { return x; }
  int operator >> (int x) { return x; }

  void toBeExtracted() {
    method();
    constMethod();
    *this << 2;
    *(this) >> 2;
    this->constMethod();
    (*(this)).constMethod();
  }
// CHECK1: (AClassWithMethods &object) {\nobject.method();\n}
// CHECK1: (const AClassWithMethods &object) {\nobject.constMethod();\n}
// CHECK1: (AClassWithMethods &object) {\nobject.method();\n    object.constMethod();\n}
// CHECK1: (const AClassWithMethods &object) {\nreturn object << 2;\n}
// CHECK1: (AClassWithMethods &object) {\nreturn (object) >> 2;\n}
// CHECK1: (const AClassWithMethods &object) {\nobject.constMethod();\n}
// CHECK1: (const AClassWithMethods &object) {\n((object)).constMethod();\n}

  void toBeExtracted2();
};
// RUN: clang-refactor-test perform -action extract -selected=%s:11:5-11:13 -selected=%s:12:5-12:17 -selected=%s:11:5-12:17 -selected=%s:13:5-13:14 -selected=%s:14:5-14:16 -selected=%s:15:5-15:24 -selected=%s:16:5-16:28 %s | FileCheck --check-prefix=CHECK1 %s

void takesRef(AClassWithMethods &object) {}
void takesConstRef(const AClassWithMethods &object) {}
void takesPtr(AClassWithMethods *object) {}
void takesConstPtr(const AClassWithMethods *object) {}

void AClassWithMethods::toBeExtracted2() {
  takesRef(*this);
  takesConstRef((*(this)));
  takesPtr(this);
  takesConstPtr((this));
  takesConstPtr(false ? this : (AClassWithMethods*)0);
}
// CHECK2: (AClassWithMethods &object) {\ntakesRef(object);\n}
// CHECK2: (const AClassWithMethods &object) {\ntakesConstRef(((object)));\n}
// CHECK2: (AClassWithMethods &object) {\ntakesPtr(&object);\n}
// CHECK2: (const AClassWithMethods &object) {\ntakesConstPtr((&object));\n}
// CHECK2: (AClassWithMethods &object) {\ntakesConstPtr(false ? &object : (AClassWithMethods*)0);\n}

// RUN: clang-refactor-test perform -action extract -selected=%s:36:3-36:18 -selected=%s:37:3-37:27 -selected=%s:38:3-38:17 -selected=%s:39:3-39:24 -selected=%s:40:3-40:54 %s | FileCheck --check-prefix=CHECK2 %s

#ifdef USECONST
#define CONST const
#else
#define CONST
#endif

class FallbackToMethodConstness {
  int getter() const { return 0; }
  int method(int x, FallbackToMethodConstness *other) CONST {
    return (x == 0 ? this : other)->getter();
  }
// CHECK3: (FallbackToMethodConstness &object, FallbackToMethodConstness *other, int x) {\nreturn (x == 0 ? &object : other)->getter();\n}
// CHECK3-CONST: (const FallbackToMethodConstness &object, FallbackToMethodConstness *other, int x) {\nreturn (x == 0 ? &object : other)->getter();\n}
}

// RUN: clang-refactor-test perform -action extract -selected=%s:59:5-59:45 %s | FileCheck --check-prefix=CHECK3 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:59:5-59:45 %s -DUSECONST | FileCheck --check-prefix=CHECK3-CONST %s