Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / objc / execute / bf-common.h
blob6cf7a0696b6e405d42d4b4082553e1514b07bc1c
1 #ifndef __NEXT_RUNTIME__
2 #include <objc/encoding.h>
3 #endif
4 #include "next_mapping.h"
6 void print_ivars (Class class)
8 struct objc_ivar_list* ivars = class->ivars;
9 int i;
11 for (i = 0; i < ivars->ivar_count; i++) {
12 struct objc_ivar *ivar = &(ivars->ivar_list[i]);
13 printf ("ivar '%s', type '%s', offset %d\n",
14 ivar->ivar_name, ivar->ivar_type, ivar->ivar_offset);
18 void compare_structures (Class class, const char* type)
20 struct objc_struct_layout layout;
21 struct objc_ivar_list* ivars = class->ivars;
22 int i = 0;
23 int position;
25 objc_layout_structure (type, &layout);
27 while (objc_layout_structure_next_member (&layout))
29 struct objc_ivar *ivar;
30 const char *ivar_type;
32 if (i > ivars->ivar_count)
34 printf ("too many ivars in type %s, layout = %s\n",
35 type, layout.type);
36 exit (1);
39 ivar = &(ivars->ivar_list[i]);
40 objc_layout_structure_get_info (&layout, &position, NULL, &ivar_type);
41 printf ("real ivar '%s' offset %d\n",
42 ivar->ivar_name, ivar->ivar_offset);
43 printf ("computed type '%s' offset %d\n", ivar_type, position);
44 if (position != ivar->ivar_offset)
46 printf ("offset %d and computed position %d don't match on ivar '%s'"
47 " (i = %d)\n",
48 ivar->ivar_offset, position, ivar->ivar_name, i);
49 exit (1);
51 i++;
54 printf ("%d ivars checked\n", i);
57 int main ()
59 struct class_vars
61 @defs (MyObject);
63 int size1, size2;
64 Class class = objc_get_class ("MyObject");
66 printf ("type = %s\n", @encode (struct class_vars));
67 print_ivars (class);
69 compare_structures (class, @encode(struct class_vars));
70 if ((size1 = objc_sizeof_type (@encode(struct class_vars)))
71 != (size2 = sizeof (struct class_vars)))
73 printf ("sizes don't match (computed %d, exact %d)\n", size1, size2);
74 abort ();
77 exit (0);