ASBaseDefines.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // ASBaseDefines.h
  3. // AsyncDisplayKit
  4. //
  5. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  6. // This source code is licensed under the BSD-style license found in the
  7. // LICENSE file in the root directory of this source tree. An additional grant
  8. // of patent rights can be found in the PATENTS file in the same directory.
  9. //
  10. #pragma once
  11. #import <AsyncDisplayKit/ASLog.h>
  12. #ifndef PIN_REMOTE_IMAGE
  13. #if __has_include(<PINRemoteImage/PINRemoteImage.h>)
  14. #define PIN_REMOTE_IMAGE 1
  15. #else
  16. #define PIN_REMOTE_IMAGE 0
  17. #endif
  18. #endif
  19. // The C++ compiler mangles C function names. extern "C" { /* your C functions */ } prevents this.
  20. // You should wrap all C function prototypes declared in headers with ASDISPLAYNODE_EXTERN_C_BEGIN/END, even if
  21. // they are included only from .m (Objective-C) files. It's common for .m files to start using C++
  22. // features and become .mm (Objective-C++) files. Always wrapping the prototypes with
  23. // ASDISPLAYNODE_EXTERN_C_BEGIN/END will save someone a headache once they need to do this. You do not need to
  24. // wrap constants, only C functions. See StackOverflow for more details:
  25. // http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c
  26. #ifdef __cplusplus
  27. # define ASDISPLAYNODE_EXTERN_C_BEGIN extern "C" {
  28. # define ASDISPLAYNODE_EXTERN_C_END }
  29. #else
  30. # define ASDISPLAYNODE_EXTERN_C_BEGIN
  31. # define ASDISPLAYNODE_EXTERN_C_END
  32. #endif
  33. #ifdef __GNUC__
  34. # define ASDISPLAYNODE_GNUC(major, minor) \
  35. (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
  36. #else
  37. # define ASDISPLAYNODE_GNUC(major, minor) 0
  38. #endif
  39. #ifndef ASDISPLAYNODE_INLINE
  40. # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  41. # define ASDISPLAYNODE_INLINE static inline
  42. # elif defined (__MWERKS__) || defined (__cplusplus)
  43. # define ASDISPLAYNODE_INLINE static inline
  44. # elif ASDISPLAYNODE_GNUC (3, 0)
  45. # define ASDISPLAYNODE_INLINE static __inline__ __attribute__ ((always_inline))
  46. # else
  47. # define ASDISPLAYNODE_INLINE static
  48. # endif
  49. #endif
  50. #ifndef ASDISPLAYNODE_HIDDEN
  51. # if ASDISPLAYNODE_GNUC (4,0)
  52. # define ASDISPLAYNODE_HIDDEN __attribute__ ((visibility ("hidden")))
  53. # else
  54. # define ASDISPLAYNODE_HIDDEN /* no hidden */
  55. # endif
  56. #endif
  57. #ifndef ASDISPLAYNODE_PURE
  58. # if ASDISPLAYNODE_GNUC (3, 0)
  59. # define ASDISPLAYNODE_PURE __attribute__ ((pure))
  60. # else
  61. # define ASDISPLAYNODE_PURE /* no pure */
  62. # endif
  63. #endif
  64. #ifndef ASDISPLAYNODE_CONST
  65. # if ASDISPLAYNODE_GNUC (3, 0)
  66. # define ASDISPLAYNODE_CONST __attribute__ ((const))
  67. # else
  68. # define ASDISPLAYNODE_CONST /* no const */
  69. # endif
  70. #endif
  71. #ifndef ASDISPLAYNODE_WARN_UNUSED
  72. # if ASDISPLAYNODE_GNUC (3, 4)
  73. # define ASDISPLAYNODE_WARN_UNUSED __attribute__ ((warn_unused_result))
  74. # else
  75. # define ASDISPLAYNODE_WARN_UNUSED /* no warn_unused */
  76. # endif
  77. #endif
  78. #ifndef ASDISPLAYNODE_WARN_DEPRECATED
  79. # define ASDISPLAYNODE_WARN_DEPRECATED 1
  80. #endif
  81. #ifndef ASDISPLAYNODE_DEPRECATED
  82. # if ASDISPLAYNODE_GNUC (3, 0) && ASDISPLAYNODE_WARN_DEPRECATED
  83. # define ASDISPLAYNODE_DEPRECATED __attribute__ ((deprecated))
  84. # else
  85. # define ASDISPLAYNODE_DEPRECATED
  86. # endif
  87. #endif
  88. #ifndef ASDISPLAYNODE_DEPRECATED_MSG
  89. # if ASDISPLAYNODE_GNUC (3, 0) && ASDISPLAYNODE_WARN_DEPRECATED
  90. # define ASDISPLAYNODE_DEPRECATED_MSG(msg) __deprecated_msg(msg)
  91. # else
  92. # define ASDISPLAYNODE_DEPRECATED_MSG(msg)
  93. # endif
  94. #endif
  95. #if defined (__cplusplus) && defined (__GNUC__)
  96. # define ASDISPLAYNODE_NOTHROW __attribute__ ((nothrow))
  97. #else
  98. # define ASDISPLAYNODE_NOTHROW
  99. #endif
  100. /**
  101. * The event backtraces take a static 2KB of memory
  102. * and retain all objects present in all the registers
  103. * of the stack frames. The memory consumption impact
  104. * is too significant even to be enabled during general
  105. * development.
  106. */
  107. #ifndef AS_SAVE_EVENT_BACKTRACES
  108. # define AS_SAVE_EVENT_BACKTRACES 0
  109. #endif
  110. #define ARRAY_COUNT(x) sizeof(x) / sizeof(x[0])
  111. #ifndef __has_feature // Optional.
  112. #define __has_feature(x) 0 // Compatibility with non-clang compilers.
  113. #endif
  114. #ifndef __has_attribute // Optional.
  115. #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
  116. #endif
  117. #ifndef NS_CONSUMED
  118. #if __has_feature(attribute_ns_consumed)
  119. #define NS_CONSUMED __attribute__((ns_consumed))
  120. #else
  121. #define NS_CONSUMED
  122. #endif
  123. #endif
  124. #ifndef NS_RETURNS_RETAINED
  125. #if __has_feature(attribute_ns_returns_retained)
  126. #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
  127. #else
  128. #define NS_RETURNS_RETAINED
  129. #endif
  130. #endif
  131. #ifndef CF_RETURNS_RETAINED
  132. #if __has_feature(attribute_cf_returns_retained)
  133. #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
  134. #else
  135. #define CF_RETURNS_RETAINED
  136. #endif
  137. #endif
  138. #ifndef ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER
  139. #define ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER() \
  140. do { \
  141. NSAssert2(NO, @"%@ is not the designated initializer for instances of %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class])); \
  142. return nil; \
  143. } while (0)
  144. #endif // ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER
  145. // It's hard to pass quoted strings via xcodebuild preprocessor define arguments, so we'll convert
  146. // the preprocessor values to strings here.
  147. //
  148. // It takes two steps to do this in gcc as per
  149. // http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  150. #define ASDISPLAYNODE_TO_STRING(str) #str
  151. #define ASDISPLAYNODE_TO_UNICODE_STRING(str) @ASDISPLAYNODE_TO_STRING(str)
  152. #ifndef ASDISPLAYNODE_REQUIRES_SUPER
  153. #if __has_attribute(objc_requires_super)
  154. #define ASDISPLAYNODE_REQUIRES_SUPER __attribute__((objc_requires_super))
  155. #else
  156. #define ASDISPLAYNODE_REQUIRES_SUPER
  157. #endif
  158. #endif
  159. #ifndef AS_UNAVAILABLE
  160. #if __has_attribute(unavailable)
  161. #define AS_UNAVAILABLE(message) __attribute__((unavailable(message)))
  162. #else
  163. #define AS_UNAVAILABLE(message)
  164. #endif
  165. #endif
  166. #ifndef AS_WARN_UNUSED_RESULT
  167. #if __has_attribute(warn_unused_result)
  168. #define AS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  169. #else
  170. #define AS_WARN_UNUSED_RESULT
  171. #endif
  172. #endif
  173. #define ASOVERLOADABLE __attribute__((overloadable))
  174. #if __has_attribute(noescape)
  175. #define AS_NOESCAPE __attribute__((noescape))
  176. #else
  177. #define AS_NOESCAPE
  178. #endif
  179. #if __has_attribute(objc_subclassing_restricted)
  180. #define AS_SUBCLASSING_RESTRICTED __attribute__((objc_subclassing_restricted))
  181. #else
  182. #define AS_SUBCLASSING_RESTRICTED
  183. #endif
  184. /// Ensure that class is of certain kind
  185. #define ASDynamicCast(x, c) ({ \
  186. id __val = x;\
  187. ((c *) ([__val isKindOfClass:[c class]] ? __val : nil));\
  188. })