summaryrefslogtreecommitdiffstats
path: root/test/CodeGenObjC/dot-syntax.m
blob: 5a40fd8726d2c2bc34d11789935cbe83f1f4ce43 (plain)
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
// RUN: clang -cc1 -emit-llvm -o %t %s

int printf(const char *, ...);

@interface Root
-(id) alloc;
-(id) init;
@end

typedef struct {
  float x, y, z[2];
} S;

@interface A : Root {
  int myX;
  //  __complex myY;
  S myZ;
}

@property int x;
//@property __complex int y;
@property S z;
@end

@implementation A
-(int) x {
  printf("-[A x] = %d\n", myX);
  return myX;
}
-(void) setX: (int) arg {
  myX = arg;
  printf("-[A setX: %d]\n", myX);
}

// FIXME: Add back
#if 0
-(__complex int) y {
  printf("-[A y] = (%d, %d)\n", __real myY, __imag myY);
  return myY;
}
-(void) setY: (__complex int) arg {
  myY = arg;
  printf("-[A setY: (%d, %d)]\n", __real myY, __imag myY);
}
#endif

-(S) z {
  printf("-[A z] = { %f, %f, { %f, %f } }\n", 
         myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
  return myZ;
}
-(void) setZ: (S) arg {
  myZ = arg;
  printf("-[A setZ: { %f, %f, { %f, %f } } ]\n", 
         myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
}

@end

int main() {
#define SWAP(T,a,b) { T a_tmp = a; a = b; b = a_tmp; }
  A *a = [[A alloc] init];
  A *b = [[A alloc] init];
  int a0 = 23;
  //  __complex a1 = 25 + 10i;
  S a2 =  { 246, 458, {275, 12} };
  int b0 = 42673;
  //  __complex b1 = 15 + 13i;
  S b2 =  { 26, 2, {367, 13} };

  a.x = a0;
  //  a.y = a1;
  a.z = a2;

  a.x += a0;
  //  a.y += a1;
  // Yay, no compound assign of structures. A GCC extension in the
  // works, perhaps?

  b.x = b0;
  //  b.y = b1;
  b.z = b2;

  int x0 = (b.x = b0);
  printf("(b.x = b0): %d\n", x0);

  //  int x1 = __real (b.y = b1);
  //  printf("__real (b.y = b1) = %d\n", x1);

  float x2 = (b.z = b2).x;
  printf("(b.z = b2).x: %f\n", x2);

  SWAP(int, a.x, b.x);
  //  SWAP(__complex int, a.y, b.y);
  SWAP(S, a.z, b.z);

  return 0;
}