Clean up some minor white space issues in trans-decl.c and trans-expr.c
[official-gcc.git] / gcc / testsuite / objc / execute / bf-common.h
blob43b0d32b7d6a9509a6928af48955282e7367e0b4
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "../../objc-obj-c++-shared/runtime.h"
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"
11 #if defined(__NEXT_RUNTIME__) && !defined(NEXT_OBJC_USE_NEW_INTERFACE)
12 void print_ivars (Class class)
14 struct objc_ivar_list* ivars = class->ivars;
15 int i;
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);
24 void compare_structures (Class class, const char* type)
26 struct objc_struct_layout layout;
27 struct objc_ivar_list* ivars = class->ivars;
28 int i = 0;
29 int position;
31 objc_layout_structure (type, &layout);
33 while (objc_layout_structure_next_member (&layout))
35 struct objc_ivar *ivar;
36 const char *ivar_type;
38 if (i > ivars->ivar_count)
40 printf ("too many ivars in type %s, layout = %s\n",
41 type, layout.type);
42 exit (1);
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)
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);
57 i++;
60 printf ("%d ivars checked\n", i);
62 #else
63 void print_ivars (Class class)
65 unsigned int count, i;
66 Ivar *list = class_copyIvarList (class, &count);
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]));
76 void compare_structures (Class class, const char* type)
78 struct objc_struct_layout layout;
79 unsigned int count;
80 Ivar *list = class_copyIvarList (class, &count);
81 int i = 0;
82 int position;
84 objc_layout_structure (type, &layout);
86 while (objc_layout_structure_next_member (&layout))
88 const char *ivar_type;
90 if (i > count)
92 printf ("too many ivars in type %s, layout = %s\n",
93 type, layout.type);
94 exit (1);
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]))
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);
108 i++;
111 printf ("%d ivars checked\n", i);
113 #endif
115 int main ()
117 struct class_vars
119 @defs (MyObject);
121 int size1, size2;
122 Class class = objc_getClass ("MyObject");
123 printf ("type = %s\n", @encode (struct class_vars));
124 print_ivars (class);
126 compare_structures (class, @encode(struct class_vars));
127 if ((size1 = objc_sizeof_type (@encode(struct class_vars)))
128 != (size2 = sizeof (struct class_vars)))
130 printf ("sizes don't match (computed %d, exact %d)\n", size1, size2);
131 abort ();
134 return 0;
136 #include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h"