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/bycopy-3.m | |
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/bycopy-3.m')
-rw-r--r-- | gcc/testsuite/objc/execute/bycopy-3.m | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/gcc/testsuite/objc/execute/bycopy-3.m b/gcc/testsuite/objc/execute/bycopy-3.m new file mode 100644 index 000000000..15c49a5dd --- /dev/null +++ b/gcc/testsuite/objc/execute/bycopy-3.m @@ -0,0 +1,115 @@ +/* + * Contributed by Nicola Pero <nicola@brainstorm.co.uk> + * Wed Feb 28 12:27:03 CET 2001 + */ + +/* + * This test contains some no-op code which is needed to keep it + * compile on broken gcc 3.x. Anyway, the no-op code does not + * interfere with what we are testing, which is that the `bycopy' + * keyword generates the _F_BYCOPY qualifier for the return type. */ + +extern void exit (int) __attribute__ ((noreturn)); +extern int printf (const char *, ...); + +#include <objc/Protocol.h> + +#ifndef __NEXT_RUNTIME__ +#include <objc/encoding.h> +#endif + +@protocol MyProtocol ++ (bycopy id<MyProtocol>) bycopyMethod; +@end + +/* This no-op class to keep it compile under broken gcc 3.x */ +@interface MyObject : Object <MyProtocol> +#ifdef __OBJC2__ ++ (id) initialize; ++ (id) alloc; ++ new; +- init; +#endif +@end + +@implementation MyObject ++ (bycopy id<MyProtocol>) bycopyMethod +{ + return [MyObject alloc]; +} +#ifdef __OBJC2__ ++ initialize {return self;} ++ alloc { return class_createInstance (self, 0);} ++ new { return [[self alloc] init]; } +- init {return self;} +#endif +@end + +/* 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" + +int main (void) +{ + struct objc_method_description *method; + const char *method_types; + unsigned qualifiers; + Protocol *protocol; + /* This no-op command is needed to keep the test compile on broken + gcc 3.x */ + MyObject *object = [MyObject bycopyMethod]; + + /* Get the protocol object */ + protocol = @protocol (MyProtocol); + + /* Ask to the protocol for the description of the method bycopyMethod */ + method = [protocol descriptionForClassMethod: @selector (bycopyMethod)]; + if (method == NULL) + { + printf ("Could not find method bycopyMethod in protocol!\n"); + exit (1); + } + + /* Get the method types for the method - which encode return type, + arguments etc. */ + method_types = method->types; + + /* Get the qualifiers for the return type */ + qualifiers = objc_get_type_qualifiers (method_types); + + /* If _F_BYCOPY is not there, the compiler is broken */ + if (! (qualifiers & _F_BYCOPY)) + { + printf ("Failed - selector does not contain _F_BYCOPY qualifier!\n"); + exit (1); + } + + /* Else, happy end */ + return 0; +} + +#ifdef __NEXT_RUNTIME__ +unsigned +objc_get_type_qualifiers (const char *type) +{ + unsigned res = 0; + BOOL flag = YES; + + while (flag) + switch (*type++) + { + case _C_CONST: res |= _F_CONST; break; + case _C_IN: res |= _F_IN; break; + case _C_INOUT: res |= _F_INOUT; break; + case _C_OUT: res |= _F_OUT; break; + case _C_BYCOPY: res |= _F_BYCOPY; break; + case _C_BYREF: res |= _F_BYREF; break; + case _C_ONEWAY: res |= _F_ONEWAY; break; + case _C_GCINVISIBLE: res |= _F_GCINVISIBLE; break; + default: flag = NO; + } + + return res; +} +#endif |