OSDN Git Service

PR testsuite/23611, PR testsuite/23615
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / obj-c++.dg / encode-6.mm
1 /* Encoding tests for ObjC class layouts.  */
2 /* Contributed by Ziemowit Laski <zlaski@apple.com>.  */
3 /* { dg-options "-lobjc" } */
4 /* { dg-do run } */
5
6 #include <objc/Object.h>
7 #ifdef __NEXT_RUNTIME__
8 #include <objc/objc-class.h>
9 #define OBJC_GETCLASS objc_getClass
10 #else
11 #include <objc/objc-api.h>
12 #define OBJC_GETCLASS objc_get_class
13 #endif
14
15 #include <stdlib.h>
16 #include <string.h>
17
18 #define CHECK_IF(expr) if(!(expr)) abort()
19
20 @class Int1, Int2;
21 struct Nested;
22
23 struct Innermost {
24   unsigned char a, b;
25   struct Nested *encl;
26 };
27
28 struct Nested {
29   float a, b;
30   Int1 *next;
31   struct Innermost innermost;
32 };
33
34 @interface Int1: Object {
35   signed char a, b;
36   Int2 *int2;
37   struct Nested nested;
38 }
39 @end
40
41 @interface Int2: Int1 {
42   struct Innermost *innermost;
43   Int1 *base;
44 }
45 @end
46
47 @implementation Int1
48 @end
49
50 @implementation Int2
51 @end
52
53 struct objc_ivar *ivar;
54
55 static void check_ivar(const char *name, const char *type) {
56   CHECK_IF(!strcmp(ivar->ivar_name, name));
57   CHECK_IF(!strcmp(ivar->ivar_type, type));
58   ivar++;
59 }
60
61 int main(void) {
62   ivar = ((Class)OBJC_GETCLASS("Int1"))->ivars->ivar_list;
63   check_ivar("a", "c");
64   check_ivar("b", "c");
65   check_ivar("int2", "@\"Int2\"");
66   check_ivar("nested", 
67     "{Nested=\"a\"f\"b\"f\"next\"@\"Int1\"\"innermost\"{Innermost=\"a\"C\"b\"C\"encl\"^{Nested}}}");
68     
69   ivar = ((Class)OBJC_GETCLASS("Int2"))->ivars->ivar_list;
70   check_ivar("innermost", "^{Innermost=CC^{Nested}}");
71   check_ivar("base", "@\"Int1\"");
72   
73   return 0;
74 }