blob: 6282ea491f503eaafd957cebb7e52db3899694bc [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -emit-llvm -o %t %s
Daniel Dunbarb21d6af2008-09-04 04:36:23 +00002
Daniel Dunbar23afaad2009-11-17 08:57:36 +00003int printf(const char *, ...);
Daniel Dunbarb21d6af2008-09-04 04:36:23 +00004
5@interface Root
6-(id) alloc;
7-(id) init;
8@end
9
10typedef struct {
11 float x, y, z[2];
12} S;
13
14@interface A : Root {
15 int myX;
16 // __complex myY;
17 S myZ;
18}
19
20@property int x;
21//@property __complex int y;
22@property S z;
23@end
24
25@implementation A
26-(int) x {
27 printf("-[A x] = %d\n", myX);
28 return myX;
29}
30-(void) setX: (int) arg {
31 myX = arg;
32 printf("-[A setX: %d]\n", myX);
33}
34
35// FIXME: Add back
36#if 0
37-(__complex int) y {
38 printf("-[A y] = (%d, %d)\n", __real myY, __imag myY);
39 return myY;
40}
41-(void) setY: (__complex int) arg {
42 myY = arg;
43 printf("-[A setY: (%d, %d)]\n", __real myY, __imag myY);
44}
45#endif
46
47-(S) z {
48 printf("-[A z] = { %f, %f, { %f, %f } }\n",
49 myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
50 return myZ;
51}
52-(void) setZ: (S) arg {
53 myZ = arg;
54 printf("-[A setZ: { %f, %f, { %f, %f } } ]\n",
55 myZ.x, myZ.y, myZ.z[0], myZ.z[1]);
56}
57
58@end
59
60int main() {
61#define SWAP(T,a,b) { T a_tmp = a; a = b; b = a_tmp; }
62 A *a = [[A alloc] init];
63 A *b = [[A alloc] init];
64 int a0 = 23;
65 // __complex a1 = 25 + 10i;
66 S a2 = { 246, 458, {275, 12} };
67 int b0 = 42673;
68 // __complex b1 = 15 + 13i;
69 S b2 = { 26, 2, {367, 13} };
70
71 a.x = a0;
72 // a.y = a1;
73 a.z = a2;
74
75 a.x += a0;
76 // a.y += a1;
77 // Yay, no compound assign of structures. A GCC extension in the
78 // works, perhaps?
79
80 b.x = b0;
81 // b.y = b1;
82 b.z = b2;
83
84 int x0 = (b.x = b0);
85 printf("(b.x = b0): %d\n", x0);
86
87 // int x1 = __real (b.y = b1);
88 // printf("__real (b.y = b1) = %d\n", x1);
89
90 float x2 = (b.z = b2).x;
91 printf("(b.z = b2).x: %f\n", x2);
92
93 SWAP(int, a.x, b.x);
94 // SWAP(__complex int, a.y, b.y);
95 SWAP(S, a.z, b.z);
96
97 return 0;
98}