Debian Codegraph @

gcc/testsuite/objc/execute/bf-common.h

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "../../objc-obj-c++-shared/runtime.h"
5
6 /* The following header, together with the implementation included below,
7 emulate functionality provided by the GNU runtime but not available from
8 the NeXT runtime. */
9 #include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist.h"
10
11 #if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE)
12 void print_ivars (Class class)
13 {
14 struct objc_ivar_list* ivars = class->ivars;
15 int i;
16
17 for (i = 0; i < ivars->ivar_count; i++) {
18 struct objc_ivar *ivar = &(ivars->ivar_list[i]);
19 printf ("ivar '%s', type '%s', offset %d\n",
20 ivar->ivar_name, ivar->ivar_type, ivar->ivar_offset);
21 }
22 }
23
24 void compare_structures (Class class, const char* type)
25 {
26 struct objc_struct_layout layout;
27 struct objc_ivar_list* ivars = class->ivars;
28 int i = 0;
29 int position;
30
31 objc_layout_structure (type, &layout);
32
33 while (objc_layout_structure_next_member (&layout))
34 {
35 struct objc_ivar *ivar;
36 const char *ivar_type;
37
38 if (i > ivars->ivar_count)
39 {
40 printf ("too many ivars in type %s, layout = %s\n",
41 type, layout.type);
42 exit (1);
43 }
44
45 ivar = &(ivars->ivar_list[i]);
46 objc_layout_structure_get_info (&layout, &position, NULL, &ivar_type);
47 printf ("real ivar '%s' offset %d\n",
48 ivar->ivar_name, ivar->ivar_offset);
49 printf ("computed type '%s' offset %d\n", ivar_type, position);
50 if (position != ivar->ivar_offset)
51 {
52 printf ("offset %d and computed position %d don't match on ivar '%s'"
53 " (i = %d)\n",
54 ivar->ivar_offset, position, ivar->ivar_name, i);
55 exit (1);
56 }
57 i++;
58 }
59
60 printf ("%d ivars checked\n", i);
61 }
62 #else
63 void print_ivars (Class class)
64 {
65 unsigned int count, i;
66 Ivar *list = class_copyIvarList (class, &count);
67
68 for (i = 0; i < count; i++) {
69 printf ("ivar '%s', type '%s', offset %ud\n",
70 ivar_getName (list[i]),
71 ivar_getTypeEncoding (list[i]),
72 (unsigned int)ivar_getOffset (list[i]));
73 }
74 }
75
76 void compare_structures (Class class, const char* type)
77 {
78 struct objc_struct_layout layout;
79 unsigned int count;
80 Ivar *list = class_copyIvarList (class, &count);
81 int i = 0;
82 int position;
83
84 objc_layout_structure (type, &layout);
85
86 while (objc_layout_structure_next_member (&layout))
87 {
88 const char *ivar_type;
89
90 if (i > count)
91 {
92 printf ("too many ivars in type %s, layout = %s\n",
93 type, layout.type);
94 exit (1);
95 }
96
97 objc_layout_structure_get_info (&layout, &position, NULL, &ivar_type);
98 printf ("real ivar '%s' offset %ud\n",
99 ivar_getName (list[i]), (unsigned int)ivar_getOffset (list[i]));
100 printf ("computed type '%s' offset %d\n", ivar_type, position);
101 if ((unsigned int)position != (unsigned int)ivar_getOffset (list[i]))
102 {
103 printf ("offset %ud and computed position %d don't match on ivar '%s'"
104 " (i = %d)\n",
105 (unsigned int)ivar_getOffset (list[i]), position, ivar_getName (list[i]), i);
106 exit (1);
107 }
108 i++;
109 }
110
111 printf ("%d ivars checked\n", i);
112 }
113 #endif
114
115 int main ()
116 {
117 struct class_vars
118 {
119 @defs (MyObject);
120 };
121 int size1, size2;
122 Class class = objc_getClass ("MyObject");
123 printf ("type = %s\n", @encode (struct class_vars));
124 print_ivars (class);
125
126 compare_structures (class, @encode(struct class_vars));
127 if ((size1 = objc_sizeof_type (@encode(struct class_vars)))
128 != (size2 = sizeof (struct class_vars)))
129 {
130 printf ("sizes don't match (computed %d, exact %d)\n", size1, size2);
131 abort ();
132 }
133
134 return 0;
135 }
136 #include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h"