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