diff options
author | iains <iains@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-01-11 10:14:48 +0000 |
---|---|---|
committer | iains <iains@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-01-11 10:14:48 +0000 |
commit | 21193cc2b59e9cbdace9ebb755f00086f8eeb7ba (patch) | |
tree | 5b775ac5ec0f8b64be5f92c27555c7ca090cd766 /gcc/testsuite/objc-obj-c++-shared | |
parent | 0725e25c3c1c28f88a8fe92d2eac113857e6e407 (diff) | |
download | gcc-21193cc2b59e9cbdace9ebb755f00086f8eeb7ba.tar.gz |
gcc/testsuite:
* objc-obj-c++-shared/next-mapping.h: Add copyright header.
Split type definitions and NSConstantString class into...
* objc-obj-c++-shared/objc-test-suite-types.h: New.
* objc-obj-c++-shared/nsconstantstring-class.h: New.
* objc-obj-c++-shared/nsconstantstring-class-impl.h: New.
* objc-obj-c++-shared/nsconstantstring-class-impl.m: New.
* objc-obj-c++-shared/nsconstantstring-class-impl.mm: New.
* objc-obj-c++-shared/next-abi.h: Add copyright header, minor update
to comments.
* objc-obj-c++-shared/objc-test-suite-next-encode-assist.h: Adjust
encode defines for newer NeXT system headers.
* obj-c++.dg/template-4.mm: Adjust to use nsconstantstring headers.
* obj-c++.dg/torture/strings/string1.mm: Likewise.
* objc.dg/foreach-5.m: Likewise.
* objc.dg/foreach-2.m: Likewise.
* objc.dg/foreach-4.m: Likewise.
* objc.dg/torture/strings/string1.m: Likewise.
* objc.dg/torture/strings/string2.m: Likewise.
* objc.dg/torture/strings/string3.m: Likewise.
* objc.dg/torture/strings/string4.m: Likewise.
* obj-c++.dg/torture/strings/const-str-3.mm: Adjust to use type
header and stand alone.
* obj-c++.dg/strings/strings-2.mm: Likewise.
* objc.dg/torture/strings/const-str-3.m: Likewise.
* objc.dg/strings/strings-2.m: Likewise.
* objc.dg/strings/const-str-12b.m: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@168653 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/objc-obj-c++-shared')
8 files changed, 303 insertions, 144 deletions
diff --git a/gcc/testsuite/objc-obj-c++-shared/next-abi.h b/gcc/testsuite/objc-obj-c++-shared/next-abi.h index 3ab9804e510..0ffa0fcba17 100644 --- a/gcc/testsuite/objc-obj-c++-shared/next-abi.h +++ b/gcc/testsuite/objc-obj-c++-shared/next-abi.h @@ -1,3 +1,23 @@ +/* Check which version of the API and ABI are appropriate for the target. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. + + Contributed by Iain Sandoe <iains@gcc.gnu.org> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ #ifndef _OBJC_NEXT_ABI_H_ #define _OBJC_NEXT_ABI_H_ @@ -6,9 +26,8 @@ */ /* By default we do nothing - therefore ifdef NEXT_OBJC_USE_NEW_INTERFACE - * is reliable for detecting - * (a) versions of the compiler that are transitional to the new next ABI - * (b) versions of the target that require the new ABI. + * is reliable for detecting versions of the target that require either + * API=2, or both API & ABI = 2 (m64 code). * * This applies for versions of OSX >= 10.5 (darwin9). * diff --git a/gcc/testsuite/objc-obj-c++-shared/next-mapping.h b/gcc/testsuite/objc-obj-c++-shared/next-mapping.h index 3b141c67a67..d2ae8e9e679 100644 --- a/gcc/testsuite/objc-obj-c++-shared/next-mapping.h +++ b/gcc/testsuite/objc-obj-c++-shared/next-mapping.h @@ -1,42 +1,79 @@ +/* Compatibility header between runtimes and APIs. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. + + Original Authors: Ziemowit Laski <zlaski@apple.com> + David Ayers <d.ayers@inode.at> + + re-work for ObjC2 by Iain Sandoe <iains@gcc.gnu.org> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + #ifndef _OBJC_NEXT_MAPPING_H_ #define _OBJC_NEXT_MAPPING_H_ -/* This file "renames" various ObjC GNU runtime entry points - (and fakes the existence of several others) - if the NeXT runtime is being used. */ -/* Authors: Ziemowit Laski <zlaski@apple.com> */ -/* David Ayers <d.ayers@inode.at> */ -/* Darwin 64bit/OBJC2 modifications Iain Sandoe */ +/* This file provides a two-way mapping of API names for the original + GNU & NeXT APIs. + + It is being expanded to provide mapping (where possible) between between the + older API and API-2. +*/ + +#include "objc-test-suite-types.h" #ifndef __NEXT_RUNTIME__ -#define CLASSPTRFIELD(x) (x)->class_pointer - -#else -/* Includes next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ -#ifndef _OBJC_OBJECT1_H_ -#include "Object1.h" -#endif -#include <objc/objc-class.h> -#include <ctype.h> -#include <stdlib.h> -#include <string.h> - -/* Force a definition of nil that is compatible with GNU runtime. */ -#undef nil -#define nil ((id)0) - -#define objc_get_class(C) objc_getClass(C) -#define objc_get_meta_class(C) objc_getMetaClass(C) -#define class_get_class_method(C, S) class_getClassMethod(C, S) -#define class_get_instance_method(C, S) class_getInstanceMethod(C, S) -#define sel_get_name(S) sel_getName(S) -#define class_create_instance(C) class_createInstance(C, 0) -#define class_get_class_name(C) object_getClassName(C) - -#define CLASSPTRFIELD(x) (x)->isa - -#ifdef NEXT_OBJC_USE_NEW_INTERFACE +# define CLASSFIELD class_pointer +# define CLASSPTRFIELD(x) (x)->class_pointer +# define SUPERCLASS superClass +# define OBJC_GETCLASS objc_get_class + +# ifdef __objc_api_INCLUDE_GNU +# define class_createInstance(C, S) class_create_instance(C) +# endif +# define method_get_types(M) (M)->method_types + +#else /* NeXT */ + +/* Include next-abi.h to set NEXT_OBJC_USE_NEW_INTERFACE etc.*/ +# include "next-abi.h" + +# ifdef NEXT_OBJC_USE_NEW_INTERFACE + /* API=2. */ +# include <objc/runtime.h> +# else + /* API=0. */ +# include <objc/objc-class.h> +# endif + +# define CLASSPTRFIELD(x) (x)->isa +# define SUPERCLASS superclass +# define OBJC_GETCLASS objc_getClass + +# define objc_get_class(C) objc_getClass(C) +# define objc_get_meta_class(C) objc_getMetaClass(C) +# define class_get_class_method(C, S) class_getClassMethod(C, S) +# define class_get_instance_method(C, S) class_getInstanceMethod(C, S) +# define sel_get_name(S) sel_getName(S) +# define class_create_instance(C) class_createInstance(C, 0) +# define class_get_class_name(C) object_getClassName(C) +# define objc_lookup_class(N) objc_lookUpClass(N) + +# ifdef NEXT_OBJC_USE_NEW_INTERFACE + # define object_class_name(O) (object_getClassName(O)) # define object_get_class(O) (object_getClass((id)O)) # define object_get_super_class(O) class_get_super_class(object_get_class(O)) @@ -51,7 +88,8 @@ # define class_is_meta_class(C) (class_isMetaClass((Class)C) ? YES: NO) # define class_is_class(C) (class_is_meta_class(C) == NO) -#else +# else /* OLD API */ + # define object_class_name(O) (O->name) # define object_get_super_class(O) class_get_super_class(*(struct objc_class **)O) # define object_get_class(O) (*(struct objc_class **)O) @@ -64,94 +102,8 @@ # define class_get_super_class(C) (((struct objc_class *)C)->super_class) # define class_is_meta_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_META)? YES: NO) # define class_is_class(C) (CLS_GETINFO((struct objc_class *)C, CLS_CLASS)? YES: NO) -#endif - -#define objc_lookup_class(N) objc_lookUpClass(N) - -/* You need either an empty +initialize method or an empty -forward:: method. - The NeXT runtime unconditionally sends +initialize to classes when they are - first used, and unconditionally tries to forward methods that the class - doesn't understand (including +initialize). If you have neither +initialize - nor -forward::, the runtime complains. - - The simplest workaround is to add - - + initialize { return self; } - to every root class @implementation. */ +# endif /* NEXT_OBJC_USE_NEW_INTERFACE */ -#ifndef NULL -#define NULL 0 -#endif - - -/* A small, portable NSConstantString implementation for use with the NeXT - runtime. - - On full-fledged Mac OS X systems, NSConstantString is provided - as part of the Foundation framework. However, on bare Darwin systems, - Foundation is not included, and hence there is no NSConstantString - implementation to link against. - - This code is derived from the GNU runtime's NXConstantString implementation. -*/ - -/* This definition cut out of <objc/Object.h> with the OBJC2 deprecation - messages removed. -*/ -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -struct fudge_objc_class { - Class isa; -#if NEXT_OBJC_ABI_VERSION < 2 - Class super_class ; - const char *name ; - long version ; - long info ; - long instance_size ; - struct anon *ivars ; /* objc_ivar_list */ - struct anon1 **methodLists ; /* objc_method_list */ - struct objc_cache *cache ; - struct objc_protocol_list *protocols ; -#endif -} _NSConstantStringClassReference ; -#else -struct objc_class _NSConstantStringClassReference ; -#endif - -@interface NSConstantString : Object -{ - char *c_string; - unsigned int len; -} - --(const char *) cString; --(unsigned int) length; - -@end - -@implementation NSConstantString - --(const char *) cString -{ - return (c_string); -} - --(unsigned int) length -{ - return (len); -} - -@end - -/* The NSConstantString metaclass will need to be initialized before we can - send messages to strings. */ - -void objc_constant_string_init (void) __attribute__((constructor)); -void objc_constant_string_init (void) { - memcpy (&_NSConstantStringClassReference, - objc_getClass ("NSConstantString"), - sizeof (_NSConstantStringClassReference)); -} - -#endif /*__NEXT_RUNTIME__ */ +# endif /*__NEXT_RUNTIME__ */ #endif /* _OBJC_NEXT_MAPPING_H_ */
\ No newline at end of file diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h new file mode 100644 index 00000000000..0068b4a2ae4 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.h @@ -0,0 +1,61 @@ +/* A small NSConstantString implementation for use with the NeXT runtime. + Copyright (C) 2011 Free Software Foundation, Inc. + + Contributed by Iain Sandoe <iains@gcc.gnu.org> + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifdef __NEXT_RUNTIME__ + +#include "nsconstantstring-class.h" +#include <string.h> + +/* On full-fledged Mac OS X systems, NSConstantString is provided + as part of the Foundation framework. However, on bare Darwin systems, + Foundation is not included, and hence there is no NSConstantString + implementation to link against. + + This code is derived from the GNU runtime's NXConstantString implementation. +*/ + +@implementation NSConstantString +/* NeXT requires this or forward: */ ++initialize { return self; } + +-(const char *) cString +{ + return (c_string); +} + +-(unsigned int) length +{ + return (len); +} +@end + +TNS_STRING_REF_T _NSConstantStringClassReference; + +/* The NSConstantString metaclass will need to be initialized before we can + send messages to strings. */ + +void objc_constant_string_init (void) __attribute__((constructor)); +void objc_constant_string_init (void) { + memcpy (&_NSConstantStringClassReference, + objc_getClass ("NSConstantString"), + sizeof (_NSConstantStringClassReference)); +} +#endif diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m new file mode 100644 index 00000000000..cd9c7dd8fa5 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.m @@ -0,0 +1,3 @@ +/* Allow code to be shared between the FEs but avoid issues with + C++-only flags. */ +#include "nsconstantstring-class-impl.h" diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm new file mode 100644 index 00000000000..cd9c7dd8fa5 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class-impl.mm @@ -0,0 +1,3 @@ +/* Allow code to be shared between the FEs but avoid issues with + C++-only flags. */ +#include "nsconstantstring-class-impl.h" diff --git a/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h new file mode 100644 index 00000000000..485e39e6f08 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/nsconstantstring-class.h @@ -0,0 +1,51 @@ +/* A small NSConstantString implementation for use with the NeXT runtime. + Copyright (C) 2011 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifndef _test_suite_nsconstantstring_class_h_ +#define _test_suite_nsconstantstring_class_h_ +#ifdef __NEXT_RUNTIME__ + +/* On full-fledged Mac OS X systems, NSConstantString is provided + as part of the Foundation framework. However, on bare Darwin systems, + Foundation is not included, and hence there is no NSConstantString + implementation to link against. + + This code is derived from the GNU runtime's NXConstantString implementation. +*/ + +#include "objc-test-suite-types.h" + +extern TNS_STRING_REF_T _NSConstantStringClassReference; + +@interface NSConstantString +{ + Class isa; + char *c_string; + unsigned int len; +} + ++ (id) initialize; + +- (const char *) cString; +- (unsigned int) length; + +@end + +#endif /* __NEXT_RUNTIME__ */ +#endif /* _test_suite_nsconstantstring_class_h_ */ diff --git a/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h index 0a0f93c376a..af02b278a2e 100644 --- a/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h +++ b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-next-encode-assist.h @@ -10,29 +10,18 @@ typedef void * PMETH; #else #include <objc/objc-runtime.h> typedef struct objc_method * PMETH; -#endif - -/* The NeXT headers do not define NULL. */ -#ifndef NULL -#define NULL 0 -#endif -/* The NeXT runtimes do not include these functions (at least not through - any public API). They are required for the objc/execute/bf-* and bycopy-3. */ - -/* Not sure why the following are missing from NeXT objc headers... */ - -#ifndef _C_LNG_LNG +/* Missing from old NeXT objc headers... */ #define _C_LNG_LNG 'q' -#endif -#ifndef _C_ULNG_LNG #define _C_ULNG_LNG 'Q' -#endif -#ifndef _C_ATOM #define _C_ATOM '%' -#endif -#ifndef _C_BOOL #define _C_BOOL 'B' + +#endif + +/* The NeXT headers do not define NULL. */ +#ifndef NULL +#define NULL 0 #endif #define _C_CONST 'r' @@ -53,7 +42,8 @@ typedef struct objc_method * PMETH; #define _F_ONEWAY 0x10 #define _F_GCINVISIBLE 0x20 -/* Functions available in the GNU runtime, emulated here for testing with NeXT. */ +/* The NeXT runtimes do not include these functions (at least not through + any public API). They are required for the objc/execute/bf-* and bycopy-3. */ struct objc_struct_layout { diff --git a/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h new file mode 100644 index 00000000000..ab502d46760 --- /dev/null +++ b/gcc/testsuite/objc-obj-c++-shared/objc-test-suite-types.h @@ -0,0 +1,80 @@ +/* Define test-suite types to minimize conditional test-case source. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Iain Sandoe + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + +#ifndef _OBJC_TEST_SUITE_TYPES_H_ +#define _OBJC_TEST_SUITE_TYPES_H_ + +#ifdef __cplusplus +#define ProtoBool bool +#else +#define ProtoBool _Bool +#endif + +#ifndef __NEXT_RUNTIME__ + +#define METHOD Method_t +#define IVAR_T struct objc_ivar + +/* dummy const string class ref. */ +typedef void * TNS_STRING_REF_T; + +#else /* NeXT */ + +#include "next-abi.h" +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +#include <objc/runtime.h> +#else +#include <objc/objc-runtime.h> +#endif + +/* Force a definition of nil that is compatible with GNU runtime. */ +#undef nil +#define nil ((id)0) + +#ifndef NULL +#define NULL 0 +#endif + +#define METHOD Method + +/* Where there are equivalent interfaces between APIs we substitute + a macro or typedef. */ +#ifdef NEXT_OBJC_USE_NEW_INTERFACE +typedef void * PMETH; +#define IVAR_T Ivar +#else +typedef struct objc_method * PMETH; +#define IVAR_T struct objc_ivar +#endif + +#ifdef __OBJC2__ +/* Const String Class ref. */ +typedef Class TNS_STRING_REF_T; +#else +/* Const String Class ref. */ +/* We need objc_class - but we don't need endless reminders that it's deprecated. */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +typedef struct objc_class TNS_STRING_REF_T; +#pragma GCC diagnostic pop +#endif + +#endif /*__NEXT_RUNTIME__ */ +#endif /* _OBJC_TEST_SUITE_TYPES_H_ */
\ No newline at end of file |