(root)/
gcc-13.2.0/
gcc/
testsuite/
objc-obj-c++-shared/
GNUStep/
Foundation/
NSObjCRuntime.h
       1  /** Interface to ObjC runtime for GNUStep
       2     Copyright (C) 1995, 1997, 2000 Free Software Foundation, Inc.
       3  
       4     Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
       5     Date: 1995
       6  
       7     This file is part of the GNUstep Base Library.
       8  
       9     This library is free software; you can redistribute it and/or
      10     modify it under the terms of the GNU Lesser General Public
      11     License as published by the Free Software Foundation; either
      12     version 2 of the License, or (at your option) any later version.
      13  
      14     This library is distributed in the hope that it will be useful,
      15     but WITHOUT ANY WARRANTY; without even the implied warranty of
      16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17     Library General Public License for more details.
      18  
      19     You should have received a copy of the GNU Lesser General Public
      20     License along with this library; if not, write to the Free
      21     Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      22     Boston, MA 02111 USA.
      23  
      24      AutogsdocSource: NSObjCRuntime.m
      25      AutogsdocSource: NSLog.m
      26  
      27     */
      28  
      29  #ifndef __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
      30  #define __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
      31  
      32  #ifdef __cplusplus
      33  #ifndef __STDC_LIMIT_MACROS
      34  #define __STDC_LIMIT_MACROS 1
      35  #endif
      36  #endif
      37  
      38  #import	"../GNUstepBase/GSVersionMacros.h"
      39  #import	"../GNUstepBase/GSConfig.h"
      40  #import	"../GNUstepBase/GNUstep.h"
      41  #if __BLOCKS__
      42  #import	"../GNUstepBase/GSBlocks.h"
      43  #endif
      44  
      45  #include <stdarg.h>
      46  #include <limits.h>
      47  #include <float.h>
      48  
      49  /* PA HP-UX kludge.  */
      50  #if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR)
      51  #define PRIuPTR "lu"
      52  #endif
      53  
      54  /* IRIX kludge.  */
      55  #if defined(__sgi)
      56  /* IRIX 6.5 <inttypes.h> provides all definitions, but only for C99
      57     compilations.  */
      58  #define PRId8 "hhd"
      59  #define PRIu8 "hhu"
      60  #if (_MIPS_SZLONG == 32)
      61  #define PRId64 "lld"
      62  #define PRIu64 "llu"
      63  #endif
      64  /* This doesn't match <inttypes.h>, which always has "lld" here, but the
      65     arguments are uint64_t, int64_t, which are unsigned long, long for
      66     64-bit in <sgidefs.h>.  */
      67  #if (_MIPS_SZLONG == 64)
      68  #define PRId64 "ld"
      69  #define PRIu64 "lu"
      70  #endif
      71  /* This doesn't match <inttypes.h>, which has "u" here, but the arguments
      72     are uintptr_t, which is always unsigned long.  */
      73  #define PRIuPTR "lu"
      74  #endif
      75  
      76  /* Solaris < 10 kludge.  */
      77  #if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR)
      78  #if defined(__arch64__) || defined (__x86_64__)
      79  #define PRIuPTR "lu"
      80  #define PRIdPTR "ld"
      81  #define PRIxPTR "lx"
      82  #else
      83  #define PRIuPTR "u"
      84  #define PRIdPTR "d"
      85  #define PRIxPTR "x"
      86  #endif
      87  #endif
      88  
      89  
      90  /* These typedefs must be in place before GSObjCRuntime.h is imported.
      91   */
      92  
      93  #if     !defined(NSINTEGER_DEFINED)
      94  typedef	intptr_t	NSInteger;
      95  typedef	uintptr_t	NSUInteger;
      96  #	define NSIntegerMax  INTPTR_MAX
      97  #	define NSIntegerMin  INTPTR_MIN
      98  #	define NSUIntegerMax UINTPTR_MAX
      99  #endif /* !defined(NSINTEGER_DEFINED) */
     100  
     101  #if     !defined(CGFLOAT_DEFINED)
     102  #if     GS_SIZEOF_VOIDP == 8
     103  #define CGFLOAT_IS_DBL  1
     104  typedef double          CGFloat;
     105  #define CGFLOAT_MIN	DBL_MIN
     106  #define CGFLOAT_MAX	DBL_MAX
     107  #else
     108  typedef float           CGFloat;
     109  #define CGFLOAT_MIN	FLT_MIN
     110  #define CGFLOAT_MAX	FLT_MAX
     111  #endif
     112  #endif /* !defined(CGFLOAT_DEFINED) */
     113  
     114  #define NSINTEGER_DEFINED 1
     115  #define CGFLOAT_DEFINED 1
     116  #ifndef NS_AUTOMATED_REFCOUNT_UNAVAILABLE
     117  #  if __has_feature(objc_arc)
     118  #    define NS_AUTOMATED_REFCOUNT_UNAVAILABLE \
     119        __attribute__((unavailable("Not available with automatic reference counting")))
     120  #  else
     121  #    define NS_AUTOMATED_REFCOUNT_UNAVAILABLE
     122  #  endif
     123  #endif
     124  
     125  
     126  #if	defined(__cplusplus)
     127  extern "C" {
     128  #endif
     129  
     130  
     131  /*
     132   * We can have strongly typed enums in C++11 mode or when the objc_fixed_enum
     133   * feature is availble.
     134   */
     135  #if (__has_feature(objc_fixed_enum) || (__cplusplus && (__cplusplus > 199711L) && __has_extension(cxx_strong_enums)))
     136  #  define _GS_NAMED_ENUM(ty, name) enum name : ty name; enum name : ty
     137  #  define _GS_ANON_ENUM(ty) enum : ty
     138  #  if __cplusplus
     139  #    define NS_OPTIONS(ty,name) ty name; enum : ty
     140  #  else
     141  #    define NS_OPTIONS(ty,name) NS_ENUM(ty,name)
     142  #  endif
     143  #else // this provides less information, but works with older compilers
     144  #  define _GS_NAMED_ENUM(ty, name) ty name; enum
     145  #  define _GS_ANON_ENUM(ty) enum
     146  #  define NS_OPTIONS(ty, name) NS_ENUM(ty, name)
     147  #endif
     148  // A bit of fairy dust to expand NS_ENUM to the correct variant
     149  #define _GS_GET_ENUM_MACRO(_first,_second,NAME,...) NAME
     150  /* The trick here is that placing the variadic args first will push the name
     151   * that the _GS_GET_ENUM_MACRO expands to into the correct position.
     152   */
     153  #define NS_ENUM(...) _GS_GET_ENUM_MACRO(__VA_ARGS__,_GS_NAMED_ENUM,_GS_ANON_ENUM)(__VA_ARGS__)
     154  
     155  /*
     156   * If the compiler supports nullability qualifiers, we define the macros for
     157   * non-null sections.
     158   */
     159  #if __has_feature(nullability)
     160  #  define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
     161  #  define NS_ASSUME_NONNULL_END   _Pragma("clang assume_nonnull end")
     162  #else
     163  #  define NS_ASSUME_NONNULL_BEGIN
     164  #  define NS_ASSUME_NONNULL_END
     165  #endif
     166  
     167  /*
     168   * Backwards compatibility macro for instance type.
     169   */
     170  #if !__has_feature(objc_instancetype)
     171  # define instancetype id
     172  #endif
     173  
     174  /*
     175   * Backwards compatibility macros for Objective-C lightweight generics.
     176   */
     177  #if __has_feature(objc_generics)
     178  # define GS_GENERIC_CLASS(clz, ...) clz<__VA_ARGS__>
     179  # define GS_GENERIC_TYPE_F(typeRef, fallback) typeRef
     180  #else
     181  # define GS_GENERIC_CLASS(clz, ...) clz
     182  # define GS_GENERIC_TYPE_F(typeRef, fallback) fallback
     183  #endif
     184  #define GS_GENERIC_TYPE(typeRef) GS_GENERIC_TYPE_F(typeRef, id)
     185  
     186  /**
     187   * Backwards compatibility macro for the objc_designated_initializer attribute
     188   */
     189  #if __has_attribute(objc_designated_initializer)
     190  #  define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
     191  #else
     192  #  define NS_DESIGNATED_INITIALIZER
     193  #endif
     194  
     195  /** Bitfield used to specify options to control enumeration over collections.
     196   */
     197  typedef NS_OPTIONS(NSUInteger, NSEnumerationOptions)
     198  {
     199    NSEnumerationConcurrent = (1UL << 0), /** Specifies that the enumeration
     200     * is concurrency-safe.  Note that this does not mean that it will be
     201     * carried out in a concurrent manner, only that it can be.
     202     */
     203  
     204    NSEnumerationReverse = (1UL << 1) /** Specifies that the enumeration should
     205     * happen in the opposite of the natural order of the collection.
     206     */
     207  };
     208  
     209  
     210  /** Bitfield used to specify options to control the sorting of collections.
     211   */
     212  typedef NS_OPTIONS(NSUInteger, NSSortOptions)
     213  {
     214      NSSortConcurrent = (1UL << 0), /** Specifies that the sort
     215       * is concurrency-safe.  Note that this does not mean that it will be
     216       * carried out in a concurrent manner, only that it can be.
     217       */
     218      NSSortStable = (1UL << 4) /** Specifies that the sort should keep
     219       * equal objects in the same order in the collection.
     220       */
     221  };
     222  
     223  
     224  #import "../GNUstepBase/GSObjCRuntime.h"
     225  
     226  #if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
     227  GS_EXPORT NSString	*NSStringFromProtocol(Protocol *aProtocol);
     228  GS_EXPORT Protocol	*NSProtocolFromString(NSString *aProtocolName);
     229  #endif
     230  GS_EXPORT SEL		NSSelectorFromString(NSString *aSelectorName);
     231  GS_EXPORT NSString	*NSStringFromSelector(SEL aSelector);
     232  GS_EXPORT SEL		NSSelectorFromString(NSString *aSelectorName);
     233  GS_EXPORT Class		NSClassFromString(NSString *aClassName);
     234  GS_EXPORT NSString	*NSStringFromClass(Class aClass);
     235  GS_EXPORT const char	*NSGetSizeAndAlignment(const char *typePtr,
     236    NSUInteger *sizep, NSUInteger *alignp);
     237  
     238  #if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
     239  /* Logging */
     240  /**
     241   *  OpenStep spec states that log messages go to stderr, but just in case
     242   *  someone wants them to go somewhere else, they can implement a function
     243   *  like this and assign a pointer to it to _NSLog_printf_handler.
     244   */
     245  typedef void NSLog_printf_handler (NSString* message);
     246  GS_EXPORT NSLog_printf_handler	*_NSLog_printf_handler;
     247  GS_EXPORT int	_NSLogDescriptor;
     248  @class NSRecursiveLock;
     249  GS_EXPORT NSRecursiveLock	*GSLogLock(void);
     250  #endif
     251  
     252  GS_EXPORT void	NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
     253  GS_EXPORT void	NSLogv(NSString *format, va_list args) NS_FORMAT_FUNCTION(1,0);
     254  
     255  #ifndef YES
     256  #define YES		1
     257  #endif
     258  #ifndef NO
     259  #define NO		0
     260  #endif
     261  #ifndef nil
     262  #define nil		0
     263  #endif
     264  
     265  /**
     266   * Contains values <code>NSOrderedSame</code>, <code>NSOrderedAscending</code>
     267   * <code>NSOrderedDescending</code>, for left hand side equals, less than, or
     268   * greater than right hand side.
     269   */
     270  typedef NS_ENUM(NSInteger, NSComparisonResult)
     271  {
     272    NSOrderedAscending = (NSInteger)-1, NSOrderedSame, NSOrderedDescending
     273  };
     274  
     275  enum {NSNotFound = NSIntegerMax};
     276  
     277  #if __BLOCKS__
     278  DEFINE_BLOCK_TYPE(NSComparator, NSComparisonResult, id, id);
     279  #endif
     280  
     281  /**
     282   * Declare the foundation export macro as an alias to GS_EXPORT 
     283   */
     284  #define FOUNDATION_EXPORT GS_EXPORT
     285  
     286  #if	defined(__cplusplus)
     287  }
     288  #endif
     289  
     290  /**
     291   * Declare Apple availability macros for compatibility purposes as no-ops.
     292   */
     293  #define NS_CLASS_AVAILABLE(...)
     294  #define NS_AVAILABLE(...)
     295  #define NS_AVAILABLE_MAC(...)
     296  #define NS_DEPRECATED(...)
     297  #define NS_DEPRECATED_MAC(...)
     298  #define NS_ENUM_AVAILABLE(...)
     299  #define NS_ENUM_AVAILABLE_MAC(...)
     300  #define NS_ENUM_DEPRECATED(...)
     301  #define NS_ENUM_DEPRECATED_MAC(...)
     302  #define NS_CLASS_AVAILABLE(...)
     303  #define NS_CLASS_DEPRECATED(...)
     304  #define NS_CLASS_AVAILABLE_MAC(...)
     305  #define NS_CLASS_DEPRECATED_MAC(...)
     306  #define NS_UNAVAILABLE
     307  
     308  /* Define root class NS macro */
     309  #ifndef NS_ROOT_CLASS
     310  #if __has_attribute(objc_root_class)
     311  #define NS_ROOT_CLASS __attribute__((objc_root_class))
     312  #else
     313  #define NS_ROOT_CLASS
     314  #endif
     315  #endif
     316  
     317  #endif /* __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE */