File: extract-capture-used-after-extraction.m

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (25 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download | duplicates (2)
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
void takesInt(int);
void passByPointer() {
  int x = 1;
  int y = 0, z = 2;
  takesInt(x);
  z = 2;
  x, z;
}
// CHECK1: "static void extracted(int *x, int *z) {\n*x = 1;\n  int y = 0; *z = 2;\n  takesInt(*x);\n  *z = 2;\n}\n\n"
// CHECK1-NEXT: "int x;\nint z;\nextracted(&x, &z)"
// RUN: clang-refactor-test perform -action extract -selected=%s:3:3-6:8 %s | FileCheck --check-prefix=CHECK1 %s

typedef struct { int width; int height; } Rectangle;

void handleStructInit() {
  Rectangle a = { 5, 6 };
  Rectangle b = { 1, 2 }, c = { 3, 4 };
  takesInt(a.width);
  c.height = 10;
  a, c;
}
// The produced code is invalid but we can let the user deal with it:
// CHECK2: "static void extracted(Rectangle *a, Rectangle *c) {\n*a = { 5, 6 };\n  Rectangle b = { 1, 2 }; *c = { 3, 4 };\n  takesInt(a->width);\n  c->height = 10;\n}\n\n" 15:1 -> 15:1
// CHECK2: "Rectangle a;\nRectangle c;\nextracted(&a, &c)"
// RUN: clang-refactor-test perform -action extract -selected=%s:16:3-19:16 %s | FileCheck --check-prefix=CHECK2 %s