ASBaseDefines.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Copyright (c) 2014-present, Facebook, Inc.
  2. * All rights reserved.
  3. *
  4. * This source code is licensed under the BSD-style license found in the
  5. * LICENSE file in the root directory of this source tree. An additional grant
  6. * of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #pragma once
  9. // The C++ compiler mangles C function names. extern "C" { /* your C functions */ } prevents this.
  10. // You should wrap all C function prototypes declared in headers with ASDISPLAYNODE_EXTERN_C_BEGIN/END, even if
  11. // they are included only from .m (Objective-C) files. It's common for .m files to start using C++
  12. // features and become .mm (Objective-C++) files. Always wrapping the prototypes with
  13. // ASDISPLAYNODE_EXTERN_C_BEGIN/END will save someone a headache once they need to do this. You do not need to
  14. // wrap constants, only C functions. See StackOverflow for more details:
  15. // http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c
  16. #ifdef __cplusplus
  17. # define ASDISPLAYNODE_EXTERN_C_BEGIN extern "C" {
  18. # define ASDISPLAYNODE_EXTERN_C_END }
  19. #else
  20. # define ASDISPLAYNODE_EXTERN_C_BEGIN
  21. # define ASDISPLAYNODE_EXTERN_C_END
  22. #endif
  23. #ifdef __GNUC__
  24. # define ASDISPLAYNODE_GNUC(major, minor) \
  25. (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
  26. #else
  27. # define ASDISPLAYNODE_GNUC(major, minor) 0
  28. #endif
  29. #ifndef ASDISPLAYNODE_INLINE
  30. # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  31. # define ASDISPLAYNODE_INLINE static inline
  32. # elif defined (__MWERKS__) || defined (__cplusplus)
  33. # define ASDISPLAYNODE_INLINE static inline
  34. # elif ASDISPLAYNODE_GNUC (3, 0)
  35. # define ASDISPLAYNODE_INLINE static __inline__ __attribute__ ((always_inline))
  36. # else
  37. # define ASDISPLAYNODE_INLINE static
  38. # endif
  39. #endif
  40. #ifndef ASDISPLAYNODE_HIDDEN
  41. # if ASDISPLAYNODE_GNUC (4,0)
  42. # define ASDISPLAYNODE_HIDDEN __attribute__ ((visibility ("hidden")))
  43. # else
  44. # define ASDISPLAYNODE_HIDDEN /* no hidden */
  45. # endif
  46. #endif
  47. #ifndef ASDISPLAYNODE_PURE
  48. # if ASDISPLAYNODE_GNUC (3, 0)
  49. # define ASDISPLAYNODE_PURE __attribute__ ((pure))
  50. # else
  51. # define ASDISPLAYNODE_PURE /* no pure */
  52. # endif
  53. #endif
  54. #ifndef ASDISPLAYNODE_WARN_UNUSED
  55. # if ASDISPLAYNODE_GNUC (3, 4)
  56. # define ASDISPLAYNODE_WARN_UNUSED __attribute__ ((warn_unused_result))
  57. # else
  58. # define ASDISPLAYNODE_WARN_UNUSED /* no warn_unused */
  59. # endif
  60. #endif
  61. #ifndef ASDISPLAYNODE_WARN_DEPRECATED
  62. # define ASDISPLAYNODE_WARN_DEPRECATED 1
  63. #endif
  64. #ifndef ASDISPLAYNODE_DEPRECATED
  65. # if ASDISPLAYNODE_GNUC (3, 0) && ASDISPLAYNODE_WARN_DEPRECATED
  66. # define ASDISPLAYNODE_DEPRECATED __attribute__ ((deprecated))
  67. # else
  68. # define ASDISPLAYNODE_DEPRECATED
  69. # endif
  70. #endif
  71. #if defined (__cplusplus) && defined (__GNUC__)
  72. # define ASDISPLAYNODE_NOTHROW __attribute__ ((nothrow))
  73. #else
  74. # define ASDISPLAYNODE_NOTHROW
  75. #endif
  76. #define ARRAY_COUNT(x) sizeof(x) / sizeof(x[0])
  77. #ifndef __has_feature // Optional.
  78. #define __has_feature(x) 0 // Compatibility with non-clang compilers.
  79. #endif
  80. #ifndef __has_attribute // Optional.
  81. #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
  82. #endif
  83. #ifndef NS_CONSUMED
  84. #if __has_feature(attribute_ns_consumed)
  85. #define NS_CONSUMED __attribute__((ns_consumed))
  86. #else
  87. #define NS_CONSUMED
  88. #endif
  89. #endif
  90. #ifndef NS_RETURNS_RETAINED
  91. #if __has_feature(attribute_ns_returns_retained)
  92. #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
  93. #else
  94. #define NS_RETURNS_RETAINED
  95. #endif
  96. #endif
  97. #ifndef CF_RETURNS_RETAINED
  98. #if __has_feature(attribute_cf_returns_retained)
  99. #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
  100. #else
  101. #define CF_RETURNS_RETAINED
  102. #endif
  103. #endif
  104. #ifndef ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER
  105. #define ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER() \
  106. do { \
  107. NSAssert2(NO, @"%@ is not the designated initializer for instances of %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class])); \
  108. return nil; \
  109. } while (0)
  110. #endif // ASDISPLAYNODE_NOT_DESIGNATED_INITIALIZER
  111. // It's hard to pass quoted strings via xcodebuild preprocessor define arguments, so we'll convert
  112. // the preprocessor values to strings here.
  113. //
  114. // It takes two steps to do this in gcc as per
  115. // http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  116. #define ASDISPLAYNODE_TO_STRING(str) #str
  117. #define ASDISPLAYNODE_TO_UNICODE_STRING(str) @ASDISPLAYNODE_TO_STRING(str)
  118. #ifndef ASDISPLAYNODE_REQUIRES_SUPER
  119. #if __has_attribute(objc_requires_super)
  120. #define ASDISPLAYNODE_REQUIRES_SUPER __attribute__((objc_requires_super))
  121. #else
  122. #define ASDISPLAYNODE_REQUIRES_SUPER
  123. #endif
  124. #endif