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