diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/objc/execute/bf-common.h | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/objc/execute/bf-common.h')
-rw-r--r-- | gcc/testsuite/objc/execute/bf-common.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/gcc/testsuite/objc/execute/bf-common.h b/gcc/testsuite/objc/execute/bf-common.h new file mode 100644 index 000000000..ca70c21a4 --- /dev/null +++ b/gcc/testsuite/objc/execute/bf-common.h @@ -0,0 +1,92 @@ +#include <stdio.h> +#include <stdlib.h> + +#ifndef __NEXT_RUNTIME__ +#include <objc/encoding.h> +#else +/* The following header, together with the implementation included below, + emulate functionality provided by the GNU runtime but not available from + the NeXT runtime. */ +#include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist.h" +#define objc_get_class(C) objc_getClass(C) +#endif + +#ifndef __OBJC2__ +void print_ivars (Class class) +{ + struct objc_ivar_list* ivars = class->ivars; + int i; + + for (i = 0; i < ivars->ivar_count; i++) { + struct objc_ivar *ivar = &(ivars->ivar_list[i]); + printf ("ivar '%s', type '%s', offset %d\n", + ivar->ivar_name, ivar->ivar_type, ivar->ivar_offset); + } +} + +void compare_structures (Class class, const char* type) +{ + struct objc_struct_layout layout; + struct objc_ivar_list* ivars = class->ivars; + int i = 0; + int position; + + objc_layout_structure (type, &layout); + + while (objc_layout_structure_next_member (&layout)) + { + struct objc_ivar *ivar; + const char *ivar_type; + + if (i > ivars->ivar_count) + { + printf ("too many ivars in type %s, layout = %s\n", + type, layout.type); + exit (1); + } + + ivar = &(ivars->ivar_list[i]); + objc_layout_structure_get_info (&layout, &position, NULL, &ivar_type); + printf ("real ivar '%s' offset %d\n", + ivar->ivar_name, ivar->ivar_offset); + printf ("computed type '%s' offset %d\n", ivar_type, position); + if (position != ivar->ivar_offset) + { + printf ("offset %d and computed position %d don't match on ivar '%s'" + " (i = %d)\n", + ivar->ivar_offset, position, ivar->ivar_name, i); + exit (1); + } + i++; + } + + printf ("%d ivars checked\n", i); +} +#endif + +int main () +{ +#ifndef __OBJC2__ + struct class_vars + { + @defs (MyObject); + }; + int size1, size2; + Class class = objc_get_class ("MyObject"); + printf ("type = %s\n", @encode (struct class_vars)); + print_ivars (class); + + compare_structures (class, @encode(struct class_vars)); + if ((size1 = objc_sizeof_type (@encode(struct class_vars))) + != (size2 = sizeof (struct class_vars))) + { + printf ("sizes don't match (computed %d, exact %d)\n", size1, size2); + abort (); + } +#endif + + exit (0); +} +#ifndef __OBJC2__ +#include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h" +#endif |